@@ -1232,13 +1232,7 @@ impl<Signer: Sign> Channel<Signer> {
1232
1232
make_funding_redeemscript ( & self . get_holder_pubkeys ( ) . funding_pubkey , self . counterparty_funding_pubkey ( ) )
1233
1233
}
1234
1234
1235
- /// Per HTLC, only one get_update_fail_htlc or get_update_fulfill_htlc call may be made.
1236
- /// In such cases we debug_assert!(false) and return a ChannelError::Ignore. Thus, will always
1237
- /// return Ok(_) if debug assertions are turned on or preconditions are met.
1238
- ///
1239
- /// Note that it is still possible to hit these assertions in case we find a preimage on-chain
1240
- /// but then have a reorg which settles on an HTLC-failure on chain.
1241
- fn get_update_fulfill_htlc < L : Deref > ( & mut self , htlc_id_arg : u64 , payment_preimage_arg : PaymentPreimage , logger : & L ) -> Result < ( Option < msgs:: UpdateFulfillHTLC > , Option < ChannelMonitorUpdate > ) , ChannelError > where L :: Target : Logger {
1235
+ 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 {
1242
1236
// Either ChannelFunded got set (which means it won't be unset) or there is no way any
1243
1237
// caller thought we could have something claimed (cause we wouldn't have accepted in an
1244
1238
// incoming HTLC anyway). If we got to ShutdownComplete, callers aren't allowed to call us,
@@ -1266,7 +1260,7 @@ impl<Signer: Sign> Channel<Signer> {
1266
1260
log_warn ! ( logger, "Have preimage and want to fulfill HTLC with payment hash {} we already failed against channel {}" , log_bytes!( htlc. payment_hash. 0 ) , log_bytes!( self . channel_id( ) ) ) ;
1267
1261
debug_assert ! ( false , "Tried to fulfill an HTLC that was already failed" ) ;
1268
1262
}
1269
- return Ok ( ( None , None ) ) ;
1263
+ return ( None , None ) ;
1270
1264
} ,
1271
1265
_ => {
1272
1266
debug_assert ! ( false , "Have an inbound HTLC we tried to claim before it was fully committed to" ) ;
@@ -1282,7 +1276,7 @@ impl<Signer: Sign> Channel<Signer> {
1282
1276
// If we failed to find an HTLC to fulfill, make sure it was previously fulfilled and
1283
1277
// this is simply a duplicate claim, not previously failed and we lost funds.
1284
1278
debug_assert ! ( self . historical_inbound_htlc_fulfills. contains( & htlc_id_arg) ) ;
1285
- return Ok ( ( None , None ) ) ;
1279
+ return ( None , None ) ;
1286
1280
}
1287
1281
1288
1282
// Now update local state:
@@ -1306,7 +1300,7 @@ impl<Signer: Sign> Channel<Signer> {
1306
1300
self . latest_monitor_update_id -= 1 ;
1307
1301
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
1308
1302
debug_assert ! ( self . historical_inbound_htlc_fulfills. contains( & htlc_id_arg) ) ;
1309
- return Ok ( ( None , None ) ) ;
1303
+ return ( None , None ) ;
1310
1304
}
1311
1305
} ,
1312
1306
& HTLCUpdateAwaitingACK :: FailHTLC { htlc_id, .. } => {
@@ -1315,7 +1309,7 @@ impl<Signer: Sign> Channel<Signer> {
1315
1309
// TODO: We may actually be able to switch to a fulfill here, though its
1316
1310
// rare enough it may not be worth the complexity burden.
1317
1311
debug_assert ! ( false , "Tried to fulfill an HTLC that was already failed" ) ;
1318
- return Ok ( ( None , Some ( monitor_update) ) ) ;
1312
+ return ( None , Some ( monitor_update) ) ;
1319
1313
}
1320
1314
} ,
1321
1315
_ => { }
@@ -1327,7 +1321,7 @@ impl<Signer: Sign> Channel<Signer> {
1327
1321
} ) ;
1328
1322
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
1329
1323
self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
1330
- return Ok ( ( None , Some ( monitor_update) ) ) ;
1324
+ return ( None , Some ( monitor_update) ) ;
1331
1325
}
1332
1326
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
1333
1327
self . historical_inbound_htlc_fulfills . insert ( htlc_id_arg) ;
@@ -1337,21 +1331,21 @@ impl<Signer: Sign> Channel<Signer> {
1337
1331
if let InboundHTLCState :: Committed = htlc. state {
1338
1332
} else {
1339
1333
debug_assert ! ( false , "Have an inbound HTLC we tried to claim before it was fully committed to" ) ;
1340
- return Ok ( ( None , Some ( monitor_update) ) ) ;
1334
+ return ( None , Some ( monitor_update) ) ;
1341
1335
}
1342
1336
log_trace ! ( logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!" , log_bytes!( htlc. payment_hash. 0 ) , log_bytes!( self . channel_id) ) ;
1343
1337
htlc. state = InboundHTLCState :: LocalRemoved ( InboundHTLCRemovalReason :: Fulfill ( payment_preimage_arg. clone ( ) ) ) ;
1344
1338
}
1345
1339
1346
- Ok ( ( Some ( msgs:: UpdateFulfillHTLC {
1340
+ ( Some ( msgs:: UpdateFulfillHTLC {
1347
1341
channel_id : self . channel_id ( ) ,
1348
1342
htlc_id : htlc_id_arg,
1349
1343
payment_preimage : payment_preimage_arg,
1350
- } ) , Some ( monitor_update) ) )
1344
+ } ) , Some ( monitor_update) )
1351
1345
}
1352
1346
1353
1347
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 > where L :: Target : Logger {
1354
- match self . get_update_fulfill_htlc ( htlc_id, payment_preimage, logger) ? {
1348
+ match self . get_update_fulfill_htlc ( htlc_id, payment_preimage, logger) {
1355
1349
( Some ( update_fulfill_htlc) , Some ( mut monitor_update) ) => {
1356
1350
let ( commitment, mut additional_update) = self . send_commitment_no_status_check ( logger) ?;
1357
1351
// send_commitment_no_status_check may bump latest_monitor_id but we want them to be
@@ -1360,21 +1354,22 @@ impl<Signer: Sign> Channel<Signer> {
1360
1354
monitor_update. updates . append ( & mut additional_update. updates ) ;
1361
1355
Ok ( ( Some ( ( update_fulfill_htlc, commitment) ) , Some ( monitor_update) ) )
1362
1356
} ,
1363
- ( Some ( update_fulfill_htlc) , None ) => {
1364
- let ( commitment, monitor_update) = self . send_commitment_no_status_check ( logger) ?;
1365
- Ok ( ( Some ( ( update_fulfill_htlc, commitment) ) , Some ( monitor_update) ) )
1357
+ ( Some ( _) , None ) => {
1358
+ // If we generated a claim message, we absolutely should have generated a
1359
+ // ChannelMonitorUpdate, otherwise we are going to probably lose funds.
1360
+ unreachable ! ( ) ;
1366
1361
} ,
1367
1362
( None , Some ( monitor_update) ) => Ok ( ( None , Some ( monitor_update) ) ) ,
1368
1363
( None , None ) => Ok ( ( None , None ) )
1369
1364
}
1370
1365
}
1371
1366
1372
- /// Per HTLC, only one get_update_fail_htlc or get_update_fulfill_htlc call may be made.
1373
- /// In such cases we debug_assert!(false) and return a ChannelError::Ignore. Thus, will always
1374
- /// return Ok(_) if debug assertions are turned on or preconditions are met.
1375
- ///
1376
- /// Note that it is still possible to hit these assertions in case we find a preimage on-chain
1377
- /// but then have a reorg which settles on an HTLC-failure on chain .
1367
+ /// We can only have one resolution per HTLC. In some cases around reconnect, we may fulfill
1368
+ /// and HTLC more than once or fulfill once and then attempt to fail after reconnect. We
1369
+ /// cannot, however, fail more than once as we wait for an upstream failure to be irrevocably
1370
+ /// committed before we fail backwards.
1371
+ /// If we do fail twice, we debug_assert!(false) and return a ChannelError::Ignore. Thus, will
1372
+ /// always return Ok(_) if debug assertions are turned on or preconditions are met .
1378
1373
pub fn get_update_fail_htlc < L : Deref > ( & mut self , htlc_id_arg : u64 , err_packet : msgs:: OnionErrorPacket , logger : & L ) -> Result < Option < msgs:: UpdateFailHTLC > , ChannelError > where L :: Target : Logger {
1379
1374
if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
1380
1375
panic ! ( "Was asked to fail an HTLC when channel was not in an operational state" ) ;
@@ -2468,19 +2463,10 @@ impl<Signer: Sign> Channel<Signer> {
2468
2463
}
2469
2464
} ,
2470
2465
& HTLCUpdateAwaitingACK :: ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
2471
- match self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) {
2472
- Ok ( ( update_fulfill_msg_option, additional_monitor_update_opt) ) => {
2473
- update_fulfill_htlcs. push ( update_fulfill_msg_option. unwrap ( ) ) ;
2474
- if let Some ( mut additional_monitor_update) = additional_monitor_update_opt {
2475
- monitor_update. updates . append ( & mut additional_monitor_update. updates ) ;
2476
- }
2477
- } ,
2478
- Err ( e) => {
2479
- if let ChannelError :: Ignore ( _) = e { }
2480
- else {
2481
- panic ! ( "Got a non-IgnoreError action trying to fulfill holding cell HTLC" ) ;
2482
- }
2483
- }
2466
+ let ( update_fulfill_msg_option, additional_monitor_update_opt) = self . get_update_fulfill_htlc ( htlc_id, * payment_preimage, logger) ;
2467
+ update_fulfill_htlcs. push ( update_fulfill_msg_option. unwrap ( ) ) ;
2468
+ if let Some ( mut additional_monitor_update) = additional_monitor_update_opt {
2469
+ monitor_update. updates . append ( & mut additional_monitor_update. updates ) ;
2484
2470
}
2485
2471
} ,
2486
2472
& HTLCUpdateAwaitingACK :: FailHTLC { htlc_id, ref err_packet } => {
0 commit comments