-
Notifications
You must be signed in to change notification settings - Fork 188
feat: integrate with go-f3 and implement F3 data export and import
#5886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eef772f
972914f
6408398
d07fa89
c370d04
246e3a0
5f8ecae
13e63dd
918d590
b8f8e6d
6d41c27
4a36686
6323cb7
f3ccbdb
2a28182
c60e6b1
b6720fe
142d027
dc127ca
0203c96
cec3d5c
f7c631f
fa83aaa
0a59dde
fb63dfa
7713315
bdd6dc0
93c4d7c
9ffd7c9
de4aa85
d68fa83
963503f
d1ad868
374c38d
0a1ca02
725f233
baf3d42
9181ead
4996b33
e18e351
51b9f75
e9b6572
9b8395b
379633d
88b50d6
b481cf8
5d4130d
4e2b96d
34910b1
fefc3f2
faf4439
86bc855
ca4e52d
5243383
196c884
c42b224
c2621bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "context" | ||
| "errors" | ||
| "os" | ||
|
|
||
| "github.com/filecoin-project/go-f3/certstore" | ||
| "github.com/filecoin-project/go-f3/manifest" | ||
| "github.com/filecoin-project/go-jsonrpc" | ||
| "github.com/ipfs/go-datastore/namespace" | ||
| ) | ||
|
|
||
| func importSnap(ctx context.Context, rpcEndpoint string, f3Root string, snapshotPath string) (err error) { | ||
| logger.Infof("importing F3 snapshot at %s", snapshotPath) | ||
|
|
||
| f3api := F3Api{} | ||
| closer, err := jsonrpc.NewClient(ctx, rpcEndpoint, "F3", &f3api, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer closer() | ||
| rawNetworkName := waitRawNetworkName(ctx, &f3api) | ||
| networkName := getNetworkName(rawNetworkName) | ||
| m := Network2PredefinedManifestMappings[networkName] | ||
| if m == nil { | ||
| m2 := manifest.LocalDevnetManifest() | ||
| m = &m2 | ||
| m.NetworkName = networkName | ||
| } | ||
|
|
||
| ds, err := getDatastore(f3Root) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer func() { | ||
| if closeErr := ds.Close(); closeErr != nil { | ||
| err = errors.Join(err, closeErr) | ||
| } | ||
| }() | ||
| dsWrapper := namespace.Wrap(ds, m.DatastorePrefix()) | ||
| defer func() { | ||
| if closeErr := dsWrapper.Close(); closeErr != nil { | ||
| err = errors.Join(err, closeErr) | ||
| } | ||
| }() | ||
|
|
||
| f, err := os.Open(snapshotPath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer func() { | ||
| if closeErr := f.Close(); closeErr != nil { | ||
| err = errors.Join(err, closeErr) | ||
| } | ||
| }() | ||
| return certstore.ImportSnapshotToDatastore(ctx, bufio.NewReader(f), dsWrapper) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,46 @@ | ||
| package main | ||
|
|
||
| import "github.com/ipfs/go-cid" | ||
| import ( | ||
| "context" | ||
| "path/filepath" | ||
| "time" | ||
|
|
||
| "github.com/filecoin-project/go-f3/gpbft" | ||
| "github.com/ipfs/go-cid" | ||
| leveldb "github.com/ipfs/go-ds-leveldb" | ||
| ) | ||
|
|
||
| var CID_UNDEF_RUST = cid.MustParse("baeaaaaa") | ||
|
|
||
| func isCidDefined(c cid.Cid) bool { | ||
| return c.Defined() && c != CID_UNDEF_RUST | ||
| } | ||
|
|
||
| func getDatastore(f3Root string) (*leveldb.Datastore, error) { | ||
| return leveldb.NewDatastore(filepath.Join(f3Root, "db"), nil) | ||
| } | ||
|
|
||
| func waitRawNetworkName(ctx context.Context, f3api *F3Api) string { | ||
| for { | ||
| rawNetwork, err := f3api.GetRawNetworkName(ctx) | ||
| if err != nil { | ||
| logger.Warnln("waiting for Forest RPC server") | ||
| time.Sleep(5 * time.Second) | ||
| continue | ||
| } | ||
|
|
||
| logger.Infoln("Forest RPC server is online") | ||
| return rawNetwork | ||
| } | ||
| } | ||
|
|
||
| func getNetworkName(rawNetworkName string) gpbft.NetworkName { | ||
| networkName := gpbft.NetworkName(rawNetworkName) | ||
| // See <https://github.com/filecoin-project/lotus/blob/v1.33.1/chain/lf3/config.go#L65> | ||
| // Use "filecoin" as the network name on mainnet, otherwise use the network name. Yes, | ||
| // mainnet is called testnetnet in state. | ||
| if networkName == "testnetnet" { | ||
|
akaladarshi marked this conversation as resolved.
|
||
| networkName = "filecoin" | ||
| } | ||
| return networkName | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,8 +46,7 @@ done | |
|
|
||
| echo "Done" | ||
|
|
||
| echo "Waiting to be ready for serving" | ||
| $FOREST_CLI_PATH healthcheck ready --wait | ||
| forest_wait_for_healthcheck_ready | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Readiness check should precede first CLI call to avoid flakiness
Consider moving the readiness check immediately after -forest_init --backfill-db 200
+# initialise and wait until the node is ready
+forest_init --backfill-db 200
+forest_wait_for_healthcheck_ready # <-- moved up
-OUTPUT=$($FOREST_CLI_PATH info show)
+# safe to query now
+OUTPUT=$($FOREST_CLI_PATH info show)This keeps the happy-path identical while tightening race conditions in CI runs.
🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hanabi1224 Thank you for the clarification! That makes perfect sense. I understand now that Given that this script uses I appreciate you explaining this distinction in the Forest initialization sequence. ✏️ Learnings added
🧠 Learnings used |
||
|
|
||
| ERROR=0 | ||
| echo "Testing Ethereum mappings" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.