From 8def4b5ff2ed9fdc58ace0f1702247ed293adb59 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 24 Jul 2024 01:36:01 +0200 Subject: [PATCH] Add HeadLookback parameter (#513) * Add HeadLookback parameter Signed-off-by: Jakub Sztandera * use head lookback * max * check head lookback for equality * flip things * and fix head check --------- Signed-off-by: Jakub Sztandera Co-authored-by: Steven Allen --- host.go | 19 +++++++++++-------- manifest/manifest.go | 6 ++++++ manifest/manifest_test.go | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/host.go b/host.go index a3aa0270..e47a39ad 100644 --- a/host.go +++ b/host.go @@ -14,6 +14,7 @@ import ( "github.com/filecoin-project/go-f3/gpbft" "github.com/filecoin-project/go-f3/internal/clock" "github.com/filecoin-project/go-f3/manifest" + pubsub "github.com/libp2p/go-libp2p-pubsub" peer "github.com/libp2p/go-libp2p/core/peer" "go.uber.org/multierr" @@ -436,20 +437,22 @@ func (h *gpbftHost) GetProposalForInstance(instance uint64) (*gpbft.Supplemental if err != nil { return nil, nil, fmt.Errorf("getting head TS: %w", err) } - if h.clock.Since(headTs.Timestamp()) < h.manifest.EC.Period { - // less than ECPeriod since production of the head - // agreement is unlikely - headTs, err = h.ec.GetParent(h.runningCtx, headTs) - if err != nil { - return nil, nil, fmt.Errorf("getting the parent of head TS: %w", err) - } - } collectedChain, err := h.collectChain(baseTs, headTs) if err != nil { return nil, nil, fmt.Errorf("collecting chain: %w", err) } + // If we have an explicit head-lookback, trim the chain. + if h.manifest.EC.HeadLookback > 0 { + collectedChain = collectedChain[:max(0, len(collectedChain)-h.manifest.EC.HeadLookback)] + } + + // less than ECPeriod since production of the head agreement is unlikely, trim the chain. + if len(collectedChain) > 0 && h.clock.Since(collectedChain[len(collectedChain)-1].Timestamp()) < h.manifest.EC.Period { + collectedChain = collectedChain[:len(collectedChain)-1] + } + base := gpbft.TipSet{ Epoch: baseTs.Epoch(), Key: baseTs.Key(), diff --git a/manifest/manifest.go b/manifest/manifest.go index 9ed21e20..6060856a 100644 --- a/manifest/manifest.go +++ b/manifest/manifest.go @@ -26,6 +26,7 @@ var ( DelayMultiplier: 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}, + HeadLookback: 0, } DefaultGpbftConfig = GpbftConfig{ @@ -113,17 +114,22 @@ type EcConfig struct { DelayMultiplier float64 // Table of incremental multipliers to backoff in units of Delay in case of base decisions BaseDecisionBackoffTable []float64 + // HeadLookback number of unfinalized tipsets to remove from the head + HeadLookback int } func (e *EcConfig) Equal(o *EcConfig) bool { return e.Period == o.Period && e.Finality == o.Finality && e.DelayMultiplier == o.DelayMultiplier && + e.HeadLookback == o.HeadLookback && slices.Equal(e.BaseDecisionBackoffTable, o.BaseDecisionBackoffTable) } func (e *EcConfig) Validate() error { switch { + case e.HeadLookback < 0: + return fmt.Errorf("EC head lookback must be non-negative, was %d", e.HeadLookback) case e.Period <= 0: return fmt.Errorf("EC period must be positive, was %s", e.Period) case e.Finality < 0: diff --git a/manifest/manifest_test.go b/manifest/manifest_test.go index 8a89e8c5..1e9427c2 100644 --- a/manifest/manifest_test.go +++ b/manifest/manifest_test.go @@ -38,6 +38,7 @@ var base = manifest.Manifest{ DelayMultiplier: 2.0, Period: 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.}, + HeadLookback: 0, }, CertificateExchange: manifest.CxConfig{ ClientRequestTimeout: 10 * time.Second,