From 4da0db008ac7fbe386bb286c5b5ec11ef9f62ea2 Mon Sep 17 00:00:00 2001 From: Goran Rojovic <100121253+goran-ethernal@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:47:44 +0200 Subject: [PATCH] include halt fix (#208) --- consensus/polybft/consensus_runtime.go | 5 ++ consensus/polybft/polybft.go | 22 ------ consensus/polybft/stale_sequence_check.go | 94 ----------------------- go.mod | 2 +- go.sum | 2 + 5 files changed, 8 insertions(+), 117 deletions(-) delete mode 100644 consensus/polybft/stale_sequence_check.go diff --git a/consensus/polybft/consensus_runtime.go b/consensus/polybft/consensus_runtime.go index 37838e418c..6a3488aa55 100644 --- a/consensus/polybft/consensus_runtime.go +++ b/consensus/polybft/consensus_runtime.go @@ -1005,6 +1005,11 @@ func (c *consensusRuntime) BuildCommitMessage(proposalHash []byte, view *proto.V return message } +// StartRound starts a new round with the specified view +func (c *consensusRuntime) StartRound(view *proto.View) error { + return nil +} + // BuildRoundChangeMessage builds a ROUND_CHANGE message based on the passed in proposal func (c *consensusRuntime) BuildRoundChangeMessage( proposal *proto.Proposal, diff --git a/consensus/polybft/polybft.go b/consensus/polybft/polybft.go index 3de2f1404d..d746d8c6bd 100644 --- a/consensus/polybft/polybft.go +++ b/consensus/polybft/polybft.go @@ -630,16 +630,6 @@ func (p *Polybft) startConsensusProtocol() { stopSequence func() ) - // check every block time * 1.5, so we don't artificially close a sequence - // before the actual sequence has ended properly - checkOffset := p.config.BlockTime - if checkOffset > 1 { - checkOffset /= 2 - } - - checkFrequency := time.Duration(p.config.BlockTime + checkOffset) - staleChecker := newStaleSequenceCheck(p.logger, p.blockchain.CurrentHeader, checkFrequency*time.Second) - for { latestHeader := p.blockchain.CurrentHeader() @@ -663,8 +653,6 @@ func (p *Polybft) startConsensusProtocol() { } sequenceCh, stopSequence = p.ibft.runSequence(latestHeader.Number + 1) - staleChecker.setSequence(latestHeader.Number + 1) - staleChecker.startChecking() } now := time.Now().UTC() @@ -675,26 +663,16 @@ func (p *Polybft) startConsensusProtocol() { stopSequence() p.logger.Info("canceled sequence", "sequence", latestHeader.Number+1) } - case <-staleChecker.sequenceShouldStop: - if isValidator { - stopSequence() - p.logger.Info("canceled sequence via stale checker", "sequence", latestHeader.Number+1) - } case <-sequenceCh: case <-p.closeCh: p.logger.Debug("stoping sequence", "block number", latestHeader.Number+1) if isValidator { stopSequence() - staleChecker.stopChecking() } return } - if isValidator { - staleChecker.stopChecking() - } - p.logger.Debug("time to run the sequence", "seconds", time.Since(now)) } } diff --git a/consensus/polybft/stale_sequence_check.go b/consensus/polybft/stale_sequence_check.go deleted file mode 100644 index be0b117b20..0000000000 --- a/consensus/polybft/stale_sequence_check.go +++ /dev/null @@ -1,94 +0,0 @@ -package polybft - -import ( - "sync" - "time" - - "github.com/0xPolygon/polygon-edge/types" - "github.com/hashicorp/go-hclog" -) - -type staleSequenceCheck struct { - logger hclog.Logger - currentSequence uint64 - mtx *sync.Mutex - checkFrequency time.Duration - sequenceShouldStop chan struct{} - sequenceStopping chan struct{} - stop chan struct{} - stopped chan struct{} - getHeader func() *types.Header -} - -func newStaleSequenceCheck(logger hclog.Logger, - getHeader func() *types.Header, - checkDuration time.Duration, -) *staleSequenceCheck { - return &staleSequenceCheck{ - logger: logger, - currentSequence: 0, - mtx: &sync.Mutex{}, - checkFrequency: checkDuration, - getHeader: getHeader, - } -} - -func (s *staleSequenceCheck) startChecking() { - s.sequenceShouldStop = make(chan struct{}, 1) - s.sequenceStopping = make(chan struct{}) - s.stop = make(chan struct{}) - s.stopped = make(chan struct{}) - - ticker := time.NewTicker(s.checkFrequency) - - go func() { - defer close(s.stopped) - - for { - select { - case <-s.stop: - close(s.sequenceShouldStop) - ticker.Stop() - - return - case <-s.sequenceStopping: - ticker.Stop() - case <-ticker.C: - s.checkForStaleness() - } - } - }() -} - -func (s *staleSequenceCheck) stopChecking() { - close(s.stop) - <-s.stopped -} - -func (s *staleSequenceCheck) setSequence(sequence uint64) { - s.mtx.Lock() - defer s.mtx.Unlock() - - s.currentSequence = sequence -} - -func (s *staleSequenceCheck) checkForStaleness() { - s.logger.Info("[staleSequenceCheck] checking for stale sequence") - header := s.getHeader() - s.chainHeightUpdated(header.Number) -} - -func (s *staleSequenceCheck) chainHeightUpdated(height uint64) { - s.mtx.Lock() - defer s.mtx.Unlock() - - if s.currentSequence == 0 { - return - } - - if height >= s.currentSequence { - s.logger.Info("[staleSequenceCheck] stale sequence detected", "height", height, "currentSequence", s.currentSequence) - s.sequenceShouldStop <- struct{}{} - close(s.sequenceStopping) - } -} diff --git a/go.mod b/go.mod index f9f328ca53..3554bc0466 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( cloud.google.com/go/secretmanager v1.12.0 - github.com/0xPolygon/go-ibft v0.4.1-0.20230717081138-628065cf23b6 + github.com/0xPolygon/go-ibft v0.4.1-0.20240424093031-00f7637226a6 github.com/Ethernal-Tech/blockchain-event-tracker v0.0.0-20231202204931-b886edca635a github.com/Ethernal-Tech/merkle-tree v0.0.0-20231213143318-4db9da419e04 github.com/armon/go-metrics v0.4.1 diff --git a/go.sum b/go.sum index 448c98ede9..7b569a3ea5 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/0xPolygon/go-ibft v0.4.1-0.20230717081138-628065cf23b6 h1:EL/37sEjeLmQ2RTd9xMLLOuMXY6fMV/zB8a5X0BJUMM= github.com/0xPolygon/go-ibft v0.4.1-0.20230717081138-628065cf23b6/go.mod h1:0W1BnkhtXa2K59PzTPoQvbKOnI+G6QliXIHpQWNeiAM= +github.com/0xPolygon/go-ibft v0.4.1-0.20240424093031-00f7637226a6 h1:s8YmD/yvpC2Lu3vSrb0laBThj/YCnQ1dpnVZqf4CfHo= +github.com/0xPolygon/go-ibft v0.4.1-0.20240424093031-00f7637226a6/go.mod h1:FPdz+s0jyQzW4pZK+HMnhz2b8ebsg5FaSVFTjvQi8ls= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=