@@ -309,6 +309,9 @@ pub struct CounterpartyForwardingInfo {
309
309
// Holder designates channel data owned for the benefice of the user client.
310
310
// Counterparty designates channel data owned by the another channel participant entity.
311
311
pub ( super ) struct Channel < Signer : Sign > {
312
+ #[ cfg( any( test, feature = "_test_utils" ) ) ]
313
+ pub ( crate ) config : ChannelConfig ,
314
+ #[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
312
315
config : ChannelConfig ,
313
316
314
317
user_id : u64 ,
@@ -1231,7 +1234,7 @@ impl<Signer: Sign> Channel<Signer> {
1231
1234
make_funding_redeemscript ( & self . get_holder_pubkeys ( ) . funding_pubkey , self . counterparty_funding_pubkey ( ) )
1232
1235
}
1233
1236
1234
- fn get_update_fulfill_htlc < L : Deref > ( & mut self , htlc_id_arg : u64 , payment_preimage_arg : PaymentPreimage , logger : & L ) -> ( Option < msgs:: UpdateFulfillHTLC > , Option < ChannelMonitorUpdate > ) where L :: Target : Logger {
1237
+ fn get_update_fulfill_htlc < L : Deref > ( & mut self , htlc_id_arg : u64 , payment_preimage_arg : PaymentPreimage , logger : & L ) -> ( Option < msgs:: UpdateFulfillHTLC > , Option < ( ChannelMonitorUpdate , u64 ) > ) where L :: Target : Logger {
1235
1238
// Either ChannelFunded got set (which means it won't be unset) or there is no way any
1236
1239
// caller thought we could have something claimed (cause we wouldn't have accepted in an
1237
1240
// incoming HTLC anyway). If we got to ShutdownComplete, callers aren't allowed to call us,
@@ -1248,6 +1251,7 @@ impl<Signer: Sign> Channel<Signer> {
1248
1251
// these, but for now we just have to treat them as normal.
1249
1252
1250
1253
let mut pending_idx = core:: usize:: MAX ;
1254
+ let mut htlc_value_msat = 0 ;
1251
1255
for ( idx, htlc) in self . pending_inbound_htlcs . iter ( ) . enumerate ( ) {
1252
1256
if htlc. htlc_id == htlc_id_arg {
1253
1257
assert_eq ! ( htlc. payment_hash, payment_hash_calc) ;
@@ -1267,6 +1271,7 @@ impl<Signer: Sign> Channel<Signer> {
1267
1271
}
1268
1272
}
1269
1273
pending_idx = idx;
1274
+ htlc_value_msat = htlc. amount_msat ;
1270
1275
break ;
1271
1276
}
1272
1277
}
@@ -1308,7 +1313,7 @@ impl<Signer: Sign> Channel<Signer> {
1308
1313
// TODO: We may actually be able to switch to a fulfill here, though its
1309
1314
// rare enough it may not be worth the complexity burden.
1310
1315
debug_assert ! ( false , "Tried to fulfill an HTLC that was already failed" ) ;
1311
- return ( None , Some ( monitor_update) ) ;
1316
+ return ( None , Some ( ( monitor_update, htlc_value_msat ) ) ) ;
1312
1317
}
1313
1318
} ,
1314
1319
_ => { }
@@ -1320,7 +1325,7 @@ impl<Signer: Sign> Channel<Signer> {
1320
1325
} ) ;
1321
1326
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
1322
1327
self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
1323
- return ( None , Some ( monitor_update) ) ;
1328
+ return ( None , Some ( ( monitor_update, htlc_value_msat ) ) ) ;
1324
1329
}
1325
1330
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
1326
1331
self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
@@ -1330,7 +1335,7 @@ impl<Signer: Sign> Channel<Signer> {
1330
1335
if let InboundHTLCState :: Committed = htlc. state {
1331
1336
} else {
1332
1337
debug_assert ! ( false , "Have an inbound HTLC we tried to claim before it was fully committed to" ) ;
1333
- return ( None , Some ( monitor_update) ) ;
1338
+ return ( None , Some ( ( monitor_update, htlc_value_msat ) ) ) ;
1334
1339
}
1335
1340
log_trace ! ( logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!" , log_bytes!( htlc. payment_hash. 0 ) , log_bytes!( self . channel_id) ) ;
1336
1341
htlc. state = InboundHTLCState :: LocalRemoved ( InboundHTLCRemovalReason :: Fulfill ( payment_preimage_arg. clone ( ) ) ) ;
@@ -1340,12 +1345,14 @@ impl<Signer: Sign> Channel<Signer> {
1340
1345
channel_id : self . channel_id ( ) ,
1341
1346
htlc_id : htlc_id_arg,
1342
1347
payment_preimage : payment_preimage_arg,
1343
- } ) , Some ( monitor_update) )
1348
+ } ) , Some ( ( monitor_update, htlc_value_msat ) ) )
1344
1349
}
1345
1350
1346
- pub fn get_update_fulfill_htlc_and_commit < L : Deref > ( & mut self , htlc_id : u64 , payment_preimage : PaymentPreimage , logger : & L ) -> Result < ( Option < ( msgs:: UpdateFulfillHTLC , msgs:: CommitmentSigned ) > , Option < ChannelMonitorUpdate > ) , ( ChannelError , ChannelMonitorUpdate ) > where L :: Target : Logger {
1351
+ pub fn get_update_fulfill_htlc_and_commit < L : Deref > ( & mut self , htlc_id : u64 , payment_preimage : PaymentPreimage , logger : & L )
1352
+ -> Result < ( Option < ( msgs:: UpdateFulfillHTLC , msgs:: CommitmentSigned ) > , Option < ( ChannelMonitorUpdate , u64 ) > ) ,
1353
+ ( ChannelError , ChannelMonitorUpdate ) > where L :: Target : Logger {
1347
1354
match self . get_update_fulfill_htlc ( htlc_id, payment_preimage, logger) {
1348
- ( Some ( update_fulfill_htlc) , Some ( mut monitor_update) ) => {
1355
+ ( Some ( update_fulfill_htlc) , Some ( ( mut monitor_update, htlc_value_msat ) ) ) => {
1349
1356
let ( commitment, mut additional_update) = match self . send_commitment_no_status_check ( logger) {
1350
1357
Err ( e) => return Err ( ( e, monitor_update) ) ,
1351
1358
Ok ( res) => res
@@ -1354,14 +1361,14 @@ impl<Signer: Sign> Channel<Signer> {
1354
1361
// strictly increasing by one, so decrement it here.
1355
1362
self . latest_monitor_update_id = monitor_update. update_id ;
1356
1363
monitor_update. updates . append ( & mut additional_update. updates ) ;
1357
- Ok ( ( Some ( ( update_fulfill_htlc, commitment) ) , Some ( monitor_update) ) )
1364
+ Ok ( ( Some ( ( update_fulfill_htlc, commitment) ) , Some ( ( monitor_update, htlc_value_msat ) ) ) )
1358
1365
} ,
1359
1366
( Some ( _) , None ) => {
1360
1367
// If we generated a claim message, we absolutely should have generated a
1361
1368
// ChannelMonitorUpdate, otherwise we are going to probably lose funds.
1362
1369
unreachable ! ( ) ;
1363
1370
} ,
1364
- ( None , Some ( monitor_update ) ) => Ok ( ( None , Some ( monitor_update ) ) ) ,
1371
+ ( None , Some ( monitor_and_value ) ) => Ok ( ( None , Some ( monitor_and_value ) ) ) ,
1365
1372
( None , None ) => Ok ( ( None , None ) )
1366
1373
}
1367
1374
}
@@ -2138,7 +2145,7 @@ impl<Signer: Sign> Channel<Signer> {
2138
2145
2139
2146
/// Marks an outbound HTLC which we have received update_fail/fulfill/malformed
2140
2147
#[ inline]
2141
- fn mark_outbound_htlc_removed ( & mut self , htlc_id : u64 , check_preimage : Option < PaymentHash > , fail_reason : Option < HTLCFailReason > ) -> Result < & HTLCSource , ChannelError > {
2148
+ fn mark_outbound_htlc_removed ( & mut self , htlc_id : u64 , check_preimage : Option < PaymentHash > , fail_reason : Option < HTLCFailReason > ) -> Result < & OutboundHTLCOutput , ChannelError > {
2142
2149
for htlc in self . pending_outbound_htlcs . iter_mut ( ) {
2143
2150
if htlc. htlc_id == htlc_id {
2144
2151
match check_preimage {
@@ -2157,13 +2164,13 @@ impl<Signer: Sign> Channel<Signer> {
2157
2164
OutboundHTLCState :: AwaitingRemoteRevokeToRemove ( _) | OutboundHTLCState :: AwaitingRemovedRemoteRevoke ( _) | OutboundHTLCState :: RemoteRemoved ( _) =>
2158
2165
return Err ( ChannelError :: Close ( format ! ( "Remote tried to fulfill/fail HTLC ({}) that they'd already fulfilled/failed" , htlc_id) ) ) ,
2159
2166
}
2160
- return Ok ( & htlc. source ) ;
2167
+ return Ok ( htlc) ;
2161
2168
}
2162
2169
}
2163
2170
Err ( ChannelError :: Close ( "Remote tried to fulfill/fail an HTLC we couldn't find" . to_owned ( ) ) )
2164
2171
}
2165
2172
2166
- pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < HTLCSource , ChannelError > {
2173
+ pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < ( HTLCSource , u64 ) , ChannelError > {
2167
2174
if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2168
2175
return Err ( ChannelError :: Close ( "Got fulfill HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
2169
2176
}
@@ -2172,7 +2179,7 @@ impl<Signer: Sign> Channel<Signer> {
2172
2179
}
2173
2180
2174
2181
let payment_hash = PaymentHash ( Sha256 :: hash ( & msg. payment_preimage . 0 [ ..] ) . into_inner ( ) ) ;
2175
- self . mark_outbound_htlc_removed ( msg. htlc_id , Some ( payment_hash) , None ) . map ( |source| source. clone ( ) )
2182
+ self . mark_outbound_htlc_removed ( msg. htlc_id , Some ( payment_hash) , None ) . map ( |htlc| ( htlc . source . clone ( ) , htlc . amount_msat ) )
2176
2183
}
2177
2184
2178
2185
pub fn update_fail_htlc ( & mut self , msg : & msgs:: UpdateFailHTLC , fail_reason : HTLCFailReason ) -> Result < ( ) , ChannelError > {
@@ -2467,7 +2474,7 @@ impl<Signer: Sign> Channel<Signer> {
2467
2474
& HTLCUpdateAwaitingACK :: ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
2468
2475
let ( update_fulfill_msg_option, additional_monitor_update_opt) = self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) ;
2469
2476
update_fulfill_htlcs. push ( update_fulfill_msg_option. unwrap ( ) ) ;
2470
- if let Some ( mut additional_monitor_update) = additional_monitor_update_opt {
2477
+ if let Some ( ( mut additional_monitor_update, _ ) ) = additional_monitor_update_opt {
2471
2478
monitor_update. updates . append ( & mut additional_monitor_update. updates ) ;
2472
2479
}
2473
2480
} ,
0 commit comments