actora: register storagemarket
This commit is contained in:
parent
8638cd25f5
commit
c41dd4efeb
@ -170,7 +170,7 @@ func IsBuiltinActor(code cid.Cid) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsSingletonActor(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) {
|
func (ias *InitActorState) AddActor(cst *hamt.CborIpldStore, addr address.Address) (address.Address, error) {
|
||||||
|
@ -433,7 +433,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
|
|||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -753,7 +753,7 @@ type MinerSlashConsensusFault struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sma StorageMinerActor) SlashConsensusFault(act *types.Actor, vmctx types.VMContext, params *MinerSlashConsensusFault) ([]byte, ActorError) {
|
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")
|
return nil, aerrors.New(1, "SlashConsensusFault may only be called by the storage market actor")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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, SPAMethods.CreateStorageMiner,
|
ret, _ := h.InvokeWithValue(t, ownerAddr, StoragePowerAddress, 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, SPAMethods.IsMiner,
|
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, 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, SPAMethods.PowerLookup,
|
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, 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, SPAMethods.ArbitrateConsensusFault,
|
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, 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, SPAMethods.PowerLookup,
|
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, 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, SPAMethods.IsMiner, &IsMinerParam{minerAddr})
|
ret, _ := h.Invoke(t, ownerAddr, StoragePowerAddress, SPAMethods.IsMiner, &IsMinerParam{minerAddr})
|
||||||
ApplyOK(t, ret)
|
ApplyOK(t, ret)
|
||||||
assert.Equal(t, ret.Return, cbg.CborBoolFalse)
|
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) {
|
func cheatStorageMarketTotal(t *testing.T, vm *vm.VM, bs bstore.Blockstore) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
sma, err := vm.StateTree().GetActor(StorageMarketAddress)
|
sma, err := vm.StateTree().GetActor(StoragePowerAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ func cheatStorageMarketTotal(t *testing.T, vm *vm.VM, bs bstore.Blockstore) {
|
|||||||
|
|
||||||
sma.Head = c
|
sma.Head = c
|
||||||
|
|
||||||
if err := vm.StateTree().SetActor(StorageMarketAddress, sma); err != nil {
|
if err := vm.StateTree().SetActor(StoragePowerAddress, sma); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var AccountActorCodeCid cid.Cid
|
var AccountActorCodeCid cid.Cid
|
||||||
|
var StoragePowerActorCodeCid cid.Cid
|
||||||
var StorageMarketActorCodeCid cid.Cid
|
var StorageMarketActorCodeCid cid.Cid
|
||||||
var StorageMinerCodeCid cid.Cid
|
var StorageMinerCodeCid cid.Cid
|
||||||
var MultisigActorCodeCid cid.Cid
|
var MultisigActorCodeCid cid.Cid
|
||||||
@ -16,7 +17,8 @@ var PaymentChannelActorCodeCid cid.Cid
|
|||||||
|
|
||||||
var InitActorAddress = mustIDAddress(0)
|
var InitActorAddress = mustIDAddress(0)
|
||||||
var NetworkAddress = mustIDAddress(1)
|
var NetworkAddress = mustIDAddress(1)
|
||||||
var StorageMarketAddress = mustIDAddress(2)
|
var StoragePowerAddress = mustIDAddress(2)
|
||||||
|
var StorageMarketAddress = mustIDAddress(3) // TODO: missing from spec
|
||||||
var BurntFundsAddress = mustIDAddress(99)
|
var BurntFundsAddress = mustIDAddress(99)
|
||||||
|
|
||||||
func mustIDAddress(i uint64) address.Address {
|
func mustIDAddress(i uint64) address.Address {
|
||||||
@ -37,10 +39,11 @@ func init() {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountActorCodeCid = mustSum("account")
|
AccountActorCodeCid = mustSum("filecoin/1.0/AccountActor")
|
||||||
StorageMarketActorCodeCid = mustSum("smarket")
|
StoragePowerActorCodeCid = mustSum("filecoin/1.0/StoragePowerActor")
|
||||||
StorageMinerCodeCid = mustSum("sminer")
|
StorageMarketActorCodeCid = mustSum("filecoin/1.0/StorageMarketActor")
|
||||||
MultisigActorCodeCid = mustSum("multisig")
|
StorageMinerCodeCid = mustSum("filecoin/1.0/StorageMinerActor")
|
||||||
InitActorCodeCid = mustSum("init")
|
MultisigActorCodeCid = mustSum("filecoin/1.0/MultisigActor")
|
||||||
PaymentChannelActorCodeCid = mustSum("paych")
|
InitActorCodeCid = mustSum("filecoin/1.0/InitActor")
|
||||||
|
PaymentChannelActorCodeCid = mustSum("filecoin/1.0/PaymentChannelActor")
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func TestStorageMarketActorCreateMiner(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
To: StorageMarketAddress,
|
To: StoragePowerAddress,
|
||||||
From: from,
|
From: from,
|
||||||
Method: SPAMethods.CreateStorageMiner,
|
Method: SPAMethods.CreateStorageMiner,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
|
@ -94,7 +94,7 @@ func MakeInitialStateTree(bs bstore.Blockstore, actmap map[address.Address]types
|
|||||||
return nil, xerrors.Errorf("setup storage market actor: %w", err)
|
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)
|
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{
|
return &types.Actor{
|
||||||
Code: actors.StorageMarketActorCodeCid,
|
Code: actors.StoragePowerActorCodeCid,
|
||||||
Head: stcid,
|
Head: stcid,
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
Balance: types.NewInt(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
|
// 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.SPAMethods.CreateStorageMiner, params)
|
rval, err := doExecValue(ctx, vm, actors.StoragePowerAddress, 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.SPAMethods.UpdateStorage, params)
|
_, err = doExec(ctx, vm, actors.StoragePowerAddress, 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)
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,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.StoragePowerAddress,
|
||||||
Method: actors.SPAMethods.PowerLookup,
|
Method: actors.SPAMethods.PowerLookup,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
}, ts)
|
}, ts)
|
||||||
@ -95,8 +95,8 @@ 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.StoragePowerAddress,
|
||||||
To: actors.StorageMarketAddress,
|
To: actors.StoragePowerAddress,
|
||||||
Method: actors.SPAMethods.GetTotalStorage,
|
Method: actors.SPAMethods.GetTotalStorage,
|
||||||
}, ts)
|
}, ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -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)
|
// >>> 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{
|
ret, err := cs.call(ctx, &types.Message{
|
||||||
From: actors.StorageMarketAddress,
|
From: actors.StoragePowerAddress,
|
||||||
To: actors.StorageMarketAddress,
|
To: actors.StoragePowerAddress,
|
||||||
Method: actors.SPAMethods.GetTotalStorage,
|
Method: actors.SPAMethods.GetTotalStorage,
|
||||||
}, ts)
|
}, ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -398,7 +398,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.StoragePowerAddress,
|
||||||
From: maddr,
|
From: maddr,
|
||||||
Method: actors.SPAMethods.IsMiner,
|
Method: actors.SPAMethods.IsMiner,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
|
@ -30,7 +30,8 @@ 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.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.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{})
|
||||||
|
@ -69,7 +69,7 @@ var createMinerCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
To: actors.StorageMarketAddress,
|
To: actors.StoragePowerAddress,
|
||||||
From: addr,
|
From: addr,
|
||||||
Method: actors.SPAMethods.CreateStorageMiner,
|
Method: actors.SPAMethods.CreateStorageMiner,
|
||||||
Params: params,
|
Params: params,
|
||||||
|
@ -303,7 +303,7 @@ func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
createStorageMinerMsg := &types.Message{
|
createStorageMinerMsg := &types.Message{
|
||||||
To: actors.StorageMarketAddress,
|
To: actors.StoragePowerAddress,
|
||||||
From: owner,
|
From: owner,
|
||||||
Value: collateral,
|
Value: collateral,
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ 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.StoragePowerAddress,
|
||||||
To: actors.StorageMarketAddress,
|
To: actors.StoragePowerAddress,
|
||||||
Method: actors.SPAMethods.PledgeCollateralForSize,
|
Method: actors.SPAMethods.PledgeCollateralForSize,
|
||||||
|
|
||||||
Params: param,
|
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) {
|
func (a *StateAPI) StateListMiners(ctx context.Context, ts *types.TipSet) ([]address.Address, error) {
|
||||||
var state actors.StoragePowerState
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user