From bcfb10bf5f29651196c0f6969e189bd3bb69f75d Mon Sep 17 00:00:00 2001 From: Anca Zamfir Date: Thu, 13 Jan 2022 16:33:59 +0100 Subject: [PATCH] Remove voteTime() (#7563) --- internal/consensus/invalid_test.go | 3 ++- internal/consensus/state.go | 26 +------------------------- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/internal/consensus/invalid_test.go b/internal/consensus/invalid_test.go index c404844a6..d6252815a 100644 --- a/internal/consensus/invalid_test.go +++ b/internal/consensus/invalid_test.go @@ -11,6 +11,7 @@ import ( "github.com/tendermint/tendermint/internal/p2p" "github.com/tendermint/tendermint/libs/bytes" tmrand "github.com/tendermint/tendermint/libs/rand" + tmtime "github.com/tendermint/tendermint/libs/time" tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" @@ -107,7 +108,7 @@ func invalidDoPrevoteFunc( ValidatorIndex: valIndex, Height: cs.Height, Round: cs.Round, - Timestamp: cs.voteTime(), + Timestamp: tmtime.Now(), Type: tmproto.PrecommitType, BlockID: types.BlockID{ Hash: blockHash, diff --git a/internal/consensus/state.go b/internal/consensus/state.go index cc636bd7c..4375350f4 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -2284,7 +2284,7 @@ func (cs *State) signVote( ValidatorIndex: valIdx, Height: cs.Height, Round: cs.Round, - Timestamp: cs.voteTime(), + Timestamp: tmtime.Now(), Type: msgType, BlockID: types.BlockID{Hash: hash, PartSetHeader: header}, } @@ -2314,30 +2314,6 @@ func (cs *State) signVote( return vote, err } -// voteTime ensures monotonicity of the time a validator votes on. -// It ensures that for a prior block with a BFT-timestamp of T, -// any vote from this validator will have time at least time T + 1ms. -// This is needed, as monotonicity of time is a guarantee that BFT time provides. -func (cs *State) voteTime() time.Time { - now := tmtime.Now() - minVoteTime := now - // Minimum time increment between blocks - const timeIota = time.Millisecond - // TODO: We should remove next line in case we don't vote for v in case cs.ProposalBlock == nil, - // even if cs.LockedBlock != nil. See https://docs.tendermint.com/master/spec/. - if cs.LockedBlock != nil { - // See the BFT time spec https://docs.tendermint.com/master/spec/consensus/bft-time.html - minVoteTime = cs.LockedBlock.Time.Add(timeIota) - } else if cs.ProposalBlock != nil { - minVoteTime = cs.ProposalBlock.Time.Add(timeIota) - } - - if now.After(minVoteTime) { - return now - } - return minVoteTime -} - // sign the vote and publish on internalMsgQueue func (cs *State) signAddVote(msgType tmproto.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote { if cs.privValidator == nil { // the node does not have a key