@@ -306,6 +306,7 @@ pub struct CounterpartyForwardingInfo {
306
306
enum UpdateFulfillFetch {
307
307
NewClaim {
308
308
monitor_update : ChannelMonitorUpdate ,
309
+ htlc_value_msat : u64 ,
309
310
msg : Option < msgs:: UpdateFulfillHTLC > ,
310
311
} ,
311
312
DuplicateClaim { } ,
@@ -319,6 +320,8 @@ pub enum UpdateFulfillCommitFetch {
319
320
NewClaim {
320
321
/// The ChannelMonitorUpdate which places the new payment preimage in the channel monitor
321
322
monitor_update : ChannelMonitorUpdate ,
323
+ /// The value of the HTLC which was claimed, in msat.
324
+ htlc_value_msat : u64 ,
322
325
/// The update_fulfill message and commitment_signed message (if the claim was not placed
323
326
/// in the holding cell).
324
327
msgs : Option < ( msgs:: UpdateFulfillHTLC , msgs:: CommitmentSigned ) > ,
@@ -336,6 +339,9 @@ pub enum UpdateFulfillCommitFetch {
336
339
// Holder designates channel data owned for the benefice of the user client.
337
340
// Counterparty designates channel data owned by the another channel participant entity.
338
341
pub ( super ) struct Channel < Signer : Sign > {
342
+ #[ cfg( any( test, feature = "_test_utils" ) ) ]
343
+ pub ( crate ) config : ChannelConfig ,
344
+ #[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
339
345
config : ChannelConfig ,
340
346
341
347
user_id : u64 ,
@@ -1275,6 +1281,7 @@ impl<Signer: Sign> Channel<Signer> {
1275
1281
// these, but for now we just have to treat them as normal.
1276
1282
1277
1283
let mut pending_idx = core:: usize:: MAX ;
1284
+ let mut htlc_value_msat = 0 ;
1278
1285
for ( idx, htlc) in self . pending_inbound_htlcs . iter ( ) . enumerate ( ) {
1279
1286
if htlc. htlc_id == htlc_id_arg {
1280
1287
assert_eq ! ( htlc. payment_hash, payment_hash_calc) ;
@@ -1294,6 +1301,7 @@ impl<Signer: Sign> Channel<Signer> {
1294
1301
}
1295
1302
}
1296
1303
pending_idx = idx;
1304
+ htlc_value_msat = htlc. amount_msat ;
1297
1305
break ;
1298
1306
}
1299
1307
}
@@ -1335,7 +1343,7 @@ impl<Signer: Sign> Channel<Signer> {
1335
1343
// TODO: We may actually be able to switch to a fulfill here, though its
1336
1344
// rare enough it may not be worth the complexity burden.
1337
1345
debug_assert ! ( false , "Tried to fulfill an HTLC that was already failed" ) ;
1338
- return UpdateFulfillFetch :: NewClaim { monitor_update, msg : None } ;
1346
+ return UpdateFulfillFetch :: NewClaim { monitor_update, htlc_value_msat , msg : None } ;
1339
1347
}
1340
1348
} ,
1341
1349
_ => { }
@@ -1347,7 +1355,7 @@ impl<Signer: Sign> Channel<Signer> {
1347
1355
} ) ;
1348
1356
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
1349
1357
self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
1350
- return UpdateFulfillFetch :: NewClaim { monitor_update, msg : None } ;
1358
+ return UpdateFulfillFetch :: NewClaim { monitor_update, htlc_value_msat , msg : None } ;
1351
1359
}
1352
1360
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
1353
1361
self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
@@ -1357,14 +1365,15 @@ impl<Signer: Sign> Channel<Signer> {
1357
1365
if let InboundHTLCState :: Committed = htlc. state {
1358
1366
} else {
1359
1367
debug_assert ! ( false , "Have an inbound HTLC we tried to claim before it was fully committed to" ) ;
1360
- return UpdateFulfillFetch :: NewClaim { monitor_update, msg : None } ;
1368
+ return UpdateFulfillFetch :: NewClaim { monitor_update, htlc_value_msat , msg : None } ;
1361
1369
}
1362
1370
log_trace ! ( logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!" , log_bytes!( htlc. payment_hash. 0 ) , log_bytes!( self . channel_id) ) ;
1363
1371
htlc. state = InboundHTLCState :: LocalRemoved ( InboundHTLCRemovalReason :: Fulfill ( payment_preimage_arg. clone ( ) ) ) ;
1364
1372
}
1365
1373
1366
1374
UpdateFulfillFetch :: NewClaim {
1367
1375
monitor_update,
1376
+ htlc_value_msat,
1368
1377
msg : Some ( msgs:: UpdateFulfillHTLC {
1369
1378
channel_id : self . channel_id ( ) ,
1370
1379
htlc_id : htlc_id_arg,
@@ -1375,7 +1384,7 @@ impl<Signer: Sign> Channel<Signer> {
1375
1384
1376
1385
pub fn get_update_fulfill_htlc_and_commit < L : Deref > ( & mut self , htlc_id : u64 , payment_preimage : PaymentPreimage , logger : & L ) -> Result < UpdateFulfillCommitFetch , ( ChannelError , ChannelMonitorUpdate ) > where L :: Target : Logger {
1377
1386
match self . get_update_fulfill_htlc ( htlc_id, payment_preimage, logger) {
1378
- UpdateFulfillFetch :: NewClaim { mut monitor_update, msg : Some ( update_fulfill_htlc) } => {
1387
+ UpdateFulfillFetch :: NewClaim { mut monitor_update, htlc_value_msat , msg : Some ( update_fulfill_htlc) } => {
1379
1388
let ( commitment, mut additional_update) = match self . send_commitment_no_status_check ( logger) {
1380
1389
Err ( e) => return Err ( ( e, monitor_update) ) ,
1381
1390
Ok ( res) => res
@@ -1384,9 +1393,10 @@ impl<Signer: Sign> Channel<Signer> {
1384
1393
// strictly increasing by one, so decrement it here.
1385
1394
self . latest_monitor_update_id = monitor_update. update_id ;
1386
1395
monitor_update. updates . append ( & mut additional_update. updates ) ;
1387
- Ok ( UpdateFulfillCommitFetch :: NewClaim { monitor_update, msgs : Some ( ( update_fulfill_htlc, commitment) ) } )
1396
+ Ok ( UpdateFulfillCommitFetch :: NewClaim { monitor_update, htlc_value_msat , msgs : Some ( ( update_fulfill_htlc, commitment) ) } )
1388
1397
} ,
1389
- UpdateFulfillFetch :: NewClaim { monitor_update, msg : None } => Ok ( UpdateFulfillCommitFetch :: NewClaim { monitor_update, msgs : None } ) ,
1398
+ UpdateFulfillFetch :: NewClaim { monitor_update, htlc_value_msat, msg : None } =>
1399
+ Ok ( UpdateFulfillCommitFetch :: NewClaim { monitor_update, htlc_value_msat, msgs : None } ) ,
1390
1400
UpdateFulfillFetch :: DuplicateClaim { } => Ok ( UpdateFulfillCommitFetch :: DuplicateClaim { } ) ,
1391
1401
}
1392
1402
}
@@ -2163,7 +2173,7 @@ impl<Signer: Sign> Channel<Signer> {
2163
2173
2164
2174
/// Marks an outbound HTLC which we have received update_fail/fulfill/malformed
2165
2175
#[ inline]
2166
- fn mark_outbound_htlc_removed ( & mut self , htlc_id : u64 , check_preimage : Option < PaymentHash > , fail_reason : Option < HTLCFailReason > ) -> Result < & HTLCSource , ChannelError > {
2176
+ fn mark_outbound_htlc_removed ( & mut self , htlc_id : u64 , check_preimage : Option < PaymentHash > , fail_reason : Option < HTLCFailReason > ) -> Result < & OutboundHTLCOutput , ChannelError > {
2167
2177
for htlc in self . pending_outbound_htlcs . iter_mut ( ) {
2168
2178
if htlc. htlc_id == htlc_id {
2169
2179
match check_preimage {
@@ -2182,13 +2192,13 @@ impl<Signer: Sign> Channel<Signer> {
2182
2192
OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( _) | OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( _) | OutboundHTLCState :: RemoteRemoved ( _) =>
2183
2193
return Err ( ChannelError :: Close ( format ! ( "Remote tried to fulfill/fail HTLC ({}) that they'd already fulfilled/failed" , htlc_id) ) ) ,
2184
2194
}
2185
- return Ok ( & htlc. source ) ;
2195
+ return Ok ( htlc) ;
2186
2196
}
2187
2197
}
2188
2198
Err ( ChannelError :: Close ( "Remote tried to fulfill/fail an HTLC we couldn't find" . to_owned ( ) ) )
2189
2199
}
2190
2200
2191
- pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < HTLCSource , ChannelError > {
2201
+ pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < ( HTLCSource , u64 ) , ChannelError > {
2192
2202
if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2193
2203
return Err ( ChannelError :: Close ( "Got fulfill HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
2194
2204
}
@@ -2197,7 +2207,7 @@ impl<Signer: Sign> Channel<Signer> {
2197
2207
}
2198
2208
2199
2209
let payment_hash = PaymentHash ( Sha256 :: hash ( & msg. payment_preimage . 0 [ ..] ) . into_inner ( ) ) ;
2200
- self . mark_outbound_htlc_removed ( msg. htlc_id , Some ( payment_hash) , None ) . map ( |source| source. clone ( ) )
2210
+ self . mark_outbound_htlc_removed ( msg. htlc_id , Some ( payment_hash) , None ) . map ( |htlc| ( htlc . source . clone ( ) , htlc . amount_msat ) )
2201
2211
}
2202
2212
2203
2213
pub fn update_fail_htlc ( & mut self , msg : & msgs:: UpdateFailHTLC , fail_reason : HTLCFailReason ) -> Result < ( ) , ChannelError > {
@@ -2496,7 +2506,7 @@ impl<Signer: Sign> Channel<Signer> {
2496
2506
// in it hitting the holding cell again and we cannot change the state of a
2497
2507
// holding cell HTLC from fulfill to anything else.
2498
2508
let ( update_fulfill_msg_option, mut additional_monitor_update) =
2499
- if let UpdateFulfillFetch :: NewClaim { msg, monitor_update } = self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) {
2509
+ if let UpdateFulfillFetch :: NewClaim { msg, monitor_update, .. } = self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) {
2500
2510
( msg, monitor_update)
2501
2511
} else { unreachable ! ( ) } ;
2502
2512
update_fulfill_htlcs. push ( update_fulfill_msg_option. unwrap ( ) ) ;
0 commit comments