@@ -1319,9 +1319,10 @@ impl ChannelMonitor {
1319
1319
} else { ( None , None ) }
1320
1320
}
1321
1321
1322
- fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx , per_commitment_point : & Option < PublicKey > , delayed_payment_base_key : & Option < SecretKey > ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > ) {
1322
+ fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx , per_commitment_point : & Option < PublicKey > , delayed_payment_base_key : & Option < SecretKey > ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > , Vec < TxOut > ) {
1323
1323
let mut res = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1324
1324
let mut spendable_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1325
+ let mut watch_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1325
1326
1326
1327
macro_rules! add_dynamic_output {
1327
1328
( $father_tx: expr, $vout: expr) => {
@@ -1385,24 +1386,27 @@ impl ChannelMonitor {
1385
1386
res. push ( htlc_success_tx) ;
1386
1387
}
1387
1388
}
1389
+ watch_outputs. push ( local_tx. tx . output [ htlc. transaction_output_index as usize ] . clone ( ) ) ;
1388
1390
}
1389
1391
1390
- ( res, spendable_outputs)
1392
+ ( res, spendable_outputs, watch_outputs )
1391
1393
}
1392
1394
1393
1395
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
1394
1396
/// revoked using data in local_claimable_outpoints.
1395
1397
/// Should not be used if check_spend_revoked_transaction succeeds.
1396
- fn check_spend_local_transaction ( & self , tx : & Transaction , _height : u32 ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > ) {
1398
+ fn check_spend_local_transaction ( & self , tx : & Transaction , _height : u32 ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > , ( Sha256dHash , Vec < TxOut > ) ) {
1397
1399
let commitment_txid = tx. txid ( ) ;
1398
1400
if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1399
1401
if local_tx. txid == commitment_txid {
1400
1402
match self . key_storage {
1401
1403
Storage :: Local { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
1402
- return self . broadcast_by_local_state ( local_tx, latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1404
+ let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1405
+ return ( local_txn, spendable_outputs, ( commitment_txid, watch_outputs) ) ;
1403
1406
} ,
1404
1407
Storage :: Watchtower { .. } => {
1405
- return self . broadcast_by_local_state ( local_tx, & None , & None ) ;
1408
+ let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, & None , & None ) ;
1409
+ return ( local_txn, spendable_outputs, ( commitment_txid, watch_outputs) ) ;
1406
1410
}
1407
1411
}
1408
1412
}
@@ -1411,15 +1415,17 @@ impl ChannelMonitor {
1411
1415
if local_tx. txid == commitment_txid {
1412
1416
match self . key_storage {
1413
1417
Storage :: Local { ref delayed_payment_base_key, ref prev_latest_per_commitment_point, .. } => {
1414
- return self . broadcast_by_local_state ( local_tx, prev_latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1418
+ let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, prev_latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1419
+ return ( local_txn, spendable_outputs, ( commitment_txid, watch_outputs) ) ;
1415
1420
} ,
1416
1421
Storage :: Watchtower { .. } => {
1417
- return self . broadcast_by_local_state ( local_tx, & None , & None ) ;
1422
+ let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, & None , & None ) ;
1423
+ return ( local_txn, spendable_outputs, ( commitment_txid, watch_outputs) ) ;
1418
1424
}
1419
1425
}
1420
1426
}
1421
1427
}
1422
- ( Vec :: new ( ) , Vec :: new ( ) )
1428
+ ( Vec :: new ( ) , Vec :: new ( ) , ( commitment_txid , Vec :: new ( ) ) )
1423
1429
}
1424
1430
1425
1431
/// Generate a spendable output event when closing_transaction get registered onchain.
@@ -1491,9 +1497,12 @@ impl ChannelMonitor {
1491
1497
watch_outputs. push ( new_outputs) ;
1492
1498
}
1493
1499
if txn. is_empty ( ) {
1494
- let ( remote_txn, mut outputs) = self . check_spend_local_transaction ( tx, height) ;
1495
- spendable_outputs. append ( & mut outputs) ;
1496
- txn = remote_txn;
1500
+ let ( local_txn, mut spendable_output, new_outputs) = self . check_spend_local_transaction ( tx, height) ;
1501
+ spendable_outputs. append ( & mut spendable_output) ;
1502
+ txn = local_txn;
1503
+ if !new_outputs. 1 . is_empty ( ) {
1504
+ watch_outputs. push ( new_outputs) ;
1505
+ }
1497
1506
}
1498
1507
if !funding_txo. is_none ( ) && txn. is_empty ( ) {
1499
1508
if let Some ( spendable_output) = self . check_spend_closing_transaction ( tx) {
@@ -1521,15 +1530,21 @@ impl ChannelMonitor {
1521
1530
broadcaster. broadcast_transaction ( & cur_local_tx. tx ) ;
1522
1531
match self . key_storage {
1523
1532
Storage :: Local { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
1524
- let ( txs, mut outputs) = self . broadcast_by_local_state ( & cur_local_tx, latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1525
- spendable_outputs. append ( & mut outputs) ;
1533
+ let ( txs, mut spendable_output, new_outputs) = self . broadcast_by_local_state ( & cur_local_tx, latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1534
+ spendable_outputs. append ( & mut spendable_output) ;
1535
+ if !new_outputs. is_empty ( ) {
1536
+ watch_outputs. push ( ( cur_local_tx. txid . clone ( ) , new_outputs) ) ;
1537
+ }
1526
1538
for tx in txs {
1527
1539
broadcaster. broadcast_transaction ( & tx) ;
1528
1540
}
1529
1541
} ,
1530
1542
Storage :: Watchtower { .. } => {
1531
- let ( txs, mut outputs) = self . broadcast_by_local_state ( & cur_local_tx, & None , & None ) ;
1532
- spendable_outputs. append ( & mut outputs) ;
1543
+ let ( txs, mut spendable_output, new_outputs) = self . broadcast_by_local_state ( & cur_local_tx, & None , & None ) ;
1544
+ spendable_outputs. append ( & mut spendable_output) ;
1545
+ if !new_outputs. is_empty ( ) {
1546
+ watch_outputs. push ( ( cur_local_tx. txid . clone ( ) , new_outputs) ) ;
1547
+ }
1533
1548
for tx in txs {
1534
1549
broadcaster. broadcast_transaction ( & tx) ;
1535
1550
}
0 commit comments