From c2f543bebb2cc9b3e79470217834088b580e8bf9 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Mon, 16 May 2022 11:27:45 -0400 Subject: [PATCH] update heightvoteset constructor for strict vs non strict --- internal/consensus/state.go | 7 +++++-- internal/consensus/types/height_vote_set.go | 13 +++++++++++-- internal/consensus/types/height_vote_set_test.go | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index ed04deb09..5ac54f14a 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -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 diff --git a/internal/consensus/types/height_vote_set.go b/internal/consensus/types/height_vote_set.go index 854d9b1f1..b57a3636a 100644 --- a/internal/consensus/types/height_vote_set.go +++ b/internal/consensus/types/height_vote_set.go @@ -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 diff --git a/internal/consensus/types/height_vote_set_test.go b/internal/consensus/types/height_vote_set_test.go index b21895409..acffa794c 100644 --- a/internal/consensus/types/height_vote_set_test.go +++ b/internal/consensus/types/height_vote_set_test.go @@ -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")