Skip to content

Commit

Permalink
check for free and unsealed
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Mar 29, 2022
1 parent c06e4d0 commit 6664a11
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions retrievalmarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,40 @@ func (p *Provider) GetAsk() *retrievalmarket.Ask {
return p.askStore.GetAsk()
}

// IsFreeAndUnsealed checks if the the piece `pieceCid` can be served from an unsealed sector and if the corresponding retrieval for the block
// with cid `c` is free ?
func (p *Provider) IsFreeAndUnsealed(ctx context.Context, c cid.Cid, pieceCid cid.Cid) (bool, error) {
pieceInfo, err := p.pieceStore.GetPieceInfo(pieceCid)
if err != nil {
return false, fmt.Errorf("failed to get piece info: %w", err)
}

if !p.pieceInUnsealedSector(ctx, pieceInfo) {
return false, nil
}

// The piece is in an unsealed sector
// Is it marked for free retrieval ?
input := retrievalmarket.PricingInput{
// piece from which the payload will be retrieved
PieceCID: pieceInfo.PieceCID,
PayloadCID: c,
Unsealed: true,
}

var dealsIds []abi.DealID
for _, d := range pieceInfo.Deals {
dealsIds = append(dealsIds, d.DealID)
}

ask, err := p.GetDynamicAsk(ctx, input, dealsIds)
if err != nil {
return false, fmt.Errorf("failed to get retrieval ask: %w", err)
}

return ask.PricePerByte.NilOrZero(), nil
}

// SetAsk sets the deal parameters this provider accepts
func (p *Provider) SetAsk(ask *retrievalmarket.Ask) {

Expand Down

0 comments on commit 6664a11

Please sign in to comment.