Skip to content

Commit

Permalink
feat: FIP-0076: add new methods and types
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Feb 13, 2024
1 parent c66aee5 commit 846d70c
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 6 deletions.
11 changes: 5 additions & 6 deletions builtin/v13/market/deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down
14 changes: 14 additions & 0 deletions builtin/v13/market/market_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions builtin/v13/market/market_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions builtin/v13/market/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions builtin/v13/miner/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
102 changes: 102 additions & 0 deletions builtin/v13/miner/miner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 846d70c

Please sign in to comment.