Skip to content

Commit

Permalink
[cherry-picked] Fixing handling of contexts in the ABCI++ rebased bra…
Browse files Browse the repository at this point in the history
…nch (#7768)

* Fixing context

* Removed logger change

* Fixing UTs

* Bump
  • Loading branch information
sergio-mena committed Dec 22, 2022
1 parent 4255d5d commit ef9496b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
proposerAddr := lazyProposer.privValidatorPubKey.Address()

block, err := lazyProposer.blockExec.CreateProposalBlock(
lazyProposer.Height, lazyProposer.state, extCommit, proposerAddr)
ctx, lazyProposer.Height, lazyProposer.state, extCommit, proposerAddr)
require.NoError(t, err)
blockParts, err := block.MakePartSet(types.BlockPartSizeBytes)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func decideProposal(
round int32,
) (proposal *types.Proposal, block *types.Block) {
cs1.mtx.Lock()
block, err := cs1.createProposalBlock()
block, err := cs1.createProposalBlock(ctx)
require.NoError(t, err)
blockParts, err := block.MakePartSet(types.BlockPartSizeBytes)
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func setupChainWithChangingValidators(t *testing.T, name string, nBlocks int) (*
newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower)
err = assertMempool(css[0].txNotifier).CheckTx(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)
Expand Down Expand Up @@ -390,7 +390,7 @@ func setupChainWithChangingValidators(t *testing.T, name string, nBlocks int) (*
updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25)
err = assertMempool(css[0].txNotifier).CheckTx(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)
Expand Down Expand Up @@ -429,7 +429,7 @@ func setupChainWithChangingValidators(t *testing.T, name string, nBlocks int) (*
newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower)
err = assertMempool(css[0].txNotifier).CheckTx(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)
Expand Down Expand Up @@ -506,7 +506,7 @@ func setupChainWithChangingValidators(t *testing.T, name string, nBlocks int) (*
removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0)
err = assertMempool(css[0].txNotifier).CheckTx(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)
Expand Down
11 changes: 6 additions & 5 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package consensus

import (
"bytes"
"context"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -1175,7 +1176,7 @@ func (cs *State) defaultDecideProposal(height int64, round int32) {
} else {
// Create a new proposal block from state/txs from the mempool.
var err error
block, err = cs.createProposalBlock()
block, err = cs.createProposalBlock(ctx)
if err != nil {
cs.Logger.Error("unable to create proposal block", "error", err)
return
Expand Down Expand Up @@ -1240,7 +1241,7 @@ func (cs *State) isProposalComplete() bool {
//
// NOTE: keep it side-effect free for clarity.
// CONTRACT: cs.privValidator is not nil.
func (cs *State) createProposalBlock() (*types.Block, error) {
func (cs *State) createProposalBlock(ctx context.Context) (*types.Block, error) {
if cs.privValidator == nil {
return nil, errors.New("entered createProposalBlock with privValidator being nil")
}
Expand Down Expand Up @@ -1269,7 +1270,7 @@ func (cs *State) createProposalBlock() (*types.Block, error) {

proposerAddr := cs.privValidatorPubKey.Address()

ret, err := cs.blockExec.CreateProposalBlock(cs.Height, cs.state, lastExtCommit, proposerAddr)
ret, err := cs.blockExec.CreateProposalBlock(ctx, cs.Height, cs.state, lastExtCommit, proposerAddr)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -2131,7 +2132,7 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error
return false, err
}

if err = cs.blockExec.VerifyVoteExtension(vote); err != nil {
if err = cs.blockExec.VerifyVoteExtension(ctx, vote); err != nil {
return false, err
}
}
Expand Down Expand Up @@ -2313,7 +2314,7 @@ func (cs *State) signVote(
// if the signedMessage type is for a non-nil precommit, add
// VoteExtension
if extEnabled {
ext, err := cs.blockExec.ExtendVote(vote)
ext, err := cs.blockExec.ExtendVote(ctx, vote)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestStateBadProposal(t *testing.T) {
proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
voteCh := subscribe(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
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestStateOversizedBlock(t *testing.T) {
timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
voteCh := subscribe(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()
Expand Down
2 changes: 2 additions & 0 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ func TestCreateProposalBlock(t *testing.T) {

extCommit := &types.ExtendedCommit{Height: height - 1}
block, err := blockExec.CreateProposalBlock(
ctx,
height,
state,
extCommit,
Expand Down Expand Up @@ -421,6 +422,7 @@ func TestMaxProposalBlockSize(t *testing.T) {

extCommit := &types.ExtendedCommit{Height: height - 1}
block, err := blockExec.CreateProposalBlock(
ctx,
height,
state,
extCommit,
Expand Down
8 changes: 5 additions & 3 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,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,
lastExtCommit *types.ExtendedCommit,
Expand All @@ -116,7 +117,8 @@ func (blockExec *BlockExecutor) CreateProposalBlock(
txs := blockExec.mempool.ReapMaxBytesMaxGas(maxDataBytes, maxGas)
commit := lastExtCommit.ToCommit()
block := state.MakeBlock(height, txs, commit, evidence, proposerAddr)
rpp, err := blockExec.proxyApp.PrepareProposal(context.TODO(),
rpp, err := blockExec.proxyApp.PrepareProposal(
ctx,
&abci.RequestPrepareProposal{
MaxTxBytes: maxDataBytes,
Txs: block.Txs.ToSliceOfBytes(),
Expand Down Expand Up @@ -293,7 +295,7 @@ func (blockExec *BlockExecutor) ApplyBlock(
return state, nil
}

func (blockExec *BlockExecutor) ExtendVote(vote *types.Vote) ([]byte, error) {
func (blockExec *BlockExecutor) ExtendVote(ctx context.Context, vote *types.Vote) ([]byte, error) {
req := abci.RequestExtendVote{
Hash: vote.BlockID.Hash,
Height: vote.Height,
Expand All @@ -306,7 +308,7 @@ func (blockExec *BlockExecutor) ExtendVote(vote *types.Vote) ([]byte, error) {
return resp.VoteExtension, nil
}

func (blockExec *BlockExecutor) VerifyVoteExtension(vote *types.Vote) error {
func (blockExec *BlockExecutor) VerifyVoteExtension(ctx context.Context, vote *types.Vote) error {
req := abci.RequestVerifyVoteExtension{
Hash: vote.BlockID.Hash,
ValidatorAddress: vote.ValidatorAddress,
Expand Down

0 comments on commit ef9496b

Please sign in to comment.