actors: Rename some storageminer stuff to match the spec

This commit is contained in:
Łukasz Magiera 2019-10-30 16:55:55 +01:00
parent 3e5654d575
commit a4c0610cc3
5 changed files with 143 additions and 165 deletions

View File

@ -22,22 +22,27 @@ import (
type StorageMinerActor struct{}
type StorageMinerActorState struct {
// Contains mostly static info about this miner
Info cid.Cid
// Collateral that is waiting to be withdrawn.
DePledgedCollateral types.BigInt
// Time at which the depledged collateral may be withdrawn.
DePledgeTime types.BigInt
// PreCommittedSectors is the set of sectors that have been committed to but not
// yet had their proofs submitted
PreCommittedSectors map[string]*UnprovenSector
// All sectors this miner has committed.
Sectors cid.Cid
// TODO: Spec says 'StagedCommittedSectors', which one is it?
// Sectors this miner is currently mining. It is only updated
// when a PoSt is submitted (not as each new sector commitment is added).
ProvingSet cid.Cid
// TODO: these:
// SectorTable
// SectorExpirationQueue
// ChallengeStatus
// Contains mostly static info about this miner
Info cid.Cid
// Faulty sectors reported since last SubmitPost,
// up to the current proving period's challenge time.
CurrentFaultSet types.BitField
@ -53,10 +58,6 @@ type StorageMinerActorState struct {
// removal penalization is needed.
NextDoneSet types.BitField
// UnprovenSectors is the set of sectors that have been committed to but not
// yet had their proofs submitted
UnprovenSectors map[string]*UnprovenSector
// Amount of power this miner has.
Power types.BigInt
@ -89,6 +90,8 @@ type MinerInfo struct {
// Amount of space in each sector committed to the network by this miner.
SectorSize uint64
// SubsectorCount
}
type UnprovenSector struct {
@ -106,7 +109,8 @@ type StorageMinerConstructorParams struct {
type maMethods struct {
Constructor uint64
CommitSector uint64
PreCommitSector uint64
ProveCommitSector uint64
SubmitPoSt uint64
SlashStorageFault uint64
GetCurrentProvingSet uint64
@ -121,32 +125,33 @@ type maMethods struct {
ChangeWorker uint64
IsSlashed uint64
IsLate uint64
AddFaults uint64
DeclareFaults uint64
SlashConsensusFault uint64
}
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}
func (sma StorageMinerActor) Exports() []interface{} {
return []interface{}{
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,
//15: sma.IsSlashed,
//16: sma.IsLate,
17: sma.AddFaults,
18: sma.SlashConsensusFault,
2: sma.PreCommitSector,
3: sma.ProveCommitSector,
4: sma.SubmitPoSt,
//5: sma.SlashStorageFault,
//6: sma.GetCurrentProvingSet,
//7: sma.ArbitrateDeal,
//8: sma.DePledge,
9: sma.GetOwner,
10: sma.GetWorkerAddr,
11: sma.GetPower, // TODO: Remove
12: sma.GetPeerID,
13: sma.GetSectorSize,
14: sma.UpdatePeerID,
//15: sma.ChangeWorker,
//16: sma.IsSlashed,
//17: sma.IsLate,
18: sma.DeclareFaults,
19: sma.SlashConsensusFault,
}
}
@ -206,7 +211,7 @@ func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx typ
return nil, nil
}
type OnChainSealVerifyInfo struct {
type SectorPreCommitInfo struct {
CommD []byte // TODO: update proofs code
CommR []byte
@ -215,7 +220,7 @@ type OnChainSealVerifyInfo struct {
SectorNumber uint64
}
func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContext, params *OnChainSealVerifyInfo) ([]byte, ActorError) {
func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorPreCommitInfo) ([]byte, ActorError) {
ctx := vmctx.Context()
oldstate, self, err := loadState(vmctx)
if err != nil {
@ -249,7 +254,7 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
return nil, aerrors.New(4, "not enough collateral")
}
self.UnprovenSectors[uintToStringKey(params.SectorNumber)] = &UnprovenSector{
self.PreCommittedSectors[uintToStringKey(params.SectorNumber)] = &UnprovenSector{
CommR: params.CommR,
CommD: params.CommD,
SubmitHeight: vmctx.BlockHeight(),
@ -272,13 +277,13 @@ func uintToStringKey(i uint64) string {
return string(buf[:n])
}
type SubmitSectorProofParams struct {
type SectorProveCommitInfo struct {
Proof []byte
SectorID uint64
DealIDs []uint64
}
func (sma StorageMinerActor) SubmitSectorProof(act *types.Actor, vmctx types.VMContext, params *SubmitSectorProofParams) ([]byte, ActorError) {
func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorProveCommitInfo) ([]byte, ActorError) {
ctx := vmctx.Context()
oldstate, self, err := loadState(vmctx)
if err != nil {
@ -290,11 +295,11 @@ func (sma StorageMinerActor) SubmitSectorProof(act *types.Actor, vmctx types.VMC
return nil, err
}
us, ok := self.UnprovenSectors[uintToStringKey(params.SectorID)]
us, ok := self.PreCommittedSectors[uintToStringKey(params.SectorID)]
if !ok {
return nil, aerrors.New(1, "no pre-commitment found for sector")
}
delete(self.UnprovenSectors, uintToStringKey(params.SectorID))
delete(self.PreCommittedSectors, uintToStringKey(params.SectorID))
// TODO: ensure normalization to ID address
maddr := vmctx.Message().To
@ -319,7 +324,7 @@ func (sma StorageMinerActor) SubmitSectorProof(act *types.Actor, vmctx types.VMC
// Note: As written here, every miners first PoSt will only be over one sector.
// We could set up a 'grace period' for starting mining that would allow miners
// to submit several sectors for their first proving period. Alternatively, we
// could simply make the 'CommitSector' call take multiple sectors at a time.
// could simply make the 'PreCommitSector' call take multiple sectors at a time.
//
// Note: Proving period is a function of sector size; small sectors take less
// time to prove than large sectors do. Sector size is selected when pledging.
@ -697,11 +702,11 @@ type PaymentVerifyParams struct {
Proof []byte
}
type AddFaultsParams struct {
type DeclareFaultsParams struct {
Faults types.BitField
}
func (sma StorageMinerActor) AddFaults(act *types.Actor, vmctx types.VMContext, params *AddFaultsParams) ([]byte, ActorError) {
func (sma StorageMinerActor) DeclareFaults(act *types.Actor, vmctx types.VMContext, params *DeclareFaultsParams) ([]byte, ActorError) {
oldstate, self, aerr := loadState(vmctx)
if aerr != nil {
return nil, aerr

View File

@ -329,6 +329,7 @@ func powerLookup(ctx context.Context, vmctx types.VMContext, self *StoragePowerS
return types.EmptyInt, aerrors.New(1, "miner not registered with storage power actor")
}
// TODO: Use local amt
ret, err := vmctx.Send(miner, MAMethods.GetPower, types.NewInt(0), nil)
if err != nil {
return types.EmptyInt, aerrors.Wrap(err, "invoke Miner.GetPower")

View File

@ -197,24 +197,28 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{141}); err != nil {
if _, err := w.Write([]byte{139}); err != nil {
return err
}
// t.t.Info (cid.Cid)
if err := cbg.WriteCid(w, t.Info); err != nil {
return xerrors.Errorf("failed to write cid field t.Info: %w", err)
}
// t.t.DePledgedCollateral (types.BigInt)
if err := t.DePledgedCollateral.MarshalCBOR(w); err != nil {
// t.t.PreCommittedSectors (map[string]*actors.UnprovenSector)
if err := cbg.CborWriteHeader(w, cbg.MajMap, uint64(len(t.PreCommittedSectors))); err != nil {
return err
}
// t.t.DePledgeTime (types.BigInt)
if err := t.DePledgeTime.MarshalCBOR(w); err != nil {
return err
for k, v := range t.PreCommittedSectors {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(k)))); err != nil {
return err
}
if _, err := w.Write([]byte(k)); err != nil {
return err
}
if err := v.MarshalCBOR(w); err != nil {
return err
}
}
// t.t.Sectors (cid.Cid)
@ -229,6 +233,12 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
return xerrors.Errorf("failed to write cid field t.ProvingSet: %w", err)
}
// t.t.Info (cid.Cid)
if err := cbg.WriteCid(w, t.Info); err != nil {
return xerrors.Errorf("failed to write cid field t.Info: %w", err)
}
// t.t.CurrentFaultSet (types.BitField)
if err := t.CurrentFaultSet.MarshalCBOR(w); err != nil {
return err
@ -244,26 +254,6 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
return err
}
// t.t.UnprovenSectors (map[string]*actors.UnprovenSector)
if err := cbg.CborWriteHeader(w, cbg.MajMap, uint64(len(t.UnprovenSectors))); err != nil {
return err
}
for k, v := range t.UnprovenSectors {
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(k)))); err != nil {
return err
}
if _, err := w.Write([]byte(k)); err != nil {
return err
}
if err := v.MarshalCBOR(w); err != nil {
return err
}
}
// t.t.Power (types.BigInt)
if err := t.Power.MarshalCBOR(w); err != nil {
return err
@ -297,92 +287,11 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 13 {
if extra != 11 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Info (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Info: %w", err)
}
t.Info = c
}
// t.t.DePledgedCollateral (types.BigInt)
{
if err := t.DePledgedCollateral.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.DePledgeTime (types.BigInt)
{
if err := t.DePledgeTime.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Sectors (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Sectors: %w", err)
}
t.Sectors = c
}
// t.t.ProvingSet (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.ProvingSet: %w", err)
}
t.ProvingSet = c
}
// t.t.CurrentFaultSet (types.BitField)
{
if err := t.CurrentFaultSet.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.NextFaultSet (types.BitField)
{
if err := t.NextFaultSet.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.NextDoneSet (types.BitField)
{
if err := t.NextDoneSet.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.UnprovenSectors (map[string]*actors.UnprovenSector)
// t.t.PreCommittedSectors (map[string]*actors.UnprovenSector)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
@ -392,10 +301,10 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("expected a map (major type 5)")
}
if extra > 4096 {
return fmt.Errorf("t.UnprovenSectors: map too large")
return fmt.Errorf("t.PreCommittedSectors: map too large")
}
t.UnprovenSectors = make(map[string]*UnprovenSector, extra)
t.PreCommittedSectors = make(map[string]*UnprovenSector, extra)
for i, l := 0, int(extra); i < l; i++ {
@ -432,7 +341,70 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
}
t.UnprovenSectors[k] = v
t.PreCommittedSectors[k] = v
}
// t.t.Sectors (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Sectors: %w", err)
}
t.Sectors = c
}
// t.t.ProvingSet (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.ProvingSet: %w", err)
}
t.ProvingSet = c
}
// t.t.Info (cid.Cid)
{
c, err := cbg.ReadCid(br)
if err != nil {
return xerrors.Errorf("failed to read cid field t.Info: %w", err)
}
t.Info = c
}
// t.t.CurrentFaultSet (types.BitField)
{
if err := t.CurrentFaultSet.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.NextFaultSet (types.BitField)
{
if err := t.NextFaultSet.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.NextDoneSet (types.BitField)
{
if err := t.NextDoneSet.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.Power (types.BigInt)
@ -565,7 +537,7 @@ func (t *StorageMinerConstructorParams) UnmarshalCBOR(r io.Reader) error {
return nil
}
func (t *OnChainSealVerifyInfo) MarshalCBOR(w io.Writer) error {
func (t *SectorPreCommitInfo) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
@ -610,7 +582,7 @@ func (t *OnChainSealVerifyInfo) MarshalCBOR(w io.Writer) error {
return nil
}
func (t *OnChainSealVerifyInfo) UnmarshalCBOR(r io.Reader) error {
func (t *SectorPreCommitInfo) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)

View File

@ -50,7 +50,7 @@ func main() {
actors.AccountActorState{},
actors.StorageMinerActorState{},
actors.StorageMinerConstructorParams{},
actors.OnChainSealVerifyInfo{},
actors.SectorPreCommitInfo{},
actors.UnprovenSector{},
actors.MinerInfo{},
actors.SubmitPoStParams{},

View File

@ -176,7 +176,7 @@ func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSeal
return xerrors.Errorf("getting sector deals failed: %w", err)
}
*/
params := &actors.OnChainSealVerifyInfo{
params := &actors.SectorPreCommitInfo{
CommD: sinfo.CommD[:],
CommR: sinfo.CommR[:],
Proof: sinfo.Proof,
@ -193,7 +193,7 @@ func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSeal
msg := &types.Message{
To: m.maddr,
From: m.worker,
Method: actors.MAMethods.CommitSector,
Method: actors.MAMethods.PreCommitSector,
Params: enc,
Value: types.NewInt(0), // TODO: need to ensure sufficient collateral
GasLimit: types.NewInt(1000000 /* i dont know help */),