mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-19 21:56:22 +00:00
rename vote extension param
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
+13
-12
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user