Skip to content

Commit a562518

Browse files
committed
tapfreighter: add SendStateBroadcastComplete state
Introduce a new send state to act as a threshold for transfer cancellation handling. After this state, the anchor transaction may already be in the mempool or confirmed on-chain. Before reaching this point, however, the broadcast may have failed, requiring different handling.
1 parent 2b8c3f1 commit a562518

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

itest/assertions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ func AssertSendEventsComplete(t *testing.T, scriptKey []byte,
963963
stream *EventSubscription[*taprpc.SendEvent]) {
964964

965965
AssertSendEvents(
966-
t, scriptKey, stream, tapfreighter.SendStateWaitTxConf,
966+
t, scriptKey, stream, tapfreighter.SendStateBroadcastComplete,
967967
tapfreighter.SendStateComplete,
968968
)
969969
}

itest/psbt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ func testPsbtMultiSend(t *harnessTest) {
13881388

13891389
AssertSendEvents(
13901390
t.t, scriptKey1Bytes, sendEvents,
1391-
tapfreighter.SendStateWaitTxConf,
1391+
tapfreighter.SendStateBroadcastComplete,
13921392
tapfreighter.SendStateComplete,
13931393
)
13941394

tapfreighter/chain_porter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,16 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
13951395
"transaction %v: %w", txHash, err)
13961396
}
13971397

1398+
// Set send state to the next state to evaluate.
1399+
currentPkg.SendState = SendStateBroadcastComplete
1400+
return &currentPkg, nil
1401+
1402+
// At this stage, the transaction has been broadcast to the network.
1403+
// From this point forward, the transfer cancellation methodology
1404+
// changes.
1405+
case SendStateBroadcastComplete:
1406+
log.Infof("Transfer tx broadcast complete")
1407+
13981408
// With the transaction broadcast, we'll deliver a
13991409
// notification via the transaction broadcast response channel.
14001410
currentPkg.deliverTxBroadcastResp()

tapfreighter/parcel.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ const (
4747
// ensure it properly tracks the coins allocated to the anchor output.
4848
SendStateBroadcast
4949

50+
// SendStateBroadcastComplete represents the state where the transfer
51+
// transaction has been broadcast and is either in the mempool or
52+
// confirmed on-chain. At this stage, cancellation cannot rely solely
53+
// on naive coin unlocking.
54+
SendStateBroadcastComplete
55+
5056
// SendStateWaitTxConf is a state in which we will wait for the transfer
5157
// transaction to confirm on-chain.
5258
SendStateWaitTxConf
@@ -85,6 +91,9 @@ func (s SendState) String() string {
8591
case SendStateBroadcast:
8692
return "SendStateBroadcast"
8793

94+
case SendStateBroadcastComplete:
95+
return "SendStateBroadcastComplete"
96+
8897
case SendStateWaitTxConf:
8998
return "SendStateWaitTxConf"
9099

0 commit comments

Comments
 (0)