From 8bc230d33644d37b1bb3ec75c633272a516682ce Mon Sep 17 00:00:00 2001 From: marcello33 Date: Mon, 24 Mar 2025 10:55:43 +0100 Subject: [PATCH 1/9] bump tendermint --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 90bfe7610..1561eeb44 100644 --- a/go.mod +++ b/go.mod @@ -169,7 +169,7 @@ require ( 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.4 replace github.com/tendermint/tm-db => github.com/tendermint/tm-db v0.2.0 diff --git a/go.sum b/go.sum index 1c5efaa9f..47d4c7280 100644 --- a/go.sum +++ b/go.sum @@ -2227,8 +2227,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.4 h1:O2bXPR4caHFjMWjUGV8gUm43XXlOAe+NZCHuP09TXUo= +github.com/maticnetwork/tendermint v0.33.4/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= From 6475d73abc6eef80884b2e68dd1468dea7de6a3c Mon Sep 17 00:00:00 2001 From: marcello33 Date: Mon, 24 Mar 2025 11:01:16 +0100 Subject: [PATCH 2/9] add mnemonic for e2e tests --- .github/matic-cli-config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/matic-cli-config.yml b/.github/matic-cli-config.yml index da4fef7e9..612cd301d 100644 --- a/.github/matic-cli-config.yml +++ b/.github/matic-cli-config.yml @@ -24,3 +24,4 @@ heimdallDockerBuildContext: "../../heimdall" sprintSizeBlockNumber: - '0' devnetBorFlags: config,config,config +mnemonic: 'clock radar mass judge dismiss just intact mind resemble fringe diary casino' From ca9bee060769e499dc645308ca0d6ea055d7c7ad Mon Sep 17 00:00:00 2001 From: marcello33 Date: Mon, 24 Mar 2025 11:07:39 +0100 Subject: [PATCH 3/9] fix CI --- .github/matic-cli-config.yml | 5 +++-- .github/workflows/ci.yml | 35 ++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.github/matic-cli-config.yml b/.github/matic-cli-config.yml index 612cd301d..cd475d28d 100644 --- a/.github/matic-cli-config.yml +++ b/.github/matic-cli-config.yml @@ -2,7 +2,8 @@ defaultStake: 10000 defaultFee: 2000 borChainId: 15001 heimdallChainId: heimdall-15001 -contractsBranch: mardizzone/node-16 +contractsRepo: https://github.com/0xPolygon/pos-contracts.git +contractsBranch: anvil-pos genesisContractsBranch: master sprintSize: - '64' @@ -16,7 +17,7 @@ numOfBorArchiveNodes: 0 numOfErigonValidators: 0 numOfErigonSentries: 0 numOfErigonArchiveNodes: 0 -ethURL: http://ganache:9545 +ethURL: http://anvil:9545 ethHostUser: ubuntu devnetType: docker borDockerBuildContext: "https://github.com/maticnetwork/bor.git#develop" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 888bdf8aa..5686cb7b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: if: (github.event.action != 'closed' || github.event.pull_request.merged == true) strategy: matrix: - os: [ ubuntu-20.04 ] # list of os: https://github.com/actions/virtual-environments + os: [ ubuntu-22.04 ] # list of os: https://github.com/actions/virtual-environments runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -88,9 +88,7 @@ jobs: sudo apt update sudo apt install build-essential curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash - sudo snap install solc - sudo apt install python2 jq curl - sudo ln -sf /usr/bin/python2 /usr/bin/python + sudo apt install jq curl - uses: actions/setup-node@v4 with: @@ -102,6 +100,23 @@ jobs: matic-cli/devnet/code/genesis-contracts/package-lock.json matic-cli/devnet/code/genesis-contracts/matic-contracts/package-lock.json + - name: Install solc-select + run: | + sudo apt update + sudo apt install python3 python3-pip -y + sudo ln -sf /usr/bin/python3 /usr/bin/python + pip install solc-select + + - name: Install Solidity Version + run: | + solc-select install 0.5.17 + solc-select install 0.6.12 + solc-select use 0.5.17 + solc --version + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + - name: Bootstrap devnet run: | cd matic-cli @@ -119,12 +134,14 @@ jobs: - name: Run smoke tests run: | - echo "Funding ganache accounts..." - timeout 10m bash heimdall/integration-tests/fund_ganache_accounts.sh echo "Deposit 100 matic for each account to bor network" - cd matic-cli/devnet/code/contracts - npm run truffle exec scripts/deposit.js -- --network development $(jq -r .root.tokens.MaticToken contractAddresses.json) 100000000000000000000 - cd - + cd matic-cli/devnet/devnet + SCRIPT_ADDRESS=$(jq -r '.[0].address' signer-dump.json) + SCRIPT_PRIVATE_KEY=$(jq -r '.[0].priv_key' signer-dump.json) + cd ../code/pos-contracts + CONTRACT_ADDRESS=$(jq -r .root.tokens.MaticToken contractAddresses.json) + forge script scripts/matic-cli-scripts/Deposit.s.sol:MaticDeposit --rpc-url http://localhost:9545 --private-key $SCRIPT_PRIVATE_KEY --broadcast --sig "run(address,address,uint256)" $SCRIPT_ADDRESS $CONTRACT_ADDRESS 100000000000000000000 + cd ../../../.. timeout 60m bash heimdall/integration-tests/smoke_test.sh - name: Upload logs From 81c1dd75dfbcaccea312de30c18ec0956aaa1836 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Fri, 28 Mar 2025 18:39:59 +0200 Subject: [PATCH 4/9] Dont iterate all spans in latest span query --- bor/querier.go | 13 ------------- 1 file changed, 13 deletions(-) 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 { From 74ece1f2aaf10ae67164744fb8aef9966ef5946f Mon Sep 17 00:00:00 2001 From: marcello33 Date: Thu, 10 Apr 2025 10:29:59 -0700 Subject: [PATCH 5/9] ci update --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5686cb7b9..e3725b424 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,7 +146,7 @@ jobs: - name: Upload logs if: always() - uses: actions/upload-artifact@v4.4.0 + uses: PaloAltoNetworks/upload-secure-artifact@main with: name: logs_${{ github.run_id }} path: | @@ -161,11 +161,11 @@ jobs: mkdir -p ${{ github.run_id }}/matic-cli sudo mv heimdall ${{ github.run_id }} sudo mv matic-cli/devnet ${{ github.run_id }}/matic-cli - sudo tar czf code.tar.gz ${{ github.run_id }} + sudo tar czf code.tar.gz --exclude='.git' . ${{ github.run_id }} - name: Upload code and chain data if: always() - uses: actions/upload-artifact@v4.4.0 + uses: PaloAltoNetworks/upload-secure-artifact@main with: name: code_${{ github.run_id }} path: code.tar.gz From 299ab90c7f9d31432a008c6149c65a5978f0cb8b Mon Sep 17 00:00:00 2001 From: marcello33 Date: Thu, 10 Apr 2025 12:48:41 -0700 Subject: [PATCH 6/9] fix path for logs --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3725b424..ef26c2bc5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -144,13 +144,17 @@ jobs: cd ../../../.. timeout 60m bash heimdall/integration-tests/smoke_test.sh + - name: Resolve absolute path for logs + id: pathfix + run: | + echo "ABS_LOG_PATH=$(realpath matic-cli/devnet/logs)" >> $GITHUB_ENV + - name: Upload logs if: always() uses: PaloAltoNetworks/upload-secure-artifact@main with: name: logs_${{ github.run_id }} - path: | - matic-cli/devnet/logs + path: ${{ env.ABS_LOG_PATH }} - name: Package code and chain data if: always() From 0a32b373474772b16ccf007bb29aa87ed2e840d8 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Mon, 14 Apr 2025 17:12:57 +0200 Subject: [PATCH 7/9] no warning on package code --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef26c2bc5..18f0e4273 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -165,7 +165,7 @@ jobs: mkdir -p ${{ github.run_id }}/matic-cli sudo mv heimdall ${{ github.run_id }} sudo mv matic-cli/devnet ${{ github.run_id }}/matic-cli - sudo tar czf code.tar.gz --exclude='.git' . ${{ github.run_id }} + sudo tar --warning=no-file-changed --exclude='.git' -czf code.tar.gz ${{ github.run_id }} - name: Upload code and chain data if: always() From e1aa0acded69cc1c200935a7a31dec4379a9f61e Mon Sep 17 00:00:00 2001 From: marcello33 Date: Wed, 16 Apr 2025 13:19:40 +0200 Subject: [PATCH 8/9] v1.2.3 release candidate --- .gitignore | 2 + Makefile | 2 +- checkpoint/handler_milestone_test.go | 6 +-- checkpoint/handler_test.go | 12 ++--- checkpoint/querier_test.go | 2 +- checkpoint/side_handler_test.go | 4 +- checkpoint/side_milestone_handler_test.go | 2 +- checkpoint/simulation/header.go | 4 +- go.mod | 22 ++++---- go.sum | 27 +++++----- gov/types/keys_test.go | 36 ------------- staking/handler.go | 62 ++--------------------- staking/handler_test.go | 8 +-- staking/keeper_test.go | 30 +++++------ staking/querier_test.go | 14 ++--- staking/side_handler.go | 36 +++++++++---- staking/side_handler_test.go | 29 ++++++----- staking/simulation/utils.go | 3 +- 18 files changed, 118 insertions(+), 183 deletions(-) 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/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/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) } From 1c2a348bb93c046510662765804c4c793b75b537 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Wed, 16 Apr 2025 14:12:06 +0200 Subject: [PATCH 9/9] change perms on preinst --- packaging/templates/package_scripts/preinst | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 packaging/templates/package_scripts/preinst diff --git a/packaging/templates/package_scripts/preinst b/packaging/templates/package_scripts/preinst old mode 100644 new mode 100755