From dd98161894f1dee51a8f397350f7ab2938489de9 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Fri, 11 Mar 2022 13:02:27 -0500 Subject: [PATCH] thread vote information through for future use by vote extensions --- internal/consensus/byzantine_test.go | 2 +- internal/consensus/state.go | 2 +- internal/state/execution.go | 7 ++++--- node/node_test.go | 3 +++ types/vote_set.go | 3 +++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/consensus/byzantine_test.go b/internal/consensus/byzantine_test.go index 17b76b9dc..bb2f360a0 100644 --- a/internal/consensus/byzantine_test.go +++ b/internal/consensus/byzantine_test.go @@ -201,7 +201,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { proposerAddr := lazyNodeState.privValidatorPubKey.Address() block, err := lazyNodeState.blockExec.CreateProposalBlock( - ctx, lazyNodeState.Height, lazyNodeState.state, commit, proposerAddr) + ctx, lazyNodeState.Height, lazyNodeState.state, commit, proposerAddr, nil) require.NoError(t, err) blockParts, err := block.MakePartSet(types.BlockPartSizeBytes) require.NoError(t, err) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index e636e8013..10d9f5378 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -1391,7 +1391,7 @@ func (cs *State) createProposalBlock(ctx context.Context) (block *types.Block, e proposerAddr := cs.privValidatorPubKey.Address() - return cs.blockExec.CreateProposalBlock(ctx, cs.Height, cs.state, commit, proposerAddr) + return cs.blockExec.CreateProposalBlock(ctx, cs.Height, cs.state, commit, proposerAddr, cs.LastCommit.GetVotes()) } // Enter: `timeoutPropose` after entering Propose. diff --git a/internal/state/execution.go b/internal/state/execution.go index d50ab6044..04a199170 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -103,6 +103,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock( state State, commit *types.Commit, proposerAddr []byte, + votes []*types.Vote, ) (*types.Block, error) { maxBytes := state.ConsensusParams.Block.MaxBytes @@ -123,7 +124,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock( Hash: block.Hash(), Header: *block.Header.ToProto(), Txs: block.Txs.ToSliceOfBytes(), - LocalLastCommit: extendedCommitInfo(localLastCommit), + LocalLastCommit: extendedCommitInfo(localLastCommit, votes), ByzantineValidators: block.Evidence.ToABCI(), MaxTxBytes: maxDataBytes, }, @@ -428,14 +429,14 @@ func buildLastCommitInfo(block *types.Block, store Store, initialHeight int64) a } } -func extendedCommitInfo(c abci.CommitInfo) abci.ExtendedCommitInfo { +func extendedCommitInfo(c abci.CommitInfo, votes []*types.Vote) abci.ExtendedCommitInfo { vs := make([]abci.ExtendedVoteInfo, len(c.Votes)) for i := range vs { vs[i] = abci.ExtendedVoteInfo{ Validator: c.Votes[i].Validator, SignedLastBlock: c.Votes[i].SignedLastBlock, /* - TODO: Include vote extensions information when implementing vote extension is complete. + TODO: Include vote extensions information when implementing vote extensions. VoteExtension: []byte{}, */ } diff --git a/node/node_test.go b/node/node_test.go index 698e8d70a..eeeb01008 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -341,6 +341,7 @@ func TestCreateProposalBlock(t *testing.T) { height, state, commit, proposerAddr, + nil, ) require.NoError(t, err) @@ -419,6 +420,7 @@ func TestMaxTxsProposalBlockSize(t *testing.T) { height, state, commit, proposerAddr, + nil, ) require.NoError(t, err) @@ -533,6 +535,7 @@ func TestMaxProposalBlockSize(t *testing.T) { math.MaxInt64, state, commit, proposerAddr, + nil, ) require.NoError(t, err) partSet, err := block.MakePartSet(types.BlockPartSizeBytes) diff --git a/types/vote_set.go b/types/vote_set.go index bb675e110..438d089b3 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -227,6 +227,9 @@ func (voteSet *VoteSet) getVote(valIndex int32, blockKey string) (vote *Vote, ok } func (voteSet *VoteSet) GetVotes() []*Vote { + if voteSet == nil { + return nil + } return voteSet.votes }