get sector set size from AMT

This commit is contained in:
Łukasz Magiera 2019-09-19 20:31:25 +02:00
parent 18b72b1584
commit 42b8af302f
2 changed files with 13 additions and 42 deletions

View File

@ -35,12 +35,10 @@ type StorageMinerActorState struct {
// All sectors this miner has committed. // All sectors this miner has committed.
Sectors cid.Cid // TODO: Using a HAMT for now, needs to be an AMT once we implement it Sectors cid.Cid // TODO: Using a HAMT for now, needs to be an AMT once we implement it
SectorSetSize uint64 // TODO: the AMT should be able to tell us how many items are in it. This field won't be needed at that point
// Sectors this miner is currently mining. It is only updated // Sectors this miner is currently mining. It is only updated
// when a PoSt is submitted (not as each new sector commitment is added). // when a PoSt is submitted (not as each new sector commitment is added).
ProvingSet cid.Cid ProvingSet cid.Cid
ProvingSetSize uint64
// Faulty sectors reported since last SubmitPost, // Faulty sectors reported since last SubmitPost,
// up to the current proving period's challenge time. // up to the current proving period's challenge time.
@ -269,9 +267,13 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
// //
// Note: Proving period is a function of sector size; small sectors take less // 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. // time to prove than large sectors do. Sector size is selected when pledging.
if self.ProvingSetSize == 0 { pss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
if lerr != nil {
return nil, aerrors.Escalate(lerr, "could not load proving set node")
}
if pss.Count == 0 {
self.ProvingSet = self.Sectors self.ProvingSet = self.Sectors
self.ProvingSetSize = self.SectorSetSize
self.ProvingPeriodEnd = vmctx.BlockHeight() + build.ProvingPeriodDuration self.ProvingPeriodEnd = vmctx.BlockHeight() + build.ProvingPeriodDuration
} }
@ -367,7 +369,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
pss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet) pss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
if lerr != nil { if lerr != nil {
return nil, aerrors.Escalate(lerr, "could not load sector set node") return nil, aerrors.Escalate(lerr, "could not load proving set node")
} }
var sectorInfos []sectorbuilder.SectorInfo var sectorInfos []sectorbuilder.SectorInfo
@ -413,7 +415,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
ss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet) ss, lerr := amt.LoadAMT(types.WrapStorage(vmctx.Storage()), self.ProvingSet)
if lerr != nil { if lerr != nil {
return nil, aerrors.Escalate(lerr, "could not load sector set node") return nil, aerrors.Escalate(lerr, "could not load proving set node")
} }
if err := ss.BatchDelete(params.DoneSet.All()); err != nil { if err := ss.BatchDelete(params.DoneSet.All()); err != nil {
@ -429,7 +431,7 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
} }
oldPower := self.Power oldPower := self.Power
self.Power = types.BigMul(types.NewInt(self.ProvingSetSize-uint64(len(faults))), self.Power = types.BigMul(types.NewInt(pss.Count-uint64(len(faults))),
mi.SectorSize) mi.SectorSize)
enc, err := SerializeParams(&UpdateStorageParams{Delta: types.BigSub(self.Power, oldPower)}) enc, err := SerializeParams(&UpdateStorageParams{Delta: types.BigSub(self.Power, oldPower)})
@ -443,7 +445,6 @@ func (sma StorageMinerActor) SubmitPoSt(act *types.Actor, vmctx types.VMContext,
} }
self.ProvingSet = self.Sectors self.ProvingSet = self.Sectors
self.ProvingSetSize = self.SectorSetSize
self.NextDoneSet = params.DoneSet self.NextDoneSet = params.DoneSet
c, err := vmctx.Storage().Put(self) c, err := vmctx.Storage().Put(self)

View File

@ -197,7 +197,7 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
return err return err
} }
if _, err := w.Write([]byte{142}); err != nil { if _, err := w.Write([]byte{140}); err != nil {
return err return err
} }
@ -223,22 +223,12 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
return xerrors.Errorf("failed to write cid field t.Sectors: %w", err) return xerrors.Errorf("failed to write cid field t.Sectors: %w", err)
} }
// t.t.SectorSetSize (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.SectorSetSize)); err != nil {
return err
}
// t.t.ProvingSet (cid.Cid) // t.t.ProvingSet (cid.Cid)
if err := cbg.WriteCid(w, t.ProvingSet); err != nil { if err := cbg.WriteCid(w, t.ProvingSet); err != nil {
return xerrors.Errorf("failed to write cid field t.ProvingSet: %w", err) return xerrors.Errorf("failed to write cid field t.ProvingSet: %w", err)
} }
// t.t.ProvingSetSize (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, t.ProvingSetSize)); err != nil {
return err
}
// t.t.CurrentFaultSet (types.BitField) // t.t.CurrentFaultSet (types.BitField)
if err := t.CurrentFaultSet.MarshalCBOR(w); err != nil { if err := t.CurrentFaultSet.MarshalCBOR(w); err != nil {
return err return err
@ -287,7 +277,7 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input should be of type array") return fmt.Errorf("cbor input should be of type array")
} }
if extra != 14 { if extra != 12 {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
@ -333,16 +323,6 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
t.Sectors = c t.Sectors = c
} }
// t.t.SectorSetSize (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.SectorSetSize = extra
// t.t.ProvingSet (cid.Cid) // t.t.ProvingSet (cid.Cid)
{ {
@ -355,16 +335,6 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
t.ProvingSet = c t.ProvingSet = c
} }
// t.t.ProvingSetSize (uint64)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.ProvingSetSize = extra
// t.t.CurrentFaultSet (types.BitField) // t.t.CurrentFaultSet (types.BitField)
{ {