expose state tree on vmcontext for the init actor

This commit is contained in:
whyrusleeping 2019-07-12 09:40:58 -07:00
parent f42df886be
commit d88c857deb
3 changed files with 22 additions and 4 deletions

View File

@ -101,10 +101,14 @@ func (ia InitActor) Exec(act *types.Actor, vmctx types.VMContext, p *ExecParams)
// NOTE: This is a privileged call that only the init actor is allowed to make
// FIXME: Had to comment this because state is not in interface
_ = actor
//if err := vmctx.state.SetActor(idAddr, &actor); err != nil {
//return InvokeRet{}, errors.Wrap(err, "inserting new actor into state tree")
//}
state, err := vmctx.StateTree()
if err != nil {
return InvokeRet{}, err
}
if err := state.SetActor(idAddr, &actor); err != nil {
return InvokeRet{}, errors.Wrap(err, "inserting new actor into state tree")
}
c, err := vmctx.Storage().Put(self)
if err != nil {

View File

@ -19,6 +19,11 @@ type Storage interface {
Commit(oldh cid.Cid, newh cid.Cid) error
}
type StateTree interface {
SetActor(addr address.Address, act *Actor) error
GetActor(addr address.Address) (*Actor, error)
}
type VMContext interface {
Message() *Message
Ipld() *hamt.CborIpldStore
@ -26,4 +31,5 @@ type VMContext interface {
BlockHeight() uint64
GasUsed() BigInt
Storage() Storage
StateTree() (StateTree, error)
}

View File

@ -88,6 +88,14 @@ func (vmc *VMContext) GasUsed() types.BigInt {
return types.NewInt(0)
}
func (vmc *VMContext) StateTree() (types.StateTree, error) {
if vmc.msg.To != InitActorAddress {
return nil, fmt.Errorf("only init actor can access state tree directly")
}
return vmc.state, nil
}
func makeVMContext(state *StateTree, bs bstore.Blockstore, sroot cid.Cid, msg *types.Message, height uint64) *VMContext {
cst := hamt.CSTFromBstore(bs)
return &VMContext{