From d373f78326714a174256876a3b3944ff28c04c86 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 16 Jul 2019 18:40:25 +0200 Subject: [PATCH] Adapt to need changes in spec License: MIT Signed-off-by: Jakub Sztandera --- chain/actors/actor_miner.go | 3 ++- chain/actors/actor_storagemarket.go | 2 ++ chain/actors/actor_storagemarket_test.go | 3 ++- chain/actors/harness_test.go | 6 ++++-- chain/types/vmcontext.go | 1 + chain/vm.go | 23 ++++++++++++----------- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index a03ae691b..1364628c4 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -72,6 +72,7 @@ type StorageMinerActorState struct { } type StorageMinerConstructorParams struct { + Owner address.Address Worker address.Address SectorSize types.BigInt 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) { var self StorageMinerActorState - self.Owner = vmctx.Message().From + self.Owner = params.Owner self.Worker = params.Worker self.PeerID = params.PeerID self.SectorSize = params.SectorSize diff --git a/chain/actors/actor_storagemarket.go b/chain/actors/actor_storagemarket.go index bad1f738c..ce5ab2397 100644 --- a/chain/actors/actor_storagemarket.go +++ b/chain/actors/actor_storagemarket.go @@ -30,6 +30,7 @@ type StorageMarketState struct { } type CreateStorageMinerParams struct { + Owner address.Address Worker address.Address SectorSize types.BigInt PeerID peer.ID @@ -44,6 +45,7 @@ func (sma StorageMarketActor) CreateStorageMiner(act *types.Actor, vmctx types.V } encoded, err := CreateExecParams(StorageMinerCodeCid, &StorageMinerConstructorParams{ + Owner: params.Owner, Worker: params.Worker, SectorSize: params.SectorSize, PeerID: params.PeerID, diff --git a/chain/actors/actor_storagemarket_test.go b/chain/actors/actor_storagemarket_test.go index dfd8b91f0..0adbc7b11 100644 --- a/chain/actors/actor_storagemarket_test.go +++ b/chain/actors/actor_storagemarket_test.go @@ -21,7 +21,8 @@ func TestStorageMarketCreateMiner(t *testing.T) { GasPrice: types.NewInt(1), GasLimit: types.NewInt(1), Value: types.NewInt(0), - Params: h.DumpObject(&StorageMinerConstructorParams{ + Params: h.DumpObject(&CreateStorageMinerParams{ + Owner: h.From, Worker: h.Third, SectorSize: types.NewInt(SectorSize), PeerID: "fakepeerid", diff --git a/chain/actors/harness_test.go b/chain/actors/harness_test.go index a2e9853b5..7d5c1fdc7 100644 --- a/chain/actors/harness_test.go +++ b/chain/actors/harness_test.go @@ -118,8 +118,10 @@ func TestVMInvokeHarness(t *testing.T) { Method: 1, Params: h.DumpObject( &ExecParams{ - Code: StorageMinerCodeCid, - Params: h.DumpObject(&StorageMinerConstructorParams{}), + Code: StorageMinerCodeCid, + Params: h.DumpObject(&StorageMinerConstructorParams{ + Owner: h.From, + }), }), GasPrice: types.NewInt(1), GasLimit: types.NewInt(1), diff --git a/chain/types/vmcontext.go b/chain/types/vmcontext.go index 2e638185a..9beffb97f 100644 --- a/chain/types/vmcontext.go +++ b/chain/types/vmcontext.go @@ -24,6 +24,7 @@ type StateTree interface { type VMContext interface { Message() *Message + Origin() address.Address Ipld() *hamt.CborIpldStore Send(to address.Address, method uint64, value BigInt, params []byte) ([]byte, uint8, error) BlockHeight() uint64 diff --git a/chain/vm.go b/chain/vm.go index 683605f20..6c5e2f418 100644 --- a/chain/vm.go +++ b/chain/vm.go @@ -27,6 +27,9 @@ type VMContext struct { // root cid of the state of the actor this invocation will be on sroot cid.Cid + // address that started invokation chain + origin address.Address + storage types.Storage } @@ -72,18 +75,15 @@ func (vmc *VMContext) Ipld() *hamt.CborIpldStore { 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 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{ - From: from, + From: vmc.msg.To, To: to, Method: method, Value: value, @@ -95,7 +95,7 @@ func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt 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) if err != nil { @@ -124,7 +124,7 @@ func (vmc *VMContext) StateTree() (types.StateTree, error) { 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) return &VMContext{ @@ -132,6 +132,7 @@ func (vm *VM) makeVMContext(sroot cid.Cid, msg *types.Message) *VMContext { state: vm.cstate, sroot: sroot, msg: msg, + origin: origin, height: vm.blockHeight, cst: cst, storage: &storage{ @@ -207,7 +208,7 @@ func (vm *VM) ApplyMessage(msg *types.Message) (*types.MessageReceipt, error) { } DepositFunds(toActor, msg.Value) - vmctx := vm.makeVMContext(toActor.Head, msg) + vmctx := vm.makeVMContext(toActor.Head, msg.From, msg) var errcode byte var ret []byte