use NoAllocationID instead of nil AllocationId

This commit is contained in:
Łukasz Magiera 2022-10-11 18:31:19 +02:00 committed by Aayush
parent dc102f076a
commit ce17decf3b
15 changed files with 34 additions and 36 deletions

View File

@ -86,7 +86,7 @@ type State interface {
) (weight, verifiedWeight abi.DealWeight, err error) ) (weight, verifiedWeight abi.DealWeight, err error)
NextID() (abi.DealID, error) NextID() (abi.DealID, error)
GetState() interface{} GetState() interface{}
GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error)
} }
type BalanceTable interface { type BalanceTable interface {

View File

@ -127,7 +127,7 @@ type State interface {
) (weight, verifiedWeight abi.DealWeight, err error) ) (weight, verifiedWeight abi.DealWeight, err error)
NextID() (abi.DealID, error) NextID() (abi.DealID, error)
GetState() interface{} GetState() interface{}
GetAllocationIdForPendingDeal(dealId abi.DealID) (*verifregtypes.AllocationId, error) GetAllocationIdForPendingDeal(dealId abi.DealID) (verifregtypes.AllocationId, error)
} }
type BalanceTable interface { type BalanceTable interface {

View File

@ -366,25 +366,24 @@ func (r *publishStorageDealsReturn{{.v}}) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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)}} {{if (le .v 8)}}
return nil, xerrors.Errorf("unsupported before actors v9") return verifregtypes.NoAllocationID, xerrors.Errorf("unsupported before actors v9")
{{else}} {{else}}
allocations, err := adt9.AsMap(s.store, s.PendingDealAllocationIds, builtin.DefaultHamtBitwidth) allocations, err := adt9.AsMap(s.store, s.PendingDealAllocationIds, builtin.DefaultHamtBitwidth)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err) return verifregtypes.NoAllocationID, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
} }
var allocationId cbg.CborInt var allocationId cbg.CborInt
found, err := allocations.Get(abi.UIntKey(uint64(dealId)), &allocationId) found, err := allocations.Get(abi.UIntKey(uint64(dealId)), &allocationId)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err) return verifregtypes.NoAllocationID, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
} }
if !found { if !found {
return nil, nil return verifregtypes.NoAllocationID, nil
} }
aid := verifregtypes.AllocationId(allocationId) return verifregtypes.AllocationId(allocationId), nil
return &aid, nil
{{end}} {{end}}
} }

View File

@ -302,8 +302,8 @@ func (r *publishStorageDealsReturn0) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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 nil, xerrors.Errorf("unsupported before actors v9") return verifregtypes.NoAllocationID, xerrors.Errorf("unsupported before actors v9")
} }

View File

@ -302,8 +302,8 @@ func (r *publishStorageDealsReturn2) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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 nil, xerrors.Errorf("unsupported before actors v9") return verifregtypes.NoAllocationID, xerrors.Errorf("unsupported before actors v9")
} }

View File

@ -297,8 +297,8 @@ func (r *publishStorageDealsReturn3) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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 nil, xerrors.Errorf("unsupported before actors v9") return verifregtypes.NoAllocationID, xerrors.Errorf("unsupported before actors v9")
} }

View File

@ -297,8 +297,8 @@ func (r *publishStorageDealsReturn4) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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 nil, xerrors.Errorf("unsupported before actors v9") return verifregtypes.NoAllocationID, xerrors.Errorf("unsupported before actors v9")
} }

View File

@ -297,8 +297,8 @@ func (r *publishStorageDealsReturn5) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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 nil, xerrors.Errorf("unsupported before actors v9") return verifregtypes.NoAllocationID, xerrors.Errorf("unsupported before actors v9")
} }

View File

@ -315,8 +315,8 @@ func (r *publishStorageDealsReturn6) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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 nil, xerrors.Errorf("unsupported before actors v9") return verifregtypes.NoAllocationID, xerrors.Errorf("unsupported before actors v9")
} }

View File

@ -315,8 +315,8 @@ func (r *publishStorageDealsReturn7) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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 nil, xerrors.Errorf("unsupported before actors v9") return verifregtypes.NoAllocationID, xerrors.Errorf("unsupported before actors v9")
} }

View File

@ -332,8 +332,8 @@ func (r *publishStorageDealsReturn8) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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 nil, xerrors.Errorf("unsupported before actors v9") return verifregtypes.NoAllocationID, xerrors.Errorf("unsupported before actors v9")
} }

View File

@ -328,23 +328,22 @@ func (r *publishStorageDealsReturn9) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil 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) allocations, err := adt9.AsMap(s.store, s.PendingDealAllocationIds, builtin.DefaultHamtBitwidth)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err) return verifregtypes.NoAllocationID, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
} }
var allocationId cbg.CborInt var allocationId cbg.CborInt
found, err := allocations.Get(abi.UIntKey(uint64(dealId)), &allocationId) found, err := allocations.Get(abi.UIntKey(uint64(dealId)), &allocationId)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err) return verifregtypes.NoAllocationID, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
} }
if !found { if !found {
return nil, nil return verifregtypes.NoAllocationID, nil
} }
aid := verifregtypes.AllocationId(allocationId) return verifregtypes.AllocationId(allocationId), nil
return &aid, nil
} }

2
go.mod
View File

@ -42,7 +42,7 @@ require (
github.com/filecoin-project/go-legs v0.4.4 github.com/filecoin-project/go-legs v0.4.4
github.com/filecoin-project/go-padreader v0.0.1 github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4 github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.9.0-rc1 github.com/filecoin-project/go-state-types v0.9.0-rc2
github.com/filecoin-project/go-statemachine v1.0.2 github.com/filecoin-project/go-statemachine v1.0.2
github.com/filecoin-project/go-statestore v0.2.0 github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/go-storedcounter v0.1.0 github.com/filecoin-project/go-storedcounter v0.1.0

4
go.sum
View File

@ -343,8 +343,8 @@ github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psS
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.9.0-rc1 h1:cK6OzKP11aIFt0fbor/lqvrzEBegbMGHnSr9LJN/r4g= github.com/filecoin-project/go-state-types v0.9.0-rc2 h1:HtSxHUEwAtpnhV/77/ugnUt9lwvTTcQ7PRV+5iTAcUw=
github.com/filecoin-project/go-state-types v0.9.0-rc1/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw= github.com/filecoin-project/go-state-types v0.9.0-rc2/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc= github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54= github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=

View File

@ -786,7 +786,7 @@ func (a *StateAPI) StateGetAllocationForPendingDeal(ctx context.Context, dealId
if err != nil { if err != nil {
return nil, err return nil, err
} }
if allocationId == nil { if allocationId == verifregtypes.NoAllocationID {
return nil, nil return nil, nil
} }
@ -795,7 +795,7 @@ func (a *StateAPI) StateGetAllocationForPendingDeal(ctx context.Context, dealId
return nil, err 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) { func (a *StateAPI) StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) {