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{