Skip to content

Commit

Permalink
Add HeadLookback parameter (#513)
Browse files Browse the repository at this point in the history
* Add HeadLookback parameter

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>

* use head lookback

* max

* check head lookback for equality

* flip things

* and fix head check

---------

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Co-authored-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Kubuxu and Stebalien authored Jul 23, 2024
1 parent dff5722 commit 8def4b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
19 changes: 11 additions & 8 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 6 additions & 0 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8def4b5

Please sign in to comment.