Adapt to need changes in spec

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
Jakub Sztandera 2019-07-16 18:40:25 +02:00
parent 1a1d2c8789
commit d373f78326
6 changed files with 23 additions and 15 deletions

View File

@ -72,6 +72,7 @@ type StorageMinerActorState struct {
} }
type StorageMinerConstructorParams struct { type StorageMinerConstructorParams struct {
Owner address.Address
Worker address.Address Worker address.Address
SectorSize types.BigInt SectorSize types.BigInt
PeerID peer.ID PeerID peer.ID
@ -85,7 +86,7 @@ func (sma StorageMinerActor) Exports() []interface{} {
func (sma StorageMinerActor) StorageMinerActor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) (types.InvokeRet, error) { func (sma StorageMinerActor) StorageMinerActor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) (types.InvokeRet, error) {
var self StorageMinerActorState var self StorageMinerActorState
self.Owner = vmctx.Message().From self.Owner = params.Owner
self.Worker = params.Worker self.Worker = params.Worker
self.PeerID = params.PeerID self.PeerID = params.PeerID
self.SectorSize = params.SectorSize self.SectorSize = params.SectorSize

View File

@ -30,6 +30,7 @@ type StorageMarketState struct {
} }
type CreateStorageMinerParams struct { type CreateStorageMinerParams struct {
Owner address.Address
Worker address.Address Worker address.Address
SectorSize types.BigInt SectorSize types.BigInt
PeerID peer.ID PeerID peer.ID
@ -44,6 +45,7 @@ func (sma StorageMarketActor) CreateStorageMiner(act *types.Actor, vmctx types.V
} }
encoded, err := CreateExecParams(StorageMinerCodeCid, &StorageMinerConstructorParams{ encoded, err := CreateExecParams(StorageMinerCodeCid, &StorageMinerConstructorParams{
Owner: params.Owner,
Worker: params.Worker, Worker: params.Worker,
SectorSize: params.SectorSize, SectorSize: params.SectorSize,
PeerID: params.PeerID, PeerID: params.PeerID,

View File

@ -21,7 +21,8 @@ func TestStorageMarketCreateMiner(t *testing.T) {
GasPrice: types.NewInt(1), GasPrice: types.NewInt(1),
GasLimit: types.NewInt(1), GasLimit: types.NewInt(1),
Value: types.NewInt(0), Value: types.NewInt(0),
Params: h.DumpObject(&StorageMinerConstructorParams{ Params: h.DumpObject(&CreateStorageMinerParams{
Owner: h.From,
Worker: h.Third, Worker: h.Third,
SectorSize: types.NewInt(SectorSize), SectorSize: types.NewInt(SectorSize),
PeerID: "fakepeerid", PeerID: "fakepeerid",

View File

@ -119,7 +119,9 @@ func TestVMInvokeHarness(t *testing.T) {
Params: h.DumpObject( Params: h.DumpObject(
&ExecParams{ &ExecParams{
Code: StorageMinerCodeCid, Code: StorageMinerCodeCid,
Params: h.DumpObject(&StorageMinerConstructorParams{}), Params: h.DumpObject(&StorageMinerConstructorParams{
Owner: h.From,
}),
}), }),
GasPrice: types.NewInt(1), GasPrice: types.NewInt(1),
GasLimit: types.NewInt(1), GasLimit: types.NewInt(1),

View File

@ -24,6 +24,7 @@ type StateTree interface {
type VMContext interface { type VMContext interface {
Message() *Message Message() *Message
Origin() address.Address
Ipld() *hamt.CborIpldStore Ipld() *hamt.CborIpldStore
Send(to address.Address, method uint64, value BigInt, params []byte) ([]byte, uint8, error) Send(to address.Address, method uint64, value BigInt, params []byte) ([]byte, uint8, error)
BlockHeight() uint64 BlockHeight() uint64

View File

@ -27,6 +27,9 @@ type VMContext struct {
// root cid of the state of the actor this invocation will be on // root cid of the state of the actor this invocation will be on
sroot cid.Cid sroot cid.Cid
// address that started invokation chain
origin address.Address
storage types.Storage storage types.Storage
} }
@ -72,18 +75,15 @@ func (vmc *VMContext) Ipld() *hamt.CborIpldStore {
return vmc.cst return vmc.cst
} }
func (vmc *VMContext) Origin() address.Address {
return vmc.origin
}
// Send allows the current execution context to invoke methods on other actors in the system // Send allows the current execution context to invoke methods on other actors in the system
func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt, params []byte) ([]byte, uint8, error) { func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt, params []byte) ([]byte, uint8, error) {
var from address.Address
if method == 0 {
// is constructor
from = vmc.msg.From
} else {
from = vmc.msg.To
}
msg := &types.Message{ msg := &types.Message{
From: from, From: vmc.msg.To,
To: to, To: to,
Method: method, Method: method,
Value: value, Value: value,
@ -95,7 +95,7 @@ func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt
return nil, 0, err return nil, 0, err
} }
nvmctx := vmc.vm.makeVMContext(toAct.Head, msg) nvmctx := vmc.vm.makeVMContext(toAct.Head, vmc.origin, msg)
res, ret, err := vmc.vm.Invoke(toAct, nvmctx, method, params) res, ret, err := vmc.vm.Invoke(toAct, nvmctx, method, params)
if err != nil { if err != nil {
@ -124,7 +124,7 @@ func (vmc *VMContext) StateTree() (types.StateTree, error) {
return vmc.state, nil return vmc.state, nil
} }
func (vm *VM) makeVMContext(sroot cid.Cid, msg *types.Message) *VMContext { func (vm *VM) makeVMContext(sroot cid.Cid, origin address.Address, msg *types.Message) *VMContext {
cst := hamt.CSTFromBstore(vm.cs.bs) cst := hamt.CSTFromBstore(vm.cs.bs)
return &VMContext{ return &VMContext{
@ -132,6 +132,7 @@ func (vm *VM) makeVMContext(sroot cid.Cid, msg *types.Message) *VMContext {
state: vm.cstate, state: vm.cstate,
sroot: sroot, sroot: sroot,
msg: msg, msg: msg,
origin: origin,
height: vm.blockHeight, height: vm.blockHeight,
cst: cst, cst: cst,
storage: &storage{ storage: &storage{
@ -207,7 +208,7 @@ func (vm *VM) ApplyMessage(msg *types.Message) (*types.MessageReceipt, error) {
} }
DepositFunds(toActor, msg.Value) DepositFunds(toActor, msg.Value)
vmctx := vm.makeVMContext(toActor.Head, msg) vmctx := vm.makeVMContext(toActor.Head, msg.From, msg)
var errcode byte var errcode byte
var ret []byte var ret []byte