Skip to content

Commit

Permalink
Fix exponentialBackoffer overflowing into negative, bump protocol ver…
Browse files Browse the repository at this point in the history
…sion (#516)

* Fix exponentialBackoffer overflowing into negative

Signed-off-by: Jakub Sztandera <[email protected]>

* Bump protocol version

Signed-off-by: Jakub Sztandera <[email protected]>

* Bump default protocol version

Signed-off-by: Jakub Sztandera <[email protected]>

* Bump version

Signed-off-by: Jakub Sztandera <[email protected]>

---------

Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu committed Jul 24, 2024
1 parent 660547c commit 41e850b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
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"
}

0 comments on commit 41e850b

Please sign in to comment.