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

fix: backport 1217 to release/v1.5.x #1218

Merged
merged 1 commit into from
Feb 24, 2023
Merged
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
52 changes: 32 additions & 20 deletions storagemarket/provider_dealfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,30 @@ import (

func (p *Provider) getDealFilterParams(deal *types.ProviderDealState) (*dealfilter.DealFilterParams, *acceptError) {

// Check cached sealing pipeline status and error
sealingStatus, err := p.sealingPipelineStatus()
if err != nil {
return nil, &acceptError{
error: fmt.Errorf("storage deal filter: failed to fetch sealing pipeline status: %w", err),
reason: "server error: storage deal filter: getting sealing status",
isSevereError: true,
}
params := types.DealParams{
DealUUID: deal.DealUuid,
ClientDealProposal: deal.ClientDealProposal,
DealDataRoot: deal.DealDataRoot,
Transfer: deal.Transfer,
IsOffline: deal.IsOffline,
RemoveUnsealedCopy: !deal.FastRetrieval,
SkipIPNIAnnounce: !deal.AnnounceToIPNI,
}

// Clear transfer params in case it contains sensitive information
// (eg Authorization header)
params.Transfer.Params = []byte{}

// If no external deal filter is set then return empty value for SealingPipelineState,
// FundsState and StorageState to shorten the execution. This also avoids the expensive
// p.sealingPipelineStatus() call
if p.config.StorageFilter == "" {
return &dealfilter.DealFilterParams{
DealParams: params,
SealingPipelineState: sealingpipeline.Status{},
FundsState: funds.Status{},
StorageState: storagespace.Status{},
}, nil
}

// Get the status of funds in the collateral and publish message wallets
Expand All @@ -43,20 +59,16 @@ func (p *Provider) getDealFilterParams(deal *types.ProviderDealState) (*dealfilt
}
}

params := types.DealParams{
DealUUID: deal.DealUuid,
ClientDealProposal: deal.ClientDealProposal,
DealDataRoot: deal.DealDataRoot,
Transfer: deal.Transfer,
IsOffline: deal.IsOffline,
RemoveUnsealedCopy: !deal.FastRetrieval,
SkipIPNIAnnounce: !deal.AnnounceToIPNI,
// Check cached sealing pipeline status and error
sealingStatus, err := p.sealingPipelineStatus()
if err != nil {
return nil, &acceptError{
error: fmt.Errorf("storage deal filter: failed to fetch sealing pipeline status: %w", err),
reason: "server error: storage deal filter: getting sealing status",
isSevereError: true,
}
}

// Clear transfer params in case it contains sensitive information
// (eg Authorization header)
params.Transfer.Params = []byte{}

return &dealfilter.DealFilterParams{
DealParams: params,
SealingPipelineState: sealingStatus,
Expand Down
10 changes: 5 additions & 5 deletions storagemarket/provider_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ type acceptError struct {
reason string
}

// we still need to call the BasicDealFilter() even when external deal filter is not set.
// Once BasicDealFilter() completes the checks like are we accepting online deal, verified deal etc.
// Then it runs the external "cmd" filter. Thus, runDealFilters is not optional of any type of deal
func (p *Provider) runDealFilters(deal *types.ProviderDealState) *acceptError {
if p.config.StorageFilter == "" {
return nil
}

// run custom storage deal filter decision logic
dealFilterParams, aerr := p.getDealFilterParams(deal)
Expand Down Expand Up @@ -118,7 +118,7 @@ func (p *Provider) processDealProposal(deal *types.ProviderDealState) *acceptErr
return aerr
}

// Run deal through the filter if deal filter is set
// we still need to call runDealFilters() even when external deal filter is not set
if aerr := p.runDealFilters(deal); aerr != nil {
return aerr
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func (p *Provider) processOfflineDealProposal(ds *smtypes.ProviderDealState, dh
return aerr
}

// Run deal through the filter if deal filter is set
// we still need to call runDealFilters() even when external deal filter is not set
if aerr := p.runDealFilters(ds); aerr != nil {
return aerr
}
Expand Down