pass deal IDs in SectorPreCommitInfo

This commit is contained in:
Łukasz Magiera 2019-11-07 13:03:18 +01:00
parent 12161fc607
commit be0d07e143
6 changed files with 153 additions and 171 deletions

View File

@ -21,7 +21,7 @@ func TestDealFlow(t *testing.T, b APIBuilder) {
os.Setenv("BELLMAN_NO_GPU", "1") os.Setenv("BELLMAN_NO_GPU", "1")
logging.SetAllLoggers(logging.LevelInfo) logging.SetAllLoggers(logging.LevelInfo)
ctx := context.TODO() ctx := context.Background()
n, sn := b(t, 1, []int{0}) n, sn := b(t, 1, []int{0})
client := n[0].FullNode.(*impl.FullNodeAPI) client := n[0].FullNode.(*impl.FullNodeAPI)
miner := sn[0] miner := sn[0]

View File

@ -24,7 +24,7 @@ type StorageMinerActor struct{}
type StorageMinerActorState struct { type StorageMinerActorState struct {
// PreCommittedSectors is the set of sectors that have been committed to but not // PreCommittedSectors is the set of sectors that have been committed to but not
// yet had their proofs submitted // yet had their proofs submitted
PreCommittedSectors map[string]*UnprovenSector PreCommittedSectors map[string]*PreCommittedSector
// All sectors this miner has committed. // All sectors this miner has committed.
Sectors cid.Cid Sectors cid.Cid
@ -94,11 +94,9 @@ type MinerInfo struct {
// SubsectorCount // SubsectorCount
} }
type UnprovenSector struct { type PreCommittedSector struct {
CommD []byte Info SectorPreCommitInfo
CommR []byte ReceivedEpoch uint64
SubmitHeight uint64
TicketEpoch uint64
} }
type StorageMinerConstructorParams struct { type StorageMinerConstructorParams struct {
@ -108,6 +106,14 @@ type StorageMinerConstructorParams struct {
PeerID peer.ID PeerID peer.ID
} }
type SectorPreCommitInfo struct {
SectorNumber uint64
CommR []byte // TODO: Spec says CID
SealEpoch uint64
DealIDs []uint64
}
type maMethods struct { type maMethods struct {
Constructor uint64 Constructor uint64
PreCommitSector uint64 PreCommitSector uint64
@ -212,14 +218,6 @@ func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx typ
return nil, nil return nil, nil
} }
type SectorPreCommitInfo struct {
CommD []byte // TODO: update proofs code
CommR []byte
Epoch uint64
SectorNumber uint64
}
func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorPreCommitInfo) ([]byte, ActorError) { func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMContext, params *SectorPreCommitInfo) ([]byte, ActorError) {
ctx := vmctx.Context() ctx := vmctx.Context()
oldstate, self, err := loadState(vmctx) oldstate, self, err := loadState(vmctx)
@ -227,12 +225,12 @@ func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMCon
return nil, err return nil, err
} }
if params.Epoch >= vmctx.BlockHeight()+build.SealRandomnessLookback { if params.SealEpoch >= vmctx.BlockHeight()+build.SealRandomnessLookback {
return nil, aerrors.Newf(1, "sector commitment must be based off past randomness (%d >= %d)", params.Epoch, vmctx.BlockHeight()+build.SealRandomnessLookback) return nil, aerrors.Newf(1, "sector commitment must be based off past randomness (%d >= %d)", params.SealEpoch, vmctx.BlockHeight()+build.SealRandomnessLookback)
} }
if vmctx.BlockHeight()-params.Epoch+build.SealRandomnessLookback > build.SealRandomnessLookbackLimit { if vmctx.BlockHeight()-params.SealEpoch+build.SealRandomnessLookback > build.SealRandomnessLookbackLimit {
return nil, aerrors.Newf(2, "sector commitment must be recent enough (was %d)", vmctx.BlockHeight()-params.Epoch+build.SealRandomnessLookback) return nil, aerrors.Newf(2, "sector commitment must be recent enough (was %d)", vmctx.BlockHeight()-params.SealEpoch+build.SealRandomnessLookback)
} }
mi, err := loadMinerInfo(vmctx, self) mi, err := loadMinerInfo(vmctx, self)
@ -262,11 +260,9 @@ func (sma StorageMinerActor) PreCommitSector(act *types.Actor, vmctx types.VMCon
return nil, aerrors.New(4, "not enough collateral") return nil, aerrors.New(4, "not enough collateral")
} }
self.PreCommittedSectors[uintToStringKey(params.SectorNumber)] = &UnprovenSector{ self.PreCommittedSectors[uintToStringKey(params.SectorNumber)] = &PreCommittedSector{
CommR: params.CommR, Info: *params,
CommD: params.CommD, ReceivedEpoch: vmctx.BlockHeight(),
SubmitHeight: vmctx.BlockHeight(),
TicketEpoch: params.Epoch,
} }
nstate, err := vmctx.Storage().Put(self) nstate, err := vmctx.Storage().Put(self)
@ -309,7 +305,7 @@ func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMC
return nil, aerrors.New(1, "no pre-commitment found for sector") return nil, aerrors.New(1, "no pre-commitment found for sector")
} }
if us.SubmitHeight+build.InteractivePoRepDelay > vmctx.BlockHeight() { if us.ReceivedEpoch+build.InteractivePoRepDelay > vmctx.BlockHeight() {
return nil, aerrors.New(2, "too early for proof submission") return nil, aerrors.New(2, "too early for proof submission")
} }
@ -318,12 +314,12 @@ func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMC
// TODO: ensure normalization to ID address // TODO: ensure normalization to ID address
maddr := vmctx.Message().To maddr := vmctx.Message().To
ticket, err := vmctx.GetRandomness(us.TicketEpoch - build.SealRandomnessLookback) ticket, err := vmctx.GetRandomness(us.Info.SealEpoch - build.SealRandomnessLookback)
if err != nil { if err != nil {
return nil, aerrors.Wrap(err, "failed to get ticket randomness") return nil, aerrors.Wrap(err, "failed to get ticket randomness")
} }
seed, err := vmctx.GetRandomness(us.SubmitHeight + build.InteractivePoRepDelay) seed, err := vmctx.GetRandomness(us.ReceivedEpoch + build.InteractivePoRepDelay)
if err != nil { if err != nil {
return nil, aerrors.Wrap(err, "failed to get randomness for prove sector commitment") return nil, aerrors.Wrap(err, "failed to get randomness for prove sector commitment")
} }
@ -341,16 +337,16 @@ func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMC
return nil, aerrors.Wrap(err, "failed to compute data commitment") return nil, aerrors.Wrap(err, "failed to compute data commitment")
} }
if ok, err := ValidatePoRep(maddr, mi.SectorSize, commD, us.CommR, ticket, params.Proof, seed, params.SectorID); err != nil { if ok, err := ValidatePoRep(maddr, mi.SectorSize, commD, us.Info.CommR, ticket, params.Proof, seed, params.SectorID); err != nil {
return nil, err return nil, err
} else if !ok { } else if !ok {
return nil, aerrors.Newf(2, "bad proof! (t:%x; s:%x(%d); p:%x)", ticket, seed, us.SubmitHeight+build.InteractivePoRepDelay, params.Proof) return nil, aerrors.Newf(2, "bad proof! (t:%x; s:%x(%d); p:%x)", ticket, seed, us.ReceivedEpoch+build.InteractivePoRepDelay, params.Proof)
} }
// Note: There must exist a unique index in the miner's sector set for each // Note: There must exist a unique index in the miner's sector set for each
// sector ID. The `faults`, `recovered`, and `done` parameters of the // sector ID. The `faults`, `recovered`, and `done` parameters of the
// SubmitPoSt method express indices into this sector set. // SubmitPoSt method express indices into this sector set.
nssroot, err := AddToSectorSet(ctx, vmctx.Storage(), self.Sectors, params.SectorID, us.CommR, us.CommD) nssroot, err := AddToSectorSet(ctx, vmctx.Storage(), self.Sectors, params.SectorID, us.Info.CommR, commD)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -581,6 +577,8 @@ func AddToSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, sectorID u
return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node") return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node")
} }
// TODO: Spec says to use SealCommitment, and construct commD from deals each time,
// but that would make SubmitPoSt way, way more expensive
if err := ssr.Set(sectorID, [][]byte{commR, commD}); err != nil { if err := ssr.Set(sectorID, [][]byte{commR, commD}); err != nil {
return cid.Undef, aerrors.HandleExternalError(err, "failed to set commitment in sector set") return cid.Undef, aerrors.HandleExternalError(err, "failed to set commitment in sector set")
} }

