@@ -199,10 +199,12 @@ pub enum MonitorEvent {
199
199
pub struct HTLCUpdate {
200
200
pub ( crate ) payment_hash : PaymentHash ,
201
201
pub ( crate ) payment_preimage : Option < PaymentPreimage > ,
202
- pub ( crate ) source : HTLCSource
202
+ pub ( crate ) source : HTLCSource ,
203
+ pub ( crate ) onchain_value_satoshis : Option < u64 > ,
203
204
}
204
205
impl_writeable_tlv_based ! ( HTLCUpdate , {
205
206
( 0 , payment_hash, required) ,
207
+ ( 1 , onchain_value_satoshis, option) ,
206
208
( 2 , source, required) ,
207
209
( 4 , payment_preimage, option) ,
208
210
} ) ;
@@ -385,6 +387,7 @@ enum OnchainEvent {
385
387
HTLCUpdate {
386
388
source : HTLCSource ,
387
389
payment_hash : PaymentHash ,
390
+ onchain_value_satoshis : Option < u64 > ,
388
391
} ,
389
392
MaturingOutput {
390
393
descriptor : SpendableOutputDescriptor ,
@@ -400,6 +403,7 @@ impl_writeable_tlv_based!(OnchainEventEntry, {
400
403
impl_writeable_tlv_based_enum ! ( OnchainEvent ,
401
404
( 0 , HTLCUpdate ) => {
402
405
( 0 , source, required) ,
406
+ ( 1 , onchain_value_satoshis, option) ,
403
407
( 2 , payment_hash, required) ,
404
408
} ,
405
409
( 1 , MaturingOutput ) => {
@@ -1574,6 +1578,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1574
1578
event: OnchainEvent :: HTLCUpdate {
1575
1579
source: ( * * source) . clone( ) ,
1576
1580
payment_hash: htlc. payment_hash. clone( ) ,
1581
+ onchain_value_satoshis: Some ( htlc. amount_msat / 1000 ) ,
1577
1582
} ,
1578
1583
} ;
1579
1584
log_info!( logger, "Failing HTLC with payment_hash {} from {} counterparty commitment tx due to broadcast of revoked counterparty commitment transaction, waiting for confirmation (at height {})" , log_bytes!( htlc. payment_hash. 0 ) , $commitment_tx, entry. confirmation_threshold( ) ) ;
@@ -1641,6 +1646,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1641
1646
event: OnchainEvent :: HTLCUpdate {
1642
1647
source: ( * * source) . clone( ) ,
1643
1648
payment_hash: htlc. payment_hash. clone( ) ,
1649
+ onchain_value_satoshis: Some ( htlc. amount_msat / 1000 ) ,
1644
1650
} ,
1645
1651
} ) ;
1646
1652
}
@@ -1779,27 +1785,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1779
1785
let mut claim_requests = Vec :: new ( ) ;
1780
1786
let mut watch_outputs = Vec :: new ( ) ;
1781
1787
1782
- macro_rules! wait_threshold_conf {
1783
- ( $source: expr, $commitment_tx: expr, $payment_hash: expr) => {
1784
- self . onchain_events_awaiting_threshold_conf. retain( |ref entry| {
1785
- if entry. height != height { return true ; }
1786
- match entry. event {
1787
- OnchainEvent :: HTLCUpdate { source: ref update_source, .. } => {
1788
- * update_source != $source
1789
- } ,
1790
- _ => true ,
1791
- }
1792
- } ) ;
1793
- let entry = OnchainEventEntry {
1794
- txid: commitment_txid,
1795
- height,
1796
- event: OnchainEvent :: HTLCUpdate { source: $source, payment_hash: $payment_hash } ,
1797
- } ;
1798
- log_trace!( logger, "Failing HTLC with payment_hash {} from {} holder commitment tx due to broadcast of transaction, waiting confirmation (at height{})" , log_bytes!( $payment_hash. 0 ) , $commitment_tx, entry. confirmation_threshold( ) ) ;
1799
- self . onchain_events_awaiting_threshold_conf. push( entry) ;
1800
- }
1801
- }
1802
-
1803
1788
macro_rules! append_onchain_update {
1804
1789
( $updates: expr, $to_watch: expr) => {
1805
1790
claim_requests = $updates. 0 ;
@@ -1828,21 +1813,40 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1828
1813
}
1829
1814
1830
1815
macro_rules! fail_dust_htlcs_after_threshold_conf {
1831
- ( $holder_tx: expr) => {
1816
+ ( $holder_tx: expr, $commitment_tx : expr ) => {
1832
1817
for & ( ref htlc, _, ref source) in & $holder_tx. htlc_outputs {
1833
1818
if htlc. transaction_output_index. is_none( ) {
1834
1819
if let & Some ( ref source) = source {
1835
- wait_threshold_conf!( source. clone( ) , "lastest" , htlc. payment_hash. clone( ) ) ;
1820
+ self . onchain_events_awaiting_threshold_conf. retain( |ref entry| {
1821
+ if entry. height != height { return true ; }
1822
+ match entry. event {
1823
+ OnchainEvent :: HTLCUpdate { source: ref update_source, .. } => {
1824
+ update_source != source
1825
+ } ,
1826
+ _ => true ,
1827
+ }
1828
+ } ) ;
1829
+ let entry = OnchainEventEntry {
1830
+ txid: commitment_txid,
1831
+ height,
1832
+ event: OnchainEvent :: HTLCUpdate {
1833
+ source: source. clone( ) , payment_hash: htlc. payment_hash,
1834
+ onchain_value_satoshis: Some ( htlc. amount_msat / 1000 )
1835
+ } ,
1836
+ } ;
1837
+ log_trace!( logger, "Failing HTLC with payment_hash {} from {} holder commitment tx due to broadcast of transaction, waiting confirmation (at height{})" ,
1838
+ log_bytes!( htlc. payment_hash. 0 ) , $commitment_tx, entry. confirmation_threshold( ) ) ;
1839
+ self . onchain_events_awaiting_threshold_conf. push( entry) ;
1836
1840
}
1837
1841
}
1838
1842
}
1839
1843
}
1840
1844
}
1841
1845
1842
1846
if is_holder_tx {
1843
- fail_dust_htlcs_after_threshold_conf ! ( self . current_holder_commitment_tx) ;
1847
+ fail_dust_htlcs_after_threshold_conf ! ( self . current_holder_commitment_tx, "latest" ) ;
1844
1848
if let & Some ( ref holder_tx) = & self . prev_holder_signed_commitment_tx {
1845
- fail_dust_htlcs_after_threshold_conf ! ( holder_tx) ;
1849
+ fail_dust_htlcs_after_threshold_conf ! ( holder_tx, "previous" ) ;
1846
1850
}
1847
1851
}
1848
1852
@@ -2090,7 +2094,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2090
2094
// Produce actionable events from on-chain events having reached their threshold.
2091
2095
for entry in onchain_events_reaching_threshold_conf. drain ( ..) {
2092
2096
match entry. event {
2093
- OnchainEvent :: HTLCUpdate { ref source, payment_hash } => {
2097
+ OnchainEvent :: HTLCUpdate { ref source, payment_hash, onchain_value_satoshis } => {
2094
2098
// Check for duplicate HTLC resolutions.
2095
2099
#[ cfg( debug_assertions) ]
2096
2100
{
@@ -2109,9 +2113,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2109
2113
2110
2114
log_debug ! ( logger, "HTLC {} failure update has got enough confirmations to be passed upstream" , log_bytes!( payment_hash. 0 ) ) ;
2111
2115
self . pending_monitor_events . push ( MonitorEvent :: HTLCEvent ( HTLCUpdate {
2112
- payment_hash : payment_hash ,
2116
+ payment_hash,
2113
2117
payment_preimage : None ,
2114
2118
source : source. clone ( ) ,
2119
+ onchain_value_satoshis,
2115
2120
} ) ) ;
2116
2121
} ,
2117
2122
OnchainEvent :: MaturingOutput { descriptor } => {
@@ -2328,7 +2333,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2328
2333
if pending_htlc. payment_hash == $htlc_output. payment_hash && pending_htlc. amount_msat == $htlc_output. amount_msat {
2329
2334
if let & Some ( ref source) = pending_source {
2330
2335
log_claim!( "revoked counterparty commitment tx" , false , pending_htlc, true ) ;
2331
- payment_data = Some ( ( ( * * source) . clone( ) , $htlc_output. payment_hash) ) ;
2336
+ payment_data = Some ( ( ( * * source) . clone( ) , $htlc_output. payment_hash, $htlc_output . amount_msat ) ) ;
2332
2337
break ;
2333
2338
}
2334
2339
}
@@ -2348,7 +2353,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2348
2353
// transaction. This implies we either learned a preimage, the HTLC
2349
2354
// has timed out, or we screwed up. In any case, we should now
2350
2355
// resolve the source HTLC with the original sender.
2351
- payment_data = Some ( ( ( * source) . clone( ) , htlc_output. payment_hash) ) ;
2356
+ payment_data = Some ( ( ( * source) . clone( ) , htlc_output. payment_hash, htlc_output . amount_msat ) ) ;
2352
2357
} else if !$holder_tx {
2353
2358
check_htlc_valid_counterparty!( self . current_counterparty_commitment_txid, htlc_output) ;
2354
2359
if payment_data. is_none( ) {
@@ -2381,7 +2386,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2381
2386
2382
2387
// Check that scan_commitment, above, decided there is some source worth relaying an
2383
2388
// HTLC resolution backwards to and figure out whether we learned a preimage from it.
2384
- if let Some ( ( source, payment_hash) ) = payment_data {
2389
+ if let Some ( ( source, payment_hash, amount_msat ) ) = payment_data {
2385
2390
let mut payment_preimage = PaymentPreimage ( [ 0 ; 32 ] ) ;
2386
2391
if accepted_preimage_claim {
2387
2392
if !self . pending_monitor_events . iter ( ) . any (
@@ -2390,7 +2395,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2390
2395
self . pending_monitor_events . push ( MonitorEvent :: HTLCEvent ( HTLCUpdate {
2391
2396
source,
2392
2397
payment_preimage : Some ( payment_preimage) ,
2393
- payment_hash
2398
+ payment_hash,
2399
+ onchain_value_satoshis : Some ( amount_msat / 1000 ) ,
2394
2400
} ) ) ;
2395
2401
}
2396
2402
} else if offered_preimage_claim {
@@ -2402,7 +2408,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2402
2408
self . pending_monitor_events . push ( MonitorEvent :: HTLCEvent ( HTLCUpdate {
2403
2409
source,
2404
2410
payment_preimage : Some ( payment_preimage) ,
2405
- payment_hash
2411
+ payment_hash,
2412
+ onchain_value_satoshis : Some ( amount_msat / 1000 ) ,
2406
2413
} ) ) ;
2407
2414
}
2408
2415
} else {
@@ -2418,7 +2425,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
2418
2425
let entry = OnchainEventEntry {
2419
2426
txid : tx. txid ( ) ,
2420
2427
height,
2421
- event : OnchainEvent :: HTLCUpdate { source : source, payment_hash : payment_hash } ,
2428
+ event : OnchainEvent :: HTLCUpdate {
2429
+ source, payment_hash,
2430
+ onchain_value_satoshis : Some ( amount_msat / 1000 ) ,
2431
+ } ,
2422
2432
} ;
2423
2433
log_info ! ( logger, "Failing HTLC with payment_hash {} timeout by a spend tx, waiting for confirmation (at height {})" , log_bytes!( payment_hash. 0 ) , entry. confirmation_threshold( ) ) ;
2424
2434
self . onchain_events_awaiting_threshold_conf . push ( entry) ;
0 commit comments