Skip to content

Commit ac10515

Browse files
committed
tapfreighter: use ParSliceErrCollect for delivering proofs
This commit leverages the new ParSliceErrCollect function to process transfer output proofs in parallel. This change ensures that processing continues even if a transfer output proof delivery instance fails.
1 parent fa5eca2 commit ac10515

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

tapfreighter/chain_porter.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,43 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error {
870870

871871
// If we have a non-interactive proof, then we'll launch several
872872
// goroutines to deliver the proof(s) to the receiver(s).
873-
err := fn.ParSlice(ctx, pkg.OutboundPkg.Outputs, deliver)
873+
instanceErrors, err := fn.ParSliceErrCollect(
874+
ctx, pkg.OutboundPkg.Outputs, deliver,
875+
)
874876
if err != nil {
875877
return fmt.Errorf("error delivering proof(s): %w", err)
876878
}
877879

880+
// If there were any errors during the proof delivery process, we'll
881+
// log them all here.
882+
for idx := range instanceErrors {
883+
output := pkg.OutboundPkg.Outputs[idx]
884+
instanceErr := instanceErrors[idx]
885+
886+
scriptPubKey := output.ScriptKey.PubKey.SerializeCompressed()
887+
anchorOutpoint := output.Anchor.OutPoint.String()
888+
courierAddr := string(output.ProofCourierAddr)
889+
890+
log.Errorf("Error delivering transfer output proof "+
891+
"(anchor_outpoint=%s, script_pub_key=%v, "+
892+
"position=%d, proof_courier_addr=%s, "+
893+
"proof_delivery_status=%v): %v",
894+
anchorOutpoint, scriptPubKey, output.Position,
895+
courierAddr, output.ProofDeliveryComplete,
896+
instanceErr)
897+
}
898+
899+
// Return the first error encountered during the proof delivery process,
900+
// if any.
901+
var firstErr error
902+
fn.PeekMap(instanceErrors).WhenSome(func(kv fn.KV[int, error]) {
903+
firstErr = err
904+
})
905+
906+
if firstErr != nil {
907+
return firstErr
908+
}
909+
878910
// At this point, the transfer is fully finalised and successful:
879911
// - The anchoring transaction has been confirmed on-chain.
880912
// - The proof(s) have been delivered to the receiver(s).

0 commit comments

Comments
 (0)