set up builtin actors correctly for validation testing
This commit is contained in:
parent
09a46e5d80
commit
654f933d3f
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||||
@ -18,7 +17,6 @@ import (
|
|||||||
|
|
||||||
vstate "github.com/filecoin-project/chain-validation/state"
|
vstate "github.com/filecoin-project/chain-validation/state"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/gen/genesis"
|
|
||||||
"github.com/filecoin-project/lotus/chain/state"
|
"github.com/filecoin-project/lotus/chain/state"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
@ -116,17 +114,13 @@ func (s *StateWrapper) SetActorState(addr address.Address, balance abi.TokenAmou
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateWrapper) CreateActor(code cid.Cid, addr address.Address, balance abi.TokenAmount, actorState runtime.CBORMarshaler) (vstate.Actor, address.Address, error) {
|
func (s *StateWrapper) CreateActor(code cid.Cid, addr address.Address, balance abi.TokenAmount, actorState runtime.CBORMarshaler) (vstate.Actor, address.Address, error) {
|
||||||
if addr == builtin.InitActorAddr || addr == builtin.StoragePowerActorAddr || addr == builtin.StorageMarketActorAddr {
|
idAddr := addr
|
||||||
act, err := s.SetupSingletonActor(addr)
|
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
|
||||||
if err != nil {
|
|
||||||
return nil, address.Undef, err
|
|
||||||
}
|
|
||||||
return act, addr, nil
|
|
||||||
}
|
|
||||||
tree, err := state.LoadStateTree(s.cst, s.Root())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, address.Undef, err
|
return nil, address.Undef, err
|
||||||
}
|
}
|
||||||
|
if addr.Protocol() != address.ID {
|
||||||
|
|
||||||
actHead, err := tree.Store.Put(context.Background(), actorState)
|
actHead, err := tree.Store.Put(context.Background(), actorState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, address.Undef, err
|
return nil, address.Undef, err
|
||||||
@ -137,7 +131,7 @@ func (s *StateWrapper) CreateActor(code cid.Cid, addr address.Address, balance a
|
|||||||
Balance: balance,
|
Balance: balance,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
idAddr, err := tree.RegisterNewAddress(addr)
|
idAddr, err = tree.RegisterNewAddress(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, address.Undef, xerrors.Errorf("register new address for actor: %w", err)
|
return nil, address.Undef, xerrors.Errorf("register new address for actor: %w", err)
|
||||||
}
|
}
|
||||||
@ -145,8 +139,25 @@ func (s *StateWrapper) CreateActor(code cid.Cid, addr address.Address, balance a
|
|||||||
if err := tree.SetActor(addr, &actr.Actor); err != nil {
|
if err := tree.SetActor(addr, &actr.Actor); err != nil {
|
||||||
return nil, address.Undef, xerrors.Errorf("setting new actor for actor: %w", err)
|
return nil, address.Undef, xerrors.Errorf("setting new actor for actor: %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return actr, idAddr, s.flush(tree)
|
// store newState
|
||||||
|
head, err := tree.Store.Put(context.Background(), actorState)
|
||||||
|
if err != nil {
|
||||||
|
return nil, address.Undef, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// create and store actor object
|
||||||
|
a := types.Actor{
|
||||||
|
Code: code,
|
||||||
|
Head: head,
|
||||||
|
Balance: balance,
|
||||||
|
}
|
||||||
|
if err := tree.SetActor(idAddr, &a); err != nil {
|
||||||
|
return nil, address.Undef, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &actorWrapper{a}, idAddr, s.flush(tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flushes a state tree to storage and sets this state's root to that tree's root CID.
|
// Flushes a state tree to storage and sets this state's root to that tree's root CID.
|
||||||
@ -192,46 +203,3 @@ type contextStore struct {
|
|||||||
func (s *contextStore) Context() context.Context {
|
func (s *contextStore) Context() context.Context {
|
||||||
return s.ctx
|
return s.ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateWrapper) SetupSingletonActor(addr address.Address) (vstate.Actor, error) {
|
|
||||||
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
switch addr {
|
|
||||||
case builtin.InitActorAddr:
|
|
||||||
// FIXME this is going to be a problem if go-filecoin and lotus setup their init actors with different netnames
|
|
||||||
// ideally lotus should use the init actor constructor
|
|
||||||
initact, err := genesis.SetupInitActor(s.bs, "chain-validation", nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("setup init actor: %w", err)
|
|
||||||
}
|
|
||||||
if err := tree.SetActor(builtin.InitActorAddr, initact); err != nil {
|
|
||||||
return nil, xerrors.Errorf("set init actor: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &actorWrapper{*initact}, s.flush(tree)
|
|
||||||
case builtin.StorageMarketActorAddr:
|
|
||||||
smact, err := genesis.SetupStorageMarketActor(s.bs)
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("setup storage marker actor: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := tree.SetActor(builtin.StorageMarketActorAddr, smact); err != nil {
|
|
||||||
return nil, xerrors.Errorf("set storage marker actor: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &actorWrapper{*smact}, s.flush(tree)
|
|
||||||
case builtin.StoragePowerActorAddr:
|
|
||||||
spact, err := genesis.SetupStoragePowerActor(s.bs)
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("setup storage power actor: %w", err)
|
|
||||||
}
|
|
||||||
if err := tree.SetActor(builtin.StoragePowerActorAddr, spact); err != nil {
|
|
||||||
return nil, xerrors.Errorf("set storage power actor: %w", err)
|
|
||||||
}
|
|
||||||
return &actorWrapper{*spact}, s.flush(tree)
|
|
||||||
default:
|
|
||||||
return nil, xerrors.Errorf("%v is not a singleton actor address", addr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user