Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for free and unsealed deals for Bitswap support in Boost #699

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions retrievalmarket/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package retrievalmarket
import (
"context"

"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-fil-markets/shared"
)

Expand Down Expand Up @@ -31,6 +33,8 @@ type RetrievalProvider interface {
SubscribeToEvents(subscriber ProviderSubscriber) Unsubscribe

ListDeals() map[ProviderDealIdentifier]ProviderDealState

IsFreeAndUnsealed(ctx context.Context, c cid.Cid, pieceCid cid.Cid) (bool, error)
}

// AskStore is an interface which provides access to a persisted retrieval Ask
Expand Down