@@ -1361,17 +1361,15 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1361
1361
let us = self . inner . lock ( ) . unwrap ( ) ;
1362
1362
1363
1363
let mut confirmed_txid = us. funding_spend_confirmed ;
1364
+ let mut pending_commitment_tx_conf_thresh = None ;
1364
1365
if let Some ( ( txid, conf_thresh) ) = us. onchain_events_awaiting_threshold_conf . iter ( ) . find_map ( |event| {
1365
1366
if let OnchainEvent :: FundingSpendConfirmation { txid, .. } = event. event {
1366
1367
Some ( ( txid, event. confirmation_threshold ( ) ) )
1367
1368
} else { None }
1368
1369
} ) {
1369
1370
debug_assert ! ( us. funding_spend_confirmed. is_none( ) , "We have a pending funding spend awaiting confirmation, we can't have confirmed it already!" ) ;
1370
1371
confirmed_txid = Some ( txid) ;
1371
- res. push ( ClaimableBalance :: ClaimableAwaitingConfirmations {
1372
- claimable_amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
1373
- confirmation_height : conf_thresh,
1374
- } ) ;
1372
+ pending_commitment_tx_conf_thresh = Some ( conf_thresh) ;
1375
1373
}
1376
1374
1377
1375
macro_rules! walk_htlcs {
@@ -1410,19 +1408,65 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
1410
1408
}
1411
1409
1412
1410
if let Some ( txid) = confirmed_txid {
1411
+ let mut found_commitment_tx = false ;
1413
1412
if Some ( txid) == us. current_counterparty_commitment_txid || Some ( txid) == us. prev_counterparty_commitment_txid {
1414
1413
walk_htlcs ! ( false , us. counterparty_claimable_outpoints. get( & txid) . unwrap( ) . iter( ) . map( |( a, _) | a) ) ;
1414
+ if let Some ( conf_thresh) = pending_commitment_tx_conf_thresh {
1415
+ if let Some ( value) = us. onchain_events_awaiting_threshold_conf . iter ( ) . find_map ( |event| {
1416
+ if let OnchainEvent :: MaturingOutput {
1417
+ descriptor : SpendableOutputDescriptor :: StaticPaymentOutput ( descriptor)
1418
+ } = & event. event {
1419
+ Some ( descriptor. output . value )
1420
+ } else { None }
1421
+ } ) {
1422
+ res. push ( ClaimableBalance :: ClaimableAwaitingConfirmations {
1423
+ claimable_amount_satoshis : value,
1424
+ confirmation_height : conf_thresh,
1425
+ } ) ;
1426
+ } else {
1427
+ // If a counterparty commitment transaction is awaiting confirmation, we
1428
+ // should also have a StaticPaymentOutput MaturingOutput event awaiting
1429
+ // confirmation with the same height. Not having one implies something has
1430
+ // gone terribly wrong with our commitment txid tracking.
1431
+ debug_assert ! ( false ) ;
1432
+ }
1433
+ }
1434
+ found_commitment_tx = true ;
1415
1435
} else if txid == us. current_holder_commitment_tx . txid {
1416
1436
walk_htlcs ! ( true , us. current_holder_commitment_tx. htlc_outputs. iter( ) . map( |( a, _, _) | a) ) ;
1437
+ if let Some ( conf_thresh) = pending_commitment_tx_conf_thresh {
1438
+ res. push ( ClaimableBalance :: ClaimableAwaitingConfirmations {
1439
+ claimable_amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
1440
+ confirmation_height : conf_thresh,
1441
+ } ) ;
1442
+ }
1443
+ found_commitment_tx = true ;
1417
1444
} else if let Some ( prev_commitment) = & us. prev_holder_signed_commitment_tx {
1418
1445
if txid == prev_commitment. txid {
1419
1446
walk_htlcs ! ( true , prev_commitment. htlc_outputs. iter( ) . map( |( a, _, _) | a) ) ;
1447
+ if let Some ( conf_thresh) = pending_commitment_tx_conf_thresh {
1448
+ res. push ( ClaimableBalance :: ClaimableAwaitingConfirmations {
1449
+ claimable_amount_satoshis : prev_commitment. to_self_value_sat ,
1450
+ confirmation_height : conf_thresh,
1451
+ } ) ;
1452
+ }
1453
+ found_commitment_tx = true ;
1454
+ }
1455
+ }
1456
+ if !found_commitment_tx {
1457
+ if let Some ( conf_thresh) = pending_commitment_tx_conf_thresh {
1458
+ // We blindly assume this is a cooperative close transaction here, and that the
1459
+ // counterparty didn't misbehave. At worst we've over-estimated the amount we can
1460
+ // claim as we'll punish a misbehaving counterparty (as long as we didn't
1461
+ // misbehave).
1462
+ res. push ( ClaimableBalance :: ClaimableAwaitingConfirmations {
1463
+ claimable_amount_satoshis : us. current_holder_commitment_tx . to_self_value_sat ,
1464
+ confirmation_height : conf_thresh,
1465
+ } ) ;
1420
1466
}
1421
1467
}
1422
1468
// TODO: Add logic to provide claimable balances for counterparty broadcasting revoked
1423
1469
// outputs.
1424
- // Otherwise assume we closed with a cooperative close which only needs the
1425
- // `ClaimableAwaitingConfirmations` balance pushed first.
1426
1470
} else {
1427
1471
let mut claimable_inbound_htlc_value_sat = 0 ;
1428
1472
for ( htlc, _, _) in us. current_holder_commitment_tx . htlc_outputs . iter ( ) {
0 commit comments