diff --git a/.github/matic-cli-config.yml b/.github/matic-cli-config.yml index df602a9f1..cd475d28d 100644 --- a/.github/matic-cli-config.yml +++ b/.github/matic-cli-config.yml @@ -2,7 +2,7 @@ defaultStake: 10000 defaultFee: 2000 borChainId: 15001 heimdallChainId: heimdall-15001 -contractsRepo: https://github.com/0xPolygon/pos-contracts.git +contractsRepo: https://github.com/0xPolygon/pos-contracts.git contractsBranch: anvil-pos genesisContractsBranch: master sprintSize: diff --git a/.gitignore b/.gitignore index fa3b83cec..5c676896d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ dist/ .dccache .idea/ .idea* + +cover.out diff --git a/Makefile b/Makefile index 87e8799b0..c3cacc016 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ clean: tests: # go test -v ./... - go test -v ./app/ ./auth/ ./clerk/ ./sidechannel/ ./bank/ ./chainmanager/ ./topup/ ./checkpoint/ ./staking/ ./gov/ -cover -coverprofile=cover.out -parallel 1 + go test -v ./app/ ./auth/ ./clerk/ ./sidechannel/ ./bank/ ./chainmanager/ ./topup/ ./checkpoint/ ./staking/ -cover -coverprofile=cover.out -parallel 1 # make build build: clean diff --git a/bor/querier.go b/bor/querier.go index 4fe237f36..c6b9dca0d 100644 --- a/bor/querier.go +++ b/bor/querier.go @@ -127,19 +127,6 @@ func handleQuerySpanList(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) } func handleQueryLatestSpan(ctx sdk.Context, _ abci.RequestQuery, keeper Keeper) ([]byte, sdk.Error) { - var defaultSpan hmTypes.Span - - spans := keeper.GetAllSpans(ctx) - if len(spans) == 0 { - // json record - bz, err := jsoniter.ConfigFastest.Marshal(defaultSpan) - if err != nil { - return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error())) - } - - return bz, nil - } - // explicitly fetch the last span span, err := keeper.GetLastSpan(ctx) if err != nil { diff --git a/checkpoint/handler_milestone_test.go b/checkpoint/handler_milestone_test.go index bd5fb7840..3a584f057 100644 --- a/checkpoint/handler_milestone_test.go +++ b/checkpoint/handler_milestone_test.go @@ -34,7 +34,7 @@ func (suite *HandlerTestSuite) TestHandleMsgMilestone() { // check valid milestone // generate proposer for validator set - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) stakingKeeper.MilestoneIncrementAccum(ctx, 1) lastMilestone, err := keeper.GetLastMilestone(ctx) @@ -221,7 +221,7 @@ func (suite *HandlerTestSuite) TestHandleMsgMilestoneExistInStore() { start := uint64(0) milestoneLength := helper.MilestoneLength - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) stakingKeeper.IncrementAccum(ctx, 1) lastMilestone, err := keeper.GetLastMilestone(ctx) @@ -294,7 +294,7 @@ func (suite *HandlerTestSuite) TestHandleMsgMilestoneTimeout() { proposer := hmTypes.HeimdallAddress{} - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) suite.Run("Last milestone not found", func() { msgMilestoneTimeout := types.NewMsgMilestoneTimeout( diff --git a/checkpoint/handler_test.go b/checkpoint/handler_test.go index 532a90c3c..bd815847d 100644 --- a/checkpoint/handler_test.go +++ b/checkpoint/handler_test.go @@ -73,7 +73,7 @@ func (suite *HandlerTestSuite) TestHandleMsgCheckpoint() { // check valid checkpoint // generate proposer for validator set - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) stakingKeeper.IncrementAccum(ctx, 1) lastCheckpoint, err := keeper.GetLastCheckpoint(ctx) @@ -230,7 +230,7 @@ func (suite *HandlerTestSuite) TestHandleMsgCheckpointAfterBufferTimeOut() { require.NoError(t, err) // generate proposer for validator set - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) stakingKeeper.IncrementAccum(ctx, 1) lastCheckpoint, err := keeper.GetLastCheckpoint(ctx) @@ -276,7 +276,7 @@ func (suite *HandlerTestSuite) TestHandleMsgCheckpointExistInBuffer() { err := topupKeeper.AddDividendAccount(ctx, dividendAccount) require.NoError(t, err) - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) stakingKeeper.IncrementAccum(ctx, 1) lastCheckpoint, err := keeper.GetLastCheckpoint(ctx) @@ -317,7 +317,7 @@ func (suite *HandlerTestSuite) TestHandleMsgCheckpointAck() { // check valid checkpoint // generate proposer for validator set - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) stakingKeeper.IncrementAccum(ctx, 1) lastCheckpoint, err := keeper.GetLastCheckpoint(ctx) @@ -410,7 +410,7 @@ func (suite *HandlerTestSuite) TestHandleMsgCheckpointNoAck() { // check valid checkpoint // generate proposer for validator set - chSim.LoadValidatorSet(t, 4, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, stakingKeeper, ctx, false, 10, 0) stakingKeeper.IncrementAccum(ctx, 1) lastCheckpoint, err := keeper.GetLastCheckpoint(ctx) @@ -477,7 +477,7 @@ func (suite *HandlerTestSuite) TestHandleMsgCheckpointNoAckBeforeBufferTimeout() // check valid checkpoint // generate proposer for validator set - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) stakingKeeper.IncrementAccum(ctx, 1) lastCheckpoint, err := keeper.GetLastCheckpoint(ctx) diff --git a/checkpoint/querier_test.go b/checkpoint/querier_test.go index 337cac553..37bbcd6ca 100644 --- a/checkpoint/querier_test.go +++ b/checkpoint/querier_test.go @@ -267,7 +267,7 @@ func (suite *QuerierTestSuite) TestQueryCheckpointList() { func (suite *QuerierTestSuite) TestQueryNextCheckpoint() { t, app, ctx, querier := suite.T(), suite.app, suite.ctx, suite.querier - chSim.LoadValidatorSet(t, 2, app.StakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, app.StakingKeeper, ctx, false, 10, 0) dividendAccount := hmTypes.DividendAccount{ User: hmTypes.HexToHeimdallAddress("123"), diff --git a/checkpoint/side_handler_test.go b/checkpoint/side_handler_test.go index d45f67fbd..d35868da6 100644 --- a/checkpoint/side_handler_test.go +++ b/checkpoint/side_handler_test.go @@ -334,7 +334,7 @@ func (suite *SideHandlerTestSuite) TestPostHandleMsgCheckpoint() { // check valid checkpoint // generate proposer for validator set - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) stakingKeeper.IncrementAccum(ctx, 1) lastCheckpoint, err := keeper.GetLastCheckpoint(ctx) @@ -418,7 +418,7 @@ func (suite *SideHandlerTestSuite) TestPostHandleMsgCheckpointAck() { params := keeper.GetParams(ctx) header, _ := chSim.GenRandCheckpoint(start, maxSize, params.MaxCheckpointLength) // generate proposer for validator set - chSim.LoadValidatorSet(t, 2, app.StakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, app.StakingKeeper, ctx, false, 10, 0) app.StakingKeeper.IncrementAccum(ctx, 1) // send ack diff --git a/checkpoint/side_milestone_handler_test.go b/checkpoint/side_milestone_handler_test.go index 28ff0d51d..6b3b29305 100644 --- a/checkpoint/side_milestone_handler_test.go +++ b/checkpoint/side_milestone_handler_test.go @@ -190,7 +190,7 @@ func (suite *SideHandlerTestSuite) TestPostHandleMsgMilestone() { // check valid milestone // generate proposer for validator set - chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 2, stakingKeeper, ctx, false, 10, 0) stakingKeeper.IncrementAccum(ctx, 1) lastMilestone, err := keeper.GetLastMilestone(ctx) diff --git a/checkpoint/simulation/header.go b/checkpoint/simulation/header.go index 1ececd5d5..c3a3bf023 100644 --- a/checkpoint/simulation/header.go +++ b/checkpoint/simulation/header.go @@ -33,12 +33,12 @@ func GenRandCheckpoint(start uint64, headerSize uint64, maxCheckpointLength uint } // LoadValidatorSet loads validator set -func LoadValidatorSet(t *testing.T, count int, keeper staking.Keeper, ctx sdk.Context, randomise bool, timeAlive int) types.ValidatorSet { +func LoadValidatorSet(t *testing.T, count int, keeper staking.Keeper, ctx sdk.Context, randomise bool, timeAlive int, nonce uint64) types.ValidatorSet { t.Helper() var valSet types.ValidatorSet - validators := stakingSim.GenRandomVal(count, 0, 10, uint64(timeAlive), randomise, 1) + validators := stakingSim.GenRandomVal(count, 0, 10, uint64(timeAlive), randomise, 1, nonce) for _, validator := range validators { err := keeper.AddValidator(ctx, validator) require.NoError(t, err, "Unable to set validator, Error: %v", err) diff --git a/go.mod b/go.mod index a723a0a4c..a9e0c5453 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module github.com/maticnetwork/heimdall -go 1.23.6 +go 1.23.8 require ( github.com/RichardKnop/machinery v1.10.6 github.com/cbergoon/merkletree v0.2.0 - github.com/cosmos/cosmos-sdk v0.50.12 - github.com/ethereum/go-ethereum v1.14.13 + github.com/cosmos/cosmos-sdk v0.50.13 + github.com/ethereum/go-ethereum v1.15.8 github.com/go-kit/log v0.2.1 github.com/gogo/protobuf v1.3.2 github.com/golang/mock v1.6.0 @@ -29,7 +29,7 @@ require ( github.com/tendermint/go-amino v0.16.0 github.com/tendermint/tendermint v0.34.24 github.com/tendermint/tm-db v0.6.7 - golang.org/x/sync v0.11.0 + golang.org/x/sync v0.13.0 google.golang.org/grpc v1.64.1 google.golang.org/protobuf v1.34.1 ) @@ -88,6 +88,7 @@ require ( go.uber.org/multierr v1.9.0 // indirect golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect golang.org/x/time v0.5.0 // indirect + google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect gopkg.in/ini.v1 v1.67.0 // indirect @@ -159,17 +160,16 @@ require ( go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 go.opentelemetry.io/otel/sdk v1.27.0 go.opentelemetry.io/otel/trace v1.27.0 - golang.org/x/crypto v0.35.0 // indirect - golang.org/x/net v0.36.0 // indirect - golang.org/x/oauth2 v0.20.0 // indirect - golang.org/x/sys v0.30.0 // indirect - golang.org/x/text v0.22.0 // indirect + golang.org/x/crypto v0.37.0 // indirect + golang.org/x/net v0.39.0 // indirect + golang.org/x/oauth2 v0.29.0 // indirect + golang.org/x/sys v0.32.0 // indirect + golang.org/x/text v0.24.0 // indirect google.golang.org/api v0.169.0 // indirect - google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect gopkg.in/yaml.v3 v3.0.1 ) -replace github.com/tendermint/tendermint => github.com/maticnetwork/tendermint v0.33.3 +replace github.com/tendermint/tendermint => github.com/maticnetwork/tendermint v0.33.5 replace github.com/tendermint/tm-db => github.com/tendermint/tm-db v0.2.0 diff --git a/go.sum b/go.sum index 106061dbe..069800195 100644 --- a/go.sum +++ b/go.sum @@ -2216,8 +2216,8 @@ github.com/maticnetwork/heimdall v1.0.7/go.mod h1:+ANI5+VV28ahwfdl7oMzrcNwaTEs1F github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= github.com/maticnetwork/polyproto v0.0.4 h1:qQ/qwcO6UNGS4mJlzlLJn1AUMfJK9Rqmf1v+KJgnPsk= github.com/maticnetwork/polyproto v0.0.4/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= -github.com/maticnetwork/tendermint v0.33.3 h1:s1/Ubxh7Axv2bClr+aFMWNn5qzbRKEHEw/uEVxLTc0I= -github.com/maticnetwork/tendermint v0.33.3/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk= +github.com/maticnetwork/tendermint v0.33.5 h1:Cu1VSVWCsw045q9dootXXzYI7ONUKcq3o2gd7646Fm0= +github.com/maticnetwork/tendermint v0.33.5/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk= github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= @@ -2884,8 +2884,8 @@ golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOM golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs= -golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ= +golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= +golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -3059,8 +3059,8 @@ golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= -golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA= -golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I= +golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= +golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/oauth2 v0.0.0-20170207211851-4464e7848382/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -3105,8 +3105,9 @@ golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCA golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA= golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= -golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98= +golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= golang.org/x/perf v0.0.0-20230113213139-801c7ef9e5c5/go.mod h1:UBKtEnL8aqnd+0JHqZ+2qoMDwtuy6cYhhKNoHLBiTQc= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -3132,8 +3133,8 @@ golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= -golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= +golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -3275,8 +3276,8 @@ golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= +golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/telemetry v0.0.0-20240208230135-b75ee8823808/go.mod h1:KG1lNk5ZFNssSZLrpVb4sMXKMpGwGXOxSG3rnu2gZQQ= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0= @@ -3328,8 +3329,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= -golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= +golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/gov/types/keys_test.go b/gov/types/keys_test.go index 871484bee..1e72a2729 100644 --- a/gov/types/keys_test.go +++ b/gov/types/keys_test.go @@ -35,39 +35,3 @@ func TestProposalKeys(t *testing.T) { require.Panics(t, func() { SplitProposalKey([]byte("test")) }) require.Panics(t, func() { SplitInactiveProposalQueueKey([]byte("test")) }) } - -func TestDepositKeys(t *testing.T) { - - id := 1 - - key := DepositsKey(2) - proposalID := SplitProposalKey(key) - require.Equal(t, int(proposalID), 2) - - key = DepositKey(2, hmTypes.ValidatorID(id)) - proposalID, depositorAddr := SplitKeyDeposit(key) - require.Equal(t, int(proposalID), 2) - require.Equal(t, addr, depositorAddr) - - // invalid key - key = DepositKey(5, hmTypes.ValidatorID(id)) - require.Panics(t, func() { SplitKeyDeposit(key) }) -} - -func TestVoteKeys(t *testing.T) { - - id := 1 - - key := VotesKey(2) - proposalID := SplitProposalKey(key) - require.Equal(t, int(proposalID), 2) - - key = VoteKey(2, hmTypes.ValidatorID(id)) - proposalID, voterAddr := SplitKeyDeposit(key) - require.Equal(t, int(proposalID), 2) - require.Equal(t, addr, voterAddr) - - // invalid key - key = VoteKey(5, hmTypes.ValidatorID(id)) - require.Panics(t, func() { SplitKeyVote(key) }) -} diff --git a/packaging/templates/package_scripts/preinst b/packaging/templates/package_scripts/preinst old mode 100644 new mode 100755 diff --git a/staking/handler.go b/staking/handler.go index d0db36ec8..b27859eb5 100644 --- a/staking/handler.go +++ b/staking/handler.go @@ -122,36 +122,13 @@ func HandleMsgStakeUpdate(ctx sdk.Context, msg types.MsgStakeUpdate, k Keeper, c return hmCommon.ErrOldTx(k.Codespace()).Result() } - // pull validator from store - validator, ok := k.GetValidatorFromValID(ctx, msg.ID) - if !ok { - k.Logger(ctx).Error("Fetching of validator from store failed", "validatorId", msg.ID) - return hmCommon.ErrNoValidator(k.Codespace()).Result() - } - - if msg.Nonce != validator.Nonce+1 { - k.Logger(ctx).Error("Incorrect validator nonce") - return hmCommon.ErrNonce(k.Codespace()).Result() - } - // set validator amount _, err := helper.GetPowerFromAmount(msg.NewAmount.BigInt()) if err != nil { return hmCommon.ErrInvalidMsg(k.Codespace(), fmt.Sprintf("Invalid newamount %v for validator %v", msg.NewAmount, msg.ID)).Result() } - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeStakeUpdate, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(types.AttributeKeyValidatorID, strconv.FormatUint(validator.ID.Uint64(), 10)), - sdk.NewAttribute(types.AttributeKeyValidatorNonce, strconv.FormatUint(msg.Nonce, 10)), - ), - }) - - return sdk.Result{ - Events: ctx.EventManager().Events(), - } + return sdk.Result{} // Return empty result, success determined in PostHandle } // HandleMsgSignerUpdate handles signer update message @@ -192,24 +169,8 @@ func HandleMsgSignerUpdate(ctx sdk.Context, msg types.MsgSignerUpdate, k Keeper, return hmCommon.ErrNoSignerChange(k.Codespace()).Result() } - // check nonce validity - if msg.Nonce != validator.Nonce+1 { - k.Logger(ctx).Error("Incorrect validator nonce") - return hmCommon.ErrNonce(k.Codespace()).Result() - } - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeSignerUpdate, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(types.AttributeKeyValidatorID, strconv.FormatUint(validator.ID.Uint64(), 10)), - sdk.NewAttribute(types.AttributeKeyValidatorNonce, strconv.FormatUint(msg.Nonce, 10)), - ), - }) + return sdk.Result{} // Return empty result, success determined in PostHandle - return sdk.Result{ - Events: ctx.EventManager().Events(), - } } // HandleMsgValidatorExit handle msg validator exit @@ -246,22 +207,5 @@ func HandleMsgValidatorExit(ctx sdk.Context, msg types.MsgValidatorExit, k Keepe return hmCommon.ErrOldTx(k.Codespace()).Result() } - // check nonce validity - if msg.Nonce != validator.Nonce+1 { - k.Logger(ctx).Error("Incorrect validator nonce") - return hmCommon.ErrNonce(k.Codespace()).Result() - } - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeValidatorExit, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(types.AttributeKeyValidatorID, strconv.FormatUint(validator.ID.Uint64(), 10)), - sdk.NewAttribute(types.AttributeKeyValidatorNonce, strconv.FormatUint(msg.Nonce, 10)), - ), - }) - - return sdk.Result{ - Events: ctx.EventManager().Events(), - } + return sdk.Result{} // Return empty result, success determined in PostHandle } diff --git a/staking/handler_test.go b/staking/handler_test.go index 9324562ad..ee3bf39e0 100644 --- a/staking/handler_test.go +++ b/staking/handler_test.go @@ -112,12 +112,12 @@ func (suite *HandlerTestSuite) TestHandleMsgValidatorUpdate() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := suite.app.StakingKeeper // pass 0 as time alive to generate non de-activated validators - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, 0) oldValSet := keeper.GetValidatorSet(ctx) // vals := oldValSet.(*Validators) oldSigner := oldValSet.Validators[0] - newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1) + newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1, 0) newSigner[0].ID = oldSigner.ID newSigner[0].VotingPower = oldSigner.VotingPower @@ -168,7 +168,7 @@ func (suite *HandlerTestSuite) TestHandleMsgValidatorExit() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper // pass 0 as time alive to generate non de-activated validators - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, 0) validators := keeper.GetCurrentValidators(ctx) msgTxHash := hmTypes.HexToHeimdallHash("123") chainParams := app.ChainKeeper.GetParams(ctx) @@ -214,7 +214,7 @@ func (suite *HandlerTestSuite) TestHandleMsgStakeUpdate() { keeper := app.StakingKeeper // pass 0 as time alive to generate non de-activated validators - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, 0) oldValSet := keeper.GetValidatorSet(ctx) oldVal := oldValSet.Validators[0] diff --git a/staking/keeper_test.go b/staking/keeper_test.go index 1982cbb3b..4117a5106 100644 --- a/staking/keeper_test.go +++ b/staking/keeper_test.go @@ -228,7 +228,7 @@ func (suite *KeeperTestSuite) TestRemoveValidatorSetChange() { keeper := app.StakingKeeper // load 4 validators to state - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) initValSet := keeper.GetValidatorSet(ctx) currentValSet := initValSet.Copy() @@ -260,10 +260,10 @@ func (suite *KeeperTestSuite) TestAddValidatorSetChange() { keeper := app.StakingKeeper // load 4 validators to state - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) initValSet := keeper.GetValidatorSet(ctx) - validators := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1) + validators := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1, 0) prevValSet := initValSet.Copy() valToBeAdded := validators[0] @@ -296,7 +296,7 @@ func (suite *KeeperTestSuite) TestUpdateValidatorSetChange() { keeper := app.StakingKeeper // load 4 validators to state - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) initValSet := keeper.GetValidatorSet(ctx) keeper.IncrementAccum(ctx, 2) @@ -305,7 +305,7 @@ func (suite *KeeperTestSuite) TestUpdateValidatorSetChange() { currentValSet := keeper.GetValidatorSet(ctx) valToUpdate := currentValSet.Validators[0] - newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1) + newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1, 0) err := keeper.UpdateSigner(ctx, newSigner[0].Signer, newSigner[0].PubKey, valToUpdate.Signer) require.NoError(t, err) @@ -329,7 +329,7 @@ func (suite *KeeperTestSuite) TestUpdateValidatorSetChange() { func (suite *KeeperTestSuite) TestGetCurrentValidators() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) validators := keeper.GetCurrentValidators(ctx) activeValidatorInfo, err := keeper.GetActiveValidatorInfo(ctx, validators[0].Signer.Bytes()) require.NoError(t, err) @@ -339,7 +339,7 @@ func (suite *KeeperTestSuite) TestGetCurrentValidators() { func (suite *KeeperTestSuite) TestGetCurrentProposer() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) currentValSet := keeper.GetValidatorSet(ctx) currentProposer := keeper.GetCurrentProposer(ctx) require.Equal(t, currentValSet.GetProposer(), currentProposer) @@ -348,7 +348,7 @@ func (suite *KeeperTestSuite) TestGetCurrentProposer() { func (suite *KeeperTestSuite) TestGetNextProposer() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) nextProposer := keeper.GetNextProposer(ctx) require.NotNil(t, nextProposer) @@ -357,7 +357,7 @@ func (suite *KeeperTestSuite) TestGetNextProposer() { func (suite *KeeperTestSuite) TestGetValidatorFromValID() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) validators := keeper.GetCurrentValidators(ctx) valInfo, ok := keeper.GetValidatorFromValID(ctx, validators[0].ID) @@ -368,7 +368,7 @@ func (suite *KeeperTestSuite) TestGetValidatorFromValID() { func (suite *KeeperTestSuite) TestGetLastUpdated() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) validators := keeper.GetCurrentValidators(ctx) lastUpdated, ok := keeper.GetLastUpdated(ctx, validators[0].ID) @@ -379,7 +379,7 @@ func (suite *KeeperTestSuite) TestGetLastUpdated() { func (suite *KeeperTestSuite) TestGetSpanEligibleValidators() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, 0) // Test ActCount = 0 app.CheckpointKeeper.UpdateACKCountWithValue(ctx, 0) @@ -396,7 +396,7 @@ func (suite *KeeperTestSuite) TestGetSpanEligibleValidators() { func (suite *KeeperTestSuite) TestGetMilestoneProposer() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) currentValSet1 := keeper.GetMilestoneValidatorSet(ctx) currentMilestoneProposer := keeper.GetMilestoneCurrentProposer(ctx) require.Equal(t, currentValSet1.GetProposer(), currentMilestoneProposer) @@ -415,7 +415,7 @@ func (suite *KeeperTestSuite) TestMilestoneValidatorSetIncAccumChange() { keeper := app.StakingKeeper // load 4 validators to state - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) initMilestoneValSetProp := keeper.GetMilestoneValidatorSet(ctx).Proposer //Getter for Milestone Validator Set Proposer initCheckpointValSetProp := keeper.GetValidatorSet(ctx).Proposer //Getter for Checkpoint Validator Set Proposer @@ -448,7 +448,7 @@ func (suite *KeeperTestSuite) TestUpdateMilestoneValidatorSetChange() { keeper := app.StakingKeeper // load 4 validators to state - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) initValSet := keeper.GetMilestoneValidatorSet(ctx) keeper.MilestoneIncrementAccum(ctx, 1) @@ -457,7 +457,7 @@ func (suite *KeeperTestSuite) TestUpdateMilestoneValidatorSetChange() { currentValSet := keeper.GetMilestoneValidatorSet(ctx) valToUpdate := currentValSet.Validators[0] - newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1) + newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1, 0) err := keeper.UpdateSigner(ctx, newSigner[0].Signer, newSigner[0].PubKey, valToUpdate.Signer) require.NoError(t, err) diff --git a/staking/querier_test.go b/staking/querier_test.go index d2d8bef2a..e03fec12a 100644 --- a/staking/querier_test.go +++ b/staking/querier_test.go @@ -69,7 +69,7 @@ func (suite *QuerierTestSuite) TestInvalidQuery() { func (suite *QuerierTestSuite) TestHandleQueryCurrentValidatorSet() { t, app, ctx, querier := suite.T(), suite.app, suite.ctx, suite.querier keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) path := []string{types.QueryCurrentValidatorSet} @@ -90,7 +90,7 @@ func (suite *QuerierTestSuite) TestHandleQueryCurrentValidatorSet() { func (suite *QuerierTestSuite) TesthandleQuerySigner() { t, app, ctx, querier := suite.T(), suite.app, suite.ctx, suite.querier keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) validators := keeper.GetAllValidators(ctx) path := []string{types.QuerySigner} @@ -112,7 +112,7 @@ func (suite *QuerierTestSuite) TesthandleQuerySigner() { func (suite *QuerierTestSuite) TesthandleQueryValidator() { t, app, ctx, querier := suite.T(), suite.app, suite.ctx, suite.querier keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) validators := keeper.GetAllValidators(ctx) path := []string{types.QueryValidator} @@ -134,7 +134,7 @@ func (suite *QuerierTestSuite) TesthandleQueryValidator() { func (suite *QuerierTestSuite) TestHandleQueryValidatorStatus() { t, app, ctx, querier := suite.T(), suite.app, suite.ctx, suite.querier keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) validators := keeper.GetAllValidators(ctx) path := []string{types.QueryValidatorStatus} @@ -156,7 +156,7 @@ func (suite *QuerierTestSuite) TestHandleQueryValidatorStatus() { func (suite *QuerierTestSuite) TestHandleQueryProposer() { t, app, ctx, querier := suite.T(), suite.app, suite.ctx, suite.querier keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) path := []string{types.QueryProposer} @@ -177,7 +177,7 @@ func (suite *QuerierTestSuite) TestHandleQueryProposer() { func (suite *QuerierTestSuite) TestHandleQueryMilestoneProposer() { t, app, ctx, querier := suite.T(), suite.app, suite.ctx, suite.querier keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) path := []string{types.QueryMilestoneProposer} @@ -198,7 +198,7 @@ func (suite *QuerierTestSuite) TestHandleQueryMilestoneProposer() { func (suite *QuerierTestSuite) TestHandleQueryCurrentProposer() { t, app, ctx, querier := suite.T(), suite.app, suite.ctx, suite.querier keeper := app.StakingKeeper - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 10, 0) path := []string{types.QueryCurrentProposer} diff --git a/staking/side_handler.go b/staking/side_handler.go index 613f54734..d3f92cd64 100644 --- a/staking/side_handler.go +++ b/staking/side_handler.go @@ -438,8 +438,6 @@ func PostHandleMsgStakeUpdate(ctx sdk.Context, k Keeper, msg types.MsgStakeUpdat return hmCommon.ErrOldTx(k.Codespace()).Result() } - k.Logger(ctx).Debug("Updating validator stake", "sideTxResult", sideTxResult) - // pull validator from store validator, ok := k.GetValidatorFromValID(ctx, msg.ID) if !ok { @@ -447,6 +445,14 @@ func PostHandleMsgStakeUpdate(ctx sdk.Context, k Keeper, msg types.MsgStakeUpdat return hmCommon.ErrNoValidator(k.Codespace()).Result() } + // Check nonce validity just before applying state update + if msg.Nonce != validator.Nonce+1 { + k.Logger(ctx).Error("Incorrect validator nonce during PostHandle SignerUpdate", "ValidatorNonce", validator.Nonce, "MsgNonce", msg.Nonce) + return hmCommon.ErrNonce(k.Codespace()).Result() + } + + k.Logger(ctx).Debug("Updating validator stake", "sideTxResult", sideTxResult) + // update last updated validator.LastUpdated = sequence.String() @@ -510,11 +516,6 @@ func PostHandleMsgSignerUpdate(ctx sdk.Context, k Keeper, msg types.MsgSignerUpd return hmCommon.ErrOldTx(k.Codespace()).Result() } - k.Logger(ctx).Debug("Persisting signer update", "sideTxResult", sideTxResult) - - newPubKey := msg.NewSignerPubKey - newSigner := newPubKey.Address() - // pull validator from store validator, ok := k.GetValidatorFromValID(ctx, msg.ID) if !ok { @@ -522,6 +523,17 @@ func PostHandleMsgSignerUpdate(ctx sdk.Context, k Keeper, msg types.MsgSignerUpd return hmCommon.ErrNoValidator(k.Codespace()).Result() } + // Check nonce validity just before applying state update + if msg.Nonce != validator.Nonce+1 { + k.Logger(ctx).Error("Incorrect validator nonce during PostHandle SignerUpdate", "ValidatorNonce", validator.Nonce, "MsgNonce", msg.Nonce) + return hmCommon.ErrNonce(k.Codespace()).Result() + } + + k.Logger(ctx).Debug("Persisting signer update", "sideTxResult", sideTxResult) + + newPubKey := msg.NewSignerPubKey + newSigner := newPubKey.Address() + oldValidator := validator.Copy() // update last updated @@ -632,14 +644,20 @@ func PostHandleMsgValidatorExit(ctx sdk.Context, k Keeper, msg types.MsgValidato return hmCommon.ErrOldTx(k.Codespace()).Result() } - k.Logger(ctx).Debug("Persisting validator exit", "sideTxResult", sideTxResult) - validator, ok := k.GetValidatorFromValID(ctx, msg.ID) if !ok { k.Logger(ctx).Error("Fetching of validator from store failed", "validatorID", msg.ID) return hmCommon.ErrNoValidator(k.Codespace()).Result() } + // Check nonce validity just before applying state update + if msg.Nonce != validator.Nonce+1 { + k.Logger(ctx).Error("Incorrect validator nonce during PostHandle SignerUpdate", "ValidatorNonce", validator.Nonce, "MsgNonce", msg.Nonce) + return hmCommon.ErrNonce(k.Codespace()).Result() + } + + k.Logger(ctx).Debug("Persisting validator exit", "sideTxResult", sideTxResult) + // set end epoch validator.EndEpoch = msg.DeactivationEpoch diff --git a/staking/side_handler_test.go b/staking/side_handler_test.go index c234cbcd6..72bf8dab5 100644 --- a/staking/side_handler_test.go +++ b/staking/side_handler_test.go @@ -470,17 +470,18 @@ func (suite *SideHandlerTestSuite) TestSideHandleMsgValidatorJoin() { func (suite *SideHandlerTestSuite) TestSideHandleMsgSignerUpdate() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := suite.app.StakingKeeper + nonce := big.NewInt(5) + // pass 0 as time alive to generate non de-activated validators - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, nonce.Uint64()-1) oldValSet := keeper.GetValidatorSet(ctx) oldSigner := oldValSet.Validators[0] - newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1) + newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1, nonce.Uint64()-1) newSigner[0].ID = oldSigner.ID newSigner[0].VotingPower = oldSigner.VotingPower chainParams := app.ChainKeeper.GetParams(ctx) blockNumber := big.NewInt(10) - nonce := big.NewInt(5) // gen msg msgTxHash := hmTypes.HexToHeimdallHash("123") @@ -649,14 +650,15 @@ func (suite *SideHandlerTestSuite) TestSideHandleMsgSignerUpdate() { func (suite *SideHandlerTestSuite) TestSideHandleMsgValidatorExit() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper + nonce := big.NewInt(9) + // pass 0 as time alive to generate non de-activated validators - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, nonce.Uint64()-1) validators := keeper.GetCurrentValidators(ctx) msgTxHash := hmTypes.HexToHeimdallHash("123") chainParams := app.ChainKeeper.GetParams(ctx) logIndex := uint64(0) blockNumber := big.NewInt(10) - nonce := big.NewInt(9) suite.Run("Success", func() { suite.contractCaller = mocks.IContractCaller{} @@ -901,7 +903,7 @@ func (suite *SideHandlerTestSuite) TestSideHandleMsgStakeUpdate() { keeper := app.StakingKeeper // pass 0 as time alive to generate non de-activated validators - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, 0) oldValSet := keeper.GetValidatorSet(ctx) oldVal := oldValSet.Validators[0] @@ -1204,16 +1206,18 @@ func (suite *SideHandlerTestSuite) TestPostHandleMsgValidatorJoin() { func (suite *SideHandlerTestSuite) TestPostHandleMsgSignerUpdate() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper + + nonce := big.NewInt(5) + // pass 0 as time alive to generate non de-activated validators - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, nonce.Uint64()-1) oldValSet := keeper.GetValidatorSet(ctx) oldSigner := oldValSet.Validators[0] - newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1) + newSigner := stakingSim.GenRandomVal(1, 0, 10, 10, false, 1, nonce.Uint64()-1) newSigner[0].ID = oldSigner.ID newSigner[0].VotingPower = oldSigner.VotingPower blockNumber := big.NewInt(10) - nonce := big.NewInt(5) // gen msg msgTxHash := hmTypes.HexToHeimdallHash("123") @@ -1253,12 +1257,13 @@ func (suite *SideHandlerTestSuite) TestPostHandleMsgSignerUpdate() { func (suite *SideHandlerTestSuite) TestPostHandleMsgValidatorExit() { t, app, ctx := suite.T(), suite.app, suite.ctx keeper := app.StakingKeeper + nonce := big.NewInt(9) + // pass 0 as time alive to generate non de-activated validators - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, nonce.Uint64()-1) validators := keeper.GetCurrentValidators(ctx) msgTxHash := hmTypes.HexToHeimdallHash("123") blockNumber := big.NewInt(10) - nonce := big.NewInt(9) suite.Run("No Success", func() { validators[0].EndEpoch = 10 @@ -1307,7 +1312,7 @@ func (suite *SideHandlerTestSuite) TestPostHandleMsgStakeUpdate() { keeper := app.StakingKeeper // pass 0 as time alive to generate non de-activated validators - chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0) + chSim.LoadValidatorSet(t, 4, keeper, ctx, false, 0, 0) oldValSet := keeper.GetValidatorSet(ctx) oldVal := oldValSet.Validators[0] diff --git a/staking/simulation/utils.go b/staking/simulation/utils.go index eaeb9e50a..e4f0024cb 100644 --- a/staking/simulation/utils.go +++ b/staking/simulation/utils.go @@ -11,7 +11,7 @@ import ( ) // GenRandomVal generate random validators -func GenRandomVal(count int, startBlock uint64, power int64, timeAlive uint64, randomise bool, startID uint64) (validators []types.Validator) { +func GenRandomVal(count int, startBlock uint64, power int64, timeAlive uint64, randomise bool, startID uint64, nonce uint64) (validators []types.Validator) { for i := 0; i < count; i++ { privKey1 := secp256k1.GenPrivKey() pubkey := types.NewPubKey(util.AppendPrefix(privKey1.PubKey().Bytes())) @@ -29,6 +29,7 @@ func GenRandomVal(count int, startBlock uint64, power int64, timeAlive uint64, r Signer: types.HexToHeimdallAddress(pubkey.Address().String()), PubKey: pubkey, ProposerPriority: 0, + Nonce: nonce, } validators = append(validators, newVal) }