From d1722c9c10947f50bfa910472512277807e0ebeb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 31 Mar 2022 12:58:41 +0000 Subject: [PATCH 1/5] build(deps): Bump github.com/vektra/mockery/v2 from 2.10.0 to 2.10.1 (#8226) Bumps [github.com/vektra/mockery/v2](https://github.com/vektra/mockery) from 2.10.0 to 2.10.1.
Release notes

Sourced from github.com/vektra/mockery/v2's releases.

v2.10.1

Changelog

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/vektra/mockery/v2&package-manager=go_modules&previous-version=2.10.0&new-version=2.10.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ed88618e0..21afc3375 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,7 @@ require ( github.com/creachadair/atomicfile v0.2.4 github.com/golangci/golangci-lint v1.45.2 github.com/google/go-cmp v0.5.7 - github.com/vektra/mockery/v2 v2.10.0 + github.com/vektra/mockery/v2 v2.10.1 gotest.tools v2.2.0+incompatible ) diff --git a/go.sum b/go.sum index 8ba897684..19aeb8f1f 100644 --- a/go.sum +++ b/go.sum @@ -1035,8 +1035,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus= github.com/valyala/quicktemplate v1.7.0/go.mod h1:sqKJnoaOF88V07vkO+9FL8fb9uZg/VPSJnLYn+LmLk8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= -github.com/vektra/mockery/v2 v2.10.0 h1:MiiQWxwdq7/ET6dCXLaJzSGEN17k758H7JHS9kOdiks= -github.com/vektra/mockery/v2 v2.10.0/go.mod h1:m/WO2UzWzqgVX3nvqpRQq70I4Z7jbSCRhdmkgtp+Ab4= +github.com/vektra/mockery/v2 v2.10.1 h1:EOsWLFVlkUJlNurdO/w1NBFbFE1vbemJJtaG3Bo6H/M= +github.com/vektra/mockery/v2 v2.10.1/go.mod h1:m/WO2UzWzqgVX3nvqpRQq70I4Z7jbSCRhdmkgtp+Ab4= github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8/go.mod h1:dniwbG03GafCjFohMDmz6Zc6oCuiqgH6tGNyXTkHzXE= github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE= github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= From 6af23ff757fd3a293b931b4fb841e9dad665bf82 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Thu, 31 Mar 2022 09:10:09 -0400 Subject: [PATCH 2/5] state: avoid premature genericism (#8224) --- internal/blocksync/reactor_test.go | 1 + internal/consensus/byzantine_test.go | 2 +- internal/consensus/common_test.go | 2 +- internal/consensus/reactor_test.go | 2 +- internal/consensus/replay.go | 4 ++-- internal/consensus/replay_file.go | 2 +- internal/consensus/replay_test.go | 2 +- internal/consensus/wal_generator.go | 2 +- internal/state/execution.go | 20 +++----------------- internal/state/execution_test.go | 16 ++++++++++++---- internal/state/validation_test.go | 3 +++ node/node.go | 2 +- node/node_test.go | 3 +++ 13 files changed, 31 insertions(+), 30 deletions(-) diff --git a/internal/blocksync/reactor_test.go b/internal/blocksync/reactor_test.go index 5d70c27ca..e35d45a74 100644 --- a/internal/blocksync/reactor_test.go +++ b/internal/blocksync/reactor_test.go @@ -145,6 +145,7 @@ func (rts *reactorTestSuite) addNode( sm.EmptyEvidencePool{}, blockStore, eventbus, + sm.NopMetrics(), ) for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ { diff --git a/internal/consensus/byzantine_test.go b/internal/consensus/byzantine_test.go index 40a37b812..f631452bd 100644 --- a/internal/consensus/byzantine_test.go +++ b/internal/consensus/byzantine_test.go @@ -95,7 +95,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { evpool := evidence.NewPool(logger.With("module", "evidence"), evidenceDB, stateStore, blockStore, evidence.NopMetrics(), eventBus) // Make State - blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), proxyAppConnCon, mempool, evpool, blockStore, eventBus) + blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), proxyAppConnCon, mempool, evpool, blockStore, eventBus, sm.NopMetrics()) cs, err := NewState(ctx, logger, thisConfig.Consensus, stateStore, blockExec, blockStore, mempool, evpool, eventBus) require.NoError(t, err) // set private validator diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index 6abe14f60..a69fc1240 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -490,7 +490,7 @@ func newStateWithConfigAndBlockStore( eventBus := eventbus.NewDefault(logger.With("module", "events")) require.NoError(t, eventBus.Start(ctx)) - blockExec := sm.NewBlockExecutor(stateStore, logger, proxyAppConnCon, mempool, evpool, blockStore, eventBus) + blockExec := sm.NewBlockExecutor(stateStore, logger, proxyAppConnCon, mempool, evpool, blockStore, eventBus, sm.NopMetrics()) cs, err := NewState(ctx, logger.With("module", "consensus"), thisConfig.Consensus, diff --git a/internal/consensus/reactor_test.go b/internal/consensus/reactor_test.go index a84aa8bde..886e3794a 100644 --- a/internal/consensus/reactor_test.go +++ b/internal/consensus/reactor_test.go @@ -504,7 +504,7 @@ func TestReactorWithEvidence(t *testing.T) { eventBus := eventbus.NewDefault(log.NewNopLogger().With("module", "events")) require.NoError(t, eventBus.Start(ctx)) - blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), proxyAppConnCon, mempool, evpool, blockStore, eventBus) + blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), proxyAppConnCon, mempool, evpool, blockStore, eventBus, sm.NopMetrics()) cs, err := NewState(ctx, logger.With("validator", i, "module", "consensus"), thisConfig.Consensus, stateStore, blockExec, blockStore, mempool, evpool2, eventBus) diff --git a/internal/consensus/replay.go b/internal/consensus/replay.go index 5d097df21..177b9fbad 100644 --- a/internal/consensus/replay.go +++ b/internal/consensus/replay.go @@ -484,7 +484,7 @@ func (h *Handshaker) replayBlocks( if i == finalBlock && !mutateState { // We emit events for the index services at the final block due to the sync issue when // the node shutdown during the block committing status. - blockExec := sm.NewBlockExecutor(h.stateStore, h.logger, appClient, emptyMempool{}, sm.EmptyEvidencePool{}, h.store, h.eventBus) + blockExec := sm.NewBlockExecutor(h.stateStore, h.logger, appClient, emptyMempool{}, sm.EmptyEvidencePool{}, h.store, h.eventBus, sm.NopMetrics()) appHash, err = sm.ExecCommitBlock(ctx, blockExec, appClient, block, h.logger, h.stateStore, h.genDoc.InitialHeight, state) if err != nil { @@ -526,7 +526,7 @@ func (h *Handshaker) replayBlock( // Use stubs for both mempool and evidence pool since no transactions nor // evidence are needed here - block already exists. - blockExec := sm.NewBlockExecutor(h.stateStore, h.logger, appClient, emptyMempool{}, sm.EmptyEvidencePool{}, h.store, h.eventBus) + blockExec := sm.NewBlockExecutor(h.stateStore, h.logger, appClient, emptyMempool{}, sm.EmptyEvidencePool{}, h.store, h.eventBus, sm.NopMetrics()) var err error state, err = blockExec.ApplyBlock(ctx, state, meta.BlockID, block) diff --git a/internal/consensus/replay_file.go b/internal/consensus/replay_file.go index 492d1d1ee..e88a06454 100644 --- a/internal/consensus/replay_file.go +++ b/internal/consensus/replay_file.go @@ -348,7 +348,7 @@ func newConsensusStateForReplay( } mempool, evpool := emptyMempool{}, sm.EmptyEvidencePool{} - blockExec := sm.NewBlockExecutor(stateStore, logger, proxyApp, mempool, evpool, blockStore, eventBus) + blockExec := sm.NewBlockExecutor(stateStore, logger, proxyApp, mempool, evpool, blockStore, eventBus, sm.NopMetrics()) consensusState, err := NewState(ctx, logger, csConfig, stateStore, blockExec, blockStore, mempool, evpool, eventBus) diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index d24e55d67..468d912ac 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -826,7 +826,7 @@ func applyBlock( eventBus *eventbus.EventBus, ) sm.State { testPartSize := types.BlockPartSizeBytes - blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), appClient, mempool, evpool, blockStore, eventBus) + blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), appClient, mempool, evpool, blockStore, eventBus, sm.NopMetrics()) bps, err := blk.MakePartSet(testPartSize) require.NoError(t, err) diff --git a/internal/consensus/wal_generator.go b/internal/consensus/wal_generator.go index b11930f16..8c61c1203 100644 --- a/internal/consensus/wal_generator.go +++ b/internal/consensus/wal_generator.go @@ -80,7 +80,7 @@ func WALGenerateNBlocks(ctx context.Context, t *testing.T, logger log.Logger, wr mempool := emptyMempool{} evpool := sm.EmptyEvidencePool{} - blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), proxyApp, mempool, evpool, blockStore, eventBus) + blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), proxyApp, mempool, evpool, blockStore, eventBus, sm.NopMetrics()) consensusState, err := NewState(ctx, logger, cfg.Consensus, stateStore, blockExec, blockStore, mempool, evpool, eventBus) if err != nil { t.Fatal(err) diff --git a/internal/state/execution.go b/internal/state/execution.go index 4f02092d5..bd800ae8e 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -48,14 +48,6 @@ type BlockExecutor struct { cache map[string]struct{} } -type BlockExecutorOption func(executor *BlockExecutor) - -func BlockExecutorWithMetrics(metrics *Metrics) BlockExecutorOption { - return func(blockExec *BlockExecutor) { - blockExec.metrics = metrics - } -} - // NewBlockExecutor returns a new BlockExecutor with a NopEventBus. // Call SetEventBus to provide one. func NewBlockExecutor( @@ -66,25 +58,19 @@ func NewBlockExecutor( evpool EvidencePool, blockStore BlockStore, eventBus *eventbus.EventBus, - options ...BlockExecutorOption, + metrics *Metrics, ) *BlockExecutor { - res := &BlockExecutor{ + return &BlockExecutor{ eventBus: eventBus, store: stateStore, appClient: appClient, mempool: pool, evpool: evpool, logger: logger, - metrics: NopMetrics(), + metrics: metrics, cache: make(map[string]struct{}), blockStore: blockStore, } - - for _, option := range options { - option(res) - } - - return res } func (blockExec *BlockExecutor) Store() Store { diff --git a/internal/state/execution_test.go b/internal/state/execution_test.go index 58580e7be..9c5042645 100644 --- a/internal/state/execution_test.go +++ b/internal/state/execution_test.go @@ -64,7 +64,7 @@ func TestApplyBlock(t *testing.T) { mock.Anything, mock.Anything, mock.Anything).Return(nil) - blockExec := sm.NewBlockExecutor(stateStore, logger, proxyApp, mp, sm.EmptyEvidencePool{}, blockStore, eventBus) + blockExec := sm.NewBlockExecutor(stateStore, logger, proxyApp, mp, sm.EmptyEvidencePool{}, blockStore, eventBus, sm.NopMetrics()) block := sf.MakeBlock(state, 1, new(types.Commit)) bps, err := block.MakePartSet(testPartSize) @@ -128,7 +128,7 @@ func TestFinalizeBlockDecidedLastCommit(t *testing.T) { eventBus := eventbus.NewDefault(logger) require.NoError(t, eventBus.Start(ctx)) - blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), appClient, mp, evpool, blockStore, eventBus) + blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), appClient, mp, evpool, blockStore, eventBus, sm.NopMetrics()) state, _, lastCommit := makeAndCommitGoodBlock(ctx, t, state, 1, new(types.Commit), state.NextValidators.Validators[0].Address, blockExec, privVals, nil) for idx, isAbsent := range tc.absentCommitSigs { @@ -252,8 +252,7 @@ func TestFinalizeBlockByzantineValidators(t *testing.T) { blockStore := store.NewBlockStore(dbm.NewMemDB()) - blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), proxyApp, - mp, evpool, blockStore, eventBus) + blockExec := sm.NewBlockExecutor(stateStore, log.NewNopLogger(), proxyApp, mp, evpool, blockStore, eventBus, sm.NopMetrics()) block := sf.MakeBlock(state, 1, new(types.Commit)) block.Evidence = ev @@ -298,6 +297,7 @@ func TestProcessProposal(t *testing.T) { sm.EmptyEvidencePool{}, blockStore, eventBus, + sm.NopMetrics(), ) block0 := sf.MakeBlock(state, height-1, new(types.Commit)) @@ -515,6 +515,7 @@ func TestFinalizeBlockValidatorUpdates(t *testing.T) { sm.EmptyEvidencePool{}, blockStore, eventBus, + sm.NopMetrics(), ) updatesSub, err := eventBus.SubscribeWithArgs(ctx, pubsub.SubscribeArgs{ @@ -585,6 +586,7 @@ func TestFinalizeBlockValidatorUpdatesResultingInEmptySet(t *testing.T) { sm.EmptyEvidencePool{}, blockStore, eventBus, + sm.NopMetrics(), ) block := sf.MakeBlock(state, 1, new(types.Commit)) @@ -646,6 +648,7 @@ func TestEmptyPrepareProposal(t *testing.T) { sm.EmptyEvidencePool{}, nil, eventBus, + sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) commit := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) @@ -700,6 +703,7 @@ func TestPrepareProposalPanicOnInvalid(t *testing.T) { evpool, nil, eventBus, + sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) commit := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) @@ -757,6 +761,7 @@ func TestPrepareProposalRemoveTxs(t *testing.T) { evpool, nil, eventBus, + sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) commit := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) @@ -816,6 +821,7 @@ func TestPrepareProposalAddedTxsIncluded(t *testing.T) { evpool, nil, eventBus, + sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) commit := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) @@ -872,6 +878,7 @@ func TestPrepareProposalReorderTxs(t *testing.T) { evpool, nil, eventBus, + sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) commit := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) @@ -935,6 +942,7 @@ func TestPrepareProposalModifiedTxStatusFalse(t *testing.T) { evpool, nil, eventBus, + sm.NopMetrics(), ) pa, _ := state.Validators.GetByIndex(0) commit := makeValidCommit(ctx, t, height, types.BlockID{}, state.Validators, privVals) diff --git a/internal/state/validation_test.go b/internal/state/validation_test.go index b7b56adb8..e111ec6cc 100644 --- a/internal/state/validation_test.go +++ b/internal/state/validation_test.go @@ -63,6 +63,7 @@ func TestValidateBlockHeader(t *testing.T) { sm.EmptyEvidencePool{}, blockStore, eventBus, + sm.NopMetrics(), ) lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil) @@ -166,6 +167,7 @@ func TestValidateBlockCommit(t *testing.T) { sm.EmptyEvidencePool{}, blockStore, eventBus, + sm.NopMetrics(), ) lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil) wrongSigsCommit := types.NewCommit(1, 0, types.BlockID{}, nil) @@ -315,6 +317,7 @@ func TestValidateBlockEvidence(t *testing.T) { evpool, blockStore, eventBus, + sm.NopMetrics(), ) lastCommit := types.NewCommit(0, 0, types.BlockID{}, nil) diff --git a/node/node.go b/node/node.go index 35be24330..34350e09f 100644 --- a/node/node.go +++ b/node/node.go @@ -289,7 +289,7 @@ func makeNode( evPool, blockStore, eventBus, - sm.BlockExecutorWithMetrics(nodeMetrics.state), + nodeMetrics.state, ) // Determine whether we should do block sync. This must happen after the handshake, since the diff --git a/node/node_test.go b/node/node_test.go index e70be984f..a03d7286e 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -333,6 +333,7 @@ func TestCreateProposalBlock(t *testing.T) { evidencePool, blockStore, eventBus, + sm.NopMetrics(), ) commit := types.NewCommit(height-1, 0, types.BlockID{}, nil) @@ -412,6 +413,7 @@ func TestMaxTxsProposalBlockSize(t *testing.T) { sm.EmptyEvidencePool{}, blockStore, eventBus, + sm.NopMetrics(), ) commit := types.NewCommit(height-1, 0, types.BlockID{}, nil) @@ -487,6 +489,7 @@ func TestMaxProposalBlockSize(t *testing.T) { sm.EmptyEvidencePool{}, blockStore, eventBus, + sm.NopMetrics(), ) blockID := types.BlockID{ From a79dd42d2486628415cf1cc476f737605479ff70 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Thu, 31 Mar 2022 14:37:13 -0400 Subject: [PATCH 3/5] lint: bump linter version in ci (#8234) --- .github/workflows/lint.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e22dde8fc..fa8f153f1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,7 +1,11 @@ name: Golang Linter -# Lint runs golangci-lint over the entire Tendermint repository -# This workflow is run on every pull request and push to master -# The `golangci` job will pass without running if no *.{go, mod, sum} files have been modified. +# Lint runs golangci-lint over the entire Tendermint repository. +# +# This workflow is run on every pull request and push to master. +# +# The `golangci` job will pass without running if no *.{go, mod, sum} +# files have been modified. + on: pull_request: push: @@ -25,8 +29,10 @@ jobs: go.sum - uses: golangci/golangci-lint-action@v3.1.0 with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.44 + # Required: the version of golangci-lint is required and + # must be specified without patch version: we always use the + # latest patch version. + version: v1.45 args: --timeout 10m github-token: ${{ secrets.github_token }} if: env.GIT_DIFF From b68424be47059fe9f8528e121cb2c3880c672883 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Thu, 31 Mar 2022 14:48:26 -0400 Subject: [PATCH 4/5] light: remove untracked close channel (#8228) --- light/rpc/client.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/light/rpc/client.go b/light/rpc/client.go index f1c21c994..aedf15050 100644 --- a/light/rpc/client.go +++ b/light/rpc/client.go @@ -51,7 +51,6 @@ type Client struct { keyPathFn KeyPathFunc closers []func() - quitCh chan struct{} } var _ rpcclient.Client = (*Client)(nil) @@ -92,10 +91,9 @@ func DefaultMerkleKeyPathFn() KeyPathFunc { // NewClient returns a new client. func NewClient(logger log.Logger, next rpcclient.Client, lc LightClient, opts ...Option) *Client { c := &Client{ - next: next, - lc: lc, - prt: merkle.DefaultProofRuntime(), - quitCh: make(chan struct{}), + next: next, + lc: lc, + prt: merkle.DefaultProofRuntime(), } c.BaseService = *service.NewBaseService(logger, "Client", c) for _, o := range opts { @@ -111,10 +109,6 @@ func (c *Client) OnStart(ctx context.Context) error { return err } c.closers = append(c.closers, ncancel) - go func() { - defer close(c.quitCh) - c.Wait() - }() return nil } From 4a504c068762a868de13270ac20ad890cac2ebd4 Mon Sep 17 00:00:00 2001 From: Sergio Mena Date: Thu, 31 Mar 2022 22:21:25 +0200 Subject: [PATCH 5/5] e2e: Fix hashing for app + Fix logic of TestApp_Hash (#8229) * Fix hashing of e2e App * Fix TestApp_Hash * CaMeL * Update test/e2e/app/state.go Co-authored-by: M. J. Fromberger * for-->Eventually + if-->require * Update test/e2e/tests/app_test.go Co-authored-by: Sam Kleinman * fix lint Co-authored-by: M. J. Fromberger Co-authored-by: Sam Kleinman --- test/e2e/app/snapshots.go | 2 +- test/e2e/app/state.go | 12 ++++++++---- test/e2e/tests/app_test.go | 27 ++++++++++++++------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/test/e2e/app/snapshots.go b/test/e2e/app/snapshots.go index 65edbc3a5..61e34bd07 100644 --- a/test/e2e/app/snapshots.go +++ b/test/e2e/app/snapshots.go @@ -92,7 +92,7 @@ func (s *SnapshotStore) Create(state *State) (abci.Snapshot, error) { snapshot := abci.Snapshot{ Height: state.Height, Format: 1, - Hash: hashItems(state.Values), + Hash: hashItems(state.Values, state.Height), Chunks: byteChunks(bz), } err = os.WriteFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", state.Height)), bz, 0644) diff --git a/test/e2e/app/state.go b/test/e2e/app/state.go index e82a22539..17d8cd75f 100644 --- a/test/e2e/app/state.go +++ b/test/e2e/app/state.go @@ -3,6 +3,7 @@ package app import ( "crypto/sha256" + "encoding/binary" "encoding/json" "errors" "fmt" @@ -38,7 +39,7 @@ func NewState(dir string, persistInterval uint64) (*State, error) { previousFile: filepath.Join(dir, prevStateFileName), persistInterval: persistInterval, } - state.Hash = hashItems(state.Values) + state.Hash = hashItems(state.Values, state.Height) err := state.load() switch { case errors.Is(err, os.ErrNotExist): @@ -114,7 +115,7 @@ func (s *State) Import(height uint64, jsonBytes []byte) error { } s.Height = height s.Values = values - s.Hash = hashItems(values) + s.Hash = hashItems(values, height) return s.save() } @@ -140,7 +141,6 @@ func (s *State) Set(key, value string) { func (s *State) Commit() (uint64, []byte, error) { s.Lock() defer s.Unlock() - s.Hash = hashItems(s.Values) switch { case s.Height > 0: s.Height++ @@ -149,6 +149,7 @@ func (s *State) Commit() (uint64, []byte, error) { default: s.Height = 1 } + s.Hash = hashItems(s.Values, s.Height) if s.persistInterval > 0 && s.Height%s.persistInterval == 0 { err := s.save() if err != nil { @@ -171,7 +172,7 @@ func (s *State) Rollback() error { } // hashItems hashes a set of key/value items. -func hashItems(items map[string]string) []byte { +func hashItems(items map[string]string, height uint64) []byte { keys := make([]string, 0, len(items)) for key := range items { keys = append(keys, key) @@ -179,6 +180,9 @@ func hashItems(items map[string]string) []byte { sort.Strings(keys) hasher := sha256.New() + var b [8]byte + binary.BigEndian.PutUint64(b[:], height) + _, _ = hasher.Write(b[:]) for _, key := range keys { _, _ = hasher.Write([]byte(key)) _, _ = hasher.Write([]byte{0}) diff --git a/test/e2e/tests/app_test.go b/test/e2e/tests/app_test.go index 7234a5cde..36115346b 100644 --- a/test/e2e/tests/app_test.go +++ b/test/e2e/tests/app_test.go @@ -48,23 +48,24 @@ func TestApp_Hash(t *testing.T) { info, err := client.ABCIInfo(ctx) require.NoError(t, err) require.NotEmpty(t, info.Response.LastBlockAppHash, "expected app to return app hash") + // In next-block execution, the app hash is stored in the next block + blockHeight := info.Response.LastBlockHeight + 1 - status, err := client.Status(ctx) - require.NoError(t, err) - require.NotZero(t, status.SyncInfo.LatestBlockHeight) + require.Eventually(t, func() bool { + status, err := client.Status(ctx) + require.NoError(t, err) + require.NotZero(t, status.SyncInfo.LatestBlockHeight) + return status.SyncInfo.LatestBlockHeight >= blockHeight + }, 60*time.Second, 500*time.Millisecond) - block, err := client.Block(ctx, &info.Response.LastBlockHeight) + block, err := client.Block(ctx, &blockHeight) require.NoError(t, err) - if info.Response.LastBlockHeight == block.Block.Height { - require.Equal(t, - fmt.Sprintf("%x", info.Response.LastBlockAppHash), - fmt.Sprintf("%x", block.Block.AppHash.Bytes()), - "app hash does not match last block's app hash") - } - - require.True(t, status.SyncInfo.LatestBlockHeight >= info.Response.LastBlockHeight, - "status out of sync with application") + require.Equal(t, blockHeight, block.Block.Height) + require.Equal(t, + fmt.Sprintf("%x", info.Response.LastBlockAppHash), + fmt.Sprintf("%x", block.Block.AppHash.Bytes()), + "app hash does not match last block's app hash") }) }