From 0ec79fd37c334e8332884c4c1bd85f6969dfdf23 Mon Sep 17 00:00:00 2001 From: LinZexiao <55120714+LinZexiao@users.noreply.github.com> Date: Tue, 24 Oct 2023 13:12:44 +0800 Subject: [PATCH] Merge pull request #477 from ipfs-force-community/fix/clean-blockstore fix: clean blockstore after retrieval completed --- cli/retrieval-deals.go | 4 +--- .../provider_datatransfer_sub.go | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cli/retrieval-deals.go b/cli/retrieval-deals.go index 0b703489..b486c572 100644 --- a/cli/retrieval-deals.go +++ b/cli/retrieval-deals.go @@ -111,13 +111,12 @@ part statuses: } _, _ = fmt.Fprintf(w, - "%s\t%d\t%s\t%s\t%s\t%d\t%d\t%d\t%s\n", + "%s\t%d\t%s\t%s\t%s\t%d\t%d\t%s\n", deal.Receiver.String(), deal.ID, payloadCid, retrievalmarket.DealStatuses[deal.Status], deal.PricePerByte.String(), - deal.TotalSent, deal.FundsReceived, deal.CurrentInterval, deal.Message, @@ -192,7 +191,6 @@ func outputRetrievalDeal(deal *market.ProviderDealState) error { {"PayloadCID", deal.PayloadCID}, {"Status", retrievalmarket.DealStatuses[deal.Status]}, {"PricePerByte", deal.PricePerByte.String()}, - {"BytesSent", deal.TotalSent}, {"Paid", deal.FundsReceived}, {"Interval", deal.CurrentInterval}, {"Message", deal.Message}, diff --git a/retrievalprovider/provider_datatransfer_sub.go b/retrievalprovider/provider_datatransfer_sub.go index 6648e84a..664cce06 100644 --- a/retrievalprovider/provider_datatransfer_sub.go +++ b/retrievalprovider/provider_datatransfer_sub.go @@ -24,6 +24,7 @@ func ProviderDataTransferSubscriber(deals IDatatransferHandler) datatransfer.Sub dealProposal, err := rm.DealProposalFromNode(voucher.Voucher) // if this event is for a transfer not related to storage, ignore if err != nil { + log.Errorf("received wrong voucher type: %s", err) return } @@ -40,26 +41,26 @@ func ProviderDataTransferSubscriber(deals IDatatransferHandler) datatransfer.Sub switch event.Code { case datatransfer.Accept: - mlog.With("retrievalEvent", rm.ProviderEventDealAccepted) + mlog = mlog.With("retrievalEvent", rm.ProviderEvents[rm.ProviderEventDealAccepted]) err := deals.HandleAcceptFor(ctx, identify, channelState.ChannelID()) if err != nil { log.Errorf("processing dt event: %s", err) } case datatransfer.Disconnected: - mlog.With("retrievalEvent", rm.ProviderEventDataTransferError) + mlog = mlog.With("retrievalEvent", rm.ProviderEvents[rm.ProviderEventDataTransferError]) err := deals.HandleDisconnectFor(ctx, identify, fmt.Errorf("deal data transfer stalled (peer hungup)")) if err != nil { log.Errorf("processing dt event: %s", err) } case datatransfer.Error: - mlog.With("retrievalEvent", rm.ProviderEventDataTransferError) + mlog = mlog.With("retrievalEvent", rm.ProviderEvents[rm.ProviderEventDataTransferError]) err := deals.HandleErrorForDeal(ctx, identify, fmt.Errorf("deal data transfer failed: %s", event.Message)) if err != nil { log.Errorf("processing dt event: %s", err) } case datatransfer.DataLimitExceeded: // DataLimitExceeded indicates it's time to wait for a payment - mlog.With("retrievalEvent", rm.ProviderEventPaymentRequested) + mlog = mlog.With("retrievalEvent", rm.ProviderEvents[rm.ProviderEventPaymentRequested]) err := deals.HandlePaymentRequested(ctx, identify) if err != nil { log.Errorf("processing dt event: %s", err) @@ -69,24 +70,32 @@ func ProviderDataTransferSubscriber(deals IDatatransferHandler) datatransfer.Sub // Because the legacy client expects a final voucher, we dispatch this event event when // the deal is free -- so that we have a chance to send this final voucher before completion // TODO: do not send the legacy voucher when the client no longer expects it - mlog.With("retrievalEvent", rm.ProviderEventLastPaymentRequested) + mlog = mlog.With("retrievalEvent", rm.ProviderEvents[rm.ProviderEventLastPaymentRequested]) err := deals.HandleLastPayment(ctx, identify) if err != nil { log.Errorf("processing dt event: %s", err) } case datatransfer.NewVoucher: // NewVoucher indicates a potential new payment we should attempt to process - mlog.With("retrievalEvent", rm.ProviderEventProcessPayment) + mlog = mlog.With("retrievalEvent", rm.ProviderEvents[rm.ProviderEventProcessPayment]) err := deals.HandleProcessPayment(ctx, identify) if err != nil { log.Errorf("processing dt event: %s", err) } case datatransfer.Cancel: - mlog.With("retrievalEvent", rm.ProviderEventClientCancelled) + mlog = mlog.With("retrievalEvent", rm.ProviderEvents[rm.ProviderEventClientCancelled]) err := deals.HandleCancelForDeal(ctx, identify) if err != nil { log.Errorf("processing dt event: %s", err) } + case datatransfer.NewVoucherResult: + mlog = mlog.With("channelStatus", channelState.Status()) + if channelState.Status() == datatransfer.Finalizing { + err := deals.HandleCompleteFor(ctx, identify) + if err != nil { + log.Errorf("processing dt event: %s", err) + } + } default: return }