Skip to content

Commit

Permalink
feat(f3): prepare for f3 bootstrap
Browse files Browse the repository at this point in the history
This patch:

1. Bootstraps F3 when we hit the `F3BootstrapEpoch` (when non-negative).
2. Refuses any/all dynamic manifests once we get within one finality of said epoch.
3. Sets the F3 network name for mainnet to "filecoin".
  • Loading branch information
Stebalien committed Oct 3, 2024
1 parent 0e7292a commit 21e5a25
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 52 deletions.
79 changes: 53 additions & 26 deletions chain/lf3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,68 @@ import (

"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-f3/manifest"
"github.com/filecoin-project/go-state-types/abi"

"github.com/filecoin-project/lotus/build/buildconstants"
"github.com/filecoin-project/lotus/chain/actors/policy"
"github.com/filecoin-project/lotus/node/modules/dtypes"
)

type Config struct {
InitialManifest *manifest.Manifest
DynamicManifestProvider peer.ID
StaticManifest *manifest.Manifest
DynamicManifestProvider peer.ID
PrioritizeStaticManifest bool
}

func NewConfig(manifestProvider peer.ID, initialPowerTable cid.Cid) func(dtypes.NetworkName) *Config {
return func(nn dtypes.NetworkName) *Config {
m := manifest.LocalDevnetManifest()
m.NetworkName = gpbft.NetworkName(nn)
m.EC.Period = time.Duration(buildconstants.BlockDelaySecs) * time.Second
m.CatchUpAlignment = time.Duration(buildconstants.BlockDelaySecs) * time.Second / 2
if buildconstants.F3BootstrapEpoch < 0 {
// if unset, set to a sane default so we don't get scary logs and pause.
m.BootstrapEpoch = 2 * int64(policy.ChainFinality)
m.Pause = true
} else {
m.BootstrapEpoch = int64(buildconstants.F3BootstrapEpoch)
}
m.EC.Finality = int64(policy.ChainFinality)
m.CommitteeLookback = 5
m.InitialPowerTable = initialPowerTable
m.EC.Finalize = buildconstants.F3Consensus
func NewManifest(
nn dtypes.NetworkName,
finality, bootstrapEpoch abi.ChainEpoch,
ecPeriod time.Duration,
initialPowerTable cid.Cid,
) *manifest.Manifest {
// Use "filecoin" as the network name on mainnet, otherwise use the network name. Yes,
// mainnet is called testnetnet in state.
if nn == "testnetnet" {
nn = "filecoin"
}
return &manifest.Manifest{
ProtocolVersion: manifest.VersionCapability,
BootstrapEpoch: int64(buildconstants.F3BootstrapEpoch),
NetworkName: gpbft.NetworkName(nn),
InitialPowerTable: initialPowerTable,
CommitteeLookback: manifest.DefaultCommitteeLookback,
CatchUpAlignment: ecPeriod / 2,
Gpbft: manifest.DefaultGpbftConfig,
EC: manifest.EcConfig{
Period: ecPeriod,
Finality: int64(policy.ChainFinality),
DelayMultiplier: manifest.DefaultEcConfig.DelayMultiplier,
BaseDecisionBackoffTable: manifest.DefaultEcConfig.BaseDecisionBackoffTable,
HeadLookback: 0,
Finalize: true,
},
CertificateExchange: manifest.CxConfig{
ClientRequestTimeout: manifest.DefaultCxConfig.ClientRequestTimeout,
ServerRequestTimeout: manifest.DefaultCxConfig.ServerRequestTimeout,
MinimumPollInterval: ecPeriod,
MaximumPollInterval: 4 * ecPeriod,
},
}
}

// TODO: We're forcing this to start paused for now. We need to remove this for the final
// mainnet launch.
m.Pause = true
return &Config{
InitialManifest: m,
DynamicManifestProvider: manifestProvider,
}
func NewConfig(nn dtypes.NetworkName) *Config {
c := &Config{
PrioritizeStaticManifest: true,
DynamicManifestProvider: buildconstants.F3ManifestServerID,
}
if buildconstants.F3BootstrapEpoch >= 0 {
c.StaticManifest = NewManifest(
nn,
policy.ChainFinality,
buildconstants.F3BootstrapEpoch,
time.Duration(buildconstants.BlockDelaySecs)*time.Second,
buildconstants.F3InitialPowerTableCID,
)
}
return c
}
50 changes: 43 additions & 7 deletions chain/lf3/manifest.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,57 @@
package lf3

import (
"context"
"fmt"

"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-f3/ec"
"github.com/filecoin-project/go-f3/manifest"

"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/modules/helpers"
)

type headGetter store.ChainStore

func (hg *headGetter) GetHead(context.Context) (ec.TipSet, error) {
head := (*store.ChainStore)(hg).GetHeaviestTipSet()
if head == nil {
return nil, xerrors.New("no heaviest tipset")
}
return &f3TipSet{TipSet: head}, nil
}

// Determines the max. number of configuration changes
// that are allowed for the dynamic manifest.
// If the manifest changes more than this number, the F3
// message topic will be filtered
var MaxDynamicManifestChangesAllowed = 1000

func NewManifestProvider(config *Config, ps *pubsub.PubSub, mds dtypes.MetadataDS) (manifest.ManifestProvider, error) {
func NewManifestProvider(mctx helpers.MetricsCtx, config *Config, cs *store.ChainStore, ps *pubsub.PubSub, mds dtypes.MetadataDS) (prov manifest.ManifestProvider, err error) {
if config.DynamicManifestProvider == "" {
return manifest.NewStaticManifestProvider(config.InitialManifest)
if config.StaticManifest == nil {
return manifest.NoopManifestProvider{}, nil
}
return manifest.NewStaticManifestProvider(config.StaticManifest)
}

opts := []manifest.DynamicManifestProviderOption{
manifest.DynamicManifestProviderWithDatastore(
namespace.Wrap(mds, datastore.NewKey("/f3-dynamic-manifest")),
),
}

if config.StaticManifest == nil {
return manifest.NewDynamicManifestProvider(ps, config.DynamicManifestProvider, opts...)
}

primaryNetworkName := config.InitialManifest.NetworkName
primaryNetworkName := config.StaticManifest.NetworkName
filter := func(m *manifest.Manifest) error {
if m.EC.Finalize {
return fmt.Errorf("refusing dynamic manifest that finalizes tipsets")
Expand All @@ -36,10 +64,18 @@ func NewManifestProvider(config *Config, ps *pubsub.PubSub, mds dtypes.MetadataD
}
return nil
}
ds := namespace.Wrap(mds, datastore.NewKey("/f3-dynamic-manifest"))
return manifest.NewDynamicManifestProvider(ps, config.DynamicManifestProvider,
manifest.DynamicManifestProviderWithInitialManifest(config.InitialManifest),
manifest.DynamicManifestProviderWithDatastore(ds),
opts = append(opts,
manifest.DynamicManifestProviderWithInitialManifest(config.StaticManifest),
manifest.DynamicManifestProviderWithFilter(filter),
)

prov, err = manifest.NewDynamicManifestProvider(ps, config.DynamicManifestProvider, opts...)
if err != nil {
return nil, err
}
if config.PrioritizeStaticManifest {
prov, err = manifest.NewFusingManifestProvider(mctx,
(*headGetter)(cs), prov, config.StaticManifest)
}
return prov, err
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,5 @@ require (
lukechampine.com/blake3 v1.3.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/filecoin-project/go-f3 => ../go-f3
20 changes: 7 additions & 13 deletions itests/kit/node_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,17 @@ func MutateSealingConfig(mut func(sc *config.SealingConfig)) NodeOpt {
func F3Enabled(bootstrapEpoch abi.ChainEpoch, blockDelay time.Duration, finality abi.ChainEpoch, manifestProvider peer.ID) NodeOpt {
return ConstructorOpts(
node.Override(new(*lf3.Config), func(nn dtypes.NetworkName) *lf3.Config {
c := lf3.NewConfig(manifestProvider, cid.Undef)(nn)
c.InitialManifest.Pause = false
c.InitialManifest.EC.Period = blockDelay
c.InitialManifest.Gpbft.Delta = blockDelay / 5
c.InitialManifest.EC.Finality = int64(finality)
c.InitialManifest.BootstrapEpoch = int64(bootstrapEpoch)
c.InitialManifest.EC.HeadLookback = 0
c.InitialManifest.EC.Finalize = true
c.InitialManifest.CatchUpAlignment = blockDelay / 2
c.InitialManifest.CertificateExchange.MinimumPollInterval = 2 * blockDelay
c.InitialManifest.CertificateExchange.MaximumPollInterval = 10 * blockDelay
return c
m := lf3.NewManifest(nn, finality, bootstrapEpoch, blockDelay, cid.Undef)
return &lf3.Config{
StaticManifest: m,
DynamicManifestProvider: manifestProvider,
PrioritizeStaticManifest: false,
}
}),
node.Override(new(manifest.ManifestProvider),
func(config *lf3.Config, ps *pubsub.PubSub) (manifest.ManifestProvider, error) {
return manifest.NewDynamicManifestProvider(ps, config.DynamicManifestProvider,
manifest.DynamicManifestProviderWithInitialManifest(config.InitialManifest),
manifest.DynamicManifestProviderWithInitialManifest(config.StaticManifest),
)
}),
node.Override(new(*lf3.F3), lf3.New),
Expand Down
6 changes: 1 addition & 5 deletions node/builder_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/build/buildconstants"
"github.com/filecoin-project/lotus/chain"
"github.com/filecoin-project/lotus/chain/beacon"
"github.com/filecoin-project/lotus/chain/consensus"
Expand Down Expand Up @@ -165,10 +164,7 @@ var ChainNode = Options(
),

If(build.IsF3Enabled(),
Override(new(*lf3.Config), lf3.NewConfig(
buildconstants.F3ManifestServerID,
buildconstants.F3InitialPowerTableCID,
)),
Override(new(*lf3.Config), lf3.NewConfig),
Override(new(manifest.ManifestProvider), lf3.NewManifestProvider),
Override(new(*lf3.F3), lf3.New),
),
Expand Down
2 changes: 1 addition & 1 deletion node/modules/lp2p/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
allowTopics = append(allowTopics, drandTopics...)

if in.F3Config != nil {
f3BaseTopicName := manifest.PubSubTopicFromNetworkName(in.F3Config.InitialManifest.NetworkName)
f3BaseTopicName := manifest.PubSubTopicFromNetworkName(in.F3Config.StaticManifest.NetworkName)
allowTopics = append(allowTopics, f3BaseTopicName)
if in.F3Config.DynamicManifestProvider != "" {
allowTopics = append(allowTopics, manifest.ManifestPubSubTopicName)
Expand Down

0 comments on commit 21e5a25

Please sign in to comment.