From 589d4030ce5a1067cfc76c948461db9474ae93de Mon Sep 17 00:00:00 2001 From: William Banfield Date: Mon, 16 May 2022 16:46:17 -0400 Subject: [PATCH] rename vote extension param --- internal/blocksync/reactor.go | 2 +- internal/consensus/reactor_test.go | 2 +- internal/consensus/state.go | 14 +++++++------- internal/consensus/state_test.go | 2 +- internal/state/execution.go | 6 +++--- types/params.go | 25 +++++++++++++------------ types/vote_set_test.go | 4 ++-- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/internal/blocksync/reactor.go b/internal/blocksync/reactor.go index 1902780d6..dda48fb5b 100644 --- a/internal/blocksync/reactor.go +++ b/internal/blocksync/reactor.go @@ -557,7 +557,7 @@ func (r *Reactor) poolRoutine(ctx context.Context, stateSynced bool, blockSyncCh // validate the block before we persist it err = r.blockExec.ValidateBlock(ctx, state, first) } - if err == nil && state.ConsensusParams.Vote.RequireExtensions(extCommit.Height) { + if err == nil && state.ConsensusParams.ABCI.VoteExtensionsEnabled(extCommit.Height) { // if vote extensions were required at this height, ensure they exist. err = extCommit.EnsureExtensions() } diff --git a/internal/consensus/reactor_test.go b/internal/consensus/reactor_test.go index aadc0c811..55b62589f 100644 --- a/internal/consensus/reactor_test.go +++ b/internal/consensus/reactor_test.go @@ -656,7 +656,7 @@ func TestSwitchToConsensusVoteExtensions(t *testing.T) { cs.state.LastBlockHeight = testCase.storedHeight cs.state.LastValidators = cs.state.Validators.Copy() - cs.state.ConsensusParams.Vote.ExtensionRequireHeight = testCase.initialRequiredHeight + cs.state.ConsensusParams.ABCI.VoteExtensionsEnableHeight = testCase.initialRequiredHeight propBlock, err := cs.createProposalBlock(ctx) require.NoError(t, err) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index 9a35f911a..bdb15d77e 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -697,13 +697,13 @@ func (cs *State) sendInternalMessage(ctx context.Context, mi msgInfo) { // the method will panic on an absent ExtendedCommit or an ExtendedCommit without // extension data. func (cs *State) reconstructLastCommit(state sm.State) { - requireExtensions := cs.state.ConsensusParams.Vote.RequireExtensions(state.LastBlockHeight) - votes, err := cs.votesFromExtendedCommit(state, requireExtensions) + extensionsEnabled := cs.state.ConsensusParams.ABCI.VoteExtensionsEnabled(state.LastBlockHeight) + votes, err := cs.votesFromExtendedCommit(state, extensionsEnabled) if err == nil { cs.LastCommit = votes return } - if requireExtensions { + if extensionsEnabled { panic(fmt.Sprintf("failed to reconstruct last commit; %s", err)) } votes, err = cs.votesFromSeenCommit(state) @@ -713,13 +713,13 @@ func (cs *State) reconstructLastCommit(state sm.State) { cs.LastCommit = votes } -func (cs *State) votesFromExtendedCommit(state sm.State, requireExtensions bool) (*types.VoteSet, error) { +func (cs *State) votesFromExtendedCommit(state sm.State, extensionsEnabled bool) (*types.VoteSet, error) { ec := cs.blockStore.LoadBlockExtendedCommit(state.LastBlockHeight) if ec == nil { return nil, fmt.Errorf("commit for height %v not found", state.LastBlockHeight) } var vs *types.VoteSet - if requireExtensions { + if extensionsEnabled { vs = ec.ToStrictVoteSet(state.ChainID, state.LastValidators) } else { vs = ec.ToVoteSet(state.ChainID, state.LastValidators) @@ -845,7 +845,7 @@ func (cs *State) updateToState(state sm.State) { cs.ValidRound = -1 cs.ValidBlock = nil cs.ValidBlockParts = nil - if state.ConsensusParams.Vote.RequireExtensions(height) { + if state.ConsensusParams.ABCI.VoteExtensionsEnabled(height) { cs.Votes = cstypes.NewStrictHeightVoteSet(state.ChainID, height, validators) } else { cs.Votes = cstypes.NewHeightVoteSet(state.ChainID, height, validators) @@ -2402,7 +2402,7 @@ func (cs *State) addVote( cs.metrics.MarkVoteExtensionReceived(err == nil) } else if !errors.Is(err, types.ErrVoteExtensionAbsent) { return false, err - } else if cs.state.ConsensusParams.Vote.RequireExtensions(cs.Height) { + } else if cs.state.ConsensusParams.ABCI.VoteExtensionsEnabled(cs.Height) { return false, err } } diff --git a/internal/consensus/state_test.go b/internal/consensus/state_test.go index eea671a58..fa1a88a8e 100644 --- a/internal/consensus/state_test.go +++ b/internal/consensus/state_test.go @@ -2314,7 +2314,7 @@ func TestVoteExtensionRequiredHeight(t *testing.T) { m.On("FinalizeBlock", mock.Anything, mock.Anything).Return(&abci.ResponseFinalizeBlock{}, nil).Maybe() m.On("Commit", mock.Anything).Return(&abci.ResponseCommit{}, nil).Maybe() cs1, vss := makeState(ctx, t, makeStateArgs{config: config, application: m, validators: numValidators}) - cs1.state.ConsensusParams.Vote.ExtensionRequireHeight = testCase.initialRequiredHeight + cs1.state.ConsensusParams.ABCI.VoteExtensionsEnableHeight = testCase.initialRequiredHeight height, round := cs1.Height, cs1.Round timeoutCh := subscribe(ctx, t, cs1.eventBus, types.EventQueryTimeoutPropose) diff --git a/internal/state/execution.go b/internal/state/execution.go index 68de931db..0aae93b94 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -108,7 +108,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock( &abci.RequestPrepareProposal{ MaxTxBytes: maxDataBytes, Txs: block.Txs.ToSliceOfBytes(), - LocalLastCommit: buildExtendedCommitInfo(lastExtCommit, blockExec.store, state.InitialHeight, state.ConsensusParams.Vote), + LocalLastCommit: buildExtendedCommitInfo(lastExtCommit, blockExec.store, state.InitialHeight, state.ConsensusParams.ABCI), ByzantineValidators: block.Evidence.ToABCI(), Height: block.Height, Time: block.Time, @@ -428,7 +428,7 @@ func buildLastCommitInfo(block *types.Block, store Store, initialHeight int64) a // data, it returns an empty record. // // Assumes that the commit signatures are sorted according to validator index. -func buildExtendedCommitInfo(ec *types.ExtendedCommit, store Store, initialHeight int64, vp types.VoteParams) abci.ExtendedCommitInfo { +func buildExtendedCommitInfo(ec *types.ExtendedCommit, store Store, initialHeight int64, ap types.ABCIParams) abci.ExtendedCommitInfo { if ec.Height < initialHeight { // There are no extended commits for heights below the initial height. return abci.ExtendedCommitInfo{} @@ -466,7 +466,7 @@ func buildExtendedCommitInfo(ec *types.ExtendedCommit, store Store, initialHeigh } var ext []byte - if err := ecs.EnsureExtension(); err != nil && vp.RequireExtensions(ec.Height) { + if err := ecs.EnsureExtension(); err != nil && ap.VoteExtensionsEnabled(ec.Height) { panic(fmt.Errorf("commit at height %d received with missing vote extensions data", ec.Height)) } diff --git a/types/params.go b/types/params.go index ef14db605..2a37e8666 100644 --- a/types/params.go +++ b/types/params.go @@ -43,7 +43,7 @@ type ConsensusParams struct { Version VersionParams `json:"version"` Synchrony SynchronyParams `json:"synchrony"` Timeout TimeoutParams `json:"timeout"` - Vote VoteParams `json:"vote"` + ABCI ABCIParams `json:"vote"` } // HashedParams is a subset of ConsensusParams. @@ -97,18 +97,19 @@ type TimeoutParams struct { BypassCommitTimeout bool `json:"bypass_commit_timeout"` } -// VoteParams configure validity rules of the votes within Tendermint consensus. -type VoteParams struct { - ExtensionRequireHeight int64 `json:"extension_require_height"` +// ABCIParams configure ABCI functionality specific to the Application Blockchain +// Interface. +type ABCIParams struct { + VoteExtensionsEnableHeight int64 `json:"vote_extensions_enable_height"` } -// RequireExtensions returns true if vote extensions are required at height h +// VoteExtensionsEnabled returns true if vote extensions are enabled at height h // and false otherwise. -func (v VoteParams) RequireExtensions(h int64) bool { - if v.ExtensionRequireHeight == 0 { +func (a ABCIParams) VoteExtensionsEnabled(h int64) bool { + if a.VoteExtensionsEnableHeight == 0 { return false } - return v.ExtensionRequireHeight <= h + return a.VoteExtensionsEnableHeight <= h } // DefaultConsensusParams returns a default ConsensusParams. @@ -120,7 +121,7 @@ func DefaultConsensusParams() *ConsensusParams { Version: DefaultVersionParams(), Synchrony: DefaultSynchronyParams(), Timeout: DefaultTimeoutParams(), - Vote: DefaultVoteParams(), + ABCI: DefaultABCIParams(), } } @@ -192,10 +193,10 @@ func DefaultTimeoutParams() TimeoutParams { } } -func DefaultVoteParams() VoteParams { - return VoteParams{ +func DefaultABCIParams() ABCIParams { + return ABCIParams{ // When set to 0, vote extensions are not required. - ExtensionRequireHeight: 0, + VoteExtensionsEnableHeight: 0, } } diff --git a/types/vote_set_test.go b/types/vote_set_test.go index 69c7f9d9c..58832cc04 100644 --- a/types/vote_set_test.go +++ b/types/vote_set_test.go @@ -498,9 +498,9 @@ func TestVoteSet_MakeCommit(t *testing.T) { } } -// TestVoteSet_RequireExtensions tests that the vote set correctly validates +// TestVoteSet_VoteExtensionsEnabled tests that the vote set correctly validates // vote extensions data when either required or not required. -func TestVoteSet_RequireExtensions(t *testing.T) { +func TestVoteSet_VoteExtensionsEnabled(t *testing.T) { for _, tc := range []struct { name string requireExtensions bool