patch genesis state tree to get the right code IDs
This commit is contained in:
parent
752ce9e590
commit
5d6e9ec65b
@ -580,6 +580,23 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto
|
|||||||
return nil, xerrors.Errorf("setup miners failed: %w", err)
|
return nil, xerrors.Errorf("setup miners failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if template.NetworkVersion >= network.Version16 {
|
||||||
|
st, err := state.LoadStateTree(cbor.NewCborStore(bs), stateroot)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("error loading state tree")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = patchStateTree(st, template.NetworkVersion)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("error patching state tree: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stateroot, err = st.Flush(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("flush state tree failed: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
store := adt.WrapStore(ctx, cbor.NewCborStore(bs))
|
store := adt.WrapStore(ctx, cbor.NewCborStore(bs))
|
||||||
emptyroot, err := adt0.MakeEmptyArray(store).Root()
|
emptyroot, err := adt0.MakeEmptyArray(store).Root()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5,10 +5,13 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
|
"github.com/filecoin-project/lotus/chain/state"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/vm"
|
"github.com/filecoin-project/lotus/chain/vm"
|
||||||
)
|
)
|
||||||
@ -46,3 +49,36 @@ func doExecValue(ctx context.Context, vm *vm.LegacyVM, to, from address.Address,
|
|||||||
|
|
||||||
return ret.Return, nil
|
return ret.Return, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func patchStateTree(st *state.StateTree, nv network.Version) error {
|
||||||
|
av, err := actors.VersionForNetwork(nv)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var acts []address.Address
|
||||||
|
err = st.ForEach(func(a address.Address, _ *types.Actor) error {
|
||||||
|
acts = append(acts, a)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("error collecting actors: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, a := range acts {
|
||||||
|
err = st.MutateActor(a, func(act *types.Actor) error {
|
||||||
|
name := actors.CanonicalName(builtin.ActorNameByCode(act.Code))
|
||||||
|
code, ok := actors.GetActorCodeID(av, name)
|
||||||
|
if ok {
|
||||||
|
act.Code = code
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("error mutating actor %s: %w", a, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user