2021-02-28 22:48:36 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/ipfs/go-datastore"
|
|
|
|
"github.com/ipld/go-car"
|
2022-06-14 15:00:51 +00:00
|
|
|
"go.uber.org/fx"
|
2021-02-28 22:48:36 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/store"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
2021-12-17 09:42:09 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
2021-02-28 22:48:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ErrorGenesis() Genesis {
|
|
|
|
return func() (header *types.BlockHeader, e error) {
|
|
|
|
return nil, xerrors.New("No genesis block provided, provide the file with 'lotus daemon --genesis=[genesis file]'")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
feat: refactor: actor bundling system (#8838)
1. Include the builtin-actors in the lotus source tree.
2. Embed the bundle on build instead of downloading at runtime.
3. Avoid reading the bundle whenever possible by including bundle
metadata (the bundle CID, the actor CIDs, etc.).
4. Remove everything related to dependency injection.
1. We're no longer downloading the bundle, so doing anything ahead
of time doesn't really help.
2. We register the manifests on init because, unfortunately, they're
global.
3. We explicitly load the current actors bundle in the genesis
state-tree method.
4. For testing, we just change the in-use bundle with a bit of a
hack. It's not great, but using dependency injection doesn't make
any sense either because, again, the manifest information is
global.
5. Remove the bundle.toml file. Bundles may be overridden by
specifying an override path in the parameters file, or an
environment variable.
fixes #8701
2022-06-13 17:15:00 +00:00
|
|
|
func LoadGenesis(genBytes []byte) func(fx.Lifecycle, helpers.MetricsCtx, dtypes.ChainBlockstore) Genesis {
|
|
|
|
return func(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.ChainBlockstore) Genesis {
|
2021-02-28 22:48:36 +00:00
|
|
|
return func() (header *types.BlockHeader, e error) {
|
2021-12-17 09:42:09 +00:00
|
|
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
|
|
|
c, err := car.LoadCar(ctx, bs, bytes.NewReader(genBytes))
|
2021-02-28 22:48:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("loading genesis car file failed: %w", err)
|
|
|
|
}
|
|
|
|
if len(c.Roots) != 1 {
|
|
|
|
return nil, xerrors.New("expected genesis file to have one root")
|
|
|
|
}
|
2021-12-17 09:42:09 +00:00
|
|
|
root, err := bs.Get(ctx, c.Roots[0])
|
2021-02-28 22:48:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
h, err := types.DecodeBlock(root.RawData())
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("decoding block failed: %w", err)
|
|
|
|
}
|
|
|
|
return h, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DoSetGenesis(_ dtypes.AfterGenesisSet) {}
|
|
|
|
|
feat: refactor: actor bundling system (#8838)
1. Include the builtin-actors in the lotus source tree.
2. Embed the bundle on build instead of downloading at runtime.
3. Avoid reading the bundle whenever possible by including bundle
metadata (the bundle CID, the actor CIDs, etc.).
4. Remove everything related to dependency injection.
1. We're no longer downloading the bundle, so doing anything ahead
of time doesn't really help.
2. We register the manifests on init because, unfortunately, they're
global.
3. We explicitly load the current actors bundle in the genesis
state-tree method.
4. For testing, we just change the in-use bundle with a bit of a
hack. It's not great, but using dependency injection doesn't make
any sense either because, again, the manifest information is
global.
5. Remove the bundle.toml file. Bundles may be overridden by
specifying an override path in the parameters file, or an
environment variable.
fixes #8701
2022-06-13 17:15:00 +00:00
|
|
|
func SetGenesis(lc fx.Lifecycle, mctx helpers.MetricsCtx, cs *store.ChainStore, g Genesis) (dtypes.AfterGenesisSet, error) {
|
2021-12-17 09:42:09 +00:00
|
|
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
|
|
|
genFromRepo, err := cs.GetGenesis(ctx)
|
2021-02-28 22:48:36 +00:00
|
|
|
if err == nil {
|
|
|
|
if os.Getenv("LOTUS_SKIP_GENESIS_CHECK") != "_yes_" {
|
|
|
|
expectedGenesis, err := g()
|
|
|
|
if err != nil {
|
|
|
|
return dtypes.AfterGenesisSet{}, xerrors.Errorf("getting expected genesis failed: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if genFromRepo.Cid() != expectedGenesis.Cid() {
|
|
|
|
return dtypes.AfterGenesisSet{}, xerrors.Errorf("genesis in the repo is not the one expected by this version of Lotus!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dtypes.AfterGenesisSet{}, nil // already set, noop
|
|
|
|
}
|
|
|
|
if err != datastore.ErrNotFound {
|
|
|
|
return dtypes.AfterGenesisSet{}, xerrors.Errorf("getting genesis block failed: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
genesis, err := g()
|
|
|
|
if err != nil {
|
|
|
|
return dtypes.AfterGenesisSet{}, xerrors.Errorf("genesis func failed: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-12-17 09:42:09 +00:00
|
|
|
return dtypes.AfterGenesisSet{}, cs.SetGenesis(ctx, genesis)
|
2021-02-28 22:48:36 +00:00
|
|
|
}
|