WIP: implement enough of submitPoSt that we can get things moving
This commit is contained in:
parent
abe1edb147
commit
8a0e233cbd
@ -26,22 +26,8 @@ const POST_SECTORS_COUNT = 8192
|
|||||||
type StorageMinerActor struct{}
|
type StorageMinerActor struct{}
|
||||||
|
|
||||||
type StorageMinerActorState struct {
|
type StorageMinerActorState struct {
|
||||||
// Account that owns this miner.
|
// Contains mostly static info about this miner
|
||||||
// - Income and returned collateral are paid to this address.
|
Info cid.Cid
|
||||||
// - This address is also allowed to change the worker address for the miner.
|
|
||||||
Owner address.Address
|
|
||||||
|
|
||||||
// Worker account for this miner.
|
|
||||||
// This will be the key that is used to sign blocks created by this miner, and
|
|
||||||
// sign messages sent on behalf of this miner to commit sectors, submit PoSts, and
|
|
||||||
// other day to day miner activities.
|
|
||||||
Worker address.Address
|
|
||||||
|
|
||||||
// Libp2p identity that should be used when connecting to this miner.
|
|
||||||
PeerID peer.ID
|
|
||||||
|
|
||||||
// Amount of space in each sector committed to the network by this miner.
|
|
||||||
SectorSize types.BigInt
|
|
||||||
|
|
||||||
// Collateral that is waiting to be withdrawn.
|
// Collateral that is waiting to be withdrawn.
|
||||||
DePledgedCollateral types.BigInt
|
DePledgedCollateral types.BigInt
|
||||||
@ -70,8 +56,6 @@ type StorageMinerActorState struct {
|
|||||||
// Amount of power this miner has.
|
// Amount of power this miner has.
|
||||||
Power types.BigInt
|
Power types.BigInt
|
||||||
|
|
||||||
ProvingPeriodEnd uint64
|
|
||||||
|
|
||||||
// List of sectors that this miner was slashed for.
|
// List of sectors that this miner was slashed for.
|
||||||
//SlashedSet SectorSet
|
//SlashedSet SectorSet
|
||||||
|
|
||||||
@ -80,6 +64,27 @@ type StorageMinerActorState struct {
|
|||||||
|
|
||||||
// The amount of storage collateral that is owed to clients, and cannot be used for collateral anymore.
|
// The amount of storage collateral that is owed to clients, and cannot be used for collateral anymore.
|
||||||
OwedStorageCollateral types.BigInt
|
OwedStorageCollateral types.BigInt
|
||||||
|
|
||||||
|
ProvingPeriodEnd uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
type MinerInfo struct {
|
||||||
|
// Account that owns this miner.
|
||||||
|
// - Income and returned collateral are paid to this address.
|
||||||
|
// - This address is also allowed to change the worker address for the miner.
|
||||||
|
Owner address.Address
|
||||||
|
|
||||||
|
// Worker account for this miner.
|
||||||
|
// This will be the key that is used to sign blocks created by this miner, and
|
||||||
|
// sign messages sent on behalf of this miner to commit sectors, submit PoSts, and
|
||||||
|
// other day to day miner activities.
|
||||||
|
Worker address.Address
|
||||||
|
|
||||||
|
// Libp2p identity that should be used when connecting to this miner.
|
||||||
|
PeerID peer.ID
|
||||||
|
|
||||||
|
// Amount of space in each sector committed to the network by this miner.
|
||||||
|
SectorSize types.BigInt
|
||||||
}
|
}
|
||||||
|
|
||||||
type StorageMinerConstructorParams struct {
|
type StorageMinerConstructorParams struct {
|
||||||
@ -112,9 +117,9 @@ func (sma StorageMinerActor) Exports() []interface{} {
|
|||||||
return []interface{}{
|
return []interface{}{
|
||||||
1: sma.StorageMinerConstructor,
|
1: sma.StorageMinerConstructor,
|
||||||
2: sma.CommitSector,
|
2: sma.CommitSector,
|
||||||
//3: sma.SubmitPost,
|
3: sma.SubmitPoSt,
|
||||||
//4: sma.SlashStorageFault,
|
//4: sma.SlashStorageFault,
|
||||||
//5: sma.GetCurrentProvingSet,
|
//5: sma.GetCurrentProvingSet,
|
||||||
//6: sma.ArbitrateDeal,
|
//6: sma.ArbitrateDeal,
|
||||||
//7: sma.DePledge,
|
//7: sma.DePledge,
|
||||||
8: sma.GetOwner,
|
8: sma.GetOwner,
|
||||||
@ -137,13 +142,29 @@ func loadState(vmctx types.VMContext) (cid.Cid, *StorageMinerActorState, ActorEr
|
|||||||
return oldstate, &self, nil
|
return oldstate, &self, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) ([]byte, ActorError) {
|
func loadMinerInfo(vmctx types.VMContext, m *StorageMinerActorState) (*MinerInfo, ActorError) {
|
||||||
var self StorageMinerActorState
|
var mi MinerInfo
|
||||||
self.Owner = params.Owner
|
if err := vmctx.Storage().Get(m.Info, &mi); err != nil {
|
||||||
self.Worker = params.Worker
|
return nil, err
|
||||||
self.PeerID = params.PeerID
|
}
|
||||||
self.SectorSize = params.SectorSize
|
|
||||||
|
|
||||||
|
return &mi, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) ([]byte, ActorError) {
|
||||||
|
minerInfo := &MinerInfo{
|
||||||
|
Owner: params.Owner,
|
||||||
|
Worker: params.Worker,
|
||||||
|
PeerID: params.PeerID,
|
||||||
|
SectorSize: params.SectorSize,
|
||||||
|
}
|
||||||
|
|
||||||
|
minfocid, err := vmctx.Storage().Put(minerInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var self StorageMinerActorState
|
||||||
nd := hamt.NewNode(vmctx.Ipld())
|
nd := hamt.NewNode(vmctx.Ipld())
|
||||||
sectors, nerr := vmctx.Ipld().Put(context.TODO(), nd)
|
sectors, nerr := vmctx.Ipld().Put(context.TODO(), nd)
|
||||||
if nerr != nil {
|
if nerr != nil {
|
||||||
@ -179,7 +200,12 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ValidatePoRep(self.SectorSize, params) {
|
mi, err := loadMinerInfo(vmctx, self)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ValidatePoRep(mi.SectorSize, params) {
|
||||||
return nil, aerrors.New(1, "bad proof!")
|
return nil, aerrors.New(1, "bad proof!")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +219,7 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Power of the miner after adding this sector
|
// Power of the miner after adding this sector
|
||||||
futurePower := types.BigAdd(self.Power, self.SectorSize)
|
futurePower := types.BigAdd(self.Power, mi.SectorSize)
|
||||||
collateralRequired := CollateralForPower(futurePower)
|
collateralRequired := CollateralForPower(futurePower)
|
||||||
|
|
||||||
if types.BigCmp(collateralRequired, act.Balance) < 0 {
|
if types.BigCmp(collateralRequired, act.Balance) < 0 {
|
||||||
@ -239,6 +265,36 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SubmitPoStParams struct {
|
||||||
|
// TODO: once the spec changes finish, we have more work to do here...
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext, params *SubmitPoStParams) ([]byte, ActorError) {
|
||||||
|
oldstate, self, err := loadState(vmctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
mi, err := loadMinerInfo(vmctx, self)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if vmctx.Message().From != mi.Worker {
|
||||||
|
return nil, aerrors.New(1, "not authorized to submit post for miner")
|
||||||
|
}
|
||||||
|
|
||||||
|
oldProvingSetSize := self.ProvingSetSize
|
||||||
|
|
||||||
|
self.ProvingSet = self.Sectors
|
||||||
|
self.ProvingSetSize = self.SectorSetSize
|
||||||
|
|
||||||
|
oldPower := self.Power
|
||||||
|
self.Power = (oldProvingSetSize * mi.SectorSize)
|
||||||
|
|
||||||
|
// TODO: call update power
|
||||||
|
}
|
||||||
|
|
||||||
func (sma StorageMinerActor) GetPower(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
func (sma StorageMinerActor) GetPower(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) {
|
||||||
_, self, err := loadState(vmctx)
|
_, self, err := loadState(vmctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user