refactor to pass the network bundle name through ldflags from build
This commit is contained in:
parent
70bf990294
commit
7be42d9935
3
build/bundle.go
Normal file
3
build/bundle.go
Normal file
@ -0,0 +1,3 @@
|
||||
package build
|
||||
|
||||
var NetworkBundle string
|
@ -3,8 +3,6 @@ package actors
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@ -16,10 +14,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/blockstore"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/node/bundle"
|
||||
"github.com/filecoin-project/specs-actors/v8/actors/builtin/manifest"
|
||||
|
||||
"github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
var manifestCids map[Version]cid.Cid = map[Version]cid.Cid{
|
||||
@ -122,40 +117,6 @@ func CanonicalName(name string) string {
|
||||
return name
|
||||
}
|
||||
|
||||
func FetchAndLoadBundle(ctx context.Context, basePath string, bs blockstore.Blockstore, av Version, rel, netw string) (cid.Cid, error) {
|
||||
fetcher, err := bundle.NewBundleFetcher(basePath)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error creating fetcher for builtin-actors version %d: %w", av, err)
|
||||
}
|
||||
|
||||
path, err := fetcher.Fetch(int(av), rel, netw)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error fetching bundle for builtin-actors version %d: %w", av, err)
|
||||
}
|
||||
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error opening bundle for builtin-actors vresion %d: %w", av, err)
|
||||
}
|
||||
defer f.Close() //nolint
|
||||
|
||||
data, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error reading bundle for builtin-actors vresion %d: %w", av, err)
|
||||
}
|
||||
|
||||
if err := LoadBundle(ctx, bs, av, data); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error loading bundle for builtin-actors vresion %d: %w", av, err)
|
||||
}
|
||||
|
||||
mfCid, ok := GetManifest(av)
|
||||
if !ok {
|
||||
return cid.Undef, xerrors.Errorf("missing manifest CID for builtin-actors vrsion %d", av)
|
||||
}
|
||||
|
||||
return mfCid, nil
|
||||
}
|
||||
|
||||
func LoadBundle(ctx context.Context, bs blockstore.Blockstore, av Version, data []byte) error {
|
||||
blobr := bytes.NewReader(data)
|
||||
|
||||
@ -169,34 +130,3 @@ func LoadBundle(ctx context.Context, bs blockstore.Blockstore, av Version, data
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// utility for blanket loading outside DI
|
||||
func FetchAndLoadBundles(ctx context.Context, bs blockstore.Blockstore, bar map[Version]string) error {
|
||||
// TODO: how to get the network name properly?
|
||||
netw := "mainnet"
|
||||
if v := os.Getenv("LOTUS_FIL_NETWORK"); v != "" {
|
||||
netw = v
|
||||
}
|
||||
|
||||
path := os.Getenv("LOTUS_PATH")
|
||||
if path == "" {
|
||||
var err error
|
||||
path, err = homedir.Expand("~/.lotus")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for av, rel := range bar {
|
||||
if _, err := FetchAndLoadBundle(ctx, path, bs, av, rel, netw); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
cborStore := cbor.NewCborStore(bs)
|
||||
if err := LoadManifests(ctx, cborStore); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/blockstore"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/node/bundle"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -13,7 +13,7 @@ func init() {
|
||||
// go through CI
|
||||
bs := blockstore.NewMemory()
|
||||
|
||||
if err := actors.FetchAndLoadBundles(context.Background(), bs, build.BuiltinActorReleases); err != nil {
|
||||
if err := bundle.FetchAndLoadBundles(context.Background(), bs, build.BuiltinActorReleases); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/journal"
|
||||
"github.com/filecoin-project/lotus/journal/fsjournal"
|
||||
storageminer "github.com/filecoin-project/lotus/miner"
|
||||
"github.com/filecoin-project/lotus/node/bundle"
|
||||
"github.com/filecoin-project/lotus/node/modules"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/node/repo"
|
||||
@ -219,7 +220,7 @@ var initCmd = &cli.Command{
|
||||
// load bundles
|
||||
bs := blockstore.NewMemory()
|
||||
|
||||
if err := actors.FetchAndLoadBundles(ctx, bs, build.BuiltinActorReleases); err != nil {
|
||||
if err := bundle.FetchAndLoadBundles(ctx, bs, build.BuiltinActorReleases); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
82
node/bundle/manifest.go
Normal file
82
node/bundle/manifest.go
Normal file
@ -0,0 +1,82 @@
|
||||
package bundle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/blockstore"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
|
||||
"github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
func FetchAndLoadBundle(ctx context.Context, basePath string, bs blockstore.Blockstore, av actors.Version, rel, netw string) (cid.Cid, error) {
|
||||
fetcher, err := NewBundleFetcher(basePath)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error creating fetcher for builtin-actors version %d: %w", av, err)
|
||||
}
|
||||
|
||||
path, err := fetcher.Fetch(int(av), rel, netw)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error fetching bundle for builtin-actors version %d: %w", av, err)
|
||||
}
|
||||
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error opening bundle for builtin-actors vresion %d: %w", av, err)
|
||||
}
|
||||
defer f.Close() //nolint
|
||||
|
||||
data, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error reading bundle for builtin-actors vresion %d: %w", av, err)
|
||||
}
|
||||
|
||||
if err := actors.LoadBundle(ctx, bs, av, data); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error loading bundle for builtin-actors vresion %d: %w", av, err)
|
||||
}
|
||||
|
||||
mfCid, ok := actors.GetManifest(av)
|
||||
if !ok {
|
||||
return cid.Undef, xerrors.Errorf("missing manifest CID for builtin-actors vrsion %d", av)
|
||||
}
|
||||
|
||||
return mfCid, nil
|
||||
}
|
||||
|
||||
// utility for blanket loading outside DI
|
||||
func FetchAndLoadBundles(ctx context.Context, bs blockstore.Blockstore, bar map[actors.Version]string) error {
|
||||
netw := build.NetworkBundle
|
||||
if netw == "" {
|
||||
netw = "mainnet"
|
||||
}
|
||||
|
||||
path := os.Getenv("LOTUS_PATH")
|
||||
if path == "" {
|
||||
var err error
|
||||
path, err = homedir.Expand("~/.lotus")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for av, rel := range bar {
|
||||
if _, err := FetchAndLoadBundle(ctx, path, bs, av, rel, netw); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
cborStore := cbor.NewCborStore(bs)
|
||||
if err := actors.LoadManifests(ctx, cborStore); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -2,7 +2,6 @@ package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/fx"
|
||||
@ -10,6 +9,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/node/bundle"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
"github.com/filecoin-project/lotus/node/repo"
|
||||
@ -22,12 +22,11 @@ import (
|
||||
func LoadBuiltinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRepo, bs dtypes.UniversalBlockstore, ds dtypes.MetadataDS) (result dtypes.BuiltinActorsLoaded, err error) {
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
|
||||
// TODO how to properly get the network name?
|
||||
// putting it as a dep in inputs causes a stack overflow in DI from circular dependency
|
||||
// sigh...
|
||||
netw := "mainnet"
|
||||
if v := os.Getenv("LOTUS_FIL_NETWORK"); v != "" {
|
||||
netw = v
|
||||
// We can't put it as a dep in inputs causes a stack overflow in DI from circular dependency
|
||||
// So we pass it through ldflags instead
|
||||
netw := build.NetworkBundle
|
||||
if netw == "" {
|
||||
netw = "mainnet"
|
||||
}
|
||||
|
||||
for av, rel := range build.BuiltinActorReleases {
|
||||
@ -58,7 +57,7 @@ func LoadBuiltinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRe
|
||||
}
|
||||
|
||||
// ok, we don't have it -- fetch it and add it to the blockstore
|
||||
mfCid, err := actors.FetchAndLoadBundle(ctx, r.Path(), bs, av, rel, netw)
|
||||
mfCid, err := bundle.FetchAndLoadBundle(ctx, r.Path(), bs, av, rel, netw)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@ -95,7 +94,7 @@ func LoadBuiltinActorsTesting(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtype
|
||||
for av, rel := range build.BuiltinActorReleases {
|
||||
const basePath = "/tmp/lotus-testing"
|
||||
|
||||
if _, err := actors.FetchAndLoadBundle(ctx, basePath, bs, av, rel, netw); err != nil {
|
||||
if _, err := bundle.FetchAndLoadBundle(ctx, basePath, bs, av, rel, netw); err != nil {
|
||||
return result, xerrors.Errorf("error loading bundle for builtin-actors vresion %d: %w", av, err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user