Skip to content

Commit e4cc7db

Browse files
committed
Rename HTLC input_idx fields to commitment_tx_output_idx
Several fields used in tracking on-chain HTLC outputs were named `input_idx` despite referring to the output index in the commitment transaction. Here they are all renamed `commitment_tx_output_idx` for clarity.
1 parent 75ca50f commit e4cc7db

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ enum OnchainEvent {
360360
onchain_value_satoshis: Option<u64>,
361361
/// None in the second case, above, ie when there is no relevant output in the commitment
362362
/// transaction which appeared on chain.
363-
input_idx: Option<u32>,
363+
commitment_tx_output_idx: Option<u32>,
364364
},
365365
MaturingOutput {
366366
descriptor: SpendableOutputDescriptor,
@@ -381,7 +381,7 @@ enum OnchainEvent {
381381
/// * a revoked-state HTLC transaction was broadcasted, which was claimed by the revocation
382382
/// signature.
383383
HTLCSpendConfirmation {
384-
input_idx: u32,
384+
commitment_tx_output_idx: u32,
385385
/// If the claim was made by either party with a preimage, this is filled in
386386
preimage: Option<PaymentPreimage>,
387387
/// If the claim was made by us on an inbound HTLC against a local commitment transaction,
@@ -425,7 +425,7 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
425425
(0, source, required),
426426
(1, onchain_value_satoshis, option),
427427
(2, payment_hash, required),
428-
(3, input_idx, option),
428+
(3, commitment_tx_output_idx, option),
429429
},
430430
(1, MaturingOutput) => {
431431
(0, descriptor, required),
@@ -434,7 +434,7 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
434434
(0, on_local_output_csv, option),
435435
},
436436
(5, HTLCSpendConfirmation) => {
437-
(0, input_idx, required),
437+
(0, commitment_tx_output_idx, required),
438438
(2, preimage, option),
439439
(4, on_to_local_output_csv, option),
440440
},
@@ -568,13 +568,13 @@ pub enum Balance {
568568
/// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY.
569569
#[derive(PartialEq)]
570570
struct IrrevocablyResolvedHTLC {
571-
input_idx: u32,
571+
commitment_tx_output_idx: u32,
572572
/// Only set if the HTLC claim was ours using a payment preimage
573573
payment_preimage: Option<PaymentPreimage>,
574574
}
575575

576576
impl_writeable_tlv_based!(IrrevocablyResolvedHTLC, {
577-
(0, input_idx, required),
577+
(0, commitment_tx_output_idx, required),
578578
(2, payment_preimage, option),
579579
});
580580

@@ -1391,18 +1391,18 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
13911391
macro_rules! walk_htlcs {
13921392
($holder_commitment: expr, $htlc_iter: expr) => {
13931393
for htlc in $htlc_iter {
1394-
if let Some(htlc_input_idx) = htlc.transaction_output_index {
1394+
if let Some(htlc_commitment_tx_output_idx) = htlc.transaction_output_index {
13951395
if let Some(conf_thresh) = us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
13961396
if let OnchainEvent::MaturingOutput { descriptor: SpendableOutputDescriptor::DelayedPaymentOutput(descriptor) } = &event.event {
1397-
if descriptor.outpoint.index as u32 == htlc_input_idx { Some(event.confirmation_threshold()) } else { None }
1397+
if descriptor.outpoint.index as u32 == htlc_commitment_tx_output_idx { Some(event.confirmation_threshold()) } else { None }
13981398
} else { None }
13991399
}) {
14001400
debug_assert!($holder_commitment);
14011401
res.push(Balance::ClaimableAwaitingConfirmations {
14021402
claimable_amount_satoshis: htlc.amount_msat / 1000,
14031403
confirmation_height: conf_thresh,
14041404
});
1405-
} else if us.htlcs_resolved_on_chain.iter().any(|v| v.input_idx == htlc_input_idx) {
1405+
} else if us.htlcs_resolved_on_chain.iter().any(|v| v.commitment_tx_output_idx == htlc_commitment_tx_output_idx) {
14061406
// Funding transaction spends should be fully confirmed by the time any
14071407
// HTLC transactions are resolved, unless we're talking about a holder
14081408
// commitment tx, whose resolution is delayed until the CSV timeout is
@@ -1414,8 +1414,9 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
14141414
// indicating we have spent this HTLC with a timeout, claiming it back
14151415
// and awaiting confirmations on it.
14161416
let htlc_update_pending = us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
1417-
if let OnchainEvent::HTLCUpdate { input_idx: Some(input_idx), .. } = event.event {
1418-
if input_idx == htlc_input_idx { Some(event.confirmation_threshold()) } else { None }
1417+
if let OnchainEvent::HTLCUpdate { commitment_tx_output_idx: Some(commitment_tx_output_idx), .. } = event.event {
1418+
if commitment_tx_output_idx == htlc_commitment_tx_output_idx {
1419+
Some(event.confirmation_threshold()) } else { None }
14191420
} else { None }
14201421
});
14211422
if let Some(conf_thresh) = htlc_update_pending {
@@ -1436,8 +1437,8 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
14361437
// preimage, we lost funds to our counterparty! We will then continue
14371438
// to show it as ContentiousClaimable until ANTI_REORG_DELAY.
14381439
let htlc_spend_pending = us.onchain_events_awaiting_threshold_conf.iter().find_map(|event| {
1439-
if let OnchainEvent::HTLCSpendConfirmation { input_idx, preimage, .. } = event.event {
1440-
if input_idx == htlc_input_idx {
1440+
if let OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } = event.event {
1441+
if commitment_tx_output_idx == htlc_commitment_tx_output_idx {
14411442
Some((event.confirmation_threshold(), preimage.is_some()))
14421443
} else { None }
14431444
} else { None }
@@ -1546,7 +1547,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
15461547
macro_rules! walk_htlcs {
15471548
($holder_commitment: expr, $htlc_iter: expr) => {
15481549
for (htlc, source) in $htlc_iter {
1549-
if us.htlcs_resolved_on_chain.iter().any(|v| Some(v.input_idx) == htlc.transaction_output_index) {
1550+
if us.htlcs_resolved_on_chain.iter().any(|v| Some(v.commitment_tx_output_idx) == htlc.transaction_output_index) {
15501551
// We should assert that funding_spend_confirmed is_some() here, but we
15511552
// have some unit tests which violate HTLC transaction CSVs entirely and
15521553
// would fail.
@@ -1557,17 +1558,17 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
15571558
// indicating we have spent this HTLC with a timeout, claiming it back
15581559
// and awaiting confirmations on it.
15591560
let htlc_update_confd = us.onchain_events_awaiting_threshold_conf.iter().any(|event| {
1560-
if let OnchainEvent::HTLCUpdate { input_idx: Some(input_idx), .. } = event.event {
1561+
if let OnchainEvent::HTLCUpdate { commitment_tx_output_idx: Some(commitment_tx_output_idx), .. } = event.event {
15611562
// If the HTLC was timed out, we wait for ANTI_REORG_DELAY blocks
15621563
// before considering it "no longer pending" - this matches when we
15631564
// provide the ChannelManager an HTLC failure event.
1564-
Some(input_idx) == htlc.transaction_output_index &&
1565+
Some(commitment_tx_output_idx) == htlc.transaction_output_index &&
15651566
us.best_block.height() >= event.height + ANTI_REORG_DELAY - 1
1566-
} else if let OnchainEvent::HTLCSpendConfirmation { input_idx, .. } = event.event {
1567+
} else if let OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, .. } = event.event {
15671568
// If the HTLC was fulfilled with a preimage, we consider the HTLC
15681569
// immediately non-pending, matching when we provide ChannelManager
15691570
// the preimage.
1570-
Some(input_idx) == htlc.transaction_output_index
1571+
Some(commitment_tx_output_idx) == htlc.transaction_output_index
15711572
} else { false }
15721573
});
15731574
if !htlc_update_confd {
@@ -1689,7 +1690,7 @@ macro_rules! fail_unbroadcast_htlcs {
16891690
source: (**source).clone(),
16901691
payment_hash: htlc.payment_hash.clone(),
16911692
onchain_value_satoshis: Some(htlc.amount_msat / 1000),
1692-
input_idx: None,
1693+
commitment_tx_output_idx: None,
16931694
},
16941695
};
16951696
log_trace!($logger, "Failing HTLC with payment_hash {} from {} counterparty commitment tx due to broadcast of {} commitment transaction, waiting for confirmation (at height {})",
@@ -2522,7 +2523,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
25222523
// Produce actionable events from on-chain events having reached their threshold.
25232524
for entry in onchain_events_reaching_threshold_conf.drain(..) {
25242525
match entry.event {
2525-
OnchainEvent::HTLCUpdate { ref source, payment_hash, onchain_value_satoshis, input_idx } => {
2526+
OnchainEvent::HTLCUpdate { ref source, payment_hash, onchain_value_satoshis, commitment_tx_output_idx } => {
25262527
// Check for duplicate HTLC resolutions.
25272528
#[cfg(debug_assertions)]
25282529
{
@@ -2546,8 +2547,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
25462547
source: source.clone(),
25472548
onchain_value_satoshis,
25482549
}));
2549-
if let Some(idx) = input_idx {
2550-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { input_idx: idx, payment_preimage: None });
2550+
if let Some(idx) = commitment_tx_output_idx {
2551+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx: idx, payment_preimage: None });
25512552
}
25522553
},
25532554
OnchainEvent::MaturingOutput { descriptor } => {
@@ -2556,8 +2557,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
25562557
outputs: vec![descriptor]
25572558
});
25582559
},
2559-
OnchainEvent::HTLCSpendConfirmation { input_idx, preimage, .. } => {
2560-
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { input_idx, payment_preimage: preimage });
2560+
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
2561+
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { commitment_tx_output_idx, payment_preimage: preimage });
25612562
},
25622563
OnchainEvent::FundingSpendConfirmation { .. } => {
25632564
self.funding_spend_confirmed = Some(entry.txid);
@@ -2826,7 +2827,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
28262827
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
28272828
txid: tx.txid(), height,
28282829
event: OnchainEvent::HTLCSpendConfirmation {
2829-
input_idx: input.previous_output.vout,
2830+
commitment_tx_output_idx: input.previous_output.vout,
28302831
preimage: if accepted_preimage_claim || offered_preimage_claim {
28312832
Some(payment_preimage) } else { None },
28322833
// If this is a payment to us (!outbound_htlc, above),
@@ -2877,7 +2878,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
28772878
txid: tx.txid(),
28782879
height,
28792880
event: OnchainEvent::HTLCSpendConfirmation {
2880-
input_idx: input.previous_output.vout,
2881+
commitment_tx_output_idx: input.previous_output.vout,
28812882
preimage: Some(payment_preimage),
28822883
on_to_local_output_csv: None,
28832884
},
@@ -2898,7 +2899,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
28982899
txid: tx.txid(),
28992900
height,
29002901
event: OnchainEvent::HTLCSpendConfirmation {
2901-
input_idx: input.previous_output.vout,
2902+
commitment_tx_output_idx: input.previous_output.vout,
29022903
preimage: Some(payment_preimage),
29032904
on_to_local_output_csv: None,
29042905
},
@@ -2926,7 +2927,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29262927
event: OnchainEvent::HTLCUpdate {
29272928
source, payment_hash,
29282929
onchain_value_satoshis: Some(amount_msat / 1000),
2929-
input_idx: Some(input.previous_output.vout),
2930+
commitment_tx_output_idx: Some(input.previous_output.vout),
29302931
},
29312932
};
29322933
log_info!(logger, "Failing HTLC with payment_hash {} timeout by a spend tx, waiting for confirmation (at height {})", log_bytes!(payment_hash.0), entry.confirmation_threshold());

0 commit comments

Comments
 (0)