-
Notifications
You must be signed in to change notification settings - Fork 407
Support future removal of redundant per-HTLC signatures in CMU
s
#2101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3122,9 +3122,24 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> { | |
return Err(ChannelError::Close(format!("Got wrong number of HTLC signatures ({}) from remote. It must be {}", msg.htlc_signatures.len(), commitment_stats.num_nondust_htlcs))); | ||
} | ||
|
||
// TODO: Sadly, we pass HTLCs twice to ChannelMonitor: once via the HolderCommitmentTransaction and once via the update | ||
// Up to LDK 0.0.115, HTLC information was required to be duplicated in the | ||
// `htlcs_and_sigs` vec and in the `holder_commitment_tx` itself, both of which were passed | ||
// in the `ChannelMonitorUpdate`. In 0.0.115, support for having a separate set of | ||
// outbound-non-dust-HTLCSources in the `ChannelMonitorUpdate` was added, however for | ||
// backwards compatibility, we never use it in production. To provide test coverage, here, | ||
// we randomly decide (in test/fuzzing builds) to use the new vec sometimes. | ||
#[allow(unused_assignments, unused_mut)] | ||
let mut separate_nondust_htlc_sources = false; | ||
#[cfg(all(feature = "std", any(test, fuzzing)))] { | ||
use core::hash::{BuildHasher, Hasher}; | ||
// Get a random value using the only std API to do so - the DefaultHasher | ||
let rand_val = std::collections::hash_map::RandomState::new().build_hasher().finish(); | ||
separate_nondust_htlc_sources = rand_val % 2 == 0; | ||
} | ||
Comment on lines
+3132
to
+3138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get how this would work well with fuzzing, but for normal tests would you just have to run them a couple times to be confident the new implementation got tested? I guess this may be a temporary solution for testing so it's not a big deal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, we have a bit of randomness in tests which avoids having to run every test five times but ensures over time we will hit any issues. |
||
|
||
let mut nondust_htlc_sources = Vec::with_capacity(htlcs_cloned.len()); | ||
let mut htlcs_and_sigs = Vec::with_capacity(htlcs_cloned.len()); | ||
for (idx, (htlc, source)) in htlcs_cloned.drain(..).enumerate() { | ||
for (idx, (htlc, mut source_opt)) in htlcs_cloned.drain(..).enumerate() { | ||
if let Some(_) = htlc.transaction_output_index { | ||
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_stats.feerate_per_kw, | ||
self.get_counterparty_selected_contest_delay().unwrap(), &htlc, self.opt_anchors(), | ||
|
@@ -3139,10 +3154,18 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> { | |
if let Err(_) = self.secp_ctx.verify_ecdsa(&htlc_sighash, &msg.htlc_signatures[idx], &keys.countersignatory_htlc_key) { | ||
return Err(ChannelError::Close("Invalid HTLC tx signature from peer".to_owned())); | ||
} | ||
htlcs_and_sigs.push((htlc, Some(msg.htlc_signatures[idx]), source)); | ||
if !separate_nondust_htlc_sources { | ||
htlcs_and_sigs.push((htlc, Some(msg.htlc_signatures[idx]), source_opt.take())); | ||
} | ||
} else { | ||
htlcs_and_sigs.push((htlc, None, source)); | ||
htlcs_and_sigs.push((htlc, None, source_opt.take())); | ||
} | ||
if separate_nondust_htlc_sources { | ||
if let Some(source) = source_opt.take() { | ||
nondust_htlc_sources.push(source); | ||
wpaulino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
debug_assert!(source_opt.is_none(), "HTLCSource should have been put somewhere"); | ||
} | ||
|
||
let holder_commitment_tx = HolderCommitmentTransaction::new( | ||
|
@@ -3205,6 +3228,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> { | |
commitment_tx: holder_commitment_tx, | ||
htlc_outputs: htlcs_and_sigs, | ||
claimed_htlcs, | ||
nondust_htlc_sources, | ||
}] | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comprehension check: do dust HTLCs not have signatures because there wouldn't be a point since they have no output to ever spend/enforce on-chain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. There's simply nothing to sign.