actors: Sync with the new spec, storage actors

This commit is contained in:
Łukasz Magiera 2019-10-12 00:59:36 +02:00
parent 9a238b7d01
commit a576b72364
13 changed files with 52 additions and 52 deletions

View File

@ -433,7 +433,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
return nil, err return nil, err
} }
_, err = vmctx.Send(StorageMarketAddress, SMAMethods.UpdateStorage, types.NewInt(0), enc) _, err = vmctx.Send(StorageMarketAddress, SPAMethods.UpdateStorage, types.NewInt(0), enc)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -15,9 +15,9 @@ import (
xerrors "golang.org/x/xerrors" xerrors "golang.org/x/xerrors"
) )
type StorageMarketActor struct{} type StoragePowerActor struct{}
type smaMethods struct { type spaMethods struct {
Constructor uint64 Constructor uint64
CreateStorageMiner uint64 CreateStorageMiner uint64
ArbitrateConsensusFault uint64 ArbitrateConsensusFault uint64
@ -28,22 +28,22 @@ type smaMethods struct {
PledgeCollateralForSize uint64 PledgeCollateralForSize uint64
} }
var SMAMethods = smaMethods{1, 2, 3, 4, 5, 6, 7, 8} var SPAMethods = spaMethods{1, 2, 3, 4, 5, 6, 7, 8}
func (sma StorageMarketActor) Exports() []interface{} { func (spa StoragePowerActor) Exports() []interface{} {
return []interface{}{ return []interface{}{
//1: sma.StorageMarketConstructor, //1: spa.StoragePowerConstructor,
2: sma.CreateStorageMiner, 2: spa.CreateStorageMiner,
3: sma.ArbitrateConsensusFault, 3: spa.ArbitrateConsensusFault,
4: sma.UpdateStorage, 4: spa.UpdateStorage,
5: sma.GetTotalStorage, 5: spa.GetTotalStorage,
6: sma.PowerLookup, 6: spa.PowerLookup,
7: sma.IsMiner, 7: spa.IsMiner,
8: sma.PledgeCollateralForSize, 8: spa.PledgeCollateralForSize,
} }
} }
type StorageMarketState struct { type StoragePowerState struct {
Miners cid.Cid Miners cid.Cid
MinerCount uint64 MinerCount uint64
@ -57,12 +57,12 @@ type CreateStorageMinerParams struct {
PeerID peer.ID PeerID peer.ID
} }
func (sma StorageMarketActor) CreateStorageMiner(act *types.Actor, vmctx types.VMContext, params *CreateStorageMinerParams) ([]byte, ActorError) { func (spa StoragePowerActor) CreateStorageMiner(act *types.Actor, vmctx types.VMContext, params *CreateStorageMinerParams) ([]byte, ActorError) {
if !SupportedSectorSize(params.SectorSize) { if !SupportedSectorSize(params.SectorSize) {
return nil, aerrors.New(1, "Unsupported sector size") return nil, aerrors.New(1, "Unsupported sector size")
} }
var self StorageMarketState var self StoragePowerState
old := vmctx.Storage().GetHead() old := vmctx.Storage().GetHead()
if err := vmctx.Storage().Get(old, &self); err != nil { if err := vmctx.Storage().Get(old, &self); err != nil {
return nil, err return nil, err
@ -128,7 +128,7 @@ type ArbitrateConsensusFaultParams struct {
Block2 *types.BlockHeader Block2 *types.BlockHeader
} }
func (sma StorageMarketActor) ArbitrateConsensusFault(act *types.Actor, vmctx types.VMContext, params *ArbitrateConsensusFaultParams) ([]byte, ActorError) { func (spa StoragePowerActor) ArbitrateConsensusFault(act *types.Actor, vmctx types.VMContext, params *ArbitrateConsensusFaultParams) ([]byte, ActorError) {
if params.Block1.Miner != params.Block2.Miner { if params.Block1.Miner != params.Block2.Miner {
return nil, aerrors.New(2, "blocks must be from the same miner") return nil, aerrors.New(2, "blocks must be from the same miner")
} }
@ -158,14 +158,14 @@ func (sma StorageMarketActor) ArbitrateConsensusFault(act *types.Actor, vmctx ty
return nil, aerrors.New(6, "blocks do not prove a slashable offense") return nil, aerrors.New(6, "blocks do not prove a slashable offense")
} }
var self StorageMarketState var self StoragePowerState
old := vmctx.Storage().GetHead() old := vmctx.Storage().GetHead()
if err := vmctx.Storage().Get(old, &self); err != nil { if err := vmctx.Storage().Get(old, &self); err != nil {
return nil, err return nil, err
} }
if types.BigCmp(self.TotalStorage, types.NewInt(0)) == 0 { if types.BigCmp(self.TotalStorage, types.NewInt(0)) == 0 {
return nil, aerrors.Fatal("invalid state, storage market actor has zero total storage") return nil, aerrors.Fatal("invalid state, storage power actor has zero total storage")
} }
miner := params.Block1.Miner miner := params.Block1.Miner
@ -269,8 +269,8 @@ type UpdateStorageParams struct {
Delta types.BigInt Delta types.BigInt
} }
func (sma StorageMarketActor) UpdateStorage(act *types.Actor, vmctx types.VMContext, params *UpdateStorageParams) ([]byte, ActorError) { func (spa StoragePowerActor) UpdateStorage(act *types.Actor, vmctx types.VMContext, params *UpdateStorageParams) ([]byte, ActorError) {
var self StorageMarketState var self StoragePowerState
old := vmctx.Storage().GetHead() old := vmctx.Storage().GetHead()
if err := vmctx.Storage().Get(old, &self); err != nil { if err := vmctx.Storage().Get(old, &self); err != nil {
return nil, err return nil, err
@ -299,8 +299,8 @@ func (sma StorageMarketActor) UpdateStorage(act *types.Actor, vmctx types.VMCont
return nil, nil return nil, nil
} }
func (sma StorageMarketActor) GetTotalStorage(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) { func (spa StoragePowerActor) GetTotalStorage(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
var self StorageMarketState var self StoragePowerState
if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil { if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil {
return nil, err return nil, err
} }
@ -312,8 +312,8 @@ type PowerLookupParams struct {
Miner address.Address Miner address.Address
} }
func (sma StorageMarketActor) PowerLookup(act *types.Actor, vmctx types.VMContext, params *PowerLookupParams) ([]byte, ActorError) { func (spa StoragePowerActor) PowerLookup(act *types.Actor, vmctx types.VMContext, params *PowerLookupParams) ([]byte, ActorError) {
var self StorageMarketState var self StoragePowerState
if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil { if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil {
return nil, aerrors.Wrap(err, "getting head") return nil, aerrors.Wrap(err, "getting head")
} }
@ -326,14 +326,14 @@ func (sma StorageMarketActor) PowerLookup(act *types.Actor, vmctx types.VMContex
return pow.Bytes(), nil return pow.Bytes(), nil
} }
func powerLookup(ctx context.Context, vmctx types.VMContext, self *StorageMarketState, miner address.Address) (types.BigInt, ActorError) { func powerLookup(ctx context.Context, vmctx types.VMContext, self *StoragePowerState, miner address.Address) (types.BigInt, ActorError) {
has, err := MinerSetHas(context.TODO(), vmctx, self.Miners, miner) has, err := MinerSetHas(context.TODO(), vmctx, self.Miners, miner)
if err != nil { if err != nil {
return types.EmptyInt, err return types.EmptyInt, err
} }
if !has { if !has {
return types.EmptyInt, aerrors.New(1, "miner not registered with storage market") return types.EmptyInt, aerrors.New(1, "miner not registered with storage power actor")
} }
ret, err := vmctx.Send(miner, MAMethods.GetPower, types.NewInt(0), nil) ret, err := vmctx.Send(miner, MAMethods.GetPower, types.NewInt(0), nil)
@ -348,8 +348,8 @@ type IsMinerParam struct {
Addr address.Address Addr address.Address
} }
func (sma StorageMarketActor) IsMiner(act *types.Actor, vmctx types.VMContext, param *IsMinerParam) ([]byte, ActorError) { func (spa StoragePowerActor) IsMiner(act *types.Actor, vmctx types.VMContext, param *IsMinerParam) ([]byte, ActorError) {
var self StorageMarketState var self StoragePowerState
if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil { if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil {
return nil, err return nil, err
} }
@ -366,8 +366,8 @@ type PledgeCollateralParams struct {
Size types.BigInt Size types.BigInt
} }
func (sma StorageMarketActor) PledgeCollateralForSize(act *types.Actor, vmctx types.VMContext, param *PledgeCollateralParams) ([]byte, ActorError) { func (spa StoragePowerActor) PledgeCollateralForSize(act *types.Actor, vmctx types.VMContext, param *PledgeCollateralParams) ([]byte, ActorError) {
var self StorageMarketState var self StoragePowerState
if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil { if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil {
return nil, err return nil, err
} }

View File

@ -37,7 +37,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
// cheating the bootstrapping problem // cheating the bootstrapping problem
cheatStorageMarketTotal(t, h.vm, h.cs.Blockstore()) cheatStorageMarketTotal(t, h.vm, h.cs.Blockstore())
ret, _ := h.InvokeWithValue(t, ownerAddr, StorageMarketAddress, SMAMethods.CreateStorageMiner, ret, _ := h.InvokeWithValue(t, ownerAddr, StorageMarketAddress, SPAMethods.CreateStorageMiner,
types.NewInt(500000), types.NewInt(500000),
&CreateStorageMinerParams{ &CreateStorageMinerParams{
Owner: ownerAddr, Owner: ownerAddr,
@ -52,7 +52,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
} }
{ {
ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SMAMethods.IsMiner, ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.IsMiner,
&IsMinerParam{Addr: minerAddr}) &IsMinerParam{Addr: minerAddr})
ApplyOK(t, ret) ApplyOK(t, ret)
@ -68,7 +68,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
} }
{ {
ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SMAMethods.PowerLookup, ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.PowerLookup,
&PowerLookupParams{Miner: minerAddr}) &PowerLookupParams{Miner: minerAddr})
ApplyOK(t, ret) ApplyOK(t, ret)
power := types.BigFromBytes(ret.Return) power := types.BigFromBytes(ret.Return)
@ -93,7 +93,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
signBlock(t, h.w, workerAddr, b1) signBlock(t, h.w, workerAddr, b1)
signBlock(t, h.w, workerAddr, b2) signBlock(t, h.w, workerAddr, b2)
ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SMAMethods.ArbitrateConsensusFault, ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.ArbitrateConsensusFault,
&ArbitrateConsensusFaultParams{ &ArbitrateConsensusFaultParams{
Block1: b1, Block1: b1,
Block2: b2, Block2: b2,
@ -102,13 +102,13 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) {
} }
{ {
ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SMAMethods.PowerLookup, ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.PowerLookup,
&PowerLookupParams{Miner: minerAddr}) &PowerLookupParams{Miner: minerAddr})
assert.Equal(t, ret.ExitCode, byte(1)) assert.Equal(t, ret.ExitCode, byte(1))
} }
{ {
ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SMAMethods.IsMiner, &IsMinerParam{minerAddr}) ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.IsMiner, &IsMinerParam{minerAddr})
ApplyOK(t, ret) ApplyOK(t, ret)
assert.Equal(t, ret.Return, cbg.CborBoolFalse) assert.Equal(t, ret.Return, cbg.CborBoolFalse)
} }
@ -124,7 +124,7 @@ func cheatStorageMarketTotal(t *testing.T, vm *vm.VM, bs bstore.Blockstore) {
cst := hamt.CSTFromBstore(bs) cst := hamt.CSTFromBstore(bs)
var smastate StorageMarketState var smastate StoragePowerState
if err := cst.Get(context.TODO(), sma.Head, &smastate); err != nil { if err := cst.Get(context.TODO(), sma.Head, &smastate); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -130,7 +130,7 @@ func TestStorageMarketActorCreateMiner(t *testing.T) {
msg := &types.Message{ msg := &types.Message{
To: StorageMarketAddress, To: StorageMarketAddress,
From: from, From: from,
Method: SMAMethods.CreateStorageMiner, Method: SPAMethods.CreateStorageMiner,
Params: enc, Params: enc,
GasPrice: types.NewInt(1), GasPrice: types.NewInt(1),
GasLimit: types.NewInt(10000), GasLimit: types.NewInt(10000),

View File

@ -2379,7 +2379,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error {
return nil return nil
} }
func (t *StorageMarketState) MarshalCBOR(w io.Writer) error { func (t *StoragePowerState) MarshalCBOR(w io.Writer) error {
if t == nil { if t == nil {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
return err return err
@ -2406,7 +2406,7 @@ func (t *StorageMarketState) MarshalCBOR(w io.Writer) error {
return nil return nil
} }
func (t *StorageMarketState) UnmarshalCBOR(r io.Reader) error { func (t *StoragePowerState) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r) br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br) maj, extra, err := cbg.CborReadHeader(br)

View File

@ -143,7 +143,7 @@ func SetupStorageMarketActor(bs bstore.Blockstore) (*types.Actor, error) {
return nil, err return nil, err
} }
sms := &actors.StorageMarketState{ sms := &actors.StoragePowerState{
Miners: emptyhamt, Miners: emptyhamt,
TotalStorage: types.NewInt(0), TotalStorage: types.NewInt(0),
} }
@ -202,7 +202,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
// TODO: hardcoding 7000000 here is a little fragile, it changes any // TODO: hardcoding 7000000 here is a little fragile, it changes any
// time anyone changes the initial account allocations // time anyone changes the initial account allocations
rval, err := doExecValue(ctx, vm, actors.StorageMarketAddress, owner, types.FromFil(6500), actors.SMAMethods.CreateStorageMiner, params) rval, err := doExecValue(ctx, vm, actors.StorageMarketAddress, owner, types.FromFil(6500), actors.SPAMethods.CreateStorageMiner, params)
if err != nil { if err != nil {
return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err) return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err)
} }
@ -216,7 +216,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
params = mustEnc(&actors.UpdateStorageParams{Delta: types.NewInt(5000)}) params = mustEnc(&actors.UpdateStorageParams{Delta: types.NewInt(5000)})
_, err = doExec(ctx, vm, actors.StorageMarketAddress, maddr, actors.SMAMethods.UpdateStorage, params) _, err = doExec(ctx, vm, actors.StorageMarketAddress, maddr, actors.SPAMethods.UpdateStorage, params)
if err != nil { if err != nil {
return cid.Undef, xerrors.Errorf("failed to update total storage: %w", err) return cid.Undef, xerrors.Errorf("failed to update total storage: %w", err)
} }

View File

@ -82,7 +82,7 @@ func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr add
ret, err := sm.Call(ctx, &types.Message{ ret, err := sm.Call(ctx, &types.Message{
From: maddr, From: maddr,
To: actors.StorageMarketAddress, To: actors.StorageMarketAddress,
Method: actors.SMAMethods.PowerLookup, Method: actors.SPAMethods.PowerLookup,
Params: enc, Params: enc,
}, ts) }, ts)
if err != nil { if err != nil {
@ -98,7 +98,7 @@ func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr add
ret, err := sm.Call(ctx, &types.Message{ ret, err := sm.Call(ctx, &types.Message{
From: actors.StorageMarketAddress, From: actors.StorageMarketAddress,
To: actors.StorageMarketAddress, To: actors.StorageMarketAddress,
Method: actors.SMAMethods.GetTotalStorage, Method: actors.SPAMethods.GetTotalStorage,
}, ts) }, ts)
if err != nil { if err != nil {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get total power from chain: %w", err) return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get total power from chain: %w", err)

View File

@ -391,7 +391,7 @@ func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, b
ret, err := syncer.sm.Call(ctx, &types.Message{ ret, err := syncer.sm.Call(ctx, &types.Message{
To: actors.StorageMarketAddress, To: actors.StorageMarketAddress,
From: maddr, From: maddr,
Method: actors.SMAMethods.IsMiner, Method: actors.SPAMethods.IsMiner,
Params: enc, Params: enc,
}, baseTs) }, baseTs)
if err != nil { if err != nil {

View File

@ -30,7 +30,7 @@ func newInvoker() *invoker {
// add builtInCode using: register(cid, singleton) // add builtInCode using: register(cid, singleton)
inv.register(actors.InitActorCodeCid, actors.InitActor{}, actors.InitActorState{}) inv.register(actors.InitActorCodeCid, actors.InitActor{}, actors.InitActorState{})
inv.register(actors.StorageMarketActorCodeCid, actors.StorageMarketActor{}, actors.StorageMarketState{}) inv.register(actors.StorageMarketActorCodeCid, actors.StoragePowerActor{}, actors.StoragePowerState{})
inv.register(actors.StorageMinerCodeCid, actors.StorageMinerActor{}, actors.StorageMinerActorState{}) inv.register(actors.StorageMinerCodeCid, actors.StorageMinerActor{}, actors.StorageMinerActorState{})
inv.register(actors.MultisigActorCodeCid, actors.MultiSigActor{}, actors.MultiSigActorState{}) inv.register(actors.MultisigActorCodeCid, actors.MultiSigActor{}, actors.MultiSigActorState{})
inv.register(actors.PaymentChannelActorCodeCid, actors.PaymentChannelActor{}, actors.PaymentChannelActorState{}) inv.register(actors.PaymentChannelActorCodeCid, actors.PaymentChannelActor{}, actors.PaymentChannelActorState{})

View File

@ -71,7 +71,7 @@ var createMinerCmd = &cli.Command{
msg := &types.Message{ msg := &types.Message{
To: actors.StorageMarketAddress, To: actors.StorageMarketAddress,
From: addr, From: addr,
Method: actors.SMAMethods.CreateStorageMiner, Method: actors.SPAMethods.CreateStorageMiner,
Params: params, Params: params,
Value: types.NewInt(0), Value: types.NewInt(0),
GasPrice: types.NewInt(0), GasPrice: types.NewInt(0),

View File

@ -289,7 +289,7 @@ func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID, c
From: owner, From: owner,
Value: collateral, Value: collateral,
Method: actors.SMAMethods.CreateStorageMiner, Method: actors.SPAMethods.CreateStorageMiner,
Params: params, Params: params,
GasLimit: types.NewInt(10000), GasLimit: types.NewInt(10000),

View File

@ -67,7 +67,7 @@ func main() {
actors.LaneState{}, actors.LaneState{},
actors.PCAUpdateChannelStateParams{}, actors.PCAUpdateChannelStateParams{},
actors.PaymentInfo{}, actors.PaymentInfo{},
actors.StorageMarketState{}, actors.StoragePowerState{},
actors.CreateStorageMinerParams{}, actors.CreateStorageMinerParams{},
actors.IsMinerParam{}, actors.IsMinerParam{},
actors.PowerLookupParams{}, actors.PowerLookupParams{},

View File

@ -92,7 +92,7 @@ func (a *StateAPI) StatePledgeCollateral(ctx context.Context, ts *types.TipSet)
ret, aerr := a.StateManager.Call(ctx, &types.Message{ ret, aerr := a.StateManager.Call(ctx, &types.Message{
From: actors.StorageMarketAddress, From: actors.StorageMarketAddress,
To: actors.StorageMarketAddress, To: actors.StorageMarketAddress,
Method: actors.SMAMethods.PledgeCollateralForSize, Method: actors.SPAMethods.PledgeCollateralForSize,
Params: param, Params: param,
}, ts) }, ts)