@@ -1140,6 +1140,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1140
1140
/// Per HTLC, only one get_update_fail_htlc or get_update_fulfill_htlc call may be made.
1141
1141
/// In such cases we debug_assert!(false) and return an IgnoreError. Thus, will always return
1142
1142
/// Ok(_) if debug assertions are turned on and preconditions are met.
1143
+ ///
1144
+ /// Note that it is still possible to hit these assertions in case we find a preimage on-chain
1145
+ /// but then have a reorg which settles on an HTLC-failure on chain.
1143
1146
fn get_update_fulfill_htlc ( & mut self , htlc_id_arg : u64 , payment_preimage_arg : PaymentPreimage ) -> Result < ( Option < msgs:: UpdateFulfillHTLC > , Option < ChannelMonitorUpdate > ) , ChannelError > {
1144
1147
// Either ChannelFunded got set (which means it won't be unset) or there is no way any
1145
1148
// caller thought we could have something claimed (cause we wouldn't have accepted in an
@@ -1167,6 +1170,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1167
1170
} else {
1168
1171
log_warn ! ( self , "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( ) ) ) ;
1169
1172
}
1173
+ debug_assert ! ( false , "Tried to fulfill an HTLC that was already fail/fulfilled" ) ;
1170
1174
return Ok ( ( None , None ) ) ;
1171
1175
} ,
1172
1176
_ => {
@@ -1202,6 +1206,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1202
1206
if htlc_id_arg == htlc_id {
1203
1207
// Make sure we don't leave latest_monitor_update_id incremented here:
1204
1208
self . latest_monitor_update_id -= 1 ;
1209
+ debug_assert ! ( false , "Tried to fulfill an HTLC that was already fulfilled" ) ;
1205
1210
return Ok ( ( None , None ) ) ;
1206
1211
}
1207
1212
} ,
@@ -1210,6 +1215,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1210
1215
log_warn ! ( self , "Have preimage and want to fulfill HTLC with pending failure against channel {}" , log_bytes!( self . channel_id( ) ) ) ;
1211
1216
// TODO: We may actually be able to switch to a fulfill here, though its
1212
1217
// rare enough it may not be worth the complexity burden.
1218
+ debug_assert ! ( false , "Tried to fulfill an HTLC that was already failed" ) ;
1213
1219
return Ok ( ( None , Some ( monitor_update) ) ) ;
1214
1220
}
1215
1221
} ,
@@ -1263,6 +1269,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1263
1269
/// Per HTLC, only one get_update_fail_htlc or get_update_fulfill_htlc call may be made.
1264
1270
/// In such cases we debug_assert!(false) and return an IgnoreError. Thus, will always return
1265
1271
/// Ok(_) if debug assertions are turned on and preconditions are met.
1272
+ ///
1273
+ /// Note that it is still possible to hit these assertions in case we find a preimage on-chain
1274
+ /// but then have a reorg which settles on an HTLC-failure on chain.
1266
1275
pub fn get_update_fail_htlc ( & mut self , htlc_id_arg : u64 , err_packet : msgs:: OnionErrorPacket ) -> Result < Option < msgs:: UpdateFailHTLC > , ChannelError > {
1267
1276
if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
1268
1277
panic ! ( "Was asked to fail an HTLC when channel was not in an operational state" ) ;
@@ -1279,6 +1288,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1279
1288
match htlc. state {
1280
1289
InboundHTLCState :: Committed => { } ,
1281
1290
InboundHTLCState :: LocalRemoved ( _) => {
1291
+ debug_assert ! ( false , "Tried to fail an HTLC that was already fail/fulfilled" ) ;
1282
1292
return Ok ( None ) ;
1283
1293
} ,
1284
1294
_ => {
@@ -1299,11 +1309,13 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1299
1309
match pending_update {
1300
1310
& HTLCUpdateAwaitingACK :: ClaimHTLC { htlc_id, .. } => {
1301
1311
if htlc_id_arg == htlc_id {
1312
+ debug_assert ! ( false , "Tried to fail an HTLC that was already fulfilled" ) ;
1302
1313
return Err ( ChannelError :: Ignore ( "Unable to find a pending HTLC which matched the given HTLC ID" ) ) ;
1303
1314
}
1304
1315
} ,
1305
1316
& HTLCUpdateAwaitingACK :: FailHTLC { htlc_id, .. } => {
1306
1317
if htlc_id_arg == htlc_id {
1318
+ debug_assert ! ( false , "Tried to fail an HTLC that was already failed" ) ;
1307
1319
return Err ( ChannelError :: Ignore ( "Unable to find a pending HTLC which matched the given HTLC ID" ) ) ;
1308
1320
}
1309
1321
} ,
0 commit comments