update heightvoteset constructor for strict vs non strict

This commit is contained in:
William Banfield
2022-05-16 11:27:45 -04:00
parent bd26649455
commit c2f543bebb
3 changed files with 17 additions and 5 deletions
+5 -2
View File
@@ -845,8 +845,11 @@ func (cs *State) updateToState(state sm.State) {
cs.ValidRound = -1
cs.ValidBlock = nil
cs.ValidBlockParts = nil
requireExtensions := state.ConsensusParams.Vote.RequireExtensions(height)
cs.Votes = cstypes.NewHeightVoteSet(state.ChainID, height, validators, requireExtensions)
if state.ConsensusParams.Vote.RequireExtensions(height) {
cs.Votes = cstypes.NewStrictHeightVoteSet(state.ChainID, height, validators)
} else {
cs.Votes = cstypes.NewHeightVoteSet(state.ChainID, height, validators)
}
cs.CommitRound = -1
cs.LastValidators = state.LastValidators
cs.TriggeredTimeoutPrecommit = false
+11 -2
View File
@@ -49,10 +49,19 @@ type HeightVoteSet struct {
peerCatchupRounds map[types.NodeID][]int32 // keys: peer.ID; values: at most 2 rounds
}
func NewHeightVoteSet(chainID string, height int64, valSet *types.ValidatorSet, requireExtensions bool) *HeightVoteSet {
func NewHeightVoteSet(chainID string, height int64, valSet *types.ValidatorSet) *HeightVoteSet {
hvs := &HeightVoteSet{
chainID: chainID,
requireExtensions: requireExtensions,
requireExtensions: false,
}
hvs.Reset(height, valSet)
return hvs
}
func NewStrictHeightVoteSet(chainID string, height int64, valSet *types.ValidatorSet) *HeightVoteSet {
hvs := &HeightVoteSet{
chainID: chainID,
requireExtensions: true,
}
hvs.Reset(height, valSet)
return hvs
@@ -27,7 +27,7 @@ func TestPeerCatchupRounds(t *testing.T) {
valSet, privVals := factory.ValidatorSet(ctx, t, 10, 1)
chainID := cfg.ChainID()
hvs := NewHeightVoteSet(chainID, 1, valSet, false)
hvs := NewHeightVoteSet(chainID, 1, valSet)
vote999_0 := makeVoteHR(ctx, t, 1, 0, 999, privVals, chainID)
added, err := hvs.AddVote(vote999_0, "peer1")