From eec438ac97f87411b64a06ac0ff785c68e464236 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Thu, 12 May 2022 14:48:23 -0400 Subject: [PATCH] fix require condition to be correct --- internal/consensus/state.go | 2 +- internal/consensus/state_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index a1f09cd68..4b24ae13c 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -2764,7 +2764,7 @@ func (cs *State) calculateProposalTimestampDifferenceMetric() { func (cs *State) requireVoteExtension() bool { requireHeight := cs.state.ConsensusParams.Vote.ExtensionRequireHeight - if requireHeight < cs.Height { + if requireHeight == 0 || cs.Height < requireHeight { return false } return true diff --git a/internal/consensus/state_test.go b/internal/consensus/state_test.go index fd01dad35..36be9a04e 100644 --- a/internal/consensus/state_test.go +++ b/internal/consensus/state_test.go @@ -2260,6 +2260,9 @@ func TestPrepareProposalReceivesVoteExtensions(t *testing.T) { } } +// TestVoteExtensionRequiredHeight tests that 'ExtensionRequireHeight' correctly +// enforces that vote extensions be present in consensus for heights greater than +// or equal to the configured value. func TestVoteExtensionRequiredHeight(t *testing.T) { for _, testCase := range []struct { name string @@ -2291,6 +2294,12 @@ func TestVoteExtensionRequiredHeight(t *testing.T) { initialRequiredHeight: 1, expectSuccessfulRound: false, }, + { + name: "extension absent but required in future height", + hasExtension: false, + initialRequiredHeight: 2, + expectSuccessfulRound: true, + }, } { t.Run(testCase.name, func(t *testing.T) { config := configSetup(t)