sealing pipeline: Get allocationId with StateApi
This commit is contained in:
parent
0af9888b12
commit
dc102f076a
@ -528,7 +528,8 @@ type FullNode interface {
|
||||
StateMarketDeals(context.Context, types.TipSetKey) (map[string]*MarketDeal, error) //perm:read
|
||||
// StateMarketStorageDeal returns information about the indicated deal
|
||||
StateMarketStorageDeal(context.Context, abi.DealID, types.TipSetKey) (*MarketDeal, error) //perm:read
|
||||
// StateGetAllocationForPendingDeal returns the allocation for a given deal ID of a pending deal.
|
||||
// StateGetAllocationForPendingDeal returns the allocation for a given deal ID of a pending deal. Returns nil if
|
||||
// pending allocation is not found.
|
||||
StateGetAllocationForPendingDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
|
||||
// StateGetAllocation returns the allocation for a given address and allocation ID.
|
||||
StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
|
||||
|
Binary file not shown.
@ -86,7 +86,7 @@ type State interface {
|
||||
) (weight, verifiedWeight abi.DealWeight, err error)
|
||||
NextID() (abi.DealID, error)
|
||||
GetState() interface{}
|
||||
GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error)
|
||||
GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error)
|
||||
}
|
||||
|
||||
type BalanceTable interface {
|
||||
|
@ -127,7 +127,7 @@ type State interface {
|
||||
) (weight, verifiedWeight abi.DealWeight, err error)
|
||||
NextID() (abi.DealID, error)
|
||||
GetState() interface{}
|
||||
GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error)
|
||||
GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error)
|
||||
}
|
||||
|
||||
type BalanceTable interface {
|
||||
|
@ -366,23 +366,25 @@ func (r *publishStorageDealsReturn{{.v}}) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state{{.v}}) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state{{.v}}) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
{{if (le .v 8)}}
|
||||
return 0, xerrors.Errorf("unsupported before actors v9")
|
||||
return nil, xerrors.Errorf("unsupported before actors v9")
|
||||
{{else}}
|
||||
allocations, err := adt9.AsMap(s.store, s.PendingDealAllocationIds, builtin.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return 0, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
|
||||
return nil, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
|
||||
}
|
||||
|
||||
var allocationId cbg.CborInt
|
||||
found, err := allocations.Get(abi.UIntKey(uint64(dealId)), &allocationId)
|
||||
if err != nil {
|
||||
return 0, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
|
||||
return nil, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
|
||||
}
|
||||
if !found {
|
||||
return 0, xerrors.Errorf("failed to find allocation id for %d", dealId)
|
||||
return nil, nil
|
||||
}
|
||||
return verifregtypes.AllocationId(allocationId), nil
|
||||
|
||||
aid := verifregtypes.AllocationId(allocationId)
|
||||
return &aid, nil
|
||||
{{end}}
|
||||
}
|
||||
|
@ -302,8 +302,8 @@ func (r *publishStorageDealsReturn0) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state0) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state0) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
|
||||
return 0, xerrors.Errorf("unsupported before actors v9")
|
||||
return nil, xerrors.Errorf("unsupported before actors v9")
|
||||
|
||||
}
|
||||
|
@ -302,8 +302,8 @@ func (r *publishStorageDealsReturn2) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state2) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state2) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
|
||||
return 0, xerrors.Errorf("unsupported before actors v9")
|
||||
return nil, xerrors.Errorf("unsupported before actors v9")
|
||||
|
||||
}
|
||||
|
@ -297,8 +297,8 @@ func (r *publishStorageDealsReturn3) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state3) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state3) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
|
||||
return 0, xerrors.Errorf("unsupported before actors v9")
|
||||
return nil, xerrors.Errorf("unsupported before actors v9")
|
||||
|
||||
}
|
||||
|
@ -297,8 +297,8 @@ func (r *publishStorageDealsReturn4) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state4) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state4) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
|
||||
return 0, xerrors.Errorf("unsupported before actors v9")
|
||||
return nil, xerrors.Errorf("unsupported before actors v9")
|
||||
|
||||
}
|
||||
|
@ -297,8 +297,8 @@ func (r *publishStorageDealsReturn5) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state5) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state5) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
|
||||
return 0, xerrors.Errorf("unsupported before actors v9")
|
||||
return nil, xerrors.Errorf("unsupported before actors v9")
|
||||
|
||||
}
|
||||
|
@ -315,8 +315,8 @@ func (r *publishStorageDealsReturn6) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state6) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state6) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
|
||||
return 0, xerrors.Errorf("unsupported before actors v9")
|
||||
return nil, xerrors.Errorf("unsupported before actors v9")
|
||||
|
||||
}
|
||||
|
@ -315,8 +315,8 @@ func (r *publishStorageDealsReturn7) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state7) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state7) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
|
||||
return 0, xerrors.Errorf("unsupported before actors v9")
|
||||
return nil, xerrors.Errorf("unsupported before actors v9")
|
||||
|
||||
}
|
||||
|
@ -332,8 +332,8 @@ func (r *publishStorageDealsReturn8) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state8) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state8) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
|
||||
return 0, xerrors.Errorf("unsupported before actors v9")
|
||||
return nil, xerrors.Errorf("unsupported before actors v9")
|
||||
|
||||
}
|
||||
|
@ -328,21 +328,23 @@ func (r *publishStorageDealsReturn9) DealIDs() ([]abi.DealID, error) {
|
||||
return r.IDs, nil
|
||||
}
|
||||
|
||||
func (s *state9) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error) {
|
||||
func (s *state9) GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) {
|
||||
|
||||
allocations, err := adt9.AsMap(s.store, s.PendingDealAllocationIds, builtin.DefaultHamtBitwidth)
|
||||
if err != nil {
|
||||
return 0, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
|
||||
return nil, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
|
||||
}
|
||||
|
||||
var allocationId cbg.CborInt
|
||||
found, err := allocations.Get(abi.UIntKey(uint64(dealId)), &allocationId)
|
||||
if err != nil {
|
||||
return 0, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
|
||||
return nil, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
|
||||
}
|
||||
if !found {
|
||||
return 0, xerrors.Errorf("failed to find allocation id for %d", dealId)
|
||||
return nil, nil
|
||||
}
|
||||
return verifregtypes.AllocationId(allocationId), nil
|
||||
|
||||
aid := verifregtypes.AllocationId(allocationId)
|
||||
return &aid, nil
|
||||
|
||||
}
|
||||
|
@ -5768,7 +5768,8 @@ Response:
|
||||
```
|
||||
|
||||
### StateGetAllocationForPendingDeal
|
||||
StateGetAllocationForPendingDeal returns the allocation for a given deal ID of a pending deal.
|
||||
StateGetAllocationForPendingDeal returns the allocation for a given deal ID of a pending deal. Returns nil if
|
||||
pending allocation is not found.
|
||||
|
||||
|
||||
Perms: read
|
||||
|
@ -786,13 +786,16 @@ func (a *StateAPI) StateGetAllocationForPendingDeal(ctx context.Context, dealId
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if allocationId == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
dealState, err := a.StateMarketStorageDeal(ctx, dealId, tsk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return a.StateGetAllocation(ctx, dealState.Proposal.Client, allocationId, tsk)
|
||||
return a.StateGetAllocation(ctx, dealState.Proposal.Client, *allocationId, tsk)
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) {
|
||||
|
@ -321,7 +321,10 @@ func (m *Sealing) SectorAddPieceToAny(ctx context.Context, size abi.UnpaddedPiec
|
||||
deal.DealProposal.PieceCID, ts.Height(), deal.DealProposal.StartEpoch)
|
||||
}
|
||||
|
||||
claimTerms, err := m.getClaimTerms(ctx, deal)
|
||||
claimTerms, err := m.getClaimTerms(ctx, deal, ts.Key())
|
||||
if err != nil {
|
||||
return api.SectorOffset{}, err
|
||||
}
|
||||
|
||||
m.inputLk.Lock()
|
||||
if pp, exist := m.pendingPieces[proposalCID(deal)]; exist {
|
||||
@ -350,9 +353,25 @@ func (m *Sealing) SectorAddPieceToAny(ctx context.Context, size abi.UnpaddedPiec
|
||||
return api.SectorOffset{Sector: res.sn, Offset: res.offset.Padded()}, res.err
|
||||
}
|
||||
|
||||
func (m *Sealing) getClaimTerms(ctx context.Context, deal api.PieceDealInfo) (pieceClaimBounds, error) {
|
||||
// TODO: TODO! TODO! get the real claim bounds here
|
||||
func (m *Sealing) getClaimTerms(ctx context.Context, deal api.PieceDealInfo, tsk types.TipSetKey) (pieceClaimBounds, error) {
|
||||
nv, err := m.Api.StateNetworkVersion(ctx, tsk)
|
||||
if err != nil {
|
||||
return pieceClaimBounds{}, err
|
||||
}
|
||||
|
||||
if nv >= network.Version17 {
|
||||
all, err := m.Api.StateGetAllocationForPendingDeal(ctx, deal.DealID, tsk)
|
||||
if err != nil {
|
||||
return pieceClaimBounds{}, err
|
||||
}
|
||||
if all != nil {
|
||||
return pieceClaimBounds{
|
||||
claimTermEnd: deal.DealProposal.StartEpoch + all.TermMax,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// no allocation for this deal, so just use a really high number for "term end"
|
||||
return pieceClaimBounds{
|
||||
claimTermEnd: deal.DealProposal.EndEpoch + policy.GetSectorMaxLifetime(abi.RegisteredSealProof_StackedDrg32GiBV1_1, network.Version17),
|
||||
}, nil
|
||||
@ -706,7 +725,7 @@ func (m *Sealing) maybeUpgradeSector(ctx context.Context, sp abi.RegisteredSealP
|
||||
// todo: after nv17 "target expiration" doesn't really make that much sense
|
||||
// (tho to be fair it doesn't make too much sense now either)
|
||||
// we probably want the lowest expiration that's still above the configured
|
||||
// minimum, and has can fit most candidate deals
|
||||
// minimum, and can fit most candidate deals
|
||||
|
||||
if bestExpiration < targetExpirationEpoch {
|
||||
if expirationEpoch > bestExpiration && slowChecks(s.Number) {
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
abi "github.com/filecoin-project/go-state-types/abi"
|
||||
big "github.com/filecoin-project/go-state-types/big"
|
||||
miner "github.com/filecoin-project/go-state-types/builtin/v9/miner"
|
||||
verifreg "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
|
||||
crypto "github.com/filecoin-project/go-state-types/crypto"
|
||||
dline "github.com/filecoin-project/go-state-types/dline"
|
||||
network "github.com/filecoin-project/go-state-types/network"
|
||||
@ -138,6 +139,21 @@ func (mr *MockSealingAPIMockRecorder) StateComputeDataCID(arg0, arg1, arg2, arg3
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateComputeDataCID", reflect.TypeOf((*MockSealingAPI)(nil).StateComputeDataCID), arg0, arg1, arg2, arg3, arg4)
|
||||
}
|
||||
|
||||
// StateGetAllocationForPendingDeal mocks base method.
|
||||
func (m *MockSealingAPI) StateGetAllocationForPendingDeal(arg0 context.Context, arg1 abi.DealID, arg2 types.TipSetKey) (*verifreg.Allocation, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "StateGetAllocationForPendingDeal", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(*verifreg.Allocation)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// StateGetAllocationForPendingDeal indicates an expected call of StateGetAllocationForPendingDeal.
|
||||
func (mr *MockSealingAPIMockRecorder) StateGetAllocationForPendingDeal(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetAllocationForPendingDeal", reflect.TypeOf((*MockSealingAPI)(nil).StateGetAllocationForPendingDeal), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// StateGetRandomnessFromBeacon mocks base method.
|
||||
func (m *MockSealingAPI) StateGetRandomnessFromBeacon(arg0 context.Context, arg1 crypto.DomainSeparationTag, arg2 abi.ChainEpoch, arg3 []byte, arg4 types.TipSetKey) (abi.Randomness, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
"github.com/filecoin-project/go-state-types/builtin/v9/miner"
|
||||
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
|
||||
"github.com/filecoin-project/go-state-types/crypto"
|
||||
"github.com/filecoin-project/go-state-types/dline"
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
@ -69,6 +70,7 @@ type SealingAPI interface {
|
||||
StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error)
|
||||
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
||||
StateMinerAllocated(context.Context, address.Address, types.TipSetKey) (*bitfield.BitField, error)
|
||||
StateGetAllocationForPendingDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*verifregtypes.Allocation, error)
|
||||
|
||||
// Address selector
|
||||
WalletBalance(context.Context, address.Address) (types.BigInt, error)
|
||||
|
Loading…
Reference in New Issue
Block a user