From 9ccd06b06010e5882e6c4b0018b574607825b067 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 26 Jul 2019 14:42:38 -0700 Subject: [PATCH] start method IDs at 1, to allow 0 for basic transfers --- chain/actors/actor_init.go | 13 +++++-- chain/actors/actor_miner.go | 47 +++++++++++++++++------- chain/actors/actor_storagemarket.go | 32 +++++++++++----- chain/actors/actor_storagemarket_test.go | 6 +-- chain/actors/actors_test.go | 4 +- chain/actors/harness_test.go | 4 +- cli/createminer.go | 2 +- cmd/lotus-storage-miner/init.go | 2 +- 8 files changed, 74 insertions(+), 36 deletions(-) diff --git a/chain/actors/actor_init.go b/chain/actors/actor_init.go index 022233688..5f86fc65c 100644 --- a/chain/actors/actor_init.go +++ b/chain/actors/actor_init.go @@ -43,10 +43,16 @@ type InitActorState struct { NextID uint64 } +type iAMethods struct { + Exec uint64 +} + +var IAMethods = iAMethods{2} + func (ia InitActor) Exports() []interface{} { return []interface{}{ - nil, - ia.Exec, + 1: nil, + 2: ia.Exec, } } @@ -134,7 +140,8 @@ func (ia InitActor) Exec(act *types.Actor, vmctx types.VMContext, p *ExecParams) return nil, aerrors.Escalate(err, "inserting new actor into state tree") } - _, err = vmctx.Send(idAddr, 0, vmctx.Message().Value, p.Params) + // '1' is reserved for constructor methods + _, err = vmctx.Send(idAddr, 1, vmctx.Message().Value, p.Params) if err != nil { return nil, err } diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index 3f367fb25..34d023048 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -89,22 +89,41 @@ type StorageMinerConstructorParams struct { PeerID peer.ID } +type maMethods struct { + Constructor uint64 + CommitSector uint64 + SubmitPost uint64 + SlashStorageFault uint64 + GetCurrentProvingSet uint64 + ArbitrateDeal uint64 + DePledge uint64 + GetOwner uint64 + GetWorkerAddr uint64 + GetPower uint64 + GetPeerID uint64 + GetSectorSize uint64 + UpdatePeerID uint64 + ChangeWorker uint64 +} + +var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14} + func (sma StorageMinerActor) Exports() []interface{} { return []interface{}{ - 0: sma.StorageMinerConstructor, - 1: sma.CommitSector, - //2: sma.SubmitPost, - //3: sma.SlashStorageFault, - //4: sma.GetCurrentProvingSet, - //5: sma.ArbitrateDeal, - //6: sma.DePledge, - //7: sma.GetOwner, - //8: sma.GetWorkerAddr, - 9: sma.GetPower, - //10: sma.GetPeerID, - //11: sma.GetSectorSize, - //12: sma.UpdatePeerID, - //13: sma.ChangeWorker, + 1: sma.StorageMinerConstructor, + 2: sma.CommitSector, + //3: sma.SubmitPost, + //4: sma.SlashStorageFault, + //5: sma.GetCurrentProvingSet, + //6: sma.ArbitrateDeal, + //7: sma.DePledge, + //8: sma.GetOwner, + //9: sma.GetWorkerAddr, + 10: sma.GetPower, + //11: sma.GetPeerID, + //12: sma.GetSectorSize, + //13: sma.UpdatePeerID, + //14: sma.ChangeWorker, } } diff --git a/chain/actors/actor_storagemarket.go b/chain/actors/actor_storagemarket.go index 2ee22a3cf..494fc6ff1 100644 --- a/chain/actors/actor_storagemarket.go +++ b/chain/actors/actor_storagemarket.go @@ -20,16 +20,28 @@ func init() { type StorageMarketActor struct{} +type smaMethods struct { + Constructor uint64 + CreateStorageMiner uint64 + SlashConsensusFault uint64 + UpdateStorage uint64 + GetTotalStorage uint64 + PowerLookup uint64 + IsMiner uint64 +} + +var SMAMethods = smaMethods{1, 2, 3, 4, 5, 6, 7} + func (sma StorageMarketActor) Exports() []interface{} { return []interface{}{ - //0: sma.StorageMarketConstructor, - 1: sma.CreateStorageMiner, - //2: sma.SlashConsensusFault, - 3: sma.UpdateStorage, - 4: sma.GetTotalStorage, - 5: sma.PowerLookup, - 6: sma.IsMiner, - //7: sma.StorageCollateralForSize, + //1: sma.StorageMarketConstructor, + 2: sma.CreateStorageMiner, + //3: sma.SlashConsensusFault, + 4: sma.UpdateStorage, + 5: sma.GetTotalStorage, + 6: sma.PowerLookup, + 7: sma.IsMiner, + //8: sma.StorageCollateralForSize, } } @@ -60,7 +72,7 @@ func (sma StorageMarketActor) CreateStorageMiner(act *types.Actor, vmctx types.V return nil, err } - ret, err := vmctx.Send(InitActorAddress, 1, vmctx.Message().Value, encoded) + ret, err := vmctx.Send(InitActorAddress, IAMethods.Exec, vmctx.Message().Value, encoded) if err != nil { return nil, err } @@ -139,7 +151,7 @@ func (sma StorageMarketActor) PowerLookup(act *types.Actor, vmctx types.VMContex return nil, aerrors.New(1, "miner not registered with storage market") } - ret, err := vmctx.Send(params.Miner, 9, types.NewInt(0), EmptyStructCBOR) + ret, err := vmctx.Send(params.Miner, MAMethods.GetPower, types.NewInt(0), EmptyStructCBOR) if err != nil { return nil, aerrors.Wrap(err, "invoke Miner.GetPower") } diff --git a/chain/actors/actor_storagemarket_test.go b/chain/actors/actor_storagemarket_test.go index cb5255790..1640a0f2a 100644 --- a/chain/actors/actor_storagemarket_test.go +++ b/chain/actors/actor_storagemarket_test.go @@ -22,7 +22,7 @@ func TestStorageMarketCreateMiner(t *testing.T) { M: types.Message{ To: StorageMarketAddress, From: h.From, - Method: 1, + Method: SMAMethods.CreateStorageMiner, GasPrice: types.NewInt(1), GasLimit: types.NewInt(1), Value: types.NewInt(0), @@ -55,7 +55,7 @@ func TestStorageMarketCreateMiner(t *testing.T) { M: types.Message{ To: StorageMarketAddress, From: h.From, - Method: 6, + Method: SMAMethods.IsMiner, GasPrice: types.NewInt(1), GasLimit: types.NewInt(1), Value: types.NewInt(0), @@ -81,7 +81,7 @@ func TestStorageMarketCreateMiner(t *testing.T) { M: types.Message{ To: StorageMarketAddress, From: h.From, - Method: 5, + Method: SMAMethods.PowerLookup, GasPrice: types.NewInt(1), GasLimit: types.NewInt(1), Value: types.NewInt(0), diff --git a/chain/actors/actors_test.go b/chain/actors/actors_test.go index 3dfec9098..57efa3d17 100644 --- a/chain/actors/actors_test.go +++ b/chain/actors/actors_test.go @@ -78,7 +78,7 @@ func TestVMInvokeMethod(t *testing.T) { msg := &types.Message{ To: InitActorAddress, From: from, - Method: 1, + Method: IAMethods.Exec, Params: enc, GasPrice: types.NewInt(1), GasLimit: types.NewInt(1), @@ -122,7 +122,7 @@ func TestStorageMarketActorCreateMiner(t *testing.T) { msg := &types.Message{ To: StorageMarketAddress, From: from, - Method: 1, + Method: SMAMethods.CreateStorageMiner, Params: enc, GasPrice: types.NewInt(1), GasLimit: types.NewInt(1), diff --git a/chain/actors/harness_test.go b/chain/actors/harness_test.go index 07e11d3d8..02d1cae30 100644 --- a/chain/actors/harness_test.go +++ b/chain/actors/harness_test.go @@ -64,7 +64,7 @@ func NewHarness(t *testing.T) *Harness { h.cs = store.NewChainStore(h.bs, nil) - h.vm, err = vm.NewVM(stateroot, 1, maddr, h.cs) + h.vm, err = vm.NewVM(stateroot, IAMethods.Exec, maddr, h.cs) if err != nil { t.Fatal(err) } @@ -118,7 +118,7 @@ func TestVMInvokeHarness(t *testing.T) { M: types.Message{ To: InitActorAddress, From: h.From, - Method: 1, + Method: IAMethods.Exec, Params: h.DumpObject( &ExecParams{ Code: StorageMinerCodeCid, diff --git a/cli/createminer.go b/cli/createminer.go index bb850e85c..93d65298a 100644 --- a/cli/createminer.go +++ b/cli/createminer.go @@ -75,7 +75,7 @@ var createMinerCmd = &cli.Command{ msg := types.Message{ To: actors.StorageMarketAddress, From: addr, - Method: 1, // TODO: constants pls + Method: actors.SMAMethods.CreateStorageMiner, Params: params, Value: types.NewInt(0), Nonce: nonce, diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index f3ce44d17..7402da672 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -125,7 +125,7 @@ var initCmd = &cli.Command{ Value: collateral, - Method: 1, // TODO: Review: do we have a reverse index with these anywhere? (actor_storageminer.go) + Method: actors.SMAMethods.CreateStorageMiner, Params: params, }