From 94362fdc2fa5972d6bac8097e2a0df290e03beee Mon Sep 17 00:00:00 2001 From: ffranr Date: Thu, 22 Aug 2024 13:04:14 +0100 Subject: [PATCH] tapfreighter: use ParSliceErrorCollect for delivering proofs This commit leverages the new ParSliceErrorCollect function to process transfer output proofs in parallel. This change ensures that processing continues even if a transfer output proof delivery instance fails. --- tapfreighter/chain_porter.go | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tapfreighter/chain_porter.go b/tapfreighter/chain_porter.go index 1ce851c38..f95810066 100644 --- a/tapfreighter/chain_porter.go +++ b/tapfreighter/chain_porter.go @@ -870,11 +870,45 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error { // If we have a non-interactive proof, then we'll launch several // goroutines to deliver the proof(s) to the receiver(s). - err := fn.ParSlice(ctx, pkg.OutboundPkg.Outputs, deliver) + instanceErrors, err := fn.ParSliceErrorCollect( + ctx, pkg.OutboundPkg.Outputs, deliver, + ) if err != nil { return fmt.Errorf("error delivering proof(s): %w", err) } + // If there were any errors during the proof delivery process, we'll + // report them here and return the first error we encountered. + if len(instanceErrors) > 0 { + var firstErr error + for idx := range instanceErrors { + output := pkg.OutboundPkg.Outputs[idx] + instanceErr := instanceErrors[idx] + + // Store the first error encountered. + if firstErr == nil { + firstErr = instanceErr + } + + scriptPubKey := + output.ScriptKey.PubKey.SerializeCompressed() + anchorOutpoint := output.Anchor.OutPoint.String() + courierAddr := string(output.ProofCourierAddr) + + log.Errorf("Error delivering transfer output proof "+ + "(anchor_outpoint=%s, script_pub_key=%v, "+ + "position=%d, proof_courier_addr=%s, "+ + "proof_delivery_status=%v): %v", + anchorOutpoint, scriptPubKey, output.Position, + courierAddr, output.ProofDeliveryComplete, + instanceErr) + } + + if firstErr != nil { + return firstErr + } + } + // At this point, the transfer is fully finalised and successful: // - The anchoring transaction has been confirmed on-chain. // - The proof(s) have been delivered to the receiver(s).