Merge branch 'feat/update-sectorbuilder' of github.com:filecoin-project/go-lotus into feat/update-sectorbuilder

This commit is contained in:
Łukasz Magiera 2020-02-27 01:56:15 +01:00
commit 628d90353d
10 changed files with 45 additions and 158 deletions

View File

@ -348,16 +348,6 @@ func (t *Piece) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.CommP) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.CommP was too long")
}
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.CommP)))); err != nil {
return err
}
if _, err := w.Write(t.CommP); err != nil {
return err
}
return nil
}
@ -447,10 +437,6 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.CommP = make([]byte, extra)
if _, err := io.ReadFull(br, t.CommP); err != nil {
return err
}
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)
@ -553,17 +539,6 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.CommD) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.CommD was too long")
}
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.CommR ([]uint8) (slice)
if len("CommR") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"CommR\" was too long")
@ -576,17 +551,6 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if len(t.CommR) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.CommR was too long")
}
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.Proof ([]uint8) (slice)
if len("Proof") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Proof\" was too long")
@ -622,10 +586,6 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
return err
}
if err := t.Ticket.MarshalCBOR(w); err != nil {
return err
}
// t.PreCommitMessage (cid.Cid) (struct)
if len("PreCommitMessage") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"PreCommitMessage\" was too long")
@ -875,10 +835,6 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
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.CommR ([]uint8) (slice)
case "CommR":
@ -893,10 +849,6 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
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.Proof ([]uint8) (slice)
case "Proof":
@ -920,10 +872,6 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
{
if err := t.Ticket.UnmarshalCBOR(br); err != nil {
return err
}
}
// t.PreCommitMessage (cid.Cid) (struct)
case "PreCommitMessage":

View File

