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