Skip to content

Commit

Permalink
tapfreighter: use ParSliceErrorCollect for delivering proofs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ffranr committed Aug 22, 2024
1 parent 99392e1 commit 94362fd
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 94362fd

Please sign in to comment.