@@ -1402,9 +1402,10 @@ impl ChannelMonitor {
1402
1402
} else { ( None , None ) }
1403
1403
}
1404
1404
1405
- fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx , per_commitment_point : & Option < PublicKey > , delayed_payment_base_key : & Option < SecretKey > ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > ) {
1405
+ 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 > ) {
1406
1406
let mut res = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1407
1407
let mut spendable_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1408
+ let mut watch_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1408
1409
1409
1410
macro_rules! add_dynamic_output {
1410
1411
( $father_tx: expr, $vout: expr) => {
@@ -1468,24 +1469,27 @@ impl ChannelMonitor {
1468
1469
res. push ( htlc_success_tx) ;
1469
1470
}
1470
1471
}
1472
+ watch_outputs. push ( local_tx. tx . output [ htlc. transaction_output_index as usize ] . clone ( ) ) ;
1471
1473
}
1472
1474
1473
- ( res, spendable_outputs)
1475
+ ( res, spendable_outputs, watch_outputs )
1474
1476
}
1475
1477
1476
1478
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
1477
1479
/// revoked using data in local_claimable_outpoints.
1478
1480
/// Should not be used if check_spend_revoked_transaction succeeds.
1479
- fn check_spend_local_transaction ( & self , tx : & Transaction , _height : u32 ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > ) {
1481
+ fn check_spend_local_transaction ( & self , tx : & Transaction , _height : u32 ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > , ( Sha256dHash , Vec < TxOut > ) ) {
1480
1482
let commitment_txid = tx. txid ( ) ;
1481
1483
if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1482
1484
if local_tx. txid == commitment_txid {
1483
1485
match self . key_storage {
1484
1486
Storage :: Local { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
1485
- return self . broadcast_by_local_state ( local_tx, latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1487
+ let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1488
+ return ( local_txn, spendable_outputs, ( commitment_txid, watch_outputs) ) ;
1486
1489
} ,
1487
1490
Storage :: Watchtower { .. } => {
1488
- return self . broadcast_by_local_state ( local_tx, & None , & None ) ;
1491
+ let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, & None , & None ) ;
1492
+ return ( local_txn, spendable_outputs, ( commitment_txid, watch_outputs) ) ;
1489
1493
}
1490
1494
}
1491
1495
}
@@ -1494,15 +1498,17 @@ impl ChannelMonitor {
1494
1498
if local_tx. txid == commitment_txid {
1495
1499
match self . key_storage {
1496
1500
Storage :: Local { ref delayed_payment_base_key, ref prev_latest_per_commitment_point, .. } => {
1497
- return self . broadcast_by_local_state ( local_tx, prev_latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1501
+ let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, prev_latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1502
+ return ( local_txn, spendable_outputs, ( commitment_txid, watch_outputs) ) ;
1498
1503
} ,
1499
1504
Storage :: Watchtower { .. } => {
1500
- return self . broadcast_by_local_state ( local_tx, & None , & None ) ;
1505
+ let ( local_txn, spendable_outputs, watch_outputs) = self . broadcast_by_local_state ( local_tx, & None , & None ) ;
1506
+ return ( local_txn, spendable_outputs, ( commitment_txid, watch_outputs) ) ;
1501
1507
}
1502
1508
}
1503
1509
}
1504
1510
}
1505
- ( Vec :: new ( ) , Vec :: new ( ) )
1511
+ ( Vec :: new ( ) , Vec :: new ( ) , ( commitment_txid , Vec :: new ( ) ) )
1506
1512
}
1507
1513
1508
1514
/// Generate a spendable output event when closing_transaction get registered onchain.
@@ -1574,9 +1580,12 @@ impl ChannelMonitor {
1574
1580
watch_outputs. push ( new_outputs) ;
1575
1581
}
1576
1582
if txn. is_empty ( ) {
1577
- let ( remote_txn, mut outputs) = self . check_spend_local_transaction ( tx, height) ;
1578
- spendable_outputs. append ( & mut outputs) ;
1579
- txn = remote_txn;
1583
+ let ( local_txn, mut spendable_output, new_outputs) = self . check_spend_local_transaction ( tx, height) ;
1584
+ spendable_outputs. append ( & mut spendable_output) ;
1585
+ txn = local_txn;
1586
+ if !new_outputs. 1 . is_empty ( ) {
1587
+ watch_outputs. push ( new_outputs) ;
1588
+ }
1580
1589
}
1581
1590
if !funding_txo. is_none ( ) && txn. is_empty ( ) {
1582
1591
if let Some ( spendable_output) = self . check_spend_closing_transaction ( tx) {
@@ -1604,15 +1613,21 @@ impl ChannelMonitor {
1604
1613
broadcaster. broadcast_transaction ( & cur_local_tx. tx ) ;
1605
1614
match self . key_storage {
1606
1615
Storage :: Local { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
1607
- let ( txs, mut outputs) = self . broadcast_by_local_state ( & cur_local_tx, latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1608
- spendable_outputs. append ( & mut outputs) ;
1616
+ let ( txs, mut spendable_output, new_outputs) = self . broadcast_by_local_state ( & cur_local_tx, latest_per_commitment_point, & Some ( * delayed_payment_base_key) ) ;
1617
+ spendable_outputs. append ( & mut spendable_output) ;
1618
+ if !new_outputs. is_empty ( ) {
1619
+ watch_outputs. push ( ( cur_local_tx. txid . clone ( ) , new_outputs) ) ;
1620
+ }
1609
1621
for tx in txs {
1610
1622
broadcaster. broadcast_transaction ( & tx) ;
1611
1623
}
1612
1624
} ,
1613
1625
Storage :: Watchtower { .. } => {
1614
- let ( txs, mut outputs) = self . broadcast_by_local_state ( & cur_local_tx, & None , & None ) ;
1615
- spendable_outputs. append ( & mut outputs) ;
1626
+ let ( txs, mut spendable_output, new_outputs) = self . broadcast_by_local_state ( & cur_local_tx, & None , & None ) ;
1627
+ spendable_outputs. append ( & mut spendable_output) ;
1628
+ if !new_outputs. is_empty ( ) {
1629
+ watch_outputs. push ( ( cur_local_tx. txid . clone ( ) , new_outputs) ) ;
1630
+ }
1616
1631
for tx in txs {
1617
1632
broadcaster. broadcast_transaction ( & tx) ;
1618
1633
}
0 commit comments