Skip to content

Commit 7fc716c

Browse files
ffranrguggero
authored andcommitted
tapfreighter: re-attempt proof transfer when backoff attempts exhausted
This commit ensures that the proof transfer ChainPorter state is re-executed once proof transfer backoff attempts have been exhausted. In the absence of this commit, the next opportunity for re-attempting proof transfer would be when tapd restarts (pending parcels are processed on startup).
1 parent 1dd4f02 commit 7fc716c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tapfreighter/chain_porter.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error {
881881
// those that do not.
882882
reportProofTransfers(notDeliveringOutputs, pendingDeliveryOutputs)
883883

884+
// incompleteDelivery is set to true if any proof delivery attempts fail
885+
// and exceed the maximum backoff limit.
886+
incompleteDelivery := false
887+
884888
deliver := func(ctx context.Context, out TransferOutput) error {
885889
scriptKey := out.ScriptKey.PubKey
886890
scriptKeyBytes := scriptKey.SerializeCompressed()
@@ -940,6 +944,14 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error {
940944
// later.
941945
var backoffExecErr *proof.BackoffExecError
942946
if errors.As(err, &backoffExecErr) {
947+
log.Debugf("Exceeded backoff limit for proof delivery "+
948+
"(script_key=%x, proof_courier_addr=%s)",
949+
scriptKey.SerializeCompressed(),
950+
out.ProofCourierAddr)
951+
952+
// Set the incomplete delivery flag to true so that we
953+
// can retry the proof transfer state later.
954+
incompleteDelivery = true
943955
return nil
944956
}
945957
if err != nil {
@@ -957,6 +969,10 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error {
957969
"confirmation: %w", err)
958970
}
959971

972+
log.Infof("Transfer output proof delivery complete "+
973+
"(anchor_txid=%v, output_position=%d)",
974+
pkg.OutboundPkg.AnchorTx.TxHash(), out.Position)
975+
960976
return nil
961977
}
962978

@@ -999,6 +1015,17 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error {
9991015
return firstErr
10001016
}
10011017

1018+
// If the delivery is incomplete, we'll return early so that we can
1019+
// retry proof transfer later.
1020+
if incompleteDelivery {
1021+
log.Debugf("Proof delivery incomplete, will retry executing "+
1022+
"the proof transfer state (transfer_anchor_tx_hash=%v)",
1023+
pkg.OutboundPkg.AnchorTx.TxHash())
1024+
1025+
// Return here before setting the transfer to complete.
1026+
return nil
1027+
}
1028+
10021029
// At this point, the transfer is fully finalised and successful:
10031030
// - The anchoring transaction has been confirmed on-chain.
10041031
// - The proof(s) have been delivered to the receiver(s).

0 commit comments

Comments
 (0)