-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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". 4. Refuses any/all dynamic manifests that don't start with the expected network name prefix.
- Loading branch information
Showing
5 changed files
with
121 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,84 @@ | ||
package lf3 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"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 { | ||
opts = append(opts, | ||
manifest.DynamicManifestProviderWithInitialManifest(config.StaticManifest), | ||
) | ||
} | ||
|
||
primaryNetworkName := config.InitialManifest.NetworkName | ||
networkNameBase := config.BaseNetworkName + "/" | ||
filter := func(m *manifest.Manifest) error { | ||
if m.EC.Finalize { | ||
return fmt.Errorf("refusing dynamic manifest that finalizes tipsets") | ||
} | ||
if m.NetworkName == primaryNetworkName { | ||
if !strings.HasPrefix(string(m.NetworkName), string(networkNameBase)) { | ||
return fmt.Errorf( | ||
"refusing dynamic manifest with network name %q that clashes with initial manifest", | ||
primaryNetworkName, | ||
"refusing dynamic manifest with network name %q, must start with %q", | ||
m.NetworkName, | ||
networkNameBase, | ||
) | ||
} | ||
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.DynamicManifestProviderWithFilter(filter), | ||
) | ||
|
||
prov, err = manifest.NewDynamicManifestProvider(ps, config.DynamicManifestProvider, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if config.PrioritizeStaticManifest && config.StaticManifest != nil { | ||
prov, err = manifest.NewFusingManifestProvider(mctx, | ||
(*headGetter)(cs), prov, config.StaticManifest) | ||
} | ||
return prov, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters