diff --git a/builtin/v13/market/deal.go b/builtin/v13/market/deal.go index cbe0aca8..36b615ae 100644 --- a/builtin/v13/market/deal.go +++ b/builtin/v13/market/deal.go @@ -15,7 +15,6 @@ import ( addr "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/go-state-types/builtin/v13/verifreg" acrypto "github.com/filecoin-project/go-state-types/crypto" ) @@ -27,10 +26,10 @@ var PieceCIDPrefix = cid.Prefix{ } type DealState struct { - SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector - LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated - SlashEpoch abi.ChainEpoch // -1 if deal never slashed - VerifiedClaim verifreg.AllocationId + SectorNumber abi.SectorNumber // 0 if not yet included in proven sector (0 is also a valid sector number) + SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector + LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated + SlashEpoch abi.ChainEpoch // -1 if deal never slashed } // The DealLabel is a kinded union of string or byte slice. @@ -111,7 +110,7 @@ func (label *DealLabel) MarshalCBOR(w io.Writer) error { _, err := io.WriteString(w, string("")) return err } - if len(label.bs) > cbg.ByteArrayMaxLen { + if uint64(len(label.bs)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("label is too long to marshal (%d), max allowed (%d)", len(label.bs), cbg.ByteArrayMaxLen) } diff --git a/builtin/v13/market/market_state.go b/builtin/v13/market/market_state.go index 3dfa3bbd..344dc1e0 100644 --- a/builtin/v13/market/market_state.go +++ b/builtin/v13/market/market_state.go @@ -19,6 +19,7 @@ const EpochUndefined = abi.ChainEpoch(-1) // Bitwidth of AMTs determined empirically from mutation patterns and projections of mainnet data. const ProposalsAmtBitwidth = 5 const StatesAmtBitwidth = 6 +const ProviderSectorsHamtBitwidth = 5 type State struct { // Proposals are deals that have been proposed and not yet cleaned up after expiry or termination. @@ -55,6 +56,14 @@ type State struct { // Verified registry allocation IDs for deals that are not yet activated. PendingDealAllocationIds cid.Cid // HAMT[DealID]AllocationID + + /// Maps providers to their sector IDs to deal IDs. + /// This supports finding affected deals when a sector is terminated early + /// or has data replaced. + /// Grouping by provider limits the cost of operations in the expected use case + /// of multiple sectors all belonging to the same provider. + /// HAMT[ActorID]HAMT[SectorNumber]SectorDealIDs + ProviderSectors cid.Cid } func ConstructState(store adt.Store) (*State, error) { @@ -83,6 +92,10 @@ func ConstructState(store adt.Store) (*State, error) { if err != nil { return nil, xerrors.Errorf("failed to create empty map: %w", err) } + emptyProviderSectorsMap, err := adt.StoreEmptyMap(store, ProviderSectorsHamtBitwidth) + if err != nil { + return nil, xerrors.Errorf("failed to create empty map: %w", err) + } return &State{ Proposals: emptyProposalsArrayCid, @@ -94,6 +107,7 @@ func ConstructState(store adt.Store) (*State, error) { DealOpsByEpoch: emptyDealOpsHamtCid, LastCron: abi.ChainEpoch(-1), PendingDealAllocationIds: emptyPendingDealAllocationMapCid, + ProviderSectors: emptyProviderSectorsMap, TotalClientLockedCollateral: abi.NewTokenAmount(0), TotalProviderLockedCollateral: abi.NewTokenAmount(0), diff --git a/builtin/v13/market/market_types.go b/builtin/v13/market/market_types.go index 2519f682..a214f169 100644 --- a/builtin/v13/market/market_types.go +++ b/builtin/v13/market/market_types.go @@ -11,6 +11,8 @@ import ( "github.com/filecoin-project/go-state-types/builtin/v13/verifreg" ) +type SectorDealIDs []abi.DealID + type WithdrawBalanceParams struct { ProviderOrClientAddress addr.Address Amount abi.TokenAmount @@ -132,3 +134,7 @@ type GetDealActivationReturn struct { // Epoch at which the deal was terminated abnormally, or -1. Terminated abi.ChainEpoch } + +type GetDealSectorParams = DealQueryParams + +type GetDealSectorReturn = abi.SectorNumber diff --git a/builtin/v13/market/methods.go b/builtin/v13/market/methods.go index 74773777..d0034c6d 100644 --- a/builtin/v13/market/methods.go +++ b/builtin/v13/market/methods.go @@ -4,6 +4,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v13/miner" ) var Methods = map[abi.MethodNum]builtin.MethodMeta{ @@ -30,4 +31,6 @@ var Methods = map[abi.MethodNum]builtin.MethodMeta{ builtin.MustGenerateFRCMethodNum("GetDealProviderCollateral"): {"GetDealProviderCollateralExported", *new(func(*GetDealProviderCollateralParams) *GetDealProviderCollateralReturn)}, // GetDealProviderCollateralExported builtin.MustGenerateFRCMethodNum("GetDealVerified"): {"GetDealVerifiedExported", *new(func(*GetDealVerifiedParams) *GetDealVerifiedReturn)}, // GetDealVerifiedExported builtin.MustGenerateFRCMethodNum("GetDealActivation"): {"GetDealActivationExported", *new(func(*GetDealActivationParams) *GetDealActivationReturn)}, // GetDealActivationExported + builtin.MustGenerateFRCMethodNum("GetDealSector"): {"GetDealSectorExported", *new(func(*GetDealSectorParams) *GetDealSectorReturn)}, // GetDealSectorExported + builtin.MethodSectorContentChanged: {"SectorContentChanged", *new(func(*miner.SectorContentChangedParams) *miner.SectorContentChangedReturn)}, // SectorContentChanged } diff --git a/builtin/v13/miner/methods.go b/builtin/v13/miner/methods.go index 848d60ff..7f33f42f 100644 --- a/builtin/v13/miner/methods.go +++ b/builtin/v13/miner/methods.go @@ -59,4 +59,7 @@ var Methods = map[abi.MethodNum]builtin.MethodMeta{ builtin.MustGenerateFRCMethodNum("GetVestingFunds"): {"GetVestingFundsExported", *new(func(*abi.EmptyValue) *GetVestingFundsReturn)}, // GetVestingFundsExported builtin.MustGenerateFRCMethodNum("GetPeerID"): {"GetPeerIDExported", *new(func(*abi.EmptyValue) *GetPeerIDReturn)}, // GetPeerIDExported builtin.MustGenerateFRCMethodNum("GetMultiaddrs"): {"GetMultiaddrsExported", *new(func(*abi.EmptyValue) *GetMultiAddrsReturn)}, // GetMultiaddrsExported + // 33 MovePartitions + 34: {"ProveCommitSectors3", *new(func(*ProveCommitSectors3Params) *ProveCommitSectors3Return)}, // ProveCommitSectors3 + 35: {"ProveReplicaUpdates3", *new(func(*ProveReplicaUpdates3Params) *ProveReplicaUpdates3Return)}, // ProveReplicaUpdates3 } diff --git a/builtin/v13/miner/miner_types.go b/builtin/v13/miner/miner_types.go index ca9dda29..fabc5105 100644 --- a/builtin/v13/miner/miner_types.go +++ b/builtin/v13/miner/miner_types.go @@ -394,3 +394,105 @@ type GetPeerIDReturn struct { type GetMultiAddrsReturn struct { MultiAddrs []byte } + +// ProveCommitSectors3Params represents the parameters for proving committed sectors. +type ProveCommitSectors3Params struct { + SectorActivations []SectorActivationManifest + SectorProofs [][]byte + AggregateProof []byte + AggregateProofType *abi.RegisteredAggregationProof + RequireActivationSuccess bool + RequireNotificationSuccess bool +} + +// SectorActivationManifest contains data to activate a commitment to one sector and its data. +// All pieces of data must be specified, whether or not not claiming a FIL+ activation or being +// notified to a data consumer. +// An implicit zero piece fills any remaining sector capacity. +type SectorActivationManifest struct { + SectorNumber abi.SectorNumber + Pieces []PieceActivationManifest +} + +// PieceActivationManifest represents the manifest for activating a piece. +type PieceActivationManifest struct { + CID cid.Cid + Size abi.PaddedPieceSize + VerifiedAllocationKey *VerifiedAllocationKey + Notify []DataActivationNotification +} + +// VerifiedAllocationKey represents the key for a verified allocation. +type VerifiedAllocationKey struct { + Client abi.ActorID + ID verifreg.AllocationId +} + +// DataActivationNotification represents a notification for data activation. +type DataActivationNotification struct { + Address addr.Address + Payload []byte +} + +// ProveCommitSectors3Return represents the return value for the ProveCommit2 function. +type ProveCommitSectors3Return = BatchReturn + +type BatchReturn struct { + SuccessCount uint64 + FailCodes []FailCode +} + +type FailCode struct { + // Idx represents the index of the operation that failed within the batch. + Idx uint64 + Code xc.ExitCode // todo correct? +} + +// ProveReplicaUpdates3Params represents the parameters for proving replica updates. +type ProveReplicaUpdates3Params struct { + SectorUpdates []SectorUpdateManifest + SectorProofs [][]byte + AggregateProof []byte + UpdateProofsType abi.RegisteredUpdateProof + AggregateProofType *abi.RegisteredAggregationProof + RequireActivationSuccess bool + RequireNotificationSuccess bool +} + +// SectorUpdateManifest contains data for sector update. +type SectorUpdateManifest struct { + Sector abi.SectorNumber + Deadline uint64 + Partition uint64 + NewSealedCID cid.Cid + Pieces []PieceActivationManifest +} + +// ProveReplicaUpdates3Return represents the return value for the ProveReplicaUpdates3 function. +type ProveReplicaUpdates3Return = BatchReturn + +// SectorContentChangedParams represents a notification of change committed to sectors. +type SectorContentChangedParams = []SectorChanges + +// SectorChanges describes changes to one sector's content. +type SectorChanges struct { + Sector abi.SectorNumber + MinimumCommitmentEpoch abi.ChainEpoch + Added []PieceChange +} + +// PieceChange describes a piece of data committed to a sector. +type PieceChange struct { + Data cid.Cid + Size abi.PaddedPieceSize + Payload []byte +} + +// SectorContentChangedReturn represents the return value for the SectorContentChanged function. +type SectorContentChangedReturn = []SectorReturn + +// SectorReturn represents a result for each sector that was notified. +type SectorReturn = []PieceReturn + +// PieceReturn represents a result for each piece for the sector that was notified. +type PieceReturn = bool // Accepted = true