Skip to content

Commit ef1ca9b

Browse files
committed
f revert "Track HTLC on-chain value for HTLC-Success/-Timeout txn for balance"
1 parent 744ad57 commit ef1ca9b

File tree

1 file changed

+9
-38
lines changed

1 file changed

+9
-38
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,6 @@ enum OnchainEvent {
361361
HTLCUpdate {
362362
source: HTLCSource,
363363
payment_hash: PaymentHash,
364-
/// If the HTLC was claimed by an HTLC-Timeout transaction (ie when the HTLC exists on
365-
/// chain), this is the amount of the output of that transaction (ie `htlc_value_satoshis`
366-
/// minus fees).
367-
onchain_value_satoshis: Option<u64>,
368364
htlc_value_satoshis: Option<u64>,
369365
/// None in the second case, above, ie when there is no relevant output in the commitment
370366
/// transaction which appeared on chain.
@@ -396,10 +392,6 @@ enum OnchainEvent {
396392
/// signature.
397393
HTLCSpendConfirmation {
398394
commitment_tx_output_idx: u32,
399-
/// If the HTLC was claimed by an HTLC-Success or HTLC-Timeout transaction (ie when the
400-
/// HTLC was not claimed via the revocation path), this is the amount of the output of that
401-
/// transaction (ie `htlc_value_satoshis` minus fees).
402-
onchain_value_satoshis: Option<u64>,
403395
/// If the claim was made by either party with a preimage, this is filled in
404396
preimage: Option<PaymentPreimage>,
405397
/// If the claim was made by us on an inbound HTLC against a local commitment transaction,
@@ -447,7 +439,6 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
447439
(1, htlc_value_satoshis, option),
448440
(2, payment_hash, required),
449441
(3, commitment_tx_output_idx, option),
450-
(5, onchain_value_satoshis, option),
451442
},
452443
(1, MaturingOutput) => {
453444
(0, descriptor, required),
@@ -458,7 +449,6 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
458449
},
459450
(5, HTLCSpendConfirmation) => {
460451
(0, commitment_tx_output_idx, required),
461-
(1, onchain_value_satoshis, option),
462452
(2, preimage, option),
463453
(4, on_to_local_output_csv, option),
464454
},
@@ -1744,7 +1734,6 @@ macro_rules! fail_unbroadcast_htlcs {
17441734
source: (**source).clone(),
17451735
payment_hash: htlc.payment_hash.clone(),
17461736
htlc_value_satoshis: Some(htlc.amount_msat / 1000),
1747-
onchain_value_satoshis: None,
17481737
commitment_tx_output_idx: None,
17491738
},
17501739
};
@@ -2677,7 +2666,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26772666
// Produce actionable events from on-chain events having reached their threshold.
26782667
for entry in onchain_events_reaching_threshold_conf.drain(..) {
26792668
match entry.event {
2680-
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, commitment_tx_output_idx, .. } => {
2669+
OnchainEvent::HTLCUpdate { ref source, payment_hash, htlc_value_satoshis, commitment_tx_output_idx } => {
26812670
// Check for duplicate HTLC resolutions.
26822671
#[cfg(debug_assertions)]
26832672
{
@@ -2914,16 +2903,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29142903
let accepted_timeout_claim = witness_items == 3 && htlctype == Some(HTLCType::AcceptedHTLC) && !revocation_sig_claim;
29152904
let offered_preimage_claim = witness_items == 3 && htlctype == Some(HTLCType::OfferedHTLC) &&
29162905
!revocation_sig_claim && input.witness.second_to_last().unwrap().len() == 32;
2917-
let offered_timeout_claim = witness_items == 5 && htlctype == Some(HTLCType::OfferedHTLC);
29182906

2919-
let claim_via_htlc_tx = accepted_preimage_claim || offered_timeout_claim;
2920-
if claim_via_htlc_tx {
2921-
// If the claim was via an HTLC-Timeout/HTLC-Success transaction, it must be a
2922-
// 1-in-1-out transaction as its pre-signed.
2923-
// Note that if anchors are available these both may vary.
2924-
debug_assert_eq!(tx.input.len(), 1);
2925-
debug_assert_eq!(tx.output.len(), 1);
2926-
}
2907+
#[cfg(not(fuzzing))]
2908+
let offered_timeout_claim = witness_items == 5 && htlctype == Some(HTLCType::OfferedHTLC);
29272909

29282910
let mut payment_preimage = PaymentPreimage([0; 32]);
29292911
if accepted_preimage_claim {
@@ -2963,14 +2945,13 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29632945
}
29642946

29652947
macro_rules! check_htlc_valid_counterparty {
2966-
($counterparty_txid: expr, $htlc_output: expr, $htlc_value_sats: expr) => {
2948+
($counterparty_txid: expr, $htlc_output: expr) => {
29672949
if let Some(txid) = $counterparty_txid {
29682950
for &(ref pending_htlc, ref pending_source) in self.counterparty_claimable_outpoints.get(&txid).unwrap() {
29692951
if pending_htlc.payment_hash == $htlc_output.payment_hash && pending_htlc.amount_msat == $htlc_output.amount_msat {
29702952
if let &Some(ref source) = pending_source {
29712953
log_claim!("revoked counterparty commitment tx", false, pending_htlc, true);
2972-
payment_data = Some(((**source).clone(), $htlc_output.payment_hash,
2973-
pending_htlc.amount_msat, $htlc_value_sats));
2954+
payment_data = Some(((**source).clone(), $htlc_output.payment_hash, $htlc_output.amount_msat));
29742955
break;
29752956
}
29762957
}
@@ -2983,24 +2964,18 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29832964
($htlcs: expr, $tx_info: expr, $holder_tx: expr) => {
29842965
for (ref htlc_output, source_option) in $htlcs {
29852966
if Some(input.previous_output.vout) == htlc_output.transaction_output_index {
2986-
let htlc_value_sats = if claim_via_htlc_tx {
2987-
tx.output.iter().map(|txout| txout.value).sum::<u64>()
2988-
} else { htlc_output.amount_msat / 1000 };
29892967
if let Some(ref source) = source_option {
29902968
log_claim!($tx_info, $holder_tx, htlc_output, true);
29912969
// We have a resolution of an HTLC either from one of our latest
29922970
// holder commitment transactions or an unrevoked counterparty commitment
29932971
// transaction. This implies we either learned a preimage, the HTLC
29942972
// has timed out, or we screwed up. In any case, we should now
29952973
// resolve the source HTLC with the original sender.
2996-
payment_data = Some(((*source).clone(), htlc_output.payment_hash,
2997-
htlc_output.amount_msat, htlc_value_sats));
2974+
payment_data = Some(((*source).clone(), htlc_output.payment_hash, htlc_output.amount_msat));
29982975
} else if !$holder_tx {
2999-
check_htlc_valid_counterparty!(self.current_counterparty_commitment_txid,
3000-
htlc_output, htlc_value_sats);
2976+
check_htlc_valid_counterparty!(self.current_counterparty_commitment_txid, htlc_output);
30012977
if payment_data.is_none() {
3002-
check_htlc_valid_counterparty!(self.prev_counterparty_commitment_txid,
3003-
htlc_output, htlc_value_sats);
2978+
check_htlc_valid_counterparty!(self.prev_counterparty_commitment_txid, htlc_output);
30042979
}
30052980
}
30062981
if payment_data.is_none() {
@@ -3011,7 +2986,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30112986
txid: tx.txid(), height, transaction: Some(tx.clone()),
30122987
event: OnchainEvent::HTLCSpendConfirmation {
30132988
commitment_tx_output_idx: input.previous_output.vout,
3014-
onchain_value_satoshis: Some(htlc_value_sats),
30152989
preimage: if accepted_preimage_claim || offered_preimage_claim {
30162990
Some(payment_preimage) } else { None },
30172991
// If this is a payment to us (!outbound_htlc, above),
@@ -3054,7 +3028,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30543028

30553029
// Check that scan_commitment, above, decided there is some source worth relaying an
30563030
// HTLC resolution backwards to and figure out whether we learned a preimage from it.
3057-
if let Some((source, payment_hash, amount_msat, onchain_amount_sat)) = payment_data {
3031+
if let Some((source, payment_hash, amount_msat)) = payment_data {
30583032
if accepted_preimage_claim {
30593033
if !self.pending_monitor_events.iter().any(
30603034
|update| if let &MonitorEvent::HTLCEvent(ref upd) = update { upd.source == source } else { false }) {
@@ -3066,7 +3040,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30663040
commitment_tx_output_idx: input.previous_output.vout,
30673041
preimage: Some(payment_preimage),
30683042
on_to_local_output_csv: None,
3069-
onchain_value_satoshis: Some(onchain_amount_sat),
30703043
},
30713044
});
30723045
self.pending_monitor_events.push(MonitorEvent::HTLCEvent(HTLCUpdate {
@@ -3089,7 +3062,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30893062
commitment_tx_output_idx: input.previous_output.vout,
30903063
preimage: Some(payment_preimage),
30913064
on_to_local_output_csv: None,
3092-
onchain_value_satoshis: Some(onchain_amount_sat),
30933065
},
30943066
});
30953067
self.pending_monitor_events.push(MonitorEvent::HTLCEvent(HTLCUpdate {
@@ -3117,7 +3089,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
31173089
source, payment_hash,
31183090
htlc_value_satoshis: Some(amount_msat / 1000),
31193091
commitment_tx_output_idx: Some(input.previous_output.vout),
3120-
onchain_value_satoshis: Some(onchain_amount_sat),
31213092
},
31223093
};
31233094
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)