Skip to content

Commit

Permalink
Set round 0 timeout as twice the block time in case block time is gre…
Browse files Browse the repository at this point in the history
…ater than default round 0 timeout
  • Loading branch information
Stefan-Ethernal committed Apr 22, 2024
1 parent 56f8e49 commit 91bfd76
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion consensus/polybft/ibft_consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ func (c *IBFTConsensusWrapper) runSequence(height uint64) (<-chan struct{}, func
return sequenceDone, func() {
// stopSequence terminates the running IBFT sequence gracefully and waits for it to return
cancelSequence()
<-sequenceDone // waits until c.IBFT.RunSequenc routine finishes
<-sequenceDone // waits until c.IBFT.RunSequence routine finishes
}
}
15 changes: 12 additions & 3 deletions consensus/polybft/polybft.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"time"

"github.com/0xPolygon/go-ibft/core"
"github.com/hashicorp/go-hclog"
bolt "go.etcd.io/bbolt"

Expand All @@ -29,9 +30,10 @@ import (
)

const (
minSyncPeers = 2
pbftProto = "/pbft/0.2"
bridgeProto = "/bridge/0.2"
minSyncPeers = 2
pbftProto = "/pbft/0.2"
bridgeProto = "/bridge/0.2"
baseRoundTimeoutScaleFactor = 2
)

// polybftBackend is an interface defining polybft methods needed by fsm and sync tracker
Expand Down Expand Up @@ -496,6 +498,13 @@ func (p *Polybft) Initialize() error {
}

p.ibft = newIBFTConsensusWrapper(p.logger, p.runtime, p)
// if block time is greater than default base round timeout,
// set base round timeout as twice the block time
blockTime := time.Duration(int64(p.config.BlockTime)) * time.Second
if blockTime >= core.DefaultBaseRoundTimeout {
baseRoundTimeout := int64(blockTime.Seconds() * baseRoundTimeoutScaleFactor)
p.ibft.SetBaseRoundTimeout(time.Duration(baseRoundTimeout) * time.Second)
}

if err = p.subscribeToIbftTopic(); err != nil {
return fmt.Errorf("IBFT topic subscription failed: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240422083054-5a229e5ab009
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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240422083054-5a229e5ab009 h1:Iol+EoVz4N+M/bv0pnLlMcwKWS/RHQqjThKcSX2xHw4=
github.com/0xPolygon/go-ibft v0.4.1-0.20240422083054-5a229e5ab009/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=
Expand Down

0 comments on commit 91bfd76

Please sign in to comment.