View File

@ -201,7 +201,7 @@ func (t *StorageMinerActorState) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.PreCommittedSectors (map[string]*actors.UnprovenSector) (map) // t.t.PreCommittedSectors (map[string]*actors.PreCommittedSector) (map)
if err := cbg.CborWriteHeader(w, cbg.MajMap, uint64(len(t.PreCommittedSectors))); err != nil { if err := cbg.CborWriteHeader(w, cbg.MajMap, uint64(len(t.PreCommittedSectors))); err != nil {
return err return err
} }
@ -291,7 +291,7 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.PreCommittedSectors (map[string]*actors.UnprovenSector) (map) // t.t.PreCommittedSectors (map[string]*actors.PreCommittedSector) (map)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -304,7 +304,7 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("t.PreCommittedSectors: map too large") return fmt.Errorf("t.PreCommittedSectors: map too large")
} }
t.PreCommittedSectors = make(map[string]*UnprovenSector, extra) t.PreCommittedSectors = make(map[string]*PreCommittedSector, extra)
for i, l := 0, int(extra); i < l; i++ { for i, l := 0, int(extra); i < l; i++ {
@ -319,7 +319,7 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
k = string(sval) k = string(sval)
} }
var v *UnprovenSector var v *PreCommittedSector
{ {
@ -333,7 +333,7 @@ func (t *StorageMinerActorState) UnmarshalCBOR(r io.Reader) error {
return err return err
} }
} else { } else {
v = new(UnprovenSector) v = new(PreCommittedSector)
if err := v.UnmarshalCBOR(br); err != nil { if err := v.UnmarshalCBOR(br); err != nil {
return err return err
} }
@ -546,11 +546,8 @@ func (t *SectorPreCommitInfo) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.CommD ([]uint8) (slice) // t.t.SectorNumber (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommD)))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorNumber))); err != nil {
return err
}
if _, err := w.Write(t.CommD); err != nil {
return err return err
} }
@ -562,15 +559,20 @@ func (t *SectorPreCommitInfo) MarshalCBOR(w io.Writer) error {
return err return err
} }
// t.t.Epoch (uint64) (uint64) // t.t.SealEpoch (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Epoch))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SealEpoch))); err != nil {
return err return err
} }
// t.t.SectorNumber (uint64) (uint64) // t.t.DealIDs ([]uint64) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SectorNumber))); err != nil { if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.DealIDs)))); err != nil {
return err return err
} }
for _, v := range t.DealIDs {
if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, v); err != nil {
return err
}
}
return nil return nil
} }
@ -589,50 +591,6 @@ func (t *SectorPreCommitInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
// t.t.CommD ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.CommD: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.CommD = make([]byte, extra)
if _, err := io.ReadFull(br, t.CommD); err != nil {
return err
}
// t.t.CommR ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.CommR: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.CommR = make([]byte, extra)
if _, err := io.ReadFull(br, t.CommR); err != nil {
return err
}
// t.t.Epoch (uint64) (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.Epoch = uint64(extra)
// t.t.SectorNumber (uint64) (uint64) // t.t.SectorNumber (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
@ -643,78 +601,6 @@ func (t *SectorPreCommitInfo) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.SectorNumber = uint64(extra) t.SectorNumber = uint64(extra)
return nil
}
func (t *UnprovenSector) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{132}); err != nil {
return err
}
// t.t.CommD ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommD)))); err != nil {
return err
}
if _, err := w.Write(t.CommD); err != nil {
return err
}
// t.t.CommR ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommR)))); err != nil {
return err
}
if _, err := w.Write(t.CommR); err != nil {
return err
}
// t.t.SubmitHeight (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.SubmitHeight))); err != nil {
return err
}
// t.t.TicketEpoch (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.TicketEpoch))); err != nil {
return err
}
return nil
}
func (t *UnprovenSector) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 4 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.CommD ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.CommD: array too large (%d)", extra)
}
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.CommD = make([]byte, extra)
if _, err := io.ReadFull(br, t.CommD); err != nil {
return err
}
// t.t.CommR ([]uint8) (slice) // t.t.CommR ([]uint8) (slice)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
@ -732,7 +618,7 @@ func (t *UnprovenSector) UnmarshalCBOR(r io.Reader) error {
if _, err := io.ReadFull(br, t.CommR); err != nil { if _, err := io.ReadFull(br, t.CommR); err != nil {
return err return err
} }
// t.t.SubmitHeight (uint64) (uint64) // t.t.SealEpoch (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -741,8 +627,86 @@ func (t *UnprovenSector) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.SubmitHeight = uint64(extra) t.SealEpoch = uint64(extra)
// t.t.TicketEpoch (uint64) (uint64) // t.t.DealIDs ([]uint64) (slice)
maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.DealIDs: array too large (%d)", extra)
}
if maj != cbg.MajArray {
return fmt.Errorf("expected cbor array")
}
if extra > 0 {
t.DealIDs = make([]uint64, extra)
}
for i := 0; i < int(extra); i++ {
maj, val, err := cbg.CborReadHeader(br)
if err != nil {
return xerrors.Errorf("failed to read uint64 for t.DealIDs slice: %w", err)
}
if maj != cbg.MajUnsignedInt {
return xerrors.Errorf("value read for array t.DealIDs was not a uint, instead got %d", maj)
}
t.DealIDs[i] = val
}
return nil
}
func (t *PreCommittedSector) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}
// t.t.Info (actors.SectorPreCommitInfo) (struct)
if err := t.Info.MarshalCBOR(w); err != nil {
return err
}
// t.t.ReceivedEpoch (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ReceivedEpoch))); err != nil {
return err
}
return nil
}
func (t *PreCommittedSector) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)
maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}
if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.t.Info (actors.SectorPreCommitInfo) (struct)
{
if err := t.Info.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.t.ReceivedEpoch (uint64) (uint64)
maj, extra, err = cbg.CborReadHeader(br) maj, extra, err = cbg.CborReadHeader(br)
if err != nil { if err != nil {
@ -751,7 +715,7 @@ func (t *UnprovenSector) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.TicketEpoch = uint64(extra) t.ReceivedEpoch = uint64(extra)
return nil return nil
} }

View File

@ -577,7 +577,7 @@ func (t *ClientDeal) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull) _, err := w.Write(cbg.CborNull)
return err return err
} }
if _, err := w.Write([]byte{132}); err != nil { if _, err := w.Write([]byte{133}); err != nil {
return err return err
} }
@ -604,6 +604,11 @@ func (t *ClientDeal) MarshalCBOR(w io.Writer) error {
if _, err := w.Write([]byte(t.Miner)); err != nil { if _, err := w.Write([]byte(t.Miner)); err != nil {
return err return err
} }
// t.t.DealID (uint64) (uint64)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.DealID))); err != nil {
return err
}
return nil return nil
} }
@ -618,7 +623,7 @@ func (t *ClientDeal) 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 != 4 { if extra != 5 {
return fmt.Errorf("cbor input had wrong number of fields") return fmt.Errorf("cbor input had wrong number of fields")
} }
@ -663,6 +668,16 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
t.Miner = peer.ID(sval) t.Miner = peer.ID(sval)
} }
// t.t.DealID (uint64) (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.DealID = uint64(extra)
return nil return nil
} }

