Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exponentialBackoffer overflowing into negative, bump protocol version #516

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions gpbft/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ func WithRebroadcastBackoff(exponent float64, base, max time.Duration) Option {
}
}

func exponentialBackoffer(exponent float64, base, max time.Duration) func(attempt int) time.Duration {
func exponentialBackoffer(exponent float64, base, maxBackoff time.Duration) func(attempt int) time.Duration {
return func(attempt int) time.Duration {
nextBackoff := time.Duration(float64(base) * math.Pow(exponent, float64(attempt)))
if nextBackoff > max {
return max
nextBackoff := float64(base) * math.Pow(exponent, float64(attempt))
if nextBackoff > float64(maxBackoff) {
return maxBackoff
}
return nextBackoff
return maxBackoff
}
}
18 changes: 18 additions & 0 deletions gpbft/options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gpbft

import (
"testing"
"time"

"github.com/stretchr/testify/require"
)

func Test_exponentialBackoffer(t *testing.T) {
maxBackoff := 30 * time.Second
backoffer := exponentialBackoffer(1.3, 3*time.Second, maxBackoff)
for i := 0; i < 10_000; i++ {
backoff := backoffer(i)
require.Positivef(t, backoff, "at %d", i)
require.LessOrEqualf(t, backoff, maxBackoff, "at %d", i)
}
}
4 changes: 2 additions & 2 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ipfs/go-datastore"
)

const VersionCapability = 1
const VersionCapability = 2

var (
DefaultCommitteeLookback uint64 = 10
Expand Down Expand Up @@ -245,7 +245,7 @@ func LocalDevnetManifest() *Manifest {
rng := make([]byte, 4)
_, _ = rand.Read(rng)
m := &Manifest{
ProtocolVersion: 1,
ProtocolVersion: VersionCapability,
NetworkName: gpbft.NetworkName(fmt.Sprintf("localnet-%X", rng)),
BootstrapEpoch: 1000,
CommitteeLookback: DefaultCommitteeLookback,
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v0.0.5"
"version": "v0.0.6"
}
Loading