@ -5,12 +5,10 @@ import (
"context"
"github.com/ipfs/go-cid"
"github.com/multiformats/go-multihash"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
@ -45,7 +43,7 @@ func checkPieces(ctx context.Context, si SectorInfo, api sealingApi) error {
for i, piece := range si.Pieces {
if piece.DealID == nil {
exp := zerocomm.ForSize(piece.Size)
if string(piece.CommP) != string(exp[:]) {
if piece.CommP != exp {
return &ErrInvalidPiece{xerrors.Errorf("deal %d piece %d had non-zero CommP %+v", piece.DealID, i, piece.CommP)}
}
continue
@ -55,13 +53,8 @@ func checkPieces(ctx context.Context, si SectorInfo, api sealingApi) error {
return &ErrApi{xerrors.Errorf("getting deal %d for piece %d: %w", piece.DealID, i, err)}
}
h, err := multihash.Decode(deal.Proposal.PieceCID.Hash())
if err != nil {
return &ErrInvalidDeals{xerrors.Errorf("decoding piece CID: %w", err)}
}
if string(h.Digest) != string(piece.CommP) {
return &ErrInvalidDeals{xerrors.Errorf("piece %d (or %d) of sector %d refers deal %d with wrong CommP: %x != %x", i, len(si.Pieces), si.SectorID, piece.DealID, piece.CommP, h.Digest)}
if deal.Proposal.PieceCID != piece.CommP {
return &ErrInvalidDeals{xerrors.Errorf("piece %d (or %d) of sector %d refers deal %d with wrong CommP: %x != %x", i, len(si.Pieces), si.SectorID, piece.DealID, piece.CommP, deal.Proposal.PieceCID)}
}
if piece.Size != deal.Proposal.PieceSize.Unpadded() {
@ -84,14 +77,9 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se
return &ErrApi{xerrors.Errorf("getting chain head: %w", err)}
}
ssize, err := api.StateMinerSectorSize(ctx, maddr, head.Key())
if err != nil {
return &ErrApi{err}
}
ccparams, err := actors.SerializeParams(&market.ComputeDataCommitmentParams{
DealIDs: si.deals(),
SectorSize: ssize,
SectorType: si.SectorType,
})
if err != nil {
return xerrors.Errorf("computing params for ComputeDataCommitment: %w", err)
@ -118,12 +106,8 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se
if err := c.UnmarshalCBOR(bytes.NewReader(r.Return)); err != nil {
return err
}
cd, err := commcid.CIDToDataCommitmentV1(cid.Cid(c))
if err != nil {
return err
}
if string(cd) != string(si.CommD) {
if cid.Cid(c) != *si.CommD {
return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)}
}

View File

@ -66,14 +66,16 @@ type SectorPackingFailed struct{ error }
func (evt SectorPackingFailed) apply(*SectorInfo) {}
type SectorSealed struct {
commR []byte
commD []byte
commR cid.Cid
commD cid.Cid
ticket SealTicket
}
func (evt SectorSealed) apply(state *SectorInfo) {
state.CommD = evt.commD
state.CommR = evt.commR
commd := evt.commD
state.CommD = &commd
commr := evt.commR
state.CommR = &commr
state.Ticket = evt.ticket
}

View File

@ -32,8 +32,8 @@ func (m *Sealing) pledgeSector(ctx context.Context, sectorID abi.SectorNumber, e
existingPieceSizes = append(existingPieceSizes, size)
out[i] = Piece{
Size: ppi.Size,
CommP: ppi.CommP[:],
Size: ppi.Size.Unpadded(),
CommP: ppi.PieceCID,
}
}

View File

@ -28,7 +28,7 @@ const SectorStorePrefix = "/sectors"
var log = logging.Logger("sectors")
type TicketFn func(context.Context) (*sectorbuilder.SealTicket, error)
type TicketFn func(context.Context) (SealTicket, error)
type sealingApi interface { // TODO: trim down
// Call a read only method on actors (no interaction with the chain required)
@ -125,8 +125,8 @@ func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r i
{
DealID: &dealID,
Size: ppi.Size,
CommP: ppi.CommP[:],
Size: ppi.Size.Unpadded(),
CommP: ppi.PieceCID,
},
})
}

View File

@ -2,9 +2,9 @@ package sealing
import (
"context"
"github.com/filecoin-project/specs-actors/actors/crypto"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
@ -69,18 +69,15 @@ func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) er
return ctx.Send(SectorSealFailed{xerrors.Errorf("getting ticket failed: %w", err)})
}
rspco, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, *ticket, sector.pieceInfos())
sealed, unsealed, err := m.sb.SealPreCommit(ctx.Context(), sector.SectorID, ticket.TicketBytes, sector.pieceInfos())
if err != nil {
return ctx.Send(SectorSealFailed{xerrors.Errorf("seal pre commit failed: %w", err)})
}
return ctx.Send(SectorSealed{
commD: rspco.CommD[:],
commR: rspco.CommR[:],
ticket: SealTicket{
BlockHeight: abi.ChainEpoch(ticket.BlockHeight),
TicketBytes: ticket.TicketBytes[:],
},
commD: unsealed,
commR: sealed,
ticket: ticket,
})
}
@ -104,7 +101,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
SectorNumber: sector.SectorID,
RegisteredProof: abi.RegisteredProof_StackedDRG32GiBSeal,
SealedCID: commcid.ReplicaCommitmentV1ToCID(sector.CommR),
SealedCID: *sector.CommR,
SealRandEpoch: sector.Ticket.BlockHeight,
DealIDs: sector.deals(),
}
@ -161,7 +158,7 @@ func (m *Sealing) handleWaitSeed(ctx statemachine.Context, sector SectorInfo) er
ctx.Send(SectorSeedReady{seed: SealSeed{
BlockHeight: randHeight,
TicketBytes: rand,
TicketBytes: abi.InteractiveSealRandomness(rand),
}})
return nil
@ -182,7 +179,7 @@ func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo)
log.Infof("KOMIT %d %x(%d); %x(%d); %v; r:%x; d:%x", sector.SectorID, sector.Ticket.TicketBytes, sector.Ticket.BlockHeight, sector.Seed.TicketBytes, sector.Seed.BlockHeight, sector.pieceInfos(), sector.CommR, sector.CommD)
proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.SB(), sector.Seed.SB(), sector.pieceInfos(), sector.rspco())
proof, err := m.sb.SealCommit(ctx.Context(), sector.SectorID, sector.Ticket.TicketBytes, sector.Seed.TicketBytes, sector.pieceInfos(), *sector.CommR, *sector.CommD)
if err != nil {
return ctx.Send(SectorComputeProofFailed{xerrors.Errorf("computing seal proof failed: %w", err)})
}

View File

