Skip to content

Commit c980152

Browse files
HTLCUpdate::htlc_value_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 13c5908 commit c980152

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))), // Added in 0.4
272273
});
273274

274275
/// If an output goes from claimable only by us to claimable by us or our counterparty within this
@@ -3856,7 +3857,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
38563857
payment_hash: htlc.payment_hash,
38573858
payment_preimage: Some(*claimed_preimage),
38583859
source: *source.clone(),
3859-
htlc_value_satoshis: Some(htlc.amount_msat),
3860+
htlc_value_msat: Some(htlc.amount_msat),
38603861
user_channel_id: self.user_channel_id,
38613862
}));
38623863
}
@@ -4575,7 +4576,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45754576
if self.counterparty_fulfilled_htlcs.get(&SentHTLCId::from_source(source)).is_some() {
45764577
continue;
45774578
}
4578-
let htlc_value_satoshis = Some(amount_msat / 1000);
45794579
let logger = WithContext::from(logger, None, None, Some(payment_hash));
45804580
// Defensively mark the HTLC as failed back so the expiry-based failure
45814581
// path in `block_connected` doesn't generate a duplicate `HTLCUpdate`
@@ -4594,7 +4594,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
45944594
payment_hash,
45954595
payment_preimage: None,
45964596
source: source.clone(),
4597-
htlc_value_satoshis,
4597+
htlc_value_msat: Some(amount_msat),
45984598
user_channel_id: self.user_channel_id,
45994599
}),
46004600
&mut self.next_monitor_event_id,
@@ -4616,7 +4616,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
46164616
event: OnchainEvent::HTLCUpdate {
46174617
source: source.clone(),
46184618
payment_hash,
4619-
htlc_value_satoshis,
4619+
htlc_value_satoshis: Some(amount_msat / 1000),
46204620
commitment_tx_output_idx: None,
46214621
},
46224622
};
@@ -5932,7 +5932,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
59325932
payment_hash,
59335933
payment_preimage: None,
59345934
source,
5935-
htlc_value_satoshis,
5935+
htlc_value_msat: htlc_value_satoshis.map(|v| v * 1000),
59365936
user_channel_id: self.user_channel_id,
59375937
}));
59385938
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
@@ -6043,7 +6043,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
60436043
source: source.clone(),
60446044
payment_preimage: None,
60456045
payment_hash: htlc.payment_hash,
6046-
htlc_value_satoshis: Some(htlc.amount_msat / 1000),
6046+
htlc_value_msat: Some(htlc.amount_msat),
60476047
user_channel_id: self.user_channel_id,
60486048
}), &mut self.next_monitor_event_id);
60496049
}
@@ -6461,7 +6461,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
64616461
source,
64626462
payment_preimage: Some(payment_preimage),
64636463
payment_hash,
6464-
htlc_value_satoshis: Some(amount_msat / 1000),
6464+
htlc_value_msat: Some(amount_msat),
64656465
user_channel_id: self.user_channel_id,
64666466
}), &mut self.next_monitor_event_id);
64676467
}
@@ -6486,7 +6486,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
64866486
source,
64876487
payment_preimage: Some(payment_preimage),
64886488
payment_hash,
6489-
htlc_value_satoshis: Some(amount_msat / 1000),
6489+
htlc_value_msat: Some(amount_msat),
64906490
user_channel_id: self.user_channel_id,
64916491
}), &mut self.next_monitor_event_id);
64926492
}

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13738,7 +13738,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1373813738
self.claim_funds_internal(
1373913739
htlc_update.source,
1374013740
preimage,
13741-
htlc_update.htlc_value_satoshis.map(|v| v * 1000),
13741+
htlc_update.htlc_value_msat,
1374213742
None,
1374313743
from_onchain,
1374413744
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)