sealing: Drop redundant Piece type
This commit is contained in:
parent
29135aa77c
commit
5c485c3375
123
api/cbor_gen.go
123
api/cbor_gen.go
@ -1005,6 +1005,129 @@ func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
|
||||
return nil
|
||||
}
|
||||
func (t *SectorPiece) MarshalCBOR(w io.Writer) error {
|
||||
if t == nil {
|
||||
_, err := w.Write(cbg.CborNull)
|
||||
return err
|
||||
}
|
||||
|
||||
cw := cbg.NewCborWriter(w)
|
||||
|
||||
if _, err := cw.Write([]byte{162}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.Piece (abi.PieceInfo) (struct)
|
||||
if len("Piece") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"Piece\" was too long")
|
||||
}
|
||||
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Piece"))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := io.WriteString(w, string("Piece")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := t.Piece.MarshalCBOR(cw); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.DealInfo (api.PieceDealInfo) (struct)
|
||||
if len("DealInfo") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"DealInfo\" was too long")
|
||||
}
|
||||
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("DealInfo"))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := io.WriteString(w, string("DealInfo")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := t.DealInfo.MarshalCBOR(cw); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *SectorPiece) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
*t = SectorPiece{}
|
||||
|
||||
cr := cbg.NewCborReader(r)
|
||||
|
||||
maj, extra, err := cr.ReadHeader()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
}()
|
||||
|
||||
if maj != cbg.MajMap {
|
||||
return fmt.Errorf("cbor input should be of type map")
|
||||
}
|
||||
|
||||
if extra > cbg.MaxLength {
|
||||
return fmt.Errorf("SectorPiece: map struct too large (%d)", extra)
|
||||
}
|
||||
|
||||
var name string
|
||||
n := extra
|
||||
|
||||
for i := uint64(0); i < n; i++ {
|
||||
|
||||
{
|
||||
sval, err := cbg.ReadString(cr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name = string(sval)
|
||||
}
|
||||
|
||||
switch name {
|
||||
// t.Piece (abi.PieceInfo) (struct)
|
||||
case "Piece":
|
||||
|
||||
{
|
||||
|
||||
if err := t.Piece.UnmarshalCBOR(cr); err != nil {
|
||||
return xerrors.Errorf("unmarshaling t.Piece: %w", err)
|
||||
}
|
||||
|
||||
}
|
||||
// t.DealInfo (api.PieceDealInfo) (struct)
|
||||
case "DealInfo":
|
||||
|
||||
{
|
||||
|
||||
b, err := cr.ReadByte()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if b != cbg.CborNull[0] {
|
||||
if err := cr.UnreadByte(); err != nil {
|
||||
return err
|
||||
}
|
||||
t.DealInfo = new(PieceDealInfo)
|
||||
if err := t.DealInfo.UnmarshalCBOR(cr); err != nil {
|
||||
return xerrors.Errorf("unmarshaling t.DealInfo pointer: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
// Field doesn't exist on this type, so ignore it
|
||||
cbg.ScanForLinks(r, func(cid.Cid) {})
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func (t *DealSchedule) MarshalCBOR(w io.Writer) error {
|
||||
if t == nil {
|
||||
_, err := w.Write(cbg.CborNull)
|
||||
|
@ -314,7 +314,7 @@ func migratePreSealMeta(ctx context.Context, api v1api.FullNode, metadata string
|
||||
info := &pipeline.SectorInfo{
|
||||
State: pipeline.Proving,
|
||||
SectorNumber: sector.SectorID,
|
||||
Pieces: []pipeline.Piece{
|
||||
Pieces: []lapi.SectorPiece{
|
||||
{
|
||||
Piece: abi.PieceInfo{
|
||||
Size: abi.PaddedPieceSize(meta.SectorSize),
|
||||
|
@ -65,6 +65,7 @@ func main() {
|
||||
api.SealTicket{},
|
||||
api.SealSeed{},
|
||||
api.PieceDealInfo{},
|
||||
api.SectorPiece{},
|
||||
api.DealSchedule{},
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -962,7 +962,7 @@ func importPreSealMeta(ctx context.Context, meta genesis.Miner, mds dtypes.Metad
|
||||
info := &pipeline.SectorInfo{
|
||||
State: pipeline.Proving,
|
||||
SectorNumber: sector.SectorID,
|
||||
Pieces: []pipeline.Piece{
|
||||
Pieces: []api.SectorPiece{
|
||||
{
|
||||
Piece: abi.PieceInfo{
|
||||
Size: abi.PaddedPieceSize(meta.SectorSize),
|
||||
|
@ -22,129 +22,6 @@ var _ = cid.Undef
|
||||
var _ = math.E
|
||||
var _ = sort.Sort
|
||||
|
||||
func (t *Piece) MarshalCBOR(w io.Writer) error {
|
||||
if t == nil {
|
||||
_, err := w.Write(cbg.CborNull)
|
||||
return err
|
||||
}
|
||||
|
||||
cw := cbg.NewCborWriter(w)
|
||||
|
||||
if _, err := cw.Write([]byte{162}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.Piece (abi.PieceInfo) (struct)
|
||||
if len("Piece") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"Piece\" was too long")
|
||||
}
|
||||
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Piece"))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := io.WriteString(w, string("Piece")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := t.Piece.MarshalCBOR(cw); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.DealInfo (api.PieceDealInfo) (struct)
|
||||
if len("DealInfo") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"DealInfo\" was too long")
|
||||
}
|
||||
|
||||
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("DealInfo"))); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := io.WriteString(w, string("DealInfo")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := t.DealInfo.MarshalCBOR(cw); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Piece) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
*t = Piece{}
|
||||
|
||||
cr := cbg.NewCborReader(r)
|
||||
|
||||
maj, extra, err := cr.ReadHeader()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
}()
|
||||
|
||||
if maj != cbg.MajMap {
|
||||
return fmt.Errorf("cbor input should be of type map")
|
||||
}
|
||||
|
||||
if extra > cbg.MaxLength {
|
||||
return fmt.Errorf("Piece: map struct too large (%d)", extra)
|
||||
}
|
||||
|
||||
var name string
|
||||
n := extra
|
||||
|
||||
for i := uint64(0); i < n; i++ {
|
||||
|
||||
{
|
||||
sval, err := cbg.ReadString(cr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name = string(sval)
|
||||
}
|
||||
|
||||
switch name {
|
||||
// t.Piece (abi.PieceInfo) (struct)
|
||||
case "Piece":
|
||||
|
||||
{
|
||||
|
||||
if err := t.Piece.UnmarshalCBOR(cr); err != nil {
|
||||
return xerrors.Errorf("unmarshaling t.Piece: %w", err)
|
||||
}
|
||||
|
||||
}
|
||||
// t.DealInfo (api.PieceDealInfo) (struct)
|
||||
case "DealInfo":
|
||||
|
||||
{
|
||||
|
||||
b, err := cr.ReadByte()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if b != cbg.CborNull[0] {
|
||||
if err := cr.UnreadByte(); err != nil {
|
||||
return err
|
||||
}
|
||||
t.DealInfo = new(api.PieceDealInfo)
|
||||
if err := t.DealInfo.UnmarshalCBOR(cr); err != nil {
|
||||
return xerrors.Errorf("unmarshaling t.DealInfo pointer: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
// Field doesn't exist on this type, so ignore it
|
||||
cbg.ScanForLinks(r, func(cid.Cid) {})
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
||||
if t == nil {
|
||||
_, err := w.Write(cbg.CborNull)
|
||||
@ -240,7 +117,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
||||
}
|
||||
}
|
||||
|
||||
// t.Pieces ([]sealing.Piece) (slice)
|
||||
// t.Pieces ([]api.SectorPiece) (slice)
|
||||
if len("Pieces") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"Pieces\" was too long")
|
||||
}
|
||||
@ -573,7 +450,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.CCPieces ([]sealing.Piece) (slice)
|
||||
// t.CCPieces ([]api.SectorPiece) (slice)
|
||||
if len("CCPieces") > cbg.MaxLength {
|
||||
return xerrors.Errorf("Value in field \"CCPieces\" was too long")
|
||||
}
|
||||
@ -943,7 +820,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
|
||||
t.CreationTime = int64(extraI)
|
||||
}
|
||||
// t.Pieces ([]sealing.Piece) (slice)
|
||||
// t.Pieces ([]api.SectorPiece) (slice)
|
||||
case "Pieces":
|
||||
|
||||
maj, extra, err = cr.ReadHeader()
|
||||
@ -960,12 +837,12 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
}
|
||||
|
||||
if extra > 0 {
|
||||
t.Pieces = make([]Piece, extra)
|
||||
t.Pieces = make([]api.SectorPiece, extra)
|
||||
}
|
||||
|
||||
for i := 0; i < int(extra); i++ {
|
||||
|
||||
var v Piece
|
||||
var v api.SectorPiece
|
||||
if err := v.UnmarshalCBOR(cr); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1273,7 +1150,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
default:
|
||||
return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra)
|
||||
}
|
||||
// t.CCPieces ([]sealing.Piece) (slice)
|
||||
// t.CCPieces ([]api.SectorPiece) (slice)
|
||||
case "CCPieces":
|
||||
|
||||
maj, extra, err = cr.ReadHeader()
|
||||
@ -1290,12 +1167,12 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) (err error) {
|
||||
}
|
||||
|
||||
if extra > 0 {
|
||||
t.CCPieces = make([]Piece, extra)
|
||||
t.CCPieces = make([]api.SectorPiece, extra)
|
||||
}
|
||||
|
||||
for i := 0; i < int(extra); i++ {
|
||||
|
||||
var v Piece
|
||||
var v api.SectorPiece
|
||||
if err := v.UnmarshalCBOR(cr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
prooftypes "github.com/filecoin-project/go-state-types/proof"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/actors/policy"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
@ -41,7 +42,7 @@ type ErrCommitWaitFailed struct{ error }
|
||||
type ErrBadRU struct{ error }
|
||||
type ErrBadPR struct{ error }
|
||||
|
||||
func checkPieces(ctx context.Context, maddr address.Address, sn abi.SectorNumber, pieces []Piece, api SealingAPI, mustHaveDeals bool) error {
|
||||
func checkPieces(ctx context.Context, maddr address.Address, sn abi.SectorNumber, pieces []api.SectorPiece, api SealingAPI, mustHaveDeals bool) error {
|
||||
ts, err := api.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return &ErrApi{xerrors.Errorf("getting chain head: %w", err)}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
"github.com/filecoin-project/go-state-types/builtin/v9/miner"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
||||
)
|
||||
@ -87,7 +88,7 @@ func (evt SectorAddPiece) apply(state *SectorInfo) {
|
||||
}
|
||||
|
||||
type SectorPieceAdded struct {
|
||||
NewPieces []Piece
|
||||
NewPieces []api.SectorPiece
|
||||
}
|
||||
|
||||
func (evt SectorPieceAdded) apply(state *SectorInfo) {
|
||||
@ -113,7 +114,7 @@ type SectorPacked struct{ FillerPieces []abi.PieceInfo }
|
||||
|
||||
func (evt SectorPacked) apply(state *SectorInfo) {
|
||||
for idx := range evt.FillerPieces {
|
||||
state.Pieces = append(state.Pieces, Piece{
|
||||
state.Pieces = append(state.Pieces, api.SectorPiece{
|
||||
Piece: evt.FillerPieces[idx],
|
||||
DealInfo: nil, // filler pieces don't have deals associated with them
|
||||
})
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
|
||||
func main() {
|
||||
err := gen.WriteMapEncodersToFile("./cbor_gen.go", "sealing",
|
||||
sealing.Piece{},
|
||||
sealing.SectorInfo{},
|
||||
sealing.Log{},
|
||||
)
|
||||
|
@ -234,7 +234,7 @@ func (m *Sealing) handleAddPiece(ctx statemachine.Context, sector SectorInfo) er
|
||||
}
|
||||
|
||||
pieceSizes = append(pieceSizes, p.Unpadded())
|
||||
res.NewPieces = append(res.NewPieces, Piece{
|
||||
res.NewPieces = append(res.NewPieces, api.SectorPiece{
|
||||
Piece: ppi,
|
||||
})
|
||||
}
|
||||
@ -262,7 +262,7 @@ func (m *Sealing) handleAddPiece(ctx statemachine.Context, sector SectorInfo) er
|
||||
offset += deal.size
|
||||
pieceSizes = append(pieceSizes, deal.size)
|
||||
|
||||
res.NewPieces = append(res.NewPieces, Piece{
|
||||
res.NewPieces = append(res.NewPieces, api.SectorPiece{
|
||||
Piece: ppi,
|
||||
DealInfo: &deal.deal,
|
||||
})
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/builtin/v8/miner"
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||
"github.com/filecoin-project/lotus/chain/actors/policy"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
@ -16,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
type PreCommitPolicy interface {
|
||||
Expiration(ctx context.Context, ps ...Piece) (abi.ChainEpoch, error)
|
||||
Expiration(ctx context.Context, ps ...api.SectorPiece) (abi.ChainEpoch, error)
|
||||
}
|
||||
|
||||
type Chain interface {
|
||||
@ -59,7 +60,7 @@ func NewBasicPreCommitPolicy(api Chain, cfgGetter dtypes.GetSealingConfigFunc, p
|
||||
|
||||
// Expiration produces the pre-commit sector expiration epoch for an encoded
|
||||
// replica containing the provided enumeration of pieces and deals.
|
||||
func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...Piece) (abi.ChainEpoch, error) {
|
||||
func (p *BasicPreCommitPolicy) Expiration(ctx context.Context, ps ...api.SectorPiece) (abi.ChainEpoch, error) {
|
||||
ts, err := p.api.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -95,7 +95,7 @@ func TestBasicPolicyMostConstrictiveSchedule(t *testing.T) {
|
||||
h: abi.ChainEpoch(55),
|
||||
}, cfg, 2)
|
||||
longestDealEpochEnd := abi.ChainEpoch(547300)
|
||||
pieces := []pipeline.Piece{
|
||||
pieces := []api.SectorPiece{
|
||||
{
|
||||
Piece: abi.PieceInfo{
|
||||
Size: abi.PaddedPieceSize(1024),
|
||||
@ -136,7 +136,7 @@ func TestBasicPolicyIgnoresExistingScheduleIfExpired(t *testing.T) {
|
||||
h: abi.ChainEpoch(55),
|
||||
}, cfg, 0)
|
||||
|
||||
pieces := []pipeline.Piece{
|
||||
pieces := []api.SectorPiece{
|
||||
{
|
||||
Piece: abi.PieceInfo{
|
||||
Size: abi.PaddedPieceSize(1024),
|
||||
@ -165,7 +165,7 @@ func TestMissingDealIsIgnored(t *testing.T) {
|
||||
h: abi.ChainEpoch(55),
|
||||
}, cfg, 0)
|
||||
|
||||
pieces := []pipeline.Piece{
|
||||
pieces := []api.SectorPiece{
|
||||
{
|
||||
Piece: abi.PieceInfo{
|
||||
Size: abi.PaddedPieceSize(1024),
|
||||
|
@ -76,7 +76,7 @@ func TestStateRecoverDealIDs(t *testing.T) {
|
||||
// TODO sctx should satisfy an interface so it can be useable for mocking. This will fail because we are passing in an empty context now to get this to build.
|
||||
// https://github.com/filecoin-project/lotus/issues/7867
|
||||
err := fakeSealing.HandleRecoverDealIDs(statemachine.Context{}, pipeline.SectorInfo{
|
||||
Pieces: []pipeline.Piece{
|
||||
Pieces: []api2.SectorPiece{
|
||||
{
|
||||
DealInfo: &api2.PieceDealInfo{
|
||||
DealID: dealId,
|
||||
|
@ -22,18 +22,6 @@ type Context interface {
|
||||
Send(evt interface{}) error
|
||||
}
|
||||
|
||||
// Piece is a tuple of piece and deal info
|
||||
type PieceWithDealInfo struct {
|
||||
Piece abi.PieceInfo
|
||||
DealInfo api.PieceDealInfo
|
||||
}
|
||||
|
||||
// Piece is a tuple of piece info and optional deal
|
||||
type Piece struct {
|
||||
Piece abi.PieceInfo
|
||||
DealInfo *api.PieceDealInfo // nil for pieces which do not appear in deals (e.g. filler pieces)
|
||||
}
|
||||
|
||||
type Log struct {
|
||||
Timestamp uint64
|
||||
Trace string // for errors
|
||||
@ -61,7 +49,7 @@ type SectorInfo struct {
|
||||
|
||||
// Packing
|
||||
CreationTime int64 // unix seconds
|
||||
Pieces []Piece
|
||||
Pieces []api.SectorPiece
|
||||
|
||||
// PreCommit1
|
||||
TicketValue abi.SealRandomness
|
||||
@ -89,7 +77,7 @@ type SectorInfo struct {
|
||||
|
||||
// CCUpdate
|
||||
CCUpdate bool
|
||||
CCPieces []Piece
|
||||
CCPieces []api.SectorPiece
|
||||
UpdateSealed *cid.Cid
|
||||
UpdateUnsealed *cid.Cid
|
||||
ReplicaUpdateProof storiface.ReplicaUpdateProof
|
||||
@ -161,7 +149,7 @@ func (t *SectorInfo) sealingCtx(ctx context.Context) context.Context {
|
||||
|
||||
// Returns list of offset/length tuples of sector data ranges which clients
|
||||
// requested to keep unsealed
|
||||
func (t *SectorInfo) keepUnsealedRanges(pieces []Piece, invert, alwaysKeep bool) []storiface.Range {
|
||||
func (t *SectorInfo) keepUnsealedRanges(pieces []api.SectorPiece, invert, alwaysKeep bool) []storiface.Range {
|
||||
var out []storiface.Range
|
||||
|
||||
var at abi.UnpaddedPieceSize
|
||||
|
@ -43,7 +43,7 @@ func TestSectorInfoSerialization(t *testing.T) {
|
||||
si := &SectorInfo{
|
||||
State: "stateful",
|
||||
SectorNumber: 234,
|
||||
Pieces: []Piece{{
|
||||
Pieces: []api.SectorPiece{{
|
||||
Piece: abi.PieceInfo{
|
||||
Size: 5,
|
||||
PieceCID: dummyCid,
|
||||
|
Loading…
Reference in New Issue
Block a user