@@ -32,7 +32,7 @@ use bitcoin::{
3232 WPubkeyHash , Weight , WitnessProgram , WitnessVersion ,
3333} ;
3434use lightning:: chain:: chaininterface:: {
35- BroadcasterInterface , FundingCandidate , TransactionType as LdkTransactionType ,
35+ FundingCandidate , TransactionType as LdkTransactionType ,
3636 INCREMENTAL_RELAY_FEE_SAT_PER_1000_WEIGHT ,
3737} ;
3838use lightning:: chain:: channelmonitor:: ANTI_REORG_DELAY ;
@@ -335,21 +335,12 @@ impl Wallet {
335335 . collect ( ) ;
336336
337337 if !txs_to_broadcast. is_empty ( ) {
338- let tx_refs: Vec < (
339- & Transaction ,
340- lightning:: chain:: chaininterface:: TransactionType ,
341- ) > =
342- txs_to_broadcast
343- . iter ( )
344- . map ( |tx| {
345- ( tx, lightning:: chain:: chaininterface:: TransactionType :: Sweep { channels : vec ! [ ] } )
346- } )
347- . collect ( ) ;
348- self . broadcaster . broadcast_transactions ( & tx_refs) ;
338+ let tx_count = txs_to_broadcast. len ( ) ;
339+ self . broadcaster . broadcast_unclassified_transactions ( txs_to_broadcast) ;
349340 log_info ! (
350341 self . logger,
351342 "Rebroadcast {} unconfirmed transactions on chain tip change" ,
352- txs_to_broadcast . len ( )
343+ tx_count
353344 ) ;
354345 }
355346 }
@@ -889,12 +880,8 @@ impl Wallet {
889880 } ) ?
890881 } ;
891882
892- self . broadcaster . broadcast_transactions ( & [ (
893- & tx,
894- lightning:: chain:: chaininterface:: TransactionType :: Sweep { channels : vec ! [ ] } ,
895- ) ] ) ;
896-
897883 let txid = tx. compute_txid ( ) ;
884+ self . broadcaster . broadcast_unclassified_transactions ( vec ! [ tx] ) ;
898885
899886 match send_amount {
900887 OnchainSendAmount :: ExactRetainingReserve { amount_sats, .. } => {
@@ -1184,9 +1171,8 @@ impl Wallet {
11841171 Ok ( tx)
11851172 }
11861173
1187- /// Classifies a funding broadcast (channel open or splice) handed to the broadcaster by LDK,
1188- /// recording a payment for it before it is sent. Other transaction types are left for wallet
1189- /// sync to record normally.
1174+ /// Classifies an on-chain broadcast handed to the broadcaster by LDK, recording a payment for it
1175+ /// before it is sent when it affects this node's wallet.
11901176 pub ( crate ) async fn classify_broadcast (
11911177 & self , tx : & Transaction , tx_type : & LdkTransactionType ,
11921178 ) -> Result < ( ) , Error > {
@@ -1197,7 +1183,13 @@ impl Wallet {
11971183 LdkTransactionType :: InteractiveFunding { candidates } => {
11981184 self . classify_interactive_funding ( tx, candidates, tx_type. clone ( ) . into ( ) ) . await
11991185 } ,
1200- _ => Ok ( ( ) ) ,
1186+ LdkTransactionType :: CooperativeClose { .. }
1187+ | LdkTransactionType :: UnilateralClose { .. }
1188+ | LdkTransactionType :: AnchorBump { .. }
1189+ | LdkTransactionType :: Claim { .. }
1190+ | LdkTransactionType :: Sweep { .. } => {
1191+ self . classify_regular_broadcast ( tx, tx_type. clone ( ) . into ( ) ) . await
1192+ } ,
12011193 }
12021194 }
12031195
@@ -1338,6 +1330,40 @@ impl Wallet {
13381330 Ok ( ( ) )
13391331 }
13401332
1333+ /// Records a non-funding LDK broadcast as an on-chain payment, tagged with its transaction type.
1334+ /// Wallet sync later refreshes confirmation status while preserving the type.
1335+ async fn classify_regular_broadcast (
1336+ & self , tx : & Transaction , tx_type : TransactionType ,
1337+ ) -> Result < ( ) , Error > {
1338+ let txid = tx. compute_txid ( ) ;
1339+ let ( amount_msat, fee_paid_msat, direction) = self . onchain_payment_fields ( tx) ;
1340+
1341+ if amount_msat == Some ( 0 ) && fee_paid_msat == Some ( 0 ) {
1342+ log_trace ! (
1343+ self . logger,
1344+ "Not recording classified broadcast {} as a payment: no wallet-level activity" ,
1345+ txid,
1346+ ) ;
1347+ return Ok ( ( ) ) ;
1348+ }
1349+
1350+ let details = PaymentDetails :: new (
1351+ PaymentId ( txid. to_byte_array ( ) ) ,
1352+ PaymentKind :: Onchain {
1353+ txid,
1354+ status : ConfirmationStatus :: Unconfirmed ,
1355+ tx_type : Some ( tx_type) ,
1356+ } ,
1357+ amount_msat,
1358+ fee_paid_msat,
1359+ direction,
1360+ PaymentStatus :: Pending ,
1361+ ) ;
1362+ self . payment_store . insert_or_update ( details) . await ?;
1363+ log_debug ! ( self . logger, "Recorded classified on-chain broadcast {}" , txid) ;
1364+ Ok ( ( ) )
1365+ }
1366+
13411367 /// Writes a freshly-classified funding payment to the authoritative payment store and adds a
13421368 /// pending-store index entry, so wallet sync graduates it through `ANTI_REORG_DELAY`.
13431369 async fn persist_funding_payment (
@@ -1719,11 +1745,6 @@ impl Wallet {
17191745
17201746 let new_txid = fee_bumped_tx. compute_txid ( ) ;
17211747
1722- self . broadcaster . broadcast_transactions ( & [ (
1723- & fee_bumped_tx,
1724- lightning:: chain:: chaininterface:: TransactionType :: Sweep { channels : vec ! [ ] } ,
1725- ) ] ) ;
1726-
17271748 let new_payment = self . create_payment_from_tx (
17281749 & locked_wallet,
17291750 new_txid,
@@ -1736,9 +1757,11 @@ impl Wallet {
17361757 let pending_payment_store =
17371758 self . create_pending_payment_from_tx ( new_payment. clone ( ) , Vec :: new ( ) ) ;
17381759
1760+ self . runtime . block_on ( self . payment_store . insert_or_update ( new_payment) ) ?;
17391761 self . runtime
17401762 . block_on ( self . pending_payment_store . insert_or_update ( pending_payment_store) ) ?;
1741- self . runtime . block_on ( self . payment_store . insert_or_update ( new_payment) ) ?;
1763+
1764+ self . broadcaster . broadcast_unclassified_transactions ( vec ! [ fee_bumped_tx] ) ;
17421765
17431766 log_info ! ( self . logger, "RBF successful: replaced {} with {}" , txid, new_txid) ;
17441767
0 commit comments