diff --git a/internal/consensus/byzantine_test.go b/internal/consensus/byzantine_test.go index 217fca1af..81813e948 100644 --- a/internal/consensus/byzantine_test.go +++ b/internal/consensus/byzantine_test.go @@ -205,7 +205,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { proposerAddr := lazyNodeState.privValidatorPubKey.Address() block, blockParts, err := lazyNodeState.blockExec.CreateProposalBlock( - lazyNodeState.Height, lazyNodeState.state, commit, proposerAddr, + ctx, lazyNodeState.Height, lazyNodeState.state, commit, proposerAddr, ) require.NoError(t, err) diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index 72a6bb1a5..2ec3dda9a 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -240,7 +240,7 @@ func decideProposal( t.Helper() cs1.mtx.Lock() - block, blockParts, err := cs1.createProposalBlock() + block, blockParts, err := cs1.createProposalBlock(ctx) require.NoError(t, err) validRound := cs1.ValidRound chainID := cs1.state.ChainID diff --git a/internal/consensus/pbts_test.go b/internal/consensus/pbts_test.go index cc1e3babf..f99ec7e39 100644 --- a/internal/consensus/pbts_test.go +++ b/internal/consensus/pbts_test.go @@ -203,7 +203,7 @@ func (p *pbtsTestHarness) nextHeight(ctx context.Context, t *testing.T, proposer ensureNewRound(t, p.roundCh, p.currentHeight, p.currentRound) - b, _, err := p.observedState.createProposalBlock() + b, _, err := p.observedState.createProposalBlock(ctx) require.NoError(t, err) b.Height = p.currentHeight b.Header.Height = p.currentHeight diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index 566aa8bff..48be064e8 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -383,7 +383,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower) err = assertMempool(t, css[0].txNotifier).CheckTx(ctx, newValidatorTx1, nil, mempool.TxInfo{}) assert.NoError(t, err) - propBlock, _, err := css[0].createProposalBlock() // changeProposer(t, cs1, vs2) + propBlock, _, err := css[0].createProposalBlock(ctx) // changeProposer(t, cs1, vs2) require.NoError(t, err) propBlockParts, err := propBlock.MakePartSet(partSize) require.NoError(t, err) @@ -417,7 +417,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25) err = assertMempool(t, css[0].txNotifier).CheckTx(ctx, updateValidatorTx1, nil, mempool.TxInfo{}) assert.NoError(t, err) - propBlock, _, err = css[0].createProposalBlock() // changeProposer(t, cs1, vs2) + propBlock, _, err = css[0].createProposalBlock(ctx) // changeProposer(t, cs1, vs2) require.NoError(t, err) propBlockParts, err = propBlock.MakePartSet(partSize) require.NoError(t, err) @@ -458,7 +458,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower) err = assertMempool(t, css[0].txNotifier).CheckTx(ctx, newValidatorTx3, nil, mempool.TxInfo{}) assert.NoError(t, err) - propBlock, _, err = css[0].createProposalBlock() // changeProposer(t, cs1, vs2) + propBlock, _, err = css[0].createProposalBlock(ctx) // changeProposer(t, cs1, vs2) require.NoError(t, err) propBlockParts, err = propBlock.MakePartSet(partSize) require.NoError(t, err) @@ -546,7 +546,7 @@ func setupSimulator(ctx context.Context, t *testing.T) *simulatorTestSuite { removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0) err = assertMempool(t, css[0].txNotifier).CheckTx(ctx, removeValidatorTx3, nil, mempool.TxInfo{}) assert.NoError(t, err) - propBlock, _, err = css[0].createProposalBlock() // changeProposer(t, cs1, vs2) + propBlock, _, err = css[0].createProposalBlock(ctx) // changeProposer(t, cs1, vs2) require.NoError(t, err) propBlockParts, err = propBlock.MakePartSet(partSize) require.NoError(t, err) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index b66156aa1..4772b23d5 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -1268,7 +1268,7 @@ func (cs *State) defaultDecideProposal(ctx context.Context, height int64, round } else { // Create a new proposal block from state/txs from the mempool. var err error - block, blockParts, err = cs.createProposalBlock() + block, blockParts, err = cs.createProposalBlock(ctx) if block == nil || err != nil { return } @@ -1328,7 +1328,7 @@ func (cs *State) isProposalComplete() bool { // // NOTE: keep it side-effect free for clarity. // CONTRACT: cs.privValidator is not nil. -func (cs *State) createProposalBlock() (block *types.Block, blockParts *types.PartSet, err error) { +func (cs *State) createProposalBlock(ctx context.Context) (block *types.Block, blockParts *types.PartSet, err error) { if cs.privValidator == nil { return nil, nil, errors.New("entered createProposalBlock with privValidator being nil") } @@ -1358,7 +1358,7 @@ func (cs *State) createProposalBlock() (block *types.Block, blockParts *types.Pa proposerAddr := cs.privValidatorPubKey.Address() - return cs.blockExec.CreateProposalBlock(cs.Height, cs.state, commit, proposerAddr) + return cs.blockExec.CreateProposalBlock(ctx, cs.Height, cs.state, commit, proposerAddr) } // Enter: `timeoutPropose` after entering Propose. @@ -2235,7 +2235,7 @@ func (cs *State) addVote( // Verify VoteExtension if precommit if vote.Type == tmproto.PrecommitType { - if err = cs.blockExec.VerifyVoteExtension(vote); err != nil { + if err = cs.blockExec.VerifyVoteExtension(ctx, vote); err != nil { return false, err } } @@ -2385,7 +2385,7 @@ func (cs *State) signVote( case tmproto.PrecommitType: timeout = cs.config.TimeoutPrecommit // if the signedMessage type is for a precommit, add VoteExtension - ext, err := cs.blockExec.ExtendVote(vote) + ext, err := cs.blockExec.ExtendVote(ctx, vote) if err != nil { return nil, err } diff --git a/internal/consensus/state_test.go b/internal/consensus/state_test.go index 78f2ad0a5..77573a484 100644 --- a/internal/consensus/state_test.go +++ b/internal/consensus/state_test.go @@ -221,7 +221,7 @@ func TestStateBadProposal(t *testing.T) { proposalCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryCompleteProposal) voteCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryVote) - propBlock, _, err := cs1.createProposalBlock() // changeProposer(t, cs1, vs2) + propBlock, _, err := cs1.createProposalBlock(ctx) // changeProposer(t, cs1, vs2) require.NoError(t, err) // make the second validator the proposer by incrementing round @@ -284,7 +284,7 @@ func TestStateOversizedBlock(t *testing.T) { timeoutProposeCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryTimeoutPropose) voteCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryVote) - propBlock, _, err := cs1.createProposalBlock() + propBlock, _, err := cs1.createProposalBlock(ctx) require.NoError(t, err) propBlock.Data.Txs = []types.Tx{tmrand.Bytes(2001)} propBlock.Header.DataHash = propBlock.Data.Hash() @@ -2535,7 +2535,7 @@ func TestStateTimestamp_ProposalNotMatch(t *testing.T) { addr := pv1.Address() voteCh := subscribeToVoter(ctx, t, cs1, addr) - propBlock, _, err := cs1.createProposalBlock() + propBlock, _, err := cs1.createProposalBlock(ctx) require.NoError(t, err) round++ incrementRound(vss[1:]...) @@ -2584,7 +2584,7 @@ func TestStateTimestamp_ProposalMatch(t *testing.T) { addr := pv1.Address() voteCh := subscribeToVoter(ctx, t, cs1, addr) - propBlock, _, err := cs1.createProposalBlock() + propBlock, _, err := cs1.createProposalBlock(ctx) require.NoError(t, err) round++ incrementRound(vss[1:]...) diff --git a/internal/state/execution.go b/internal/state/execution.go index 01922266c..5cd0c718b 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -102,6 +102,7 @@ func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher) // // Contract: application will not return more bytes than are sent over the wire. func (blockExec *BlockExecutor) CreateProposalBlock( + ctx context.Context, height int64, state State, commit *types.Commit, proposerAddr []byte, @@ -118,7 +119,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock( txs := blockExec.mempool.ReapMaxBytesMaxGas(maxDataBytes, maxGas) preparedProposal, err := blockExec.proxyApp.PrepareProposal( - context.Background(), + ctx, abci.RequestPrepareProposal{BlockData: txs.ToSliceOfBytes(), BlockDataSize: maxDataBytes}, ) if err != nil { @@ -260,8 +261,7 @@ func (blockExec *BlockExecutor) ApplyBlock( return state, nil } -func (blockExec *BlockExecutor) ExtendVote(vote *types.Vote) (types.VoteExtension, error) { - ctx := context.Background() +func (blockExec *BlockExecutor) ExtendVote(ctx context.Context, vote *types.Vote) (types.VoteExtension, error) { req := abci.RequestExtendVote{ Vote: vote.ToProto(), } @@ -274,8 +274,7 @@ func (blockExec *BlockExecutor) ExtendVote(vote *types.Vote) (types.VoteExtensio return types.VoteExtensionFromProto(resp.VoteExtension), nil } -func (blockExec *BlockExecutor) VerifyVoteExtension(vote *types.Vote) error { - ctx := context.Background() +func (blockExec *BlockExecutor) VerifyVoteExtension(ctx context.Context, vote *types.Vote) error { req := abci.RequestVerifyVoteExtension{ Vote: vote.ToProto(), } diff --git a/node/node_test.go b/node/node_test.go index 99ea4aa50..514fab1e6 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -336,6 +336,7 @@ func TestCreateProposalBlock(t *testing.T) { commit := types.NewCommit(height-1, 0, types.BlockID{}, nil) block, _, err := blockExec.CreateProposalBlock( + ctx, height, state, commit, proposerAddr, @@ -410,6 +411,7 @@ func TestMaxTxsProposalBlockSize(t *testing.T) { commit := types.NewCommit(height-1, 0, types.BlockID{}, nil) block, _, err := blockExec.CreateProposalBlock( + ctx, height, state, commit, proposerAddr, @@ -520,6 +522,7 @@ func TestMaxProposalBlockSize(t *testing.T) { } block, partSet, err := blockExec.CreateProposalBlock( + ctx, math.MaxInt64, state, commit, proposerAddr,