@ -4,7 +4,6 @@ import (
"bytes"
"time"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/util/adt"
"golang.org/x/xerrors"
@ -96,13 +95,8 @@ func (m *Sealing) handlePreCommitFailed(ctx statemachine.Context, sector SectorI
return nil // TODO: SeedWait needs this currently
}
pciR, err := commcid.CIDToReplicaCommitmentV1(pci.Info.SealedCID)
if err != nil {
return err
}
if string(pciR) != string(sector.CommR) {
log.Warn("sector %d is precommitted on chain, with different CommR: %x != %x", sector.SectorID, pciR, sector.CommR)
if pci.Info.SealedCID != *sector.CommR {
log.Warn("sector %d is precommitted on chain, with different CommR: %x != %x", sector.SectorID, pci.Info.SealedCID, sector.CommR)
return nil // TODO: remove when the actor allows re-precommit
}

View File

@ -1,7 +1,6 @@
package sealing
import (
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
@ -9,24 +8,12 @@ import (
type SealTicket struct {
BlockHeight abi.ChainEpoch
TicketBytes []byte
}
func (t *SealTicket) SB() sectorbuilder.SealTicket {
out := sectorbuilder.SealTicket{BlockHeight: uint64(t.BlockHeight)}
copy(out.TicketBytes[:], t.TicketBytes)
return out
TicketBytes abi.SealRandomness
}
type SealSeed struct {
BlockHeight abi.ChainEpoch
TicketBytes []byte
}
func (t *SealSeed) SB() sectorbuilder.SealSeed {
out := sectorbuilder.SealSeed{BlockHeight: uint64(t.BlockHeight)}
copy(out.TicketBytes[:], t.TicketBytes)
return out
TicketBytes abi.InteractiveSealRandomness
}
func (t *SealSeed) Equals(o *SealSeed) bool {
@ -37,13 +24,7 @@ type Piece struct {
DealID *abi.DealID
Size abi.UnpaddedPieceSize
CommP []byte
}
func (p *Piece) ppi() (out sectorbuilder.PublicPieceInfo) {
out.Size = p.Size
copy(out.CommP[:], p.CommP)
return out
CommP cid.Cid
}
type Log struct {
@ -61,13 +42,15 @@ type SectorInfo struct {
SectorID abi.SectorNumber
Nonce uint64 // TODO: remove
SectorType abi.RegisteredProof
// Packing
Pieces []Piece
// PreCommit
CommD []byte
CommR []byte
CommD *cid.Cid
CommR *cid.Cid
Proof []byte
Ticket SealTicket
@ -88,10 +71,13 @@ type SectorInfo struct {
Log []Log
}
func (t *SectorInfo) pieceInfos() []sectorbuilder.PublicPieceInfo {
out := make([]sectorbuilder.PublicPieceInfo, len(t.Pieces))
func (t *SectorInfo) pieceInfos() []abi.PieceInfo {
out := make([]abi.PieceInfo, len(t.Pieces))
for i, piece := range t.Pieces {
out[i] = piece.ppi()
out[i] = abi.PieceInfo{
Size: piece.Size.Padded(),
PieceCID: piece.CommP,
}
}
return out
}
@ -114,12 +100,3 @@ func (t *SectorInfo) existingPieces() []abi.UnpaddedPieceSize {
}
return out
}
func (t *SectorInfo) rspco() sectorbuilder.RawSealPreCommitOutput {
var out sectorbuilder.RawSealPreCommitOutput
copy(out.CommD[:], t.CommD)
copy(out.CommR[:], t.CommR)
return out
}

View File

@ -5,14 +5,17 @@ import (
"testing"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"gotest.tools/assert"
"github.com/filecoin-project/go-cbor-util"
cborutil "github.com/filecoin-project/go-cbor-util"
)
func TestSectorInfoSelialization(t *testing.T) {
d := abi.DealID(1234)
dummyCid := builtin.AccountActorCodeID
si := &SectorInfo{
State: 123,
SectorID: 234,
@ -20,9 +23,9 @@ func TestSectorInfoSelialization(t *testing.T) {
Pieces: []Piece{{
DealID: &d,
Size: 5,
CommP: []byte{3},
CommP: dummyCid,
}},
CommD: []byte{32, 4},
CommD: &dummyCid,
CommR: nil,
Proof: nil,
Ticket: SealTicket{

View File

@ -5,8 +5,6 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/storage/sbmock"
"github.com/stretchr/testify/assert"
)
@ -45,19 +43,3 @@ func TestFillersFromRem(t *testing.T) {
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub4})
}
}
func TestFastPledge(t *testing.T) {
sz := abi.PaddedPieceSize(16 << 20)
s := Sealing{sb: sbmock.NewMockSectorBuilder(0, abi.SectorSize(sz))}
if _, err := s.fastPledgeCommitment(sz.Unpadded(), 5); err != nil {
t.Fatalf("%+v", err)
}
sz = abi.PaddedPieceSize(1024)
s = Sealing{sb: sbmock.NewMockSectorBuilder(0, abi.SectorSize(sz))}
if _, err := s.fastPledgeCommitment(sz.Unpadded(), 64); err != nil {
t.Fatalf("%+v", err)
}
}