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