@@ -643,6 +643,7 @@ struct IrrevocablyResolvedHTLC {
643
643
/// was not present in the confirmed commitment transaction), HTLC-Success, or HTLC-Timeout
644
644
/// transaction.
645
645
resolving_txid : Option < Txid > , // Added as optional, but always filled in, in 0.0.110
646
+ resolving_tx : Option < Transaction > ,
646
647
/// Only set if the HTLC claim was ours using a payment preimage
647
648
payment_preimage : Option < PaymentPreimage > ,
648
649
}
@@ -658,6 +659,7 @@ impl Writeable for IrrevocablyResolvedHTLC {
658
659
( 0 , mapped_commitment_tx_output_idx, required) ,
659
660
( 1 , self . resolving_txid, option) ,
660
661
( 2 , self . payment_preimage, option) ,
662
+ ( 3 , self . resolving_tx, option) ,
661
663
} ) ;
662
664
Ok ( ( ) )
663
665
}
@@ -668,15 +670,18 @@ impl Readable for IrrevocablyResolvedHTLC {
668
670
let mut mapped_commitment_tx_output_idx = 0 ;
669
671
let mut resolving_txid = None ;
670
672
let mut payment_preimage = None ;
673
+ let mut resolving_tx = None ;
671
674
read_tlv_fields ! ( reader, {
672
675
( 0 , mapped_commitment_tx_output_idx, required) ,
673
676
( 1 , resolving_txid, option) ,
674
677
( 2 , payment_preimage, option) ,
678
+ ( 3 , resolving_tx, option) ,
675
679
} ) ;
676
680
Ok ( Self {
677
681
commitment_tx_output_idx : if mapped_commitment_tx_output_idx == u32:: max_value ( ) { None } else { Some ( mapped_commitment_tx_output_idx) } ,
678
682
resolving_txid,
679
683
payment_preimage,
684
+ resolving_tx,
680
685
} )
681
686
}
682
687
}
@@ -1510,24 +1515,24 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1510
1515
let htlc_commitment_tx_output_idx =
1511
1516
if let Some ( v) = htlc. transaction_output_index { v } else { return None ; } ;
1512
1517
1513
- let mut htlc_spend_txid_opt = None ;
1518
+ let mut htlc_spend_tx_opt = None ;
1514
1519
let mut holder_timeout_spend_pending = None ;
1515
1520
let mut htlc_spend_pending = None ;
1516
1521
let mut holder_delayed_output_pending = None ;
1517
1522
for event in self . onchain_events_awaiting_threshold_conf . iter ( ) {
1518
1523
match event. event {
1519
1524
OnchainEvent :: HTLCUpdate { commitment_tx_output_idx, htlc_value_satoshis, .. }
1520
1525
if commitment_tx_output_idx == Some ( htlc_commitment_tx_output_idx) => {
1521
- debug_assert ! ( htlc_spend_txid_opt . is_none( ) ) ;
1522
- htlc_spend_txid_opt = event. transaction . as_ref ( ) . map ( |tx| tx . txid ( ) ) ;
1526
+ debug_assert ! ( htlc_spend_tx_opt . is_none( ) ) ;
1527
+ htlc_spend_tx_opt = event. transaction . clone ( ) ;
1523
1528
debug_assert ! ( holder_timeout_spend_pending. is_none( ) ) ;
1524
1529
debug_assert_eq ! ( htlc_value_satoshis. unwrap( ) , htlc. amount_msat / 1000 ) ;
1525
1530
holder_timeout_spend_pending = Some ( event. confirmation_threshold ( ) ) ;
1526
1531
} ,
1527
1532
OnchainEvent :: HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. }
1528
1533
if commitment_tx_output_idx == htlc_commitment_tx_output_idx => {
1529
- debug_assert ! ( htlc_spend_txid_opt . is_none( ) ) ;
1530
- htlc_spend_txid_opt = event. transaction . as_ref ( ) . map ( |tx| tx . txid ( ) ) ;
1534
+ debug_assert ! ( htlc_spend_tx_opt . is_none( ) ) ;
1535
+ htlc_spend_tx_opt = event. transaction . clone ( ) ;
1531
1536
debug_assert ! ( htlc_spend_pending. is_none( ) ) ;
1532
1537
htlc_spend_pending = Some ( ( event. confirmation_threshold ( ) , preimage. is_some ( ) ) ) ;
1533
1538
} ,
@@ -1542,20 +1547,22 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1542
1547
}
1543
1548
let htlc_resolved = self . htlcs_resolved_on_chain . iter ( )
1544
1549
. find ( |v| if v. commitment_tx_output_idx == Some ( htlc_commitment_tx_output_idx) {
1545
- debug_assert ! ( htlc_spend_txid_opt . is_none( ) ) ;
1546
- htlc_spend_txid_opt = v. resolving_txid ;
1550
+ debug_assert ! ( htlc_spend_tx_opt . is_none( ) ) ;
1551
+ htlc_spend_tx_opt = v. resolving_tx . clone ( ) ;
1547
1552
true
1548
1553
} else { false } ) ;
1549
1554
debug_assert ! ( holder_timeout_spend_pending. is_some( ) as u8 + htlc_spend_pending. is_some( ) as u8 + htlc_resolved. is_some( ) as u8 <= 1 ) ;
1550
1555
1556
+ let htlc_commitment_outpoint = BitcoinOutPoint :: new ( confirmed_txid. unwrap ( ) , htlc_commitment_tx_output_idx) ;
1551
1557
let htlc_output_to_spend =
1552
- if let Some ( txid) = htlc_spend_txid_opt {
1553
- debug_assert ! (
1554
- self . onchain_tx_handler. channel_transaction_parameters. opt_anchors. is_none( ) ,
1555
- "This code needs updating for anchors" ) ;
1556
- BitcoinOutPoint :: new ( txid, 0 )
1558
+ if let Some ( ref tx) = htlc_spend_tx_opt {
1559
+ let htlc_input_idx = tx. input . iter ( ) . enumerate ( )
1560
+ . find ( |( _, input) | input. previous_output == htlc_commitment_outpoint)
1561
+ . map ( |( idx, _) | idx as u32 )
1562
+ . unwrap ( ) ;
1563
+ BitcoinOutPoint :: new ( tx. txid ( ) , htlc_input_idx)
1557
1564
} else {
1558
- BitcoinOutPoint :: new ( confirmed_txid . unwrap ( ) , htlc_commitment_tx_output_idx )
1565
+ htlc_commitment_outpoint
1559
1566
} ;
1560
1567
let htlc_output_spend_pending = self . onchain_tx_handler . is_output_spend_pending ( & htlc_output_to_spend) ;
1561
1568
@@ -1578,9 +1585,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1578
1585
descriptor : SpendableOutputDescriptor :: StaticOutput { .. }
1579
1586
} = & event. event {
1580
1587
if event. transaction . as_ref ( ) . map ( |tx| tx. input . iter ( ) . any ( |inp| {
1581
- if let Some ( htlc_spend_txid ) = htlc_spend_txid_opt {
1582
- Some ( tx . txid ( ) ) == htlc_spend_txid_opt ||
1583
- inp. previous_output . txid == htlc_spend_txid
1588
+ if let Some ( ref htlc_spend_tx ) = htlc_spend_tx_opt {
1589
+ let htlc_spend_txid = htlc_spend_tx . txid ( ) ;
1590
+ tx . txid ( ) == htlc_spend_txid || inp. previous_output . txid == htlc_spend_txid
1584
1591
} else {
1585
1592
Some ( inp. previous_output . txid ) == confirmed_txid &&
1586
1593
inp. previous_output . vout == htlc_commitment_tx_output_idx
@@ -3048,7 +3055,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
3048
3055
htlc_value_satoshis,
3049
3056
} ) ) ;
3050
3057
self . htlcs_resolved_on_chain . push ( IrrevocablyResolvedHTLC {
3051
- commitment_tx_output_idx, resolving_txid : Some ( entry. txid ) ,
3058
+ commitment_tx_output_idx,
3059
+ resolving_txid : Some ( entry. txid ) ,
3060
+ resolving_tx : entry. transaction ,
3052
3061
payment_preimage : None ,
3053
3062
} ) ;
3054
3063
} ,
@@ -3060,7 +3069,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
3060
3069
} ,
3061
3070
OnchainEvent :: HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
3062
3071
self . htlcs_resolved_on_chain . push ( IrrevocablyResolvedHTLC {
3063
- commitment_tx_output_idx : Some ( commitment_tx_output_idx) , resolving_txid : Some ( entry. txid ) ,
3072
+ commitment_tx_output_idx : Some ( commitment_tx_output_idx) ,
3073
+ resolving_txid : Some ( entry. txid ) ,
3074
+ resolving_tx : entry. transaction ,
3064
3075
payment_preimage : preimage,
3065
3076
} ) ;
3066
3077
} ,
0 commit comments