View File

@ -91,7 +91,7 @@ func main() {
actors.StorageMinerActorState{}, actors.StorageMinerActorState{},
actors.StorageMinerConstructorParams{}, actors.StorageMinerConstructorParams{},
actors.SectorPreCommitInfo{}, actors.SectorPreCommitInfo{},
actors.UnprovenSector{}, actors.PreCommittedSector{},
actors.MinerInfo{}, actors.MinerInfo{},
actors.SubmitPoStParams{}, actors.SubmitPoStParams{},
actors.PaymentVerifyParams{}, actors.PaymentVerifyParams{},

View File

@ -78,12 +78,17 @@ func (m *Miner) sealPreCommit(ctx context.Context, sector SectorInfo) (func(*Sec
} }
func (m *Miner) preCommit(ctx context.Context, sector SectorInfo) (func(*SectorInfo), error) { func (m *Miner) preCommit(ctx context.Context, sector SectorInfo) (func(*SectorInfo), error) {
params := &actors.SectorPreCommitInfo{ deals, err := m.secst.DealsForCommit(sector.SectorID, false)
CommD: sector.CommD, if err != nil {
CommR: sector.CommR, return nil, err
Epoch: sector.Ticket.BlockHeight, }
params := &actors.SectorPreCommitInfo{
SectorNumber: sector.SectorID, SectorNumber: sector.SectorID,
CommR: sector.CommR,
SealEpoch: sector.Ticket.BlockHeight,
DealIDs: deals,
} }
enc, aerr := actors.SerializeParams(params) enc, aerr := actors.SerializeParams(params)
if aerr != nil { if aerr != nil {