Skip to content

Commit ccf2fa5

Browse files
HTLCUpdate::htlcvalue_satoshis -> msats
We need this level of precision when generating this event for off-chain claims. One test failed due to us previously overreporting a fee due to this lack of precision, fixed now.
1 parent 23413e4 commit ccf2fa5

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

lightning/src/chain/channelmonitor.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,16 @@ pub struct HTLCUpdate {
260260
pub(crate) payment_hash: PaymentHash,
261261
pub(crate) payment_preimage: Option<PaymentPreimage>,
262262
pub(crate) source: HTLCSource,
263-
pub(crate) htlc_value_satoshis: Option<u64>,
263+
pub(crate) htlc_value_msat: Option<u64>,
264264
pub(crate) user_channel_id: Option<u128>,
265265
}
266266
impl_writeable_tlv_based!(HTLCUpdate, {
267267
(0, payment_hash, required),
268-
(1, htlc_value_satoshis, option),
268+
(1, htlc_value_satoshis, (legacy, u64, |_| Ok(()), |us: &HTLCUpdate| us.htlc_value_msat.map(|v| v / 1000))),
269269
(2, source, required),
270270
(4, payment_preimage, option),
271271
(5, user_channel_id, option),
272+
(7, htlc_value_msat, (default_value, htlc_value_satoshis.map(|v: u64| v * 1000))),
272273
});
273274

274275
/// If an output goes from claimable only by us to claimable by us or our counterparty within this
@@ -3854,7 +3855,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
38543855
payment_hash: htlc.payment_hash,
38553856
payment_preimage: Some(*claimed_preimage),
38563857
source: *source.clone(),
3857-
htlc_value_satoshis: Some(htlc.amount_msat),
3858+
htlc_value_msat: Some(htlc.amount_msat),
38583859
user_channel_id: self.user_channel_id,
38593860
}));
38603861
}
@@ -4573,7 +4574,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45734574
if self.counterparty_fulfilled_htlcs.get(&SentHTLCId::from_source(source)).is_some() {
45744575
continue;
45754576
}
4576-
let htlc_value_satoshis = Some(amount_msat / 1000);
45774577
let logger = WithContext::from(logger, None, None, Some(payment_hash));
45784578
// Defensively mark the HTLC as failed back so the expiry-based failure
45794579
// path in `block_connected` doesn't generate a duplicate `HTLCUpdate`
@@ -4592,7 +4592,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45924592
payment_hash,
45934593
payment_preimage: None,
45944594
source: source.clone(),
4595-
htlc_value_satoshis,
4595+
htlc_value_msat: Some(amount_msat),
45964596
user_channel_id: self.user_channel_id,
45974597
}),
45984598
&mut self.next_monitor_event_id,
@@ -4614,7 +4614,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
46144614
event: OnchainEvent::HTLCUpdate {
46154615
source: source.clone(),
46164616
payment_hash,
4617-
htlc_value_satoshis,
4617+
htlc_value_satoshis: Some(amount_msat / 1000),
46184618
commitment_tx_output_idx: None,
46194619
},
46204620
};
@@ -5930,7 +5930,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
59305930
payment_hash,
59315931
payment_preimage: None,
59325932
source,
5933-
htlc_value_satoshis,
5933+
htlc_value_msat: htlc_value_satoshis.map(|v| v * 1000),
59345934
user_channel_id: self.user_channel_id,
59355935
}));
59365936
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
@@ -6041,7 +6041,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
60416041
source: source.clone(),
60426042
payment_preimage: None,
60436043
payment_hash: htlc.payment_hash,
6044-
htlc_value_satoshis: Some(htlc.amount_msat / 1000),
6044+
htlc_value_msat: Some(htlc.amount_msat),
60456045
user_channel_id: self.user_channel_id,
60466046
}), &mut self.next_monitor_event_id);
60476047
}
@@ -6459,7 +6459,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
64596459
source,
64606460
payment_preimage: Some(payment_preimage),
64616461
payment_hash,
6462-
htlc_value_satoshis: Some(amount_msat / 1000),
6462+
htlc_value_msat: Some(amount_msat),
64636463
user_channel_id: self.user_channel_id,
64646464
}), &mut self.next_monitor_event_id);
64656465
}
@@ -6484,7 +6484,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
64846484
source,
64856485
payment_preimage: Some(payment_preimage),
64866486
payment_hash,
6487-
htlc_value_satoshis: Some(amount_msat / 1000),
6487+
htlc_value_msat: Some(amount_msat),
64886488
user_channel_id: self.user_channel_id,
64896489
}), &mut self.next_monitor_event_id);
64906490
}

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13717,7 +13717,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1371713717
self.claim_funds_internal(
1371813718
htlc_update.source,
1371913719
preimage,
13720-
htlc_update.htlc_value_satoshis.map(|v| v * 1000),
13720+
htlc_update.htlc_value_msat,
1372113721
None,
1372213722
from_onchain,
1372313723
counterparty_node_id,

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4294,7 +4294,7 @@ pub fn test_duplicate_payment_hash_one_failure_one_success() {
42944294
// Finally, give node B the HTLC success transaction and ensure it extracts the preimage to
42954295
// provide to node A.
42964296
mine_transaction(&nodes[1], htlc_success_tx_to_confirm);
4297-
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(392), true, true);
4297+
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(196), true, true);
42984298
let mut updates = get_htlc_update_msgs(&nodes[1], &node_a_id);
42994299
assert!(updates.update_add_htlcs.is_empty());
43004300
assert!(updates.update_fail_htlcs.is_empty());

0 commit comments

Comments
 (0)