Skip to content

Commit

Permalink
Revert changes to EC backoff introduced in #382 (#399)
Browse files Browse the repository at this point in the history
* Revert the ECPeriod changes (#382)

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

* Revert changes to EC backoff introduced in #382

Additionally move backoff params to manifest

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

* Fix manifest in tests

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

* Change max backoff to 15min

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

---------

Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu authored Jul 4, 2024
1 parent 2834f11 commit ab0e2ed
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
36 changes: 15 additions & 21 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,36 +320,29 @@ func (h *gpbftHost) ReceiveDecision(decision *gpbft.Justification) time.Time {
h.log.Infof("got decision at instance %d, finalized head at epoch: %d",
decision.Vote.Instance, decision.Vote.Value.Head().Epoch)
err := h.saveDecision(decision)

manifest := h.manifest.Manifest()
ecDelay := time.Duration(manifest.ECDelayMultiplier * float64(manifest.ECPeriod))

if err != nil {
h.log.Errorf("error while saving decision: %+v", err)
}
ts, err := h.client.ec.GetTipset(h.runningCtx, decision.Vote.Value.Head().Key)
if err != nil {
// this should not happen
h.log.Errorf("could not get timestamp of just finalized tipset: %+v", err)
// We use the period, not the delay, because we expect to start an instance once per
// period and we just finished the last instance.
return time.Now().Add(h.manifest.Manifest().ECPeriod)
return time.Now().Add(ecDelay)
}

if decision.Vote.Value.HasSuffix() {
// we decided on something new, use just the ECDelay plus the period.
return ts.Timestamp().Add(h.manifest.Manifest().ECPeriod + h.manifest.Manifest().ECDelay)
// we decided on something new, the tipset that got finalized can at minimum be 30-60s old.
return ts.Timestamp().Add(ecDelay)
}

// we decided on base, calculate how much we should back off
// all of this should go into manifest but I think Alfonso dislikes me already :P
const (
minBackoff = 2.
maxBackoff = 20. // 10m with 30s ECPeriod
)
// the backoff is defined in multiples of ECPeriod starting at the last finalized tipset
// each additional base decision beyond that will incurr the maxBackoff
var backoffTable = []float64{1, 1.3, 1.69, 2.197, 2.8561, 3.71293, 3.71293, 4.826809, 6.2748517, 8.15730721} // 1.3^i+1 backoff, table for more flexibility
//TODO move all the above to manifest
backoffTable := manifest.BaseDecisionBackoffTable

attempts := 0
var backoffMultipler float64
for instance := decision.Vote.Instance - 1; instance > h.manifest.Manifest().InitialInstance; instance-- {
backoffMultipler := 1.0 // to account for the one ECDelay after which we got the base decistion
for instance := decision.Vote.Instance - 1; instance > manifest.InitialInstance; instance-- {
cert, err := h.client.certStore.Get(h.runningCtx, instance)
if err != nil {
h.log.Errorf("error while getting instance %d from certstore: %+v", instance, err)
Expand All @@ -359,13 +352,14 @@ func (h *gpbftHost) ReceiveDecision(decision *gpbft.Justification) time.Time {
attempts += 1
}
if attempts < len(backoffTable) {
backoffMultipler += min(backoffTable[attempts], maxBackoff)
backoffMultipler += backoffTable[attempts]
} else {
backoffMultipler += maxBackoff
// if we are beyond backoffTable, reuse the last element
backoffMultipler += backoffTable[len(backoffTable)-1]
}
}

backoff := h.manifest.Manifest().ECDelay + time.Duration(float64(h.manifest.Manifest().ECPeriod)*backoffMultipler)
backoff := time.Duration(float64(ecDelay) * backoffMultipler)
h.log.Infof("backing off for: %v", backoff)

return ts.Timestamp().Add(backoff)
Expand Down
24 changes: 15 additions & 9 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import (
var (
// Default configuration for the EC Backend
DefaultEcConfig = &EcConfig{
ECFinality: 900,
CommiteeLookback: 5,
ECDelay: 60 * time.Second,
ECPeriod: 30 * time.Second,
ECFinality: 900,
CommiteeLookback: 5,
ECPeriod: 30 * time.Second,
ECDelayMultiplier: 2.,
// MaxBackoff is 15min given default params
BaseDecisionBackoffTable: []float64{1.3, 1.69, 2.2, 2.86, 3.71, 4.83, 6.27, 7.5},
}

DefaultGpbftConfig = &GpbftConfig{
Expand Down Expand Up @@ -60,12 +62,16 @@ type GpbftConfig struct {
}

type EcConfig struct {
ECFinality int64
// The delay after a tipset is produced before we attempt to finalize it.
ECDelay time.Duration
// The delay between tipsets.
ECPeriod time.Duration
CommiteeLookback uint64
ECPeriod time.Duration
// Number of epochs required to reach EC defined fianlity
ECFinality int64
// The multiplier on top of the ECPeriod of the time we will wait before starting a new instance,
// referencing the timestampt of the latest finalized tipset.
ECDelayMultiplier float64
// Table of incremental multipliers to backoff in units of ECDelay in case of base decisions
BaseDecisionBackoffTable []float64
CommiteeLookback uint64
}

// Manifest identifies the specific configuration for
Expand Down
10 changes: 5 additions & 5 deletions manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ var base manifest.Manifest = manifest.Manifest{
MaxLookaheadRounds: 10,
},
EcConfig: &manifest.EcConfig{
ECFinality: 900,
CommiteeLookback: 5,
ECDelay: 30 * time.Second,

ECPeriod: 30 * time.Second,
ECFinality: 900,
CommiteeLookback: 5,
ECDelayMultiplier: 2.0,
ECPeriod: 30 * time.Second,
BaseDecisionBackoffTable: []float64{1.3, 1.69, 2.2, 2.86, 3.71, 4.83, 6.27, 8.16, 10.6, 13.79, 15.},
},
}

Expand Down
5 changes: 3 additions & 2 deletions test/f3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ var base manifest.Manifest = manifest.Manifest{
ECFinality: 10,
CommiteeLookback: 5,
// increased delay and period to accelerate test times.
ECDelay: 500 * time.Millisecond,
ECPeriod: 500 * time.Millisecond,
ECPeriod: 500 * time.Millisecond,
ECDelayMultiplier: 1.0,
BaseDecisionBackoffTable: []float64{1.3, 1.69, 2.2, 2.86, 3.71, 4.83, 6.27, 8.16, 10.6, 13.79, 15.},
},
}

Expand Down

0 comments on commit ab0e2ed

Please sign in to comment.