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

always try to return some message to the client #498

Merged
merged 2 commits into from
Mar 22, 2021
Merged
Changes from 1 commit
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
64 changes: 42 additions & 22 deletions storagemarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,33 +465,69 @@ func (p *Provider) HandleDealStatusStream(s network.DealStatusStream) {
return
}

dealState, err := p.processDealStatusRequest(&request)
if err != nil {
log.Errorf("failed to process deal status request: %s", err)
return
}

signature, err := p.sign(ctx, dealState)
if err != nil {
log.Errorf("failed to sign deal status response: %s", err)
return
}

response := network.DealStatusResponse{
DealState: *dealState,
Signature: *signature,
}

if err := s.WriteDealStatusResponse(response, p.sign); err != nil {
log.Warnf("failed to write deal status response: %s", err)
return
}
}

func (p *Provider) processDealStatusRequest(request *network.DealStatusRequest) (*storagemarket.ProviderDealState, error) {
// fetch deal state
var md = storagemarket.MinerDeal{}
if err := p.deals.Get(request.Proposal).Get(&md); err != nil {
log.Errorf("proposal doesn't exist in state store: %s", err)
return
return &storagemarket.ProviderDealState{
State: storagemarket.StorageDealError,
Message: "no such proposal",
}, nil
}

// verify query signature
buf, err := cborutil.Dump(&request.Proposal)
if err != nil {
log.Errorf("failed to serialize status request: %s", err)
return
return &storagemarket.ProviderDealState{
State: storagemarket.StorageDealError,
Message: "internal error",
}, nil
}

tok, _, err := p.spn.GetChainHead(ctx)
if err != nil {
log.Errorf("failed to get chain head: %s", err)
return
return &storagemarket.ProviderDealState{
State: storagemarket.StorageDealError,
Message: "internal error",
}, nil
}

err = providerutils.VerifySignature(ctx, request.Signature, md.ClientDealProposal.Proposal.Client, buf, tok, p.spn.VerifySignature)
if err != nil {
log.Errorf("invalid deal status request signature: %s", err)
return
return &storagemarket.ProviderDealState{
State: storagemarket.StorageDealError,
Message: "internal error",
}, nil
}

dealState := storagemarket.ProviderDealState{
return &storagemarket.ProviderDealState{
State: md.State,
Message: md.Message,
Proposal: &md.Proposal,
Expand All @@ -500,23 +536,7 @@ func (p *Provider) HandleDealStatusStream(s network.DealStatusStream) {
PublishCid: md.PublishCid,
DealID: md.DealID,
FastRetrieval: md.FastRetrieval,
}

signature, err := p.sign(ctx, &dealState)
if err != nil {
log.Errorf("failed to sign deal status response: %s", err)
return
}

response := network.DealStatusResponse{
DealState: dealState,
Signature: *signature,
}

if err := s.WriteDealStatusResponse(response, p.sign); err != nil {
log.Warnf("failed to write deal status response: %s", err)
return
}
}, nil
}

// Configure applies the given list of StorageProviderOptions after a StorageProvider
Expand Down