From c41dd4efeb044f1b9ac9d830a24c7ef49e208d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sat, 19 Oct 2019 10:06:41 +0200 Subject: [PATCH] actora: register storagemarket --- chain/actors/actor_init.go | 2 +- chain/actors/actor_miner.go | 4 ++-- chain/actors/actor_storagepower_test.go | 16 ++++++++-------- chain/actors/actors.go | 17 ++++++++++------- chain/actors/actors_test.go | 2 +- chain/gen/utils.go | 8 ++++---- chain/stmgr/utils.go | 6 +++--- chain/store/weight.go | 4 ++-- chain/sync.go | 2 +- chain/vm/invoker.go | 3 ++- cli/createminer.go | 2 +- cmd/lotus-storage-miner/init.go | 2 +- node/impl/full/state.go | 6 +++--- 13 files changed, 39 insertions(+), 35 deletions(-) diff --git a/chain/actors/actor_init.go b/chain/actors/actor_init.go index 64a154b71..fdff41589 100644 --- a/chain/actors/actor_init.go +++ b/chain/actors/actor_init.go @@ -170,7 +170,7 @@ func IsBuiltinActor(code cid.Cid) bool { } func IsSingletonActor(code cid.Cid) bool { - return code == StorageMarketActorCodeCid || code == InitActorCodeCid + return code == StoragePowerActorCodeCid || code == InitActorCodeCid } func (ias *InitActorState) AddActor(cst *hamt.CborIpldStore, addr address.Address) (address.Address, error) { diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index de7e4d225..ba805cd2d 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -433,7 +433,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext, return nil, err } - _, err = vmctx.Send(StorageMarketAddress, SPAMethods.UpdateStorage, types.NewInt(0), enc) + _, err = vmctx.Send(StoragePowerAddress, SPAMethods.UpdateStorage, types.NewInt(0), enc) if err != nil { return nil, err } @@ -753,7 +753,7 @@ type MinerSlashConsensusFault struct { } func (sma StorageMinerActor) SlashConsensusFault(act *types.Actor, vmctx types.VMContext, params *MinerSlashConsensusFault) ([]byte, ActorError) { - if vmctx.Message().From != StorageMarketAddress { + if vmctx.Message().From != StoragePowerAddress { return nil, aerrors.New(1, "SlashConsensusFault may only be called by the storage market actor") } diff --git a/chain/actors/actor_storagepower_test.go b/chain/actors/actor_storagepower_test.go index cc4ef921c..76af74c9d 100644 --- a/chain/actors/actor_storagepower_test.go +++ b/chain/actors/actor_storagepower_test.go @@ -37,7 +37,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) { // cheating the bootstrapping problem cheatStorageMarketTotal(t, h.vm, h.cs.Blockstore()) - ret, _ := h.InvokeWithValue(t, ownerAddr, StorageMarketAddress, SPAMethods.CreateStorageMiner, + ret, _ := h.InvokeWithValue(t, ownerAddr, StoragePowerAddress, SPAMethods.CreateStorageMiner, types.NewInt(500000), &CreateStorageMinerParams{ Owner: ownerAddr, @@ -52,7 +52,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) { } { - ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.IsMiner, + ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.IsMiner, &IsMinerParam{Addr: minerAddr}) ApplyOK(t, ret) @@ -68,7 +68,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) { } { - ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.PowerLookup, + ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.PowerLookup, &PowerLookupParams{Miner: minerAddr}) ApplyOK(t, ret) 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, b2) - ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.ArbitrateConsensusFault, + ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.ArbitrateConsensusFault, &ArbitrateConsensusFaultParams{ Block1: b1, Block2: b2, @@ -102,13 +102,13 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) { } { - ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.PowerLookup, + ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.PowerLookup, &PowerLookupParams{Miner: minerAddr}) assert.Equal(t, ret.ExitCode, byte(1)) } { - ret, _ := h.Invoke(t, ownerAddr, StorageMarketAddress, SPAMethods.IsMiner, &IsMinerParam{minerAddr}) + ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.IsMiner, &IsMinerParam{minerAddr}) ApplyOK(t, ret) assert.Equal(t, ret.Return, cbg.CborBoolFalse) } @@ -117,7 +117,7 @@ func TestStorageMarketCreateAndSlashMiner(t *testing.T) { func cheatStorageMarketTotal(t *testing.T, vm *vm.VM, bs bstore.Blockstore) { t.Helper() - sma, err := vm.StateTree().GetActor(StorageMarketAddress) + sma, err := vm.StateTree().GetActor(StoragePowerAddress) if err != nil { t.Fatal(err) } @@ -138,7 +138,7 @@ func cheatStorageMarketTotal(t *testing.T, vm *vm.VM, bs bstore.Blockstore) { sma.Head = c - if err := vm.StateTree().SetActor(StorageMarketAddress, sma); err != nil { + if err := vm.StateTree().SetActor(StoragePowerAddress, sma); err != nil { t.Fatal(err) } } diff --git a/chain/actors/actors.go b/chain/actors/actors.go index 72d3b96d5..0f18964cb 100644 --- a/chain/actors/actors.go +++ b/chain/actors/actors.go @@ -8,6 +8,7 @@ import ( ) var AccountActorCodeCid cid.Cid +var StoragePowerActorCodeCid cid.Cid var StorageMarketActorCodeCid cid.Cid var StorageMinerCodeCid cid.Cid var MultisigActorCodeCid cid.Cid @@ -16,7 +17,8 @@ var PaymentChannelActorCodeCid cid.Cid var InitActorAddress = mustIDAddress(0) var NetworkAddress = mustIDAddress(1) -var StorageMarketAddress = mustIDAddress(2) +var StoragePowerAddress = mustIDAddress(2) +var StorageMarketAddress = mustIDAddress(3) // TODO: missing from spec var BurntFundsAddress = mustIDAddress(99) func mustIDAddress(i uint64) address.Address { @@ -37,10 +39,11 @@ func init() { return c } - AccountActorCodeCid = mustSum("account") - StorageMarketActorCodeCid = mustSum("smarket") - StorageMinerCodeCid = mustSum("sminer") - MultisigActorCodeCid = mustSum("multisig") - InitActorCodeCid = mustSum("init") - PaymentChannelActorCodeCid = mustSum("paych") + AccountActorCodeCid = mustSum("filecoin/1.0/AccountActor") + StoragePowerActorCodeCid = mustSum("filecoin/1.0/StoragePowerActor") + StorageMarketActorCodeCid = mustSum("filecoin/1.0/StorageMarketActor") + StorageMinerCodeCid = mustSum("filecoin/1.0/StorageMinerActor") + MultisigActorCodeCid = mustSum("filecoin/1.0/MultisigActor") + InitActorCodeCid = mustSum("filecoin/1.0/InitActor") + PaymentChannelActorCodeCid = mustSum("filecoin/1.0/PaymentChannelActor") } diff --git a/chain/actors/actors_test.go b/chain/actors/actors_test.go index 36902de75..27946664c 100644 --- a/chain/actors/actors_test.go +++ b/chain/actors/actors_test.go @@ -128,7 +128,7 @@ func TestStorageMarketActorCreateMiner(t *testing.T) { } msg := &types.Message{ - To: StorageMarketAddress, + To: StoragePowerAddress, From: from, Method: SPAMethods.CreateStorageMiner, Params: enc, diff --git a/chain/gen/utils.go b/chain/gen/utils.go index 6a1a5ca34..06ade0030 100644 --- a/chain/gen/utils.go +++ b/chain/gen/utils.go @@ -94,7 +94,7 @@ func MakeInitialStateTree(bs bstore.Blockstore, actmap map[address.Address]types return nil, xerrors.Errorf("setup storage market actor: %w", err) } - if err := state.SetActor(actors.StorageMarketAddress, smact); err != nil { + if err := state.SetActor(actors.StoragePowerAddress, smact); err != nil { return nil, xerrors.Errorf("set storage market actor: %w", err) } @@ -154,7 +154,7 @@ func SetupStorageMarketActor(bs bstore.Blockstore) (*types.Actor, error) { } return &types.Actor{ - Code: actors.StorageMarketActorCodeCid, + Code: actors.StoragePowerActorCodeCid, Head: stcid, Nonce: 0, Balance: 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 // time anyone changes the initial account allocations - rval, err := doExecValue(ctx, vm, actors.StorageMarketAddress, owner, types.FromFil(6500), actors.SPAMethods.CreateStorageMiner, params) + rval, err := doExecValue(ctx, vm, actors.StoragePowerAddress, owner, types.FromFil(6500), actors.SPAMethods.CreateStorageMiner, params) if err != nil { 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)}) - _, err = doExec(ctx, vm, actors.StorageMarketAddress, maddr, actors.SPAMethods.UpdateStorage, params) + _, err = doExec(ctx, vm, actors.StoragePowerAddress, maddr, actors.SPAMethods.UpdateStorage, params) if err != nil { return cid.Undef, xerrors.Errorf("failed to update total storage: %w", err) } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 025a8deb7..8a7398b9a 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -80,7 +80,7 @@ func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr add } ret, err := sm.Call(ctx, &types.Message{ From: maddr, - To: actors.StorageMarketAddress, + To: actors.StoragePowerAddress, Method: actors.SPAMethods.PowerLookup, Params: enc, }, ts) @@ -95,8 +95,8 @@ func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr add } ret, err := sm.Call(ctx, &types.Message{ - From: actors.StorageMarketAddress, - To: actors.StorageMarketAddress, + From: actors.StoragePowerAddress, + To: actors.StoragePowerAddress, Method: actors.SPAMethods.GetTotalStorage, }, ts) if err != nil { diff --git a/chain/store/weight.go b/chain/store/weight.go index cf992554a..7c1f80ceb 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -23,8 +23,8 @@ func (cs *ChainStore) Weight(ctx context.Context, ts *types.TipSet) (types.BigIn // >>> wFunction(totalPowerAtTipset(ts)) * 2^8 <<< + (wFunction(totalPowerAtTipset(ts)) * len(ts.blocks) * wRatio_num * 2^8) / (e * wRatio_den) ret, err := cs.call(ctx, &types.Message{ - From: actors.StorageMarketAddress, - To: actors.StorageMarketAddress, + From: actors.StoragePowerAddress, + To: actors.StoragePowerAddress, Method: actors.SPAMethods.GetTotalStorage, }, ts) if err != nil { diff --git a/chain/sync.go b/chain/sync.go index def95c25e..c27532e09 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -398,7 +398,7 @@ func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, b } ret, err := syncer.sm.Call(ctx, &types.Message{ - To: actors.StorageMarketAddress, + To: actors.StoragePowerAddress, From: maddr, Method: actors.SPAMethods.IsMiner, Params: enc, diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 713f64d39..c91109734 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -30,7 +30,8 @@ func newInvoker() *invoker { // add builtInCode using: register(cid, singleton) inv.register(actors.InitActorCodeCid, actors.InitActor{}, actors.InitActorState{}) - inv.register(actors.StorageMarketActorCodeCid, actors.StoragePowerActor{}, actors.StoragePowerState{}) + inv.register(actors.StoragePowerActorCodeCid, actors.StoragePowerActor{}, actors.StoragePowerState{}) + inv.register(actors.StorageMarketActorCodeCid, actors.StorageMarketActor{}, actors.StorageMarketState{}) inv.register(actors.StorageMinerCodeCid, actors.StorageMinerActor{}, actors.StorageMinerActorState{}) inv.register(actors.MultisigActorCodeCid, actors.MultiSigActor{}, actors.MultiSigActorState{}) inv.register(actors.PaymentChannelActorCodeCid, actors.PaymentChannelActor{}, actors.PaymentChannelActorState{}) diff --git a/cli/createminer.go b/cli/createminer.go index 551528613..25640b5fa 100644 --- a/cli/createminer.go +++ b/cli/createminer.go @@ -69,7 +69,7 @@ var createMinerCmd = &cli.Command{ } msg := &types.Message{ - To: actors.StorageMarketAddress, + To: actors.StoragePowerAddress, From: addr, Method: actors.SPAMethods.CreateStorageMiner, Params: params, diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index a0085fe81..d4e7a7235 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -303,7 +303,7 @@ func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID, c } createStorageMinerMsg := &types.Message{ - To: actors.StorageMarketAddress, + To: actors.StoragePowerAddress, From: owner, Value: collateral, diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 135317ca9..e357c0814 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -90,8 +90,8 @@ func (a *StateAPI) StatePledgeCollateral(ctx context.Context, ts *types.TipSet) } ret, aerr := a.StateManager.Call(ctx, &types.Message{ - From: actors.StorageMarketAddress, - To: actors.StorageMarketAddress, + From: actors.StoragePowerAddress, + To: actors.StoragePowerAddress, Method: actors.SPAMethods.PledgeCollateralForSize, Params: param, @@ -210,7 +210,7 @@ func (a *StateAPI) StateWaitMsg(ctx context.Context, msg cid.Cid) (*api.MsgWait, func (a *StateAPI) StateListMiners(ctx context.Context, ts *types.TipSet) ([]address.Address, error) { var state actors.StoragePowerState - if _, err := a.StateManager.LoadActorState(ctx, actors.StorageMarketAddress, &state, ts); err != nil { + if _, err := a.StateManager.LoadActorState(ctx, actors.StoragePowerAddress, &state, ts); err != nil { return nil, err }