Skip to content

Commit

Permalink
Fixing handling of contexts in the ABCI++ rebased branch (tendermint#…
Browse files Browse the repository at this point in the history
…7768)

* Fixing context

* Removed logger change

* Fixing UTs

* Bump
  • Loading branch information
sergio-mena authored and tychoish committed Feb 4, 2022
1 parent a11a7c0 commit b55d74d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/pbts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions internal/consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:]...)
Expand Down Expand Up @@ -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:]...)
Expand Down
9 changes: 4 additions & 5 deletions internal/state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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(),
}
Expand Down
3 changes: 3 additions & 0 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -520,6 +522,7 @@ func TestMaxProposalBlockSize(t *testing.T) {
}

block, partSet, err := blockExec.CreateProposalBlock(
ctx,
math.MaxInt64,
state, commit,
proposerAddr,
Expand Down

0 comments on commit b55d74d

Please sign in to comment.