diff --git a/storagemarket/impl/provider.go b/storagemarket/impl/provider.go index a51895bb..bb8835d8 100644 --- a/storagemarket/impl/provider.go +++ b/storagemarket/impl/provider.go @@ -465,33 +465,60 @@ func (p *Provider) HandleDealStatusStream(s network.DealStatusStream) { return } + dealState, err := p.processDealStatusRequest(ctx, &request) + if err != nil { + log.Errorf("failed to process deal status request: %s", err) + dealState = &storagemarket.ProviderDealState{ + State: storagemarket.StorageDealError, + Message: err.Error(), + } + } + + 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(ctx context.Context, 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 nil, xerrors.Errorf("no such proposal") } // verify query signature buf, err := cborutil.Dump(&request.Proposal) if err != nil { log.Errorf("failed to serialize status request: %s", err) - return + return nil, xerrors.Errorf("internal error") } tok, _, err := p.spn.GetChainHead(ctx) if err != nil { log.Errorf("failed to get chain head: %s", err) - return + return nil, xerrors.Errorf("internal error") } 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 nil, xerrors.Errorf("internal error") } - dealState := storagemarket.ProviderDealState{ + return &storagemarket.ProviderDealState{ State: md.State, Message: md.Message, Proposal: &md.Proposal, @@ -500,23 +527,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