update the VoteSet methods to only validate extensions when enabled

This commit is contained in:
William Banfield
2022-05-16 19:08:34 -04:00
parent 78c0c9c6ce
commit 44f1f045e2
7 changed files with 29 additions and 24 deletions
+1 -1
View File
@@ -669,7 +669,7 @@ func TestSwitchToConsensusVoteExtensions(t *testing.T) {
var voteSet *types.VoteSet
if testCase.includeExtensions {
voteSet = types.NewStrictVoteSet(cs.state.ChainID, testCase.storedHeight, 0, tmproto.PrecommitType, cs.state.Validators)
voteSet = types.NewExtendedVoteSet(cs.state.ChainID, testCase.storedHeight, 0, tmproto.PrecommitType, cs.state.Validators)
} else {
voteSet = types.NewVoteSet(cs.state.ChainID, testCase.storedHeight, 0, tmproto.PrecommitType, cs.state.Validators)
}
+3 -3
View File
@@ -704,7 +704,7 @@ func (cs *State) reconstructLastCommit(state sm.State) {
return
}
if extensionsEnabled {
panic(fmt.Sprintf("failed to reconstruct last commit; %s", err))
panic(fmt.Sprintf("failed to reconstruct last extended commit; %s", err))
}
votes, err = cs.votesFromSeenCommit(state)
if err != nil {
@@ -720,7 +720,7 @@ func (cs *State) votesFromExtendedCommit(state sm.State, extensionsEnabled bool)
}
var vs *types.VoteSet
if extensionsEnabled {
vs = ec.ToStrictVoteSet(state.ChainID, state.LastValidators)
vs = ec.ToExtendedVoteSet(state.ChainID, state.LastValidators)
} else {
vs = ec.ToVoteSet(state.ChainID, state.LastValidators)
}
@@ -846,7 +846,7 @@ func (cs *State) updateToState(state sm.State) {
cs.ValidBlock = nil
cs.ValidBlockParts = nil
if state.ConsensusParams.ABCI.VoteExtensionsEnabled(height) {
cs.Votes = cstypes.NewStrictHeightVoteSet(state.ChainID, height, validators)
cs.Votes = cstypes.NewExtendedHeightVoteSet(state.ChainID, height, validators)
} else {
cs.Votes = cstypes.NewHeightVoteSet(state.ChainID, height, validators)
}
+6 -6
View File
@@ -41,7 +41,7 @@ type HeightVoteSet struct {
chainID string
height int64
valSet *types.ValidatorSet
requireExtensions bool
extensionsEnabled bool
mtx sync.Mutex
round int32 // max tracked round
@@ -52,16 +52,16 @@ type HeightVoteSet struct {
func NewHeightVoteSet(chainID string, height int64, valSet *types.ValidatorSet) *HeightVoteSet {
hvs := &HeightVoteSet{
chainID: chainID,
requireExtensions: false,
extensionsEnabled: false,
}
hvs.Reset(height, valSet)
return hvs
}
func NewStrictHeightVoteSet(chainID string, height int64, valSet *types.ValidatorSet) *HeightVoteSet {
func NewExtendedHeightVoteSet(chainID string, height int64, valSet *types.ValidatorSet) *HeightVoteSet {
hvs := &HeightVoteSet{
chainID: chainID,
requireExtensions: true,
extensionsEnabled: true,
}
hvs.Reset(height, valSet)
return hvs
@@ -120,8 +120,8 @@ func (hvs *HeightVoteSet) addRound(round int32) {
// log.Debug("addRound(round)", "round", round)
prevotes := types.NewVoteSet(hvs.chainID, hvs.height, round, tmproto.PrevoteType, hvs.valSet)
var precommits *types.VoteSet
if hvs.requireExtensions {
precommits = types.NewStrictVoteSet(hvs.chainID, hvs.height, round, tmproto.PrecommitType, hvs.valSet)
if hvs.extensionsEnabled {
precommits = types.NewExtendedVoteSet(hvs.chainID, hvs.height, round, tmproto.PrecommitType, hvs.valSet)
} else {
precommits = types.NewVoteSet(hvs.chainID, hvs.height, round, tmproto.PrecommitType, hvs.valSet)
}