start method IDs at 1, to allow 0 for basic transfers

This commit is contained in:
whyrusleeping 2019-07-26 14:42:38 -07:00
parent e1b95fdc8d
commit 9ccd06b060
8 changed files with 74 additions and 36 deletions

View File

@ -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
}

View File

@ -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,
}
}

View File

@ -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")
}

View File

@ -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),

View File

@ -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),

View File

@ -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,

View File

@ -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,

View File

@ -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,
}