Skip to content

Commit

Permalink
tapfreighter: use ParSliceErrCollect for delivering proofs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ffranr committed Aug 27, 2024
1 parent fa5eca2 commit ac10515
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,43 @@ 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.ParSliceErrCollect(
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
// log them all here.
for idx := range instanceErrors {
output := pkg.OutboundPkg.Outputs[idx]
instanceErr := instanceErrors[idx]

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)
}

// Return the first error encountered during the proof delivery process,
// if any.
var firstErr error
fn.PeekMap(instanceErrors).WhenSome(func(kv fn.KV[int, error]) {
firstErr = err
})

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 ac10515

Please sign in to comment.