state: avoid premature genericism (#8224)

This commit is contained in:
Sam Kleinman
2022-03-31 09:10:09 -04:00
committed by GitHub
parent d1722c9c10
commit 6af23ff757
13 changed files with 31 additions and 30 deletions

View File

@@ -145,6 +145,7 @@ func (rts *reactorTestSuite) addNode(
sm.EmptyEvidencePool{},
blockStore,
eventbus,
sm.NopMetrics(),
)
for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ {

View File

@@ -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

View File

@@ -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,

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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{