Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,7 +317,7 @@ impl HolderCommitment {
let delayed_payment_key = &tx_keys.broadcaster_delayed_payment_key;
let per_commitment_point = &tx_keys.per_commitment_point;

let mut nondust_htlcs = self.tx.htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut nondust_htlcs = self.tx.nondust_htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut sources = self.nondust_htlc_sources.iter();

// Use an iterator to write `htlc_outputs` to avoid allocations.
Expand DownExpand Up@@ -937,7 +937,7 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
// HTLC sources, separately. All offered, non-dust HTLCs must have a source available.

let mut missing_nondust_source = false;
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.htlcs().len());
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand DownExpand Up@@ -967,16 +967,16 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment

impl HolderCommitment {
fn has_htlcs(&self) -> bool {
self.tx.htlcs().len() > 0 || self.dust_htlcs.len() > 0
self.tx.nondust_htlcs().len() > 0 || self.dust_htlcs.len() > 0
}

fn htlcs(&self) -> impl Iterator<Item = &HTLCOutputInCommitment> {
self.tx.htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
self.tx.nondust_htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
}

fn htlcs_with_sources(&self) -> impl Iterator<Item = (&HTLCOutputInCommitment, Option<&HTLCSource>)> {
let mut sources = self.nondust_htlc_sources.iter();
let nondust_htlcs = self.tx.htlcs().iter().map(move |htlc| {
let nondust_htlcs = self.tx.nondust_htlcs().iter().map(move |htlc| {
let mut source = None;
if htlc.offered && htlc.transaction_output_index.is_some() {
source = sources.next();
Expand DownExpand Up@@ -3098,8 +3098,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
// and just pass in source data via `nondust_htlc_sources`.
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().htlcs().iter()) {
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().nondust_htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().nondust_htlcs().iter()) {
debug_assert_eq!(a, b);
}
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.counterparty_htlc_sigs.len());
Expand All@@ -3109,7 +3109,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Backfill the non-dust HTLC sources.
debug_assert!(nondust_htlc_sources.is_empty());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.htlcs().len());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand All@@ -3129,18 +3129,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// `nondust_htlc_sources` and the `holder_commitment_tx`
{
let mut prev = -1;
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
prev = htlc.transaction_output_index.unwrap() as i32;
}
}

debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
debug_assert_eq!(holder_commitment_tx.trust().nondust_htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());

let mut sources = nondust_htlc_sources.iter();
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
if htlc.offered {
let source = sources.next().expect("Non-dust HTLC sources didn't match commitment tx");
assert!(source.possibly_matches_output(htlc));
Expand DownExpand Up@@ -3955,9 +3955,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
&self, holder_tx: &HolderCommitmentTransaction,
) -> Vec<HTLCDescriptor> {
let tx = holder_tx.trust();
let mut htlcs = Vec::with_capacity(holder_tx.htlcs().len());
debug_assert_eq!(holder_tx.htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
let mut htlcs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
debug_assert_eq!(holder_tx.nondust_htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.nondust_htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
assert!(htlc.transaction_output_index.is_some(), "Expected transaction output index for non-dust HTLC");

let preimage = if htlc.offered {
Expand DownExpand Up@@ -4026,9 +4026,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Returns holder HTLC outputs to watch and react to in case of spending.
fn get_broadcasted_holder_watch_outputs(&self, holder_tx: &HolderCommitmentTransaction) -> Vec<(u32, TxOut)> {
let mut watch_outputs = Vec::with_capacity(holder_tx.htlcs().len());
let mut watch_outputs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
let tx = holder_tx.trust();
for htlc in holder_tx.htlcs() {
for htlc in holder_tx.nondust_htlcs() {
if let Some(transaction_output_index) = htlc.transaction_output_index {
watch_outputs.push((
transaction_output_index,
Expand DownExpand Up@@ -4121,7 +4121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let txid = self.funding.current_holder_commitment.tx.trust().txid();
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand All@@ -4135,7 +4135,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
if txid != *confirmed_commitment_txid {
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in prev_holder_commitment.tx.htlcs() {
for htlc in prev_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -688,7 +688,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
OnchainClaim::Event(ClaimEvent::BumpCommitment {
package_target_feerate_sat_per_1000_weight,
commitment_tx: tx,
pending_nondust_htlcs: holder_commitment.htlcs().to_vec(),
pending_nondust_htlcs: holder_commitment.nondust_htlcs().to_vec(),
commitment_tx_fee_satoshis: fee_sat,
anchor_output_idx: idx,
channel_parameters: channel_parameters.clone(),
Expand DownExpand Up@@ -1339,7 +1339,7 @@ mod tests {
let holder_commit = tx_handler.current_holder_commitment_tx();
let holder_commit_txid = holder_commit.trust().txid();
let mut requests = Vec::new();
for (htlc, counterparty_sig) in holder_commit.htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
for (htlc, counterparty_sig) in holder_commit.nondust_htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
requests.push(PackageTemplate::build_package(
holder_commit_txid,
htlc.transaction_output_index.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/package.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,7 +472,7 @@ impl HolderHTLCOutput {
}

let (htlc, counterparty_sig) =
trusted_tx.htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
trusted_tx.nondust_htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
.find(|(htlc, _)| htlc.transaction_output_index.unwrap() == outp.vout)
.unwrap();

Expand Down
30 changes: 15 additions & 15 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1430,7 +1430,7 @@ pub struct CommitmentTransaction {
feerate_per_kw: u32,
// The set of non-dust HTLCs included in the commitment. They must be sorted in increasing
// output index order.
htlcs: Vec<HTLCOutputInCommitment>,
nondust_htlcs: Vec<HTLCOutputInCommitment>,
// Note that on upgrades, some features of existing outputs may be missed.
channel_type_features: ChannelTypeFeatures,
// A cache of the parties' pubkeys required to construct the transaction, see doc for trust()
Expand All@@ -1446,7 +1446,7 @@ impl PartialEq for CommitmentTransaction {
self.to_broadcaster_value_sat == o.to_broadcaster_value_sat &&
self.to_countersignatory_value_sat == o.to_countersignatory_value_sat &&
self.feerate_per_kw == o.feerate_per_kw &&
self.htlcs == o.htlcs &&
self.nondust_htlcs == o.nondust_htlcs &&
self.channel_type_features == o.channel_type_features &&
self.keys == o.keys;
if eq {
Expand All@@ -1468,7 +1468,7 @@ impl Writeable for CommitmentTransaction {
(6, self.feerate_per_kw, required),
(8, self.keys, required),
(10, self.built, required),
(12, self.htlcs, required_vec),
(12, self.nondust_htlcs, required_vec),
(14, legacy_deserialization_prevention_marker, option),
(15, self.channel_type_features, required),
});
Expand All@@ -1486,7 +1486,7 @@ impl Readable for CommitmentTransaction {
(6, feerate_per_kw, required),
(8, keys, required),
(10, built, required),
(12, htlcs, required_vec),
(12, nondust_htlcs, required_vec),
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
(15, channel_type_features, option),
});
Expand All@@ -1503,7 +1503,7 @@ impl Readable for CommitmentTransaction {
feerate_per_kw: feerate_per_kw.0.unwrap(),
keys: keys.0.unwrap(),
built: built.0.unwrap(),
htlcs,
nondust_htlcs,
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
})
}
Expand All@@ -1526,7 +1526,7 @@ impl CommitmentTransaction {
let keys = TxCreationKeys::from_channel_static_keys(per_commitment_point, channel_parameters.broadcaster_pubkeys(), channel_parameters.countersignatory_pubkeys(), secp_ctx);

// Sort outputs and populate output indices while keeping track of the auxiliary data
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
let (outputs, nondust_htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);

let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand All@@ -1537,7 +1537,7 @@ impl CommitmentTransaction {
to_countersignatory_value_sat,
to_broadcaster_delay: Some(channel_parameters.contest_delay()),
feerate_per_kw,
htlcs,
nondust_htlcs,
channel_type_features: channel_parameters.channel_type_features().clone(),
keys,
built: BuiltCommitmentTransaction {
Expand All@@ -1558,7 +1558,7 @@ impl CommitmentTransaction {
fn internal_rebuild_transaction(&self, keys: &TxCreationKeys, channel_parameters: &DirectedChannelTransactionParameters) -> BuiltCommitmentTransaction {
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);

let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
let mut htlcs_with_aux = self.nondust_htlcs.iter().map(|h| (h.clone(), ())).collect();
let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters);

let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand DownExpand Up@@ -1653,7 +1653,7 @@ impl CommitmentTransaction {
}
}

let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
let mut nondust_htlcs = Vec::with_capacity(htlcs_with_aux.len());
for (htlc, _) in htlcs_with_aux {
let script = get_htlc_redeemscript(htlc, channel_type, keys);
let txout = TxOut {
Expand DownExpand Up@@ -1683,11 +1683,11 @@ impl CommitmentTransaction {
for (idx, out) in txouts.drain(..).enumerate() {
if let Some(htlc) = out.1 {
htlc.transaction_output_index = Some(idx as u32);
htlcs.push(htlc.clone());
nondust_htlcs.push(htlc.clone());
}
outputs.push(out.0);
}
(outputs, htlcs)
(outputs, nondust_htlcs)
}

fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
Expand DownExpand Up@@ -1746,8 +1746,8 @@ impl CommitmentTransaction {
///
/// This is not exported to bindings users as we cannot currently convert Vec references to/from C, though we should
/// expose a less effecient version which creates a Vec of references in the future.
pub fn htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.htlcs
pub fn nondust_htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.nondust_htlcs
}

/// Trust our pre-built transaction and derived transaction creation public keys.
Expand DownExpand Up@@ -1831,10 +1831,10 @@ impl<'a> TrustedCommitmentTransaction<'a> {
let inner = self.inner;
let keys = &inner.keys;
let txid = inner.built.txid;
let mut ret = Vec::with_capacity(inner.htlcs.len());
let mut ret = Vec::with_capacity(inner.nondust_htlcs.len());
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key);

for this_htlc in inner.htlcs.iter() {
for this_htlc in inner.nondust_htlcs.iter() {
assert!(this_htlc.transaction_output_index.is_some());
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,7 +317,7 @@ impl HolderCommitment {
let delayed_payment_key = &tx_keys.broadcaster_delayed_payment_key;
let per_commitment_point = &tx_keys.per_commitment_point;

let mut nondust_htlcs = self.tx.htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut nondust_htlcs = self.tx.nondust_htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut sources = self.nondust_htlc_sources.iter();

// Use an iterator to write `htlc_outputs` to avoid allocations.
Expand DownExpand Up@@ -937,7 +937,7 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
// HTLC sources, separately. All offered, non-dust HTLCs must have a source available.

let mut missing_nondust_source = false;
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.htlcs().len());
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand DownExpand Up@@ -967,16 +967,16 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment

impl HolderCommitment {
fn has_htlcs(&self) -> bool {
self.tx.htlcs().len() > 0 || self.dust_htlcs.len() > 0
self.tx.nondust_htlcs().len() > 0 || self.dust_htlcs.len() > 0
}

fn htlcs(&self) -> impl Iterator<Item = &HTLCOutputInCommitment> {
self.tx.htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
self.tx.nondust_htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
}

fn htlcs_with_sources(&self) -> impl Iterator<Item = (&HTLCOutputInCommitment, Option<&HTLCSource>)> {
let mut sources = self.nondust_htlc_sources.iter();
let nondust_htlcs = self.tx.htlcs().iter().map(move |htlc| {
let nondust_htlcs = self.tx.nondust_htlcs().iter().map(move |htlc| {
let mut source = None;
if htlc.offered && htlc.transaction_output_index.is_some() {
source = sources.next();
Expand DownExpand Up@@ -3098,8 +3098,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
// and just pass in source data via `nondust_htlc_sources`.
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().htlcs().iter()) {
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().nondust_htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().nondust_htlcs().iter()) {
debug_assert_eq!(a, b);
}
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.counterparty_htlc_sigs.len());
Expand All@@ -3109,7 +3109,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Backfill the non-dust HTLC sources.
debug_assert!(nondust_htlc_sources.is_empty());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.htlcs().len());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand All@@ -3129,18 +3129,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// `nondust_htlc_sources` and the `holder_commitment_tx`
{
let mut prev = -1;
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
prev = htlc.transaction_output_index.unwrap() as i32;
}
}

debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
debug_assert_eq!(holder_commitment_tx.trust().nondust_htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());

let mut sources = nondust_htlc_sources.iter();
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
if htlc.offered {
let source = sources.next().expect("Non-dust HTLC sources didn't match commitment tx");
assert!(source.possibly_matches_output(htlc));
Expand DownExpand Up@@ -3955,9 +3955,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
&self, holder_tx: &HolderCommitmentTransaction,
) -> Vec<HTLCDescriptor> {
let tx = holder_tx.trust();
let mut htlcs = Vec::with_capacity(holder_tx.htlcs().len());
debug_assert_eq!(holder_tx.htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
let mut htlcs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
debug_assert_eq!(holder_tx.nondust_htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.nondust_htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
assert!(htlc.transaction_output_index.is_some(), "Expected transaction output index for non-dust HTLC");

let preimage = if htlc.offered {
Expand DownExpand Up@@ -4026,9 +4026,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Returns holder HTLC outputs to watch and react to in case of spending.
fn get_broadcasted_holder_watch_outputs(&self, holder_tx: &HolderCommitmentTransaction) -> Vec<(u32, TxOut)> {
let mut watch_outputs = Vec::with_capacity(holder_tx.htlcs().len());
let mut watch_outputs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
let tx = holder_tx.trust();
for htlc in holder_tx.htlcs() {
for htlc in holder_tx.nondust_htlcs() {
if let Some(transaction_output_index) = htlc.transaction_output_index {
watch_outputs.push((
transaction_output_index,
Expand DownExpand Up@@ -4121,7 +4121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let txid = self.funding.current_holder_commitment.tx.trust().txid();
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand All@@ -4135,7 +4135,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
if txid != *confirmed_commitment_txid {
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in prev_holder_commitment.tx.htlcs() {
for htlc in prev_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -688,7 +688,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
OnchainClaim::Event(ClaimEvent::BumpCommitment {
package_target_feerate_sat_per_1000_weight,
commitment_tx: tx,
pending_nondust_htlcs: holder_commitment.htlcs().to_vec(),
pending_nondust_htlcs: holder_commitment.nondust_htlcs().to_vec(),
commitment_tx_fee_satoshis: fee_sat,
anchor_output_idx: idx,
channel_parameters: channel_parameters.clone(),
Expand DownExpand Up@@ -1339,7 +1339,7 @@ mod tests {
let holder_commit = tx_handler.current_holder_commitment_tx();
let holder_commit_txid = holder_commit.trust().txid();
let mut requests = Vec::new();
for (htlc, counterparty_sig) in holder_commit.htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
for (htlc, counterparty_sig) in holder_commit.nondust_htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
requests.push(PackageTemplate::build_package(
holder_commit_txid,
htlc.transaction_output_index.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/package.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,7 +472,7 @@ impl HolderHTLCOutput {
}

let (htlc, counterparty_sig) =
trusted_tx.htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
trusted_tx.nondust_htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
.find(|(htlc, _)| htlc.transaction_output_index.unwrap() == outp.vout)
.unwrap();

Expand Down
30 changes: 15 additions & 15 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1430,7 +1430,7 @@ pub struct CommitmentTransaction {
feerate_per_kw: u32,
// The set of non-dust HTLCs included in the commitment. They must be sorted in increasing
// output index order.
htlcs: Vec<HTLCOutputInCommitment>,
nondust_htlcs: Vec<HTLCOutputInCommitment>,
// Note that on upgrades, some features of existing outputs may be missed.
channel_type_features: ChannelTypeFeatures,
// A cache of the parties' pubkeys required to construct the transaction, see doc for trust()
Expand All@@ -1446,7 +1446,7 @@ impl PartialEq for CommitmentTransaction {
self.to_broadcaster_value_sat == o.to_broadcaster_value_sat &&
self.to_countersignatory_value_sat == o.to_countersignatory_value_sat &&
self.feerate_per_kw == o.feerate_per_kw &&
self.htlcs == o.htlcs &&
self.nondust_htlcs == o.nondust_htlcs &&
self.channel_type_features == o.channel_type_features &&
self.keys == o.keys;
if eq {
Expand All@@ -1468,7 +1468,7 @@ impl Writeable for CommitmentTransaction {
(6, self.feerate_per_kw, required),
(8, self.keys, required),
(10, self.built, required),
(12, self.htlcs, required_vec),
(12, self.nondust_htlcs, required_vec),
(14, legacy_deserialization_prevention_marker, option),
(15, self.channel_type_features, required),
});
Expand All@@ -1486,7 +1486,7 @@ impl Readable for CommitmentTransaction {
(6, feerate_per_kw, required),
(8, keys, required),
(10, built, required),
(12, htlcs, required_vec),
(12, nondust_htlcs, required_vec),
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
(15, channel_type_features, option),
});
Expand All@@ -1503,7 +1503,7 @@ impl Readable for CommitmentTransaction {
feerate_per_kw: feerate_per_kw.0.unwrap(),
keys: keys.0.unwrap(),
built: built.0.unwrap(),
htlcs,
nondust_htlcs,
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
})
}
Expand All@@ -1526,7 +1526,7 @@ impl CommitmentTransaction {
let keys = TxCreationKeys::from_channel_static_keys(per_commitment_point, channel_parameters.broadcaster_pubkeys(), channel_parameters.countersignatory_pubkeys(), secp_ctx);

// Sort outputs and populate output indices while keeping track of the auxiliary data
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
let (outputs, nondust_htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);

let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand All@@ -1537,7 +1537,7 @@ impl CommitmentTransaction {
to_countersignatory_value_sat,
to_broadcaster_delay: Some(channel_parameters.contest_delay()),
feerate_per_kw,
htlcs,
nondust_htlcs,
channel_type_features: channel_parameters.channel_type_features().clone(),
keys,
built: BuiltCommitmentTransaction {
Expand All@@ -1558,7 +1558,7 @@ impl CommitmentTransaction {
fn internal_rebuild_transaction(&self, keys: &TxCreationKeys, channel_parameters: &DirectedChannelTransactionParameters) -> BuiltCommitmentTransaction {
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);

let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
let mut htlcs_with_aux = self.nondust_htlcs.iter().map(|h| (h.clone(), ())).collect();
let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters);

let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand DownExpand Up@@ -1653,7 +1653,7 @@ impl CommitmentTransaction {
}
}

let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
let mut nondust_htlcs = Vec::with_capacity(htlcs_with_aux.len());
for (htlc, _) in htlcs_with_aux {
let script = get_htlc_redeemscript(htlc, channel_type, keys);
let txout = TxOut {
Expand DownExpand Up@@ -1683,11 +1683,11 @@ impl CommitmentTransaction {
for (idx, out) in txouts.drain(..).enumerate() {
if let Some(htlc) = out.1 {
htlc.transaction_output_index = Some(idx as u32);
htlcs.push(htlc.clone());
nondust_htlcs.push(htlc.clone());
}
outputs.push(out.0);
}
(outputs, htlcs)
(outputs, nondust_htlcs)
}

fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
Expand DownExpand Up@@ -1746,8 +1746,8 @@ impl CommitmentTransaction {
///
/// This is not exported to bindings users as we cannot currently convert Vec references to/from C, though we should
/// expose a less effecient version which creates a Vec of references in the future.
pub fn htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.htlcs
pub fn nondust_htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.nondust_htlcs
}

/// Trust our pre-built transaction and derived transaction creation public keys.
Expand DownExpand Up@@ -1831,10 +1831,10 @@ impl<'a> TrustedCommitmentTransaction<'a> {
let inner = self.inner;
let keys = &inner.keys;
let txid = inner.built.txid;
let mut ret = Vec::with_capacity(inner.htlcs.len());
let mut ret = Vec::with_capacity(inner.nondust_htlcs.len());
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key);

for this_htlc in inner.htlcs.iter() {
for this_htlc in inner.nondust_htlcs.iter() {
assert!(this_htlc.transaction_output_index.is_some());
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,7 +317,7 @@ impl HolderCommitment {
let delayed_payment_key = &tx_keys.broadcaster_delayed_payment_key;
let per_commitment_point = &tx_keys.per_commitment_point;

let mut nondust_htlcs = self.tx.htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut nondust_htlcs = self.tx.nondust_htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut sources = self.nondust_htlc_sources.iter();

// Use an iterator to write `htlc_outputs` to avoid allocations.
Expand DownExpand Up@@ -937,7 +937,7 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
// HTLC sources, separately. All offered, non-dust HTLCs must have a source available.

let mut missing_nondust_source = false;
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.htlcs().len());
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand DownExpand Up@@ -967,16 +967,16 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment

impl HolderCommitment {
fn has_htlcs(&self) -> bool {
self.tx.htlcs().len() > 0 || self.dust_htlcs.len() > 0
self.tx.nondust_htlcs().len() > 0 || self.dust_htlcs.len() > 0
}

fn htlcs(&self) -> impl Iterator<Item = &HTLCOutputInCommitment> {
self.tx.htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
self.tx.nondust_htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
}

fn htlcs_with_sources(&self) -> impl Iterator<Item = (&HTLCOutputInCommitment, Option<&HTLCSource>)> {
let mut sources = self.nondust_htlc_sources.iter();
let nondust_htlcs = self.tx.htlcs().iter().map(move |htlc| {
let nondust_htlcs = self.tx.nondust_htlcs().iter().map(move |htlc| {
let mut source = None;
if htlc.offered && htlc.transaction_output_index.is_some() {
source = sources.next();
Expand DownExpand Up@@ -3098,8 +3098,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
// and just pass in source data via `nondust_htlc_sources`.
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().htlcs().iter()) {
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().nondust_htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().nondust_htlcs().iter()) {
debug_assert_eq!(a, b);
}
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.counterparty_htlc_sigs.len());
Expand All@@ -3109,7 +3109,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Backfill the non-dust HTLC sources.
debug_assert!(nondust_htlc_sources.is_empty());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.htlcs().len());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand All@@ -3129,18 +3129,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// `nondust_htlc_sources` and the `holder_commitment_tx`
{
let mut prev = -1;
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
prev = htlc.transaction_output_index.unwrap() as i32;
}
}

debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
debug_assert_eq!(holder_commitment_tx.trust().nondust_htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());

let mut sources = nondust_htlc_sources.iter();
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
if htlc.offered {
let source = sources.next().expect("Non-dust HTLC sources didn't match commitment tx");
assert!(source.possibly_matches_output(htlc));
Expand DownExpand Up@@ -3955,9 +3955,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
&self, holder_tx: &HolderCommitmentTransaction,
) -> Vec<HTLCDescriptor> {
let tx = holder_tx.trust();
let mut htlcs = Vec::with_capacity(holder_tx.htlcs().len());
debug_assert_eq!(holder_tx.htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
let mut htlcs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
debug_assert_eq!(holder_tx.nondust_htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.nondust_htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
assert!(htlc.transaction_output_index.is_some(), "Expected transaction output index for non-dust HTLC");

let preimage = if htlc.offered {
Expand DownExpand Up@@ -4026,9 +4026,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Returns holder HTLC outputs to watch and react to in case of spending.
fn get_broadcasted_holder_watch_outputs(&self, holder_tx: &HolderCommitmentTransaction) -> Vec<(u32, TxOut)> {
let mut watch_outputs = Vec::with_capacity(holder_tx.htlcs().len());
let mut watch_outputs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
let tx = holder_tx.trust();
for htlc in holder_tx.htlcs() {
for htlc in holder_tx.nondust_htlcs() {
if let Some(transaction_output_index) = htlc.transaction_output_index {
watch_outputs.push((
transaction_output_index,
Expand DownExpand Up@@ -4121,7 +4121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let txid = self.funding.current_holder_commitment.tx.trust().txid();
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand All@@ -4135,7 +4135,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
if txid != *confirmed_commitment_txid {
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in prev_holder_commitment.tx.htlcs() {
for htlc in prev_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -688,7 +688,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
OnchainClaim::Event(ClaimEvent::BumpCommitment {
package_target_feerate_sat_per_1000_weight,
commitment_tx: tx,
pending_nondust_htlcs: holder_commitment.htlcs().to_vec(),
pending_nondust_htlcs: holder_commitment.nondust_htlcs().to_vec(),
commitment_tx_fee_satoshis: fee_sat,
anchor_output_idx: idx,
channel_parameters: channel_parameters.clone(),
Expand DownExpand Up@@ -1339,7 +1339,7 @@ mod tests {
let holder_commit = tx_handler.current_holder_commitment_tx();
let holder_commit_txid = holder_commit.trust().txid();
let mut requests = Vec::new();
for (htlc, counterparty_sig) in holder_commit.htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
for (htlc, counterparty_sig) in holder_commit.nondust_htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
requests.push(PackageTemplate::build_package(
holder_commit_txid,
htlc.transaction_output_index.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/package.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,7 +472,7 @@ impl HolderHTLCOutput {
}

let (htlc, counterparty_sig) =
trusted_tx.htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
trusted_tx.nondust_htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
.find(|(htlc, _)| htlc.transaction_output_index.unwrap() == outp.vout)
.unwrap();

Expand Down
30 changes: 15 additions & 15 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1430,7 +1430,7 @@ pub struct CommitmentTransaction {
feerate_per_kw: u32,
// The set of non-dust HTLCs included in the commitment. They must be sorted in increasing
// output index order.
htlcs: Vec<HTLCOutputInCommitment>,
nondust_htlcs: Vec<HTLCOutputInCommitment>,
// Note that on upgrades, some features of existing outputs may be missed.
channel_type_features: ChannelTypeFeatures,
// A cache of the parties' pubkeys required to construct the transaction, see doc for trust()
Expand All@@ -1446,7 +1446,7 @@ impl PartialEq for CommitmentTransaction {
self.to_broadcaster_value_sat == o.to_broadcaster_value_sat &&
self.to_countersignatory_value_sat == o.to_countersignatory_value_sat &&
self.feerate_per_kw == o.feerate_per_kw &&
self.htlcs == o.htlcs &&
self.nondust_htlcs == o.nondust_htlcs &&
self.channel_type_features == o.channel_type_features &&
self.keys == o.keys;
if eq {
Expand All@@ -1468,7 +1468,7 @@ impl Writeable for CommitmentTransaction {
(6, self.feerate_per_kw, required),
(8, self.keys, required),
(10, self.built, required),
(12, self.htlcs, required_vec),
(12, self.nondust_htlcs, required_vec),
(14, legacy_deserialization_prevention_marker, option),
(15, self.channel_type_features, required),
});
Expand All@@ -1486,7 +1486,7 @@ impl Readable for CommitmentTransaction {
(6, feerate_per_kw, required),
(8, keys, required),
(10, built, required),
(12, htlcs, required_vec),
(12, nondust_htlcs, required_vec),
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
(15, channel_type_features, option),
});
Expand All@@ -1503,7 +1503,7 @@ impl Readable for CommitmentTransaction {
feerate_per_kw: feerate_per_kw.0.unwrap(),
keys: keys.0.unwrap(),
built: built.0.unwrap(),
htlcs,
nondust_htlcs,
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
})
}
Expand All@@ -1526,7 +1526,7 @@ impl CommitmentTransaction {
let keys = TxCreationKeys::from_channel_static_keys(per_commitment_point, channel_parameters.broadcaster_pubkeys(), channel_parameters.countersignatory_pubkeys(), secp_ctx);

// Sort outputs and populate output indices while keeping track of the auxiliary data
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
let (outputs, nondust_htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);

let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand All@@ -1537,7 +1537,7 @@ impl CommitmentTransaction {
to_countersignatory_value_sat,
to_broadcaster_delay: Some(channel_parameters.contest_delay()),
feerate_per_kw,
htlcs,
nondust_htlcs,
channel_type_features: channel_parameters.channel_type_features().clone(),
keys,
built: BuiltCommitmentTransaction {
Expand All@@ -1558,7 +1558,7 @@ impl CommitmentTransaction {
fn internal_rebuild_transaction(&self, keys: &TxCreationKeys, channel_parameters: &DirectedChannelTransactionParameters) -> BuiltCommitmentTransaction {
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);

let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
let mut htlcs_with_aux = self.nondust_htlcs.iter().map(|h| (h.clone(), ())).collect();
let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters);

let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand DownExpand Up@@ -1653,7 +1653,7 @@ impl CommitmentTransaction {
}
}

let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
let mut nondust_htlcs = Vec::with_capacity(htlcs_with_aux.len());
for (htlc, _) in htlcs_with_aux {
let script = get_htlc_redeemscript(htlc, channel_type, keys);
let txout = TxOut {
Expand DownExpand Up@@ -1683,11 +1683,11 @@ impl CommitmentTransaction {
for (idx, out) in txouts.drain(..).enumerate() {
if let Some(htlc) = out.1 {
htlc.transaction_output_index = Some(idx as u32);
htlcs.push(htlc.clone());
nondust_htlcs.push(htlc.clone());
}
outputs.push(out.0);
}
(outputs, htlcs)
(outputs, nondust_htlcs)
}

fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
Expand DownExpand Up@@ -1746,8 +1746,8 @@ impl CommitmentTransaction {
///
/// This is not exported to bindings users as we cannot currently convert Vec references to/from C, though we should
/// expose a less effecient version which creates a Vec of references in the future.
pub fn htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.htlcs
pub fn nondust_htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.nondust_htlcs
}

/// Trust our pre-built transaction and derived transaction creation public keys.
Expand DownExpand Up@@ -1831,10 +1831,10 @@ impl<'a> TrustedCommitmentTransaction<'a> {
let inner = self.inner;
let keys = &inner.keys;
let txid = inner.built.txid;
let mut ret = Vec::with_capacity(inner.htlcs.len());
let mut ret = Vec::with_capacity(inner.nondust_htlcs.len());
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key);

for this_htlc in inner.htlcs.iter() {
for this_htlc in inner.nondust_htlcs.iter() {
assert!(this_htlc.transaction_output_index.is_some());
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,7 +317,7 @@ impl HolderCommitment {
let delayed_payment_key = &tx_keys.broadcaster_delayed_payment_key;
let per_commitment_point = &tx_keys.per_commitment_point;

let mut nondust_htlcs = self.tx.htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut nondust_htlcs = self.tx.nondust_htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut sources = self.nondust_htlc_sources.iter();

// Use an iterator to write `htlc_outputs` to avoid allocations.
Expand DownExpand Up@@ -937,7 +937,7 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
// HTLC sources, separately. All offered, non-dust HTLCs must have a source available.

let mut missing_nondust_source = false;
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.htlcs().len());
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand DownExpand Up@@ -967,16 +967,16 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment

impl HolderCommitment {
fn has_htlcs(&self) -> bool {
self.tx.htlcs().len() > 0 || self.dust_htlcs.len() > 0
self.tx.nondust_htlcs().len() > 0 || self.dust_htlcs.len() > 0
}

fn htlcs(&self) -> impl Iterator<Item = &HTLCOutputInCommitment> {
self.tx.htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
self.tx.nondust_htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
}

fn htlcs_with_sources(&self) -> impl Iterator<Item = (&HTLCOutputInCommitment, Option<&HTLCSource>)> {
let mut sources = self.nondust_htlc_sources.iter();
let nondust_htlcs = self.tx.htlcs().iter().map(move |htlc| {
let nondust_htlcs = self.tx.nondust_htlcs().iter().map(move |htlc| {
let mut source = None;
if htlc.offered && htlc.transaction_output_index.is_some() {
source = sources.next();
Expand DownExpand Up@@ -3098,8 +3098,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
// and just pass in source data via `nondust_htlc_sources`.
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().htlcs().iter()) {
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().nondust_htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().nondust_htlcs().iter()) {
debug_assert_eq!(a, b);
}
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.counterparty_htlc_sigs.len());
Expand All@@ -3109,7 +3109,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Backfill the non-dust HTLC sources.
debug_assert!(nondust_htlc_sources.is_empty());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.htlcs().len());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand All@@ -3129,18 +3129,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// `nondust_htlc_sources` and the `holder_commitment_tx`
{
let mut prev = -1;
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
prev = htlc.transaction_output_index.unwrap() as i32;
}
}

debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
debug_assert_eq!(holder_commitment_tx.trust().nondust_htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());

let mut sources = nondust_htlc_sources.iter();
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
if htlc.offered {
let source = sources.next().expect("Non-dust HTLC sources didn't match commitment tx");
assert!(source.possibly_matches_output(htlc));
Expand DownExpand Up@@ -3955,9 +3955,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
&self, holder_tx: &HolderCommitmentTransaction,
) -> Vec<HTLCDescriptor> {
let tx = holder_tx.trust();
let mut htlcs = Vec::with_capacity(holder_tx.htlcs().len());
debug_assert_eq!(holder_tx.htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
let mut htlcs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
debug_assert_eq!(holder_tx.nondust_htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.nondust_htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
assert!(htlc.transaction_output_index.is_some(), "Expected transaction output index for non-dust HTLC");

let preimage = if htlc.offered {
Expand DownExpand Up@@ -4026,9 +4026,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Returns holder HTLC outputs to watch and react to in case of spending.
fn get_broadcasted_holder_watch_outputs(&self, holder_tx: &HolderCommitmentTransaction) -> Vec<(u32, TxOut)> {
let mut watch_outputs = Vec::with_capacity(holder_tx.htlcs().len());
let mut watch_outputs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
let tx = holder_tx.trust();
for htlc in holder_tx.htlcs() {
for htlc in holder_tx.nondust_htlcs() {
if let Some(transaction_output_index) = htlc.transaction_output_index {
watch_outputs.push((
transaction_output_index,
Expand DownExpand Up@@ -4121,7 +4121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let txid = self.funding.current_holder_commitment.tx.trust().txid();
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand All@@ -4135,7 +4135,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
if txid != *confirmed_commitment_txid {
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in prev_holder_commitment.tx.htlcs() {
for htlc in prev_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -688,7 +688,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
OnchainClaim::Event(ClaimEvent::BumpCommitment {
package_target_feerate_sat_per_1000_weight,
commitment_tx: tx,
pending_nondust_htlcs: holder_commitment.htlcs().to_vec(),
pending_nondust_htlcs: holder_commitment.nondust_htlcs().to_vec(),
commitment_tx_fee_satoshis: fee_sat,
anchor_output_idx: idx,
channel_parameters: channel_parameters.clone(),
Expand DownExpand Up@@ -1339,7 +1339,7 @@ mod tests {
let holder_commit = tx_handler.current_holder_commitment_tx();
let holder_commit_txid = holder_commit.trust().txid();
let mut requests = Vec::new();
for (htlc, counterparty_sig) in holder_commit.htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
for (htlc, counterparty_sig) in holder_commit.nondust_htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
requests.push(PackageTemplate::build_package(
holder_commit_txid,
htlc.transaction_output_index.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/package.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,7 +472,7 @@ impl HolderHTLCOutput {
}

let (htlc, counterparty_sig) =
trusted_tx.htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
trusted_tx.nondust_htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
.find(|(htlc, _)| htlc.transaction_output_index.unwrap() == outp.vout)
.unwrap();

Expand Down
30 changes: 15 additions & 15 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1430,7 +1430,7 @@ pub struct CommitmentTransaction {
feerate_per_kw: u32,
// The set of non-dust HTLCs included in the commitment. They must be sorted in increasing
// output index order.
htlcs: Vec<HTLCOutputInCommitment>,
nondust_htlcs: Vec<HTLCOutputInCommitment>,
// Note that on upgrades, some features of existing outputs may be missed.
channel_type_features: ChannelTypeFeatures,
// A cache of the parties' pubkeys required to construct the transaction, see doc for trust()
Expand All@@ -1446,7 +1446,7 @@ impl PartialEq for CommitmentTransaction {
self.to_broadcaster_value_sat == o.to_broadcaster_value_sat &&
self.to_countersignatory_value_sat == o.to_countersignatory_value_sat &&
self.feerate_per_kw == o.feerate_per_kw &&
self.htlcs == o.htlcs &&
self.nondust_htlcs == o.nondust_htlcs &&
self.channel_type_features == o.channel_type_features &&
self.keys == o.keys;
if eq {
Expand All@@ -1468,7 +1468,7 @@ impl Writeable for CommitmentTransaction {
(6, self.feerate_per_kw, required),
(8, self.keys, required),
(10, self.built, required),
(12, self.htlcs, required_vec),
(12, self.nondust_htlcs, required_vec),
(14, legacy_deserialization_prevention_marker, option),
(15, self.channel_type_features, required),
});
Expand All@@ -1486,7 +1486,7 @@ impl Readable for CommitmentTransaction {
(6, feerate_per_kw, required),
(8, keys, required),
(10, built, required),
(12, htlcs, required_vec),
(12, nondust_htlcs, required_vec),
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
(15, channel_type_features, option),
});
Expand All@@ -1503,7 +1503,7 @@ impl Readable for CommitmentTransaction {
feerate_per_kw: feerate_per_kw.0.unwrap(),
keys: keys.0.unwrap(),
built: built.0.unwrap(),
htlcs,
nondust_htlcs,
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
})
}
Expand All@@ -1526,7 +1526,7 @@ impl CommitmentTransaction {
let keys = TxCreationKeys::from_channel_static_keys(per_commitment_point, channel_parameters.broadcaster_pubkeys(), channel_parameters.countersignatory_pubkeys(), secp_ctx);

// Sort outputs and populate output indices while keeping track of the auxiliary data
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
let (outputs, nondust_htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);

let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand All@@ -1537,7 +1537,7 @@ impl CommitmentTransaction {
to_countersignatory_value_sat,
to_broadcaster_delay: Some(channel_parameters.contest_delay()),
feerate_per_kw,
htlcs,
nondust_htlcs,
channel_type_features: channel_parameters.channel_type_features().clone(),
keys,
built: BuiltCommitmentTransaction {
Expand All@@ -1558,7 +1558,7 @@ impl CommitmentTransaction {
fn internal_rebuild_transaction(&self, keys: &TxCreationKeys, channel_parameters: &DirectedChannelTransactionParameters) -> BuiltCommitmentTransaction {
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);

let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
let mut htlcs_with_aux = self.nondust_htlcs.iter().map(|h| (h.clone(), ())).collect();
let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters);

let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand DownExpand Up@@ -1653,7 +1653,7 @@ impl CommitmentTransaction {
}
}

let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
let mut nondust_htlcs = Vec::with_capacity(htlcs_with_aux.len());
for (htlc, _) in htlcs_with_aux {
let script = get_htlc_redeemscript(htlc, channel_type, keys);
let txout = TxOut {
Expand DownExpand Up@@ -1683,11 +1683,11 @@ impl CommitmentTransaction {
for (idx, out) in txouts.drain(..).enumerate() {
if let Some(htlc) = out.1 {
htlc.transaction_output_index = Some(idx as u32);
htlcs.push(htlc.clone());
nondust_htlcs.push(htlc.clone());
}
outputs.push(out.0);
}
(outputs, htlcs)
(outputs, nondust_htlcs)
}

fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
Expand DownExpand Up@@ -1746,8 +1746,8 @@ impl CommitmentTransaction {
///
/// This is not exported to bindings users as we cannot currently convert Vec references to/from C, though we should
/// expose a less effecient version which creates a Vec of references in the future.
pub fn htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.htlcs
pub fn nondust_htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.nondust_htlcs
}

/// Trust our pre-built transaction and derived transaction creation public keys.
Expand DownExpand Up@@ -1831,10 +1831,10 @@ impl<'a> TrustedCommitmentTransaction<'a> {
let inner = self.inner;
let keys = &inner.keys;
let txid = inner.built.txid;
let mut ret = Vec::with_capacity(inner.htlcs.len());
let mut ret = Vec::with_capacity(inner.nondust_htlcs.len());
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key);

for this_htlc in inner.htlcs.iter() {
for this_htlc in inner.nondust_htlcs.iter() {
assert!(this_htlc.transaction_output_index.is_some());
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,7 +317,7 @@ impl HolderCommitment {
let delayed_payment_key = &tx_keys.broadcaster_delayed_payment_key;
let per_commitment_point = &tx_keys.per_commitment_point;

let mut nondust_htlcs = self.tx.htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut nondust_htlcs = self.tx.nondust_htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut sources = self.nondust_htlc_sources.iter();

// Use an iterator to write `htlc_outputs` to avoid allocations.
Expand DownExpand Up@@ -937,7 +937,7 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
// HTLC sources, separately. All offered, non-dust HTLCs must have a source available.

let mut missing_nondust_source = false;
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.htlcs().len());
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand DownExpand Up@@ -967,16 +967,16 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment

impl HolderCommitment {
fn has_htlcs(&self) -> bool {
self.tx.htlcs().len() > 0 || self.dust_htlcs.len() > 0
self.tx.nondust_htlcs().len() > 0 || self.dust_htlcs.len() > 0
}

fn htlcs(&self) -> impl Iterator<Item = &HTLCOutputInCommitment> {
self.tx.htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
self.tx.nondust_htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
}

fn htlcs_with_sources(&self) -> impl Iterator<Item = (&HTLCOutputInCommitment, Option<&HTLCSource>)> {
let mut sources = self.nondust_htlc_sources.iter();
let nondust_htlcs = self.tx.htlcs().iter().map(move |htlc| {
let nondust_htlcs = self.tx.nondust_htlcs().iter().map(move |htlc| {
let mut source = None;
if htlc.offered && htlc.transaction_output_index.is_some() {
source = sources.next();
Expand DownExpand Up@@ -3098,8 +3098,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
// and just pass in source data via `nondust_htlc_sources`.
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().htlcs().iter()) {
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().nondust_htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().nondust_htlcs().iter()) {
debug_assert_eq!(a, b);
}
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.counterparty_htlc_sigs.len());
Expand All@@ -3109,7 +3109,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Backfill the non-dust HTLC sources.
debug_assert!(nondust_htlc_sources.is_empty());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.htlcs().len());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand All@@ -3129,18 +3129,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// `nondust_htlc_sources` and the `holder_commitment_tx`
{
let mut prev = -1;
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
prev = htlc.transaction_output_index.unwrap() as i32;
}
}

debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
debug_assert_eq!(holder_commitment_tx.trust().nondust_htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());

let mut sources = nondust_htlc_sources.iter();
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
if htlc.offered {
let source = sources.next().expect("Non-dust HTLC sources didn't match commitment tx");
assert!(source.possibly_matches_output(htlc));
Expand DownExpand Up@@ -3955,9 +3955,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
&self, holder_tx: &HolderCommitmentTransaction,
) -> Vec<HTLCDescriptor> {
let tx = holder_tx.trust();
let mut htlcs = Vec::with_capacity(holder_tx.htlcs().len());
debug_assert_eq!(holder_tx.htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
let mut htlcs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
debug_assert_eq!(holder_tx.nondust_htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.nondust_htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
assert!(htlc.transaction_output_index.is_some(), "Expected transaction output index for non-dust HTLC");

let preimage = if htlc.offered {
Expand DownExpand Up@@ -4026,9 +4026,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Returns holder HTLC outputs to watch and react to in case of spending.
fn get_broadcasted_holder_watch_outputs(&self, holder_tx: &HolderCommitmentTransaction) -> Vec<(u32, TxOut)> {
let mut watch_outputs = Vec::with_capacity(holder_tx.htlcs().len());
let mut watch_outputs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
let tx = holder_tx.trust();
for htlc in holder_tx.htlcs() {
for htlc in holder_tx.nondust_htlcs() {
if let Some(transaction_output_index) = htlc.transaction_output_index {
watch_outputs.push((
transaction_output_index,
Expand DownExpand Up@@ -4121,7 +4121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let txid = self.funding.current_holder_commitment.tx.trust().txid();
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand All@@ -4135,7 +4135,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
if txid != *confirmed_commitment_txid {
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in prev_holder_commitment.tx.htlcs() {
for htlc in prev_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -688,7 +688,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
OnchainClaim::Event(ClaimEvent::BumpCommitment {
package_target_feerate_sat_per_1000_weight,
commitment_tx: tx,
pending_nondust_htlcs: holder_commitment.htlcs().to_vec(),
pending_nondust_htlcs: holder_commitment.nondust_htlcs().to_vec(),
commitment_tx_fee_satoshis: fee_sat,
anchor_output_idx: idx,
channel_parameters: channel_parameters.clone(),
Expand DownExpand Up@@ -1339,7 +1339,7 @@ mod tests {
let holder_commit = tx_handler.current_holder_commitment_tx();
let holder_commit_txid = holder_commit.trust().txid();
let mut requests = Vec::new();
for (htlc, counterparty_sig) in holder_commit.htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
for (htlc, counterparty_sig) in holder_commit.nondust_htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
requests.push(PackageTemplate::build_package(
holder_commit_txid,
htlc.transaction_output_index.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/package.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,7 +472,7 @@ impl HolderHTLCOutput {
}

let (htlc, counterparty_sig) =
trusted_tx.htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
trusted_tx.nondust_htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
.find(|(htlc, _)| htlc.transaction_output_index.unwrap() == outp.vout)
.unwrap();

Expand Down
30 changes: 15 additions & 15 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1430,7 +1430,7 @@ pub struct CommitmentTransaction {
feerate_per_kw: u32,
// The set of non-dust HTLCs included in the commitment. They must be sorted in increasing
// output index order.
htlcs: Vec<HTLCOutputInCommitment>,
nondust_htlcs: Vec<HTLCOutputInCommitment>,
// Note that on upgrades, some features of existing outputs may be missed.
channel_type_features: ChannelTypeFeatures,
// A cache of the parties' pubkeys required to construct the transaction, see doc for trust()
Expand All@@ -1446,7 +1446,7 @@ impl PartialEq for CommitmentTransaction {
self.to_broadcaster_value_sat == o.to_broadcaster_value_sat &&
self.to_countersignatory_value_sat == o.to_countersignatory_value_sat &&
self.feerate_per_kw == o.feerate_per_kw &&
self.htlcs == o.htlcs &&
self.nondust_htlcs == o.nondust_htlcs &&
self.channel_type_features == o.channel_type_features &&
self.keys == o.keys;
if eq {
Expand All@@ -1468,7 +1468,7 @@ impl Writeable for CommitmentTransaction {
(6, self.feerate_per_kw, required),
(8, self.keys, required),
(10, self.built, required),
(12, self.htlcs, required_vec),
(12, self.nondust_htlcs, required_vec),
(14, legacy_deserialization_prevention_marker, option),
(15, self.channel_type_features, required),
});
Expand All@@ -1486,7 +1486,7 @@ impl Readable for CommitmentTransaction {
(6, feerate_per_kw, required),
(8, keys, required),
(10, built, required),
(12, htlcs, required_vec),
(12, nondust_htlcs, required_vec),
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
(15, channel_type_features, option),
});
Expand All@@ -1503,7 +1503,7 @@ impl Readable for CommitmentTransaction {
feerate_per_kw: feerate_per_kw.0.unwrap(),
keys: keys.0.unwrap(),
built: built.0.unwrap(),
htlcs,
nondust_htlcs,
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
})
}
Expand All@@ -1526,7 +1526,7 @@ impl CommitmentTransaction {
let keys = TxCreationKeys::from_channel_static_keys(per_commitment_point, channel_parameters.broadcaster_pubkeys(), channel_parameters.countersignatory_pubkeys(), secp_ctx);

// Sort outputs and populate output indices while keeping track of the auxiliary data
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
let (outputs, nondust_htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);

let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand All@@ -1537,7 +1537,7 @@ impl CommitmentTransaction {
to_countersignatory_value_sat,
to_broadcaster_delay: Some(channel_parameters.contest_delay()),
feerate_per_kw,
htlcs,
nondust_htlcs,
channel_type_features: channel_parameters.channel_type_features().clone(),
keys,
built: BuiltCommitmentTransaction {
Expand All@@ -1558,7 +1558,7 @@ impl CommitmentTransaction {
fn internal_rebuild_transaction(&self, keys: &TxCreationKeys, channel_parameters: &DirectedChannelTransactionParameters) -> BuiltCommitmentTransaction {
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);

let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
let mut htlcs_with_aux = self.nondust_htlcs.iter().map(|h| (h.clone(), ())).collect();
let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters);

let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand DownExpand Up@@ -1653,7 +1653,7 @@ impl CommitmentTransaction {
}
}

let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
let mut nondust_htlcs = Vec::with_capacity(htlcs_with_aux.len());
for (htlc, _) in htlcs_with_aux {
let script = get_htlc_redeemscript(htlc, channel_type, keys);
let txout = TxOut {
Expand DownExpand Up@@ -1683,11 +1683,11 @@ impl CommitmentTransaction {
for (idx, out) in txouts.drain(..).enumerate() {
if let Some(htlc) = out.1 {
htlc.transaction_output_index = Some(idx as u32);
htlcs.push(htlc.clone());
nondust_htlcs.push(htlc.clone());
}
outputs.push(out.0);
}
(outputs, htlcs)
(outputs, nondust_htlcs)
}

fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
Expand DownExpand Up@@ -1746,8 +1746,8 @@ impl CommitmentTransaction {
///
/// This is not exported to bindings users as we cannot currently convert Vec references to/from C, though we should
/// expose a less effecient version which creates a Vec of references in the future.
pub fn htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.htlcs
pub fn nondust_htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.nondust_htlcs
}

/// Trust our pre-built transaction and derived transaction creation public keys.
Expand DownExpand Up@@ -1831,10 +1831,10 @@ impl<'a> TrustedCommitmentTransaction<'a> {
let inner = self.inner;
let keys = &inner.keys;
let txid = inner.built.txid;
let mut ret = Vec::with_capacity(inner.htlcs.len());
let mut ret = Vec::with_capacity(inner.nondust_htlcs.len());
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key);

for this_htlc in inner.htlcs.iter() {
for this_htlc in inner.nondust_htlcs.iter() {
assert!(this_htlc.transaction_output_index.is_some());
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,7 +317,7 @@ impl HolderCommitment {
let delayed_payment_key = &tx_keys.broadcaster_delayed_payment_key;
let per_commitment_point = &tx_keys.per_commitment_point;

let mut nondust_htlcs = self.tx.htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut nondust_htlcs = self.tx.nondust_htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut sources = self.nondust_htlc_sources.iter();

// Use an iterator to write `htlc_outputs` to avoid allocations.
Expand DownExpand Up@@ -937,7 +937,7 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
// HTLC sources, separately. All offered, non-dust HTLCs must have a source available.

let mut missing_nondust_source = false;
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.htlcs().len());
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand DownExpand Up@@ -967,16 +967,16 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment

impl HolderCommitment {
fn has_htlcs(&self) -> bool {
self.tx.htlcs().len() > 0 || self.dust_htlcs.len() > 0
self.tx.nondust_htlcs().len() > 0 || self.dust_htlcs.len() > 0
}

fn htlcs(&self) -> impl Iterator<Item = &HTLCOutputInCommitment> {
self.tx.htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
self.tx.nondust_htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
}

fn htlcs_with_sources(&self) -> impl Iterator<Item = (&HTLCOutputInCommitment, Option<&HTLCSource>)> {
let mut sources = self.nondust_htlc_sources.iter();
let nondust_htlcs = self.tx.htlcs().iter().map(move |htlc| {
let nondust_htlcs = self.tx.nondust_htlcs().iter().map(move |htlc| {
let mut source = None;
if htlc.offered && htlc.transaction_output_index.is_some() {
source = sources.next();
Expand DownExpand Up@@ -3098,8 +3098,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
// and just pass in source data via `nondust_htlc_sources`.
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().htlcs().iter()) {
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().nondust_htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().nondust_htlcs().iter()) {
debug_assert_eq!(a, b);
}
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.counterparty_htlc_sigs.len());
Expand All@@ -3109,7 +3109,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Backfill the non-dust HTLC sources.
debug_assert!(nondust_htlc_sources.is_empty());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.htlcs().len());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand All@@ -3129,18 +3129,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// `nondust_htlc_sources` and the `holder_commitment_tx`
{
let mut prev = -1;
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
prev = htlc.transaction_output_index.unwrap() as i32;
}
}

debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
debug_assert_eq!(holder_commitment_tx.trust().nondust_htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());

let mut sources = nondust_htlc_sources.iter();
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
if htlc.offered {
let source = sources.next().expect("Non-dust HTLC sources didn't match commitment tx");
assert!(source.possibly_matches_output(htlc));
Expand DownExpand Up@@ -3955,9 +3955,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
&self, holder_tx: &HolderCommitmentTransaction,
) -> Vec<HTLCDescriptor> {
let tx = holder_tx.trust();
let mut htlcs = Vec::with_capacity(holder_tx.htlcs().len());
debug_assert_eq!(holder_tx.htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
let mut htlcs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
debug_assert_eq!(holder_tx.nondust_htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.nondust_htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
assert!(htlc.transaction_output_index.is_some(), "Expected transaction output index for non-dust HTLC");

let preimage = if htlc.offered {
Expand DownExpand Up@@ -4026,9 +4026,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Returns holder HTLC outputs to watch and react to in case of spending.
fn get_broadcasted_holder_watch_outputs(&self, holder_tx: &HolderCommitmentTransaction) -> Vec<(u32, TxOut)> {
let mut watch_outputs = Vec::with_capacity(holder_tx.htlcs().len());
let mut watch_outputs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
let tx = holder_tx.trust();
for htlc in holder_tx.htlcs() {
for htlc in holder_tx.nondust_htlcs() {
if let Some(transaction_output_index) = htlc.transaction_output_index {
watch_outputs.push((
transaction_output_index,
Expand DownExpand Up@@ -4121,7 +4121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let txid = self.funding.current_holder_commitment.tx.trust().txid();
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand All@@ -4135,7 +4135,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
if txid != *confirmed_commitment_txid {
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in prev_holder_commitment.tx.htlcs() {
for htlc in prev_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -688,7 +688,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
OnchainClaim::Event(ClaimEvent::BumpCommitment {
package_target_feerate_sat_per_1000_weight,
commitment_tx: tx,
pending_nondust_htlcs: holder_commitment.htlcs().to_vec(),
pending_nondust_htlcs: holder_commitment.nondust_htlcs().to_vec(),
commitment_tx_fee_satoshis: fee_sat,
anchor_output_idx: idx,
channel_parameters: channel_parameters.clone(),
Expand DownExpand Up@@ -1339,7 +1339,7 @@ mod tests {
let holder_commit = tx_handler.current_holder_commitment_tx();
let holder_commit_txid = holder_commit.trust().txid();
let mut requests = Vec::new();
for (htlc, counterparty_sig) in holder_commit.htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
for (htlc, counterparty_sig) in holder_commit.nondust_htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
requests.push(PackageTemplate::build_package(
holder_commit_txid,
htlc.transaction_output_index.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/package.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,7 +472,7 @@ impl HolderHTLCOutput {
}

let (htlc, counterparty_sig) =
trusted_tx.htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
trusted_tx.nondust_htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
.find(|(htlc, _)| htlc.transaction_output_index.unwrap() == outp.vout)
.unwrap();

Expand Down
30 changes: 15 additions & 15 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1430,7 +1430,7 @@ pub struct CommitmentTransaction {
feerate_per_kw: u32,
// The set of non-dust HTLCs included in the commitment. They must be sorted in increasing
// output index order.
htlcs: Vec<HTLCOutputInCommitment>,
nondust_htlcs: Vec<HTLCOutputInCommitment>,
// Note that on upgrades, some features of existing outputs may be missed.
channel_type_features: ChannelTypeFeatures,
// A cache of the parties' pubkeys required to construct the transaction, see doc for trust()
Expand All@@ -1446,7 +1446,7 @@ impl PartialEq for CommitmentTransaction {
self.to_broadcaster_value_sat == o.to_broadcaster_value_sat &&
self.to_countersignatory_value_sat == o.to_countersignatory_value_sat &&
self.feerate_per_kw == o.feerate_per_kw &&
self.htlcs == o.htlcs &&
self.nondust_htlcs == o.nondust_htlcs &&
self.channel_type_features == o.channel_type_features &&
self.keys == o.keys;
if eq {
Expand All@@ -1468,7 +1468,7 @@ impl Writeable for CommitmentTransaction {
(6, self.feerate_per_kw, required),
(8, self.keys, required),
(10, self.built, required),
(12, self.htlcs, required_vec),
(12, self.nondust_htlcs, required_vec),
(14, legacy_deserialization_prevention_marker, option),
(15, self.channel_type_features, required),
});
Expand All@@ -1486,7 +1486,7 @@ impl Readable for CommitmentTransaction {
(6, feerate_per_kw, required),
(8, keys, required),
(10, built, required),
(12, htlcs, required_vec),
(12, nondust_htlcs, required_vec),
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
(15, channel_type_features, option),
});
Expand All@@ -1503,7 +1503,7 @@ impl Readable for CommitmentTransaction {
feerate_per_kw: feerate_per_kw.0.unwrap(),
keys: keys.0.unwrap(),
built: built.0.unwrap(),
htlcs,
nondust_htlcs,
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
})
}
Expand All@@ -1526,7 +1526,7 @@ impl CommitmentTransaction {
let keys = TxCreationKeys::from_channel_static_keys(per_commitment_point, channel_parameters.broadcaster_pubkeys(), channel_parameters.countersignatory_pubkeys(), secp_ctx);

// Sort outputs and populate output indices while keeping track of the auxiliary data
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
let (outputs, nondust_htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);

let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand All@@ -1537,7 +1537,7 @@ impl CommitmentTransaction {
to_countersignatory_value_sat,
to_broadcaster_delay: Some(channel_parameters.contest_delay()),
feerate_per_kw,
htlcs,
nondust_htlcs,
channel_type_features: channel_parameters.channel_type_features().clone(),
keys,
built: BuiltCommitmentTransaction {
Expand All@@ -1558,7 +1558,7 @@ impl CommitmentTransaction {
fn internal_rebuild_transaction(&self, keys: &TxCreationKeys, channel_parameters: &DirectedChannelTransactionParameters) -> BuiltCommitmentTransaction {
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);

let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
let mut htlcs_with_aux = self.nondust_htlcs.iter().map(|h| (h.clone(), ())).collect();
let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters);

let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand DownExpand Up@@ -1653,7 +1653,7 @@ impl CommitmentTransaction {
}
}

let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
let mut nondust_htlcs = Vec::with_capacity(htlcs_with_aux.len());
for (htlc, _) in htlcs_with_aux {
let script = get_htlc_redeemscript(htlc, channel_type, keys);
let txout = TxOut {
Expand DownExpand Up@@ -1683,11 +1683,11 @@ impl CommitmentTransaction {
for (idx, out) in txouts.drain(..).enumerate() {
if let Some(htlc) = out.1 {
htlc.transaction_output_index = Some(idx as u32);
htlcs.push(htlc.clone());
nondust_htlcs.push(htlc.clone());
}
outputs.push(out.0);
}
(outputs, htlcs)
(outputs, nondust_htlcs)
}

fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
Expand DownExpand Up@@ -1746,8 +1746,8 @@ impl CommitmentTransaction {
///
/// This is not exported to bindings users as we cannot currently convert Vec references to/from C, though we should
/// expose a less effecient version which creates a Vec of references in the future.
pub fn htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.htlcs
pub fn nondust_htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.nondust_htlcs
}

/// Trust our pre-built transaction and derived transaction creation public keys.
Expand DownExpand Up@@ -1831,10 +1831,10 @@ impl<'a> TrustedCommitmentTransaction<'a> {
let inner = self.inner;
let keys = &inner.keys;
let txid = inner.built.txid;
let mut ret = Vec::with_capacity(inner.htlcs.len());
let mut ret = Vec::with_capacity(inner.nondust_htlcs.len());
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key);

for this_htlc in inner.htlcs.iter() {
for this_htlc in inner.nondust_htlcs.iter() {
assert!(this_htlc.transaction_output_index.is_some());
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,7 +317,7 @@ impl HolderCommitment {
let delayed_payment_key = &tx_keys.broadcaster_delayed_payment_key;
let per_commitment_point = &tx_keys.per_commitment_point;

let mut nondust_htlcs = self.tx.htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut nondust_htlcs = self.tx.nondust_htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut sources = self.nondust_htlc_sources.iter();

// Use an iterator to write `htlc_outputs` to avoid allocations.
Expand DownExpand Up@@ -937,7 +937,7 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
// HTLC sources, separately. All offered, non-dust HTLCs must have a source available.

let mut missing_nondust_source = false;
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.htlcs().len());
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand DownExpand Up@@ -967,16 +967,16 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment

impl HolderCommitment {
fn has_htlcs(&self) -> bool {
self.tx.htlcs().len() > 0 || self.dust_htlcs.len() > 0
self.tx.nondust_htlcs().len() > 0 || self.dust_htlcs.len() > 0
}

fn htlcs(&self) -> impl Iterator<Item = &HTLCOutputInCommitment> {
self.tx.htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
self.tx.nondust_htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
}

fn htlcs_with_sources(&self) -> impl Iterator<Item = (&HTLCOutputInCommitment, Option<&HTLCSource>)> {
let mut sources = self.nondust_htlc_sources.iter();
let nondust_htlcs = self.tx.htlcs().iter().map(move |htlc| {
let nondust_htlcs = self.tx.nondust_htlcs().iter().map(move |htlc| {
let mut source = None;
if htlc.offered && htlc.transaction_output_index.is_some() {
source = sources.next();
Expand DownExpand Up@@ -3098,8 +3098,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
// and just pass in source data via `nondust_htlc_sources`.
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().htlcs().iter()) {
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().nondust_htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().nondust_htlcs().iter()) {
debug_assert_eq!(a, b);
}
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.counterparty_htlc_sigs.len());
Expand All@@ -3109,7 +3109,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Backfill the non-dust HTLC sources.
debug_assert!(nondust_htlc_sources.is_empty());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.htlcs().len());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand All@@ -3129,18 +3129,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// `nondust_htlc_sources` and the `holder_commitment_tx`
{
let mut prev = -1;
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
prev = htlc.transaction_output_index.unwrap() as i32;
}
}

debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
debug_assert_eq!(holder_commitment_tx.trust().nondust_htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());

let mut sources = nondust_htlc_sources.iter();
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
if htlc.offered {
let source = sources.next().expect("Non-dust HTLC sources didn't match commitment tx");
assert!(source.possibly_matches_output(htlc));
Expand DownExpand Up@@ -3955,9 +3955,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
&self, holder_tx: &HolderCommitmentTransaction,
) -> Vec<HTLCDescriptor> {
let tx = holder_tx.trust();
let mut htlcs = Vec::with_capacity(holder_tx.htlcs().len());
debug_assert_eq!(holder_tx.htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
let mut htlcs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
debug_assert_eq!(holder_tx.nondust_htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.nondust_htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
assert!(htlc.transaction_output_index.is_some(), "Expected transaction output index for non-dust HTLC");

let preimage = if htlc.offered {
Expand DownExpand Up@@ -4026,9 +4026,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Returns holder HTLC outputs to watch and react to in case of spending.
fn get_broadcasted_holder_watch_outputs(&self, holder_tx: &HolderCommitmentTransaction) -> Vec<(u32, TxOut)> {
let mut watch_outputs = Vec::with_capacity(holder_tx.htlcs().len());
let mut watch_outputs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
let tx = holder_tx.trust();
for htlc in holder_tx.htlcs() {
for htlc in holder_tx.nondust_htlcs() {
if let Some(transaction_output_index) = htlc.transaction_output_index {
watch_outputs.push((
transaction_output_index,
Expand DownExpand Up@@ -4121,7 +4121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let txid = self.funding.current_holder_commitment.tx.trust().txid();
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand All@@ -4135,7 +4135,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
if txid != *confirmed_commitment_txid {
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in prev_holder_commitment.tx.htlcs() {
for htlc in prev_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -688,7 +688,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
OnchainClaim::Event(ClaimEvent::BumpCommitment {
package_target_feerate_sat_per_1000_weight,
commitment_tx: tx,
pending_nondust_htlcs: holder_commitment.htlcs().to_vec(),
pending_nondust_htlcs: holder_commitment.nondust_htlcs().to_vec(),
commitment_tx_fee_satoshis: fee_sat,
anchor_output_idx: idx,
channel_parameters: channel_parameters.clone(),
Expand DownExpand Up@@ -1339,7 +1339,7 @@ mod tests {
let holder_commit = tx_handler.current_holder_commitment_tx();
let holder_commit_txid = holder_commit.trust().txid();
let mut requests = Vec::new();
for (htlc, counterparty_sig) in holder_commit.htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
for (htlc, counterparty_sig) in holder_commit.nondust_htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
requests.push(PackageTemplate::build_package(
holder_commit_txid,
htlc.transaction_output_index.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/package.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,7 +472,7 @@ impl HolderHTLCOutput {
}

let (htlc, counterparty_sig) =
trusted_tx.htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
trusted_tx.nondust_htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
.find(|(htlc, _)| htlc.transaction_output_index.unwrap() == outp.vout)
.unwrap();

Expand Down
30 changes: 15 additions & 15 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1430,7 +1430,7 @@ pub struct CommitmentTransaction {
feerate_per_kw: u32,
// The set of non-dust HTLCs included in the commitment. They must be sorted in increasing
// output index order.
htlcs: Vec<HTLCOutputInCommitment>,
nondust_htlcs: Vec<HTLCOutputInCommitment>,
// Note that on upgrades, some features of existing outputs may be missed.
channel_type_features: ChannelTypeFeatures,
// A cache of the parties' pubkeys required to construct the transaction, see doc for trust()
Expand All@@ -1446,7 +1446,7 @@ impl PartialEq for CommitmentTransaction {
self.to_broadcaster_value_sat == o.to_broadcaster_value_sat &&
self.to_countersignatory_value_sat == o.to_countersignatory_value_sat &&
self.feerate_per_kw == o.feerate_per_kw &&
self.htlcs == o.htlcs &&
self.nondust_htlcs == o.nondust_htlcs &&
self.channel_type_features == o.channel_type_features &&
self.keys == o.keys;
if eq {
Expand All@@ -1468,7 +1468,7 @@ impl Writeable for CommitmentTransaction {
(6, self.feerate_per_kw, required),
(8, self.keys, required),
(10, self.built, required),
(12, self.htlcs, required_vec),
(12, self.nondust_htlcs, required_vec),
(14, legacy_deserialization_prevention_marker, option),
(15, self.channel_type_features, required),
});
Expand All@@ -1486,7 +1486,7 @@ impl Readable for CommitmentTransaction {
(6, feerate_per_kw, required),
(8, keys, required),
(10, built, required),
(12, htlcs, required_vec),
(12, nondust_htlcs, required_vec),
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
(15, channel_type_features, option),
});
Expand All@@ -1503,7 +1503,7 @@ impl Readable for CommitmentTransaction {
feerate_per_kw: feerate_per_kw.0.unwrap(),
keys: keys.0.unwrap(),
built: built.0.unwrap(),
htlcs,
nondust_htlcs,
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
})
}
Expand All@@ -1526,7 +1526,7 @@ impl CommitmentTransaction {
let keys = TxCreationKeys::from_channel_static_keys(per_commitment_point, channel_parameters.broadcaster_pubkeys(), channel_parameters.countersignatory_pubkeys(), secp_ctx);

// Sort outputs and populate output indices while keeping track of the auxiliary data
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
let (outputs, nondust_htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);

let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand All@@ -1537,7 +1537,7 @@ impl CommitmentTransaction {
to_countersignatory_value_sat,
to_broadcaster_delay: Some(channel_parameters.contest_delay()),
feerate_per_kw,
htlcs,
nondust_htlcs,
channel_type_features: channel_parameters.channel_type_features().clone(),
keys,
built: BuiltCommitmentTransaction {
Expand All@@ -1558,7 +1558,7 @@ impl CommitmentTransaction {
fn internal_rebuild_transaction(&self, keys: &TxCreationKeys, channel_parameters: &DirectedChannelTransactionParameters) -> BuiltCommitmentTransaction {
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);

let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
let mut htlcs_with_aux = self.nondust_htlcs.iter().map(|h| (h.clone(), ())).collect();
let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters);

let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand DownExpand Up@@ -1653,7 +1653,7 @@ impl CommitmentTransaction {
}
}

let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
let mut nondust_htlcs = Vec::with_capacity(htlcs_with_aux.len());
for (htlc, _) in htlcs_with_aux {
let script = get_htlc_redeemscript(htlc, channel_type, keys);
let txout = TxOut {
Expand DownExpand Up@@ -1683,11 +1683,11 @@ impl CommitmentTransaction {
for (idx, out) in txouts.drain(..).enumerate() {
if let Some(htlc) = out.1 {
htlc.transaction_output_index = Some(idx as u32);
htlcs.push(htlc.clone());
nondust_htlcs.push(htlc.clone());
}
outputs.push(out.0);
}
(outputs, htlcs)
(outputs, nondust_htlcs)
}

fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
Expand DownExpand Up@@ -1746,8 +1746,8 @@ impl CommitmentTransaction {
///
/// This is not exported to bindings users as we cannot currently convert Vec references to/from C, though we should
/// expose a less effecient version which creates a Vec of references in the future.
pub fn htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.htlcs
pub fn nondust_htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.nondust_htlcs
}

/// Trust our pre-built transaction and derived transaction creation public keys.
Expand DownExpand Up@@ -1831,10 +1831,10 @@ impl<'a> TrustedCommitmentTransaction<'a> {
let inner = self.inner;
let keys = &inner.keys;
let txid = inner.built.txid;
let mut ret = Vec::with_capacity(inner.htlcs.len());
let mut ret = Vec::with_capacity(inner.nondust_htlcs.len());
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key);

for this_htlc in inner.htlcs.iter() {
for this_htlc in inner.nondust_htlcs.iter() {
assert!(this_htlc.transaction_output_index.is_some());
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lightning/src/chain/channelmonitor.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -317,7 +317,7 @@ impl HolderCommitment {
let delayed_payment_key = &tx_keys.broadcaster_delayed_payment_key;
let per_commitment_point = &tx_keys.per_commitment_point;

let mut nondust_htlcs = self.tx.htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut nondust_htlcs = self.tx.nondust_htlcs().iter().zip(self.tx.counterparty_htlc_sigs.iter());
let mut sources = self.nondust_htlc_sources.iter();

// Use an iterator to write `htlc_outputs` to avoid allocations.
Expand DownExpand Up@@ -937,7 +937,7 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment
// HTLC sources, separately. All offered, non-dust HTLCs must have a source available.

let mut missing_nondust_source = false;
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.htlcs().len());
let mut nondust_htlc_sources = Vec::with_capacity(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = holder_signed_tx.htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand DownExpand Up@@ -967,16 +967,16 @@ impl TryFrom<(HolderCommitmentTransaction, HolderSignedTx)> for HolderCommitment

impl HolderCommitment {
fn has_htlcs(&self) -> bool {
self.tx.htlcs().len() > 0 || self.dust_htlcs.len() > 0
self.tx.nondust_htlcs().len() > 0 || self.dust_htlcs.len() > 0
}

fn htlcs(&self) -> impl Iterator<Item = &HTLCOutputInCommitment> {
self.tx.htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
self.tx.nondust_htlcs().iter().chain(self.dust_htlcs.iter().map(|(htlc, _)| htlc))
}

fn htlcs_with_sources(&self) -> impl Iterator<Item = (&HTLCOutputInCommitment, Option<&HTLCSource>)> {
let mut sources = self.nondust_htlc_sources.iter();
let nondust_htlcs = self.tx.htlcs().iter().map(move |htlc| {
let nondust_htlcs = self.tx.nondust_htlcs().iter().map(move |htlc| {
let mut source = None;
if htlc.offered && htlc.transaction_output_index.is_some() {
source = sources.next();
Expand DownExpand Up@@ -3098,8 +3098,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
// and just pass in source data via `nondust_htlc_sources`.
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().htlcs().iter()) {
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.trust().nondust_htlcs().len());
for (a, b) in htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).map(|(h, _, _)| h).zip(holder_commitment_tx.trust().nondust_htlcs().iter()) {
debug_assert_eq!(a, b);
}
debug_assert_eq!(htlc_outputs.iter().filter(|(_, s, _)| s.is_some()).count(), holder_commitment_tx.counterparty_htlc_sigs.len());
Expand All@@ -3109,7 +3109,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Backfill the non-dust HTLC sources.
debug_assert!(nondust_htlc_sources.is_empty());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.htlcs().len());
nondust_htlc_sources.reserve_exact(holder_commitment_tx.nondust_htlcs().len());
let dust_htlcs = htlc_outputs.into_iter().filter_map(|(htlc, _, source)| {
// Filter our non-dust HTLCs, while at the same time pushing their sources into
// `nondust_htlc_sources`.
Expand All@@ -3129,18 +3129,18 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// `nondust_htlc_sources` and the `holder_commitment_tx`
{
let mut prev = -1;
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
assert!(htlc.transaction_output_index.unwrap() as i32 > prev);
prev = htlc.transaction_output_index.unwrap() as i32;
}
}

debug_assert!(htlc_outputs.iter().all(|(htlc, _, _)| htlc.transaction_output_index.is_none()));
debug_assert!(htlc_outputs.iter().all(|(_, sig_opt, _)| sig_opt.is_none()));
debug_assert_eq!(holder_commitment_tx.trust().htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());
debug_assert_eq!(holder_commitment_tx.trust().nondust_htlcs().len(), holder_commitment_tx.counterparty_htlc_sigs.len());

let mut sources = nondust_htlc_sources.iter();
for htlc in holder_commitment_tx.trust().htlcs().iter() {
for htlc in holder_commitment_tx.trust().nondust_htlcs().iter() {
if htlc.offered {
let source = sources.next().expect("Non-dust HTLC sources didn't match commitment tx");
assert!(source.possibly_matches_output(htlc));
Expand DownExpand Up@@ -3955,9 +3955,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
&self, holder_tx: &HolderCommitmentTransaction,
) -> Vec<HTLCDescriptor> {
let tx = holder_tx.trust();
let mut htlcs = Vec::with_capacity(holder_tx.htlcs().len());
debug_assert_eq!(holder_tx.htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
let mut htlcs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
debug_assert_eq!(holder_tx.nondust_htlcs().len(), holder_tx.counterparty_htlc_sigs.len());
for (htlc, counterparty_sig) in holder_tx.nondust_htlcs().iter().zip(holder_tx.counterparty_htlc_sigs.iter()) {
assert!(htlc.transaction_output_index.is_some(), "Expected transaction output index for non-dust HTLC");

let preimage = if htlc.offered {
Expand DownExpand Up@@ -4026,9 +4026,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {

// Returns holder HTLC outputs to watch and react to in case of spending.
fn get_broadcasted_holder_watch_outputs(&self, holder_tx: &HolderCommitmentTransaction) -> Vec<(u32, TxOut)> {
let mut watch_outputs = Vec::with_capacity(holder_tx.htlcs().len());
let mut watch_outputs = Vec::with_capacity(holder_tx.nondust_htlcs().len());
let tx = holder_tx.trust();
for htlc in holder_tx.htlcs() {
for htlc in holder_tx.nondust_htlcs() {
if let Some(transaction_output_index) = htlc.transaction_output_index {
watch_outputs.push((
transaction_output_index,
Expand DownExpand Up@@ -4121,7 +4121,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let txid = self.funding.current_holder_commitment.tx.trust().txid();
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in self.funding.current_holder_commitment.tx.htlcs() {
for htlc in self.funding.current_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand All@@ -4135,7 +4135,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
if txid != *confirmed_commitment_txid {
log_trace!(logger, "Canceling claims for previously broadcast holder commitment {}", txid);
let mut outpoint = BitcoinOutPoint { txid, vout: 0 };
for htlc in prev_holder_commitment.tx.htlcs() {
for htlc in prev_holder_commitment.tx.nondust_htlcs() {
if let Some(vout) = htlc.transaction_output_index {
outpoint.vout = vout;
self.onchain_tx_handler.abandon_claim(&outpoint);
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -688,7 +688,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
OnchainClaim::Event(ClaimEvent::BumpCommitment {
package_target_feerate_sat_per_1000_weight,
commitment_tx: tx,
pending_nondust_htlcs: holder_commitment.htlcs().to_vec(),
pending_nondust_htlcs: holder_commitment.nondust_htlcs().to_vec(),
commitment_tx_fee_satoshis: fee_sat,
anchor_output_idx: idx,
channel_parameters: channel_parameters.clone(),
Expand DownExpand Up@@ -1339,7 +1339,7 @@ mod tests {
let holder_commit = tx_handler.current_holder_commitment_tx();
let holder_commit_txid = holder_commit.trust().txid();
let mut requests = Vec::new();
for (htlc, counterparty_sig) in holder_commit.htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
for (htlc, counterparty_sig) in holder_commit.nondust_htlcs().iter().zip(holder_commit.counterparty_htlc_sigs.iter()) {
requests.push(PackageTemplate::build_package(
holder_commit_txid,
htlc.transaction_output_index.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/package.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,7 +472,7 @@ impl HolderHTLCOutput {
}

let (htlc, counterparty_sig) =
trusted_tx.htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
trusted_tx.nondust_htlcs().iter().zip(holder_commitment.counterparty_htlc_sigs.iter())
.find(|(htlc, _)| htlc.transaction_output_index.unwrap() == outp.vout)
.unwrap();

Expand Down
30 changes: 15 additions & 15 deletions lightning/src/ln/chan_utils.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1430,7 +1430,7 @@ pub struct CommitmentTransaction {
feerate_per_kw: u32,
// The set of non-dust HTLCs included in the commitment. They must be sorted in increasing
// output index order.
htlcs: Vec<HTLCOutputInCommitment>,
nondust_htlcs: Vec<HTLCOutputInCommitment>,
// Note that on upgrades, some features of existing outputs may be missed.
channel_type_features: ChannelTypeFeatures,
// A cache of the parties' pubkeys required to construct the transaction, see doc for trust()
Expand All@@ -1446,7 +1446,7 @@ impl PartialEq for CommitmentTransaction {
self.to_broadcaster_value_sat == o.to_broadcaster_value_sat &&
self.to_countersignatory_value_sat == o.to_countersignatory_value_sat &&
self.feerate_per_kw == o.feerate_per_kw &&
self.htlcs == o.htlcs &&
self.nondust_htlcs == o.nondust_htlcs &&
self.channel_type_features == o.channel_type_features &&
self.keys == o.keys;
if eq {
Expand All@@ -1468,7 +1468,7 @@ impl Writeable for CommitmentTransaction {
(6, self.feerate_per_kw, required),
(8, self.keys, required),
(10, self.built, required),
(12, self.htlcs, required_vec),
(12, self.nondust_htlcs, required_vec),
(14, legacy_deserialization_prevention_marker, option),
(15, self.channel_type_features, required),
});
Expand All@@ -1486,7 +1486,7 @@ impl Readable for CommitmentTransaction {
(6, feerate_per_kw, required),
(8, keys, required),
(10, built, required),
(12, htlcs, required_vec),
(12, nondust_htlcs, required_vec),
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
(15, channel_type_features, option),
});
Expand All@@ -1503,7 +1503,7 @@ impl Readable for CommitmentTransaction {
feerate_per_kw: feerate_per_kw.0.unwrap(),
keys: keys.0.unwrap(),
built: built.0.unwrap(),
htlcs,
nondust_htlcs,
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
})
}
Expand All@@ -1526,7 +1526,7 @@ impl CommitmentTransaction {
let keys = TxCreationKeys::from_channel_static_keys(per_commitment_point, channel_parameters.broadcaster_pubkeys(), channel_parameters.countersignatory_pubkeys(), secp_ctx);

// Sort outputs and populate output indices while keeping track of the auxiliary data
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);
let (outputs, nondust_htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters);

let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand All@@ -1537,7 +1537,7 @@ impl CommitmentTransaction {
to_countersignatory_value_sat,
to_broadcaster_delay: Some(channel_parameters.contest_delay()),
feerate_per_kw,
htlcs,
nondust_htlcs,
channel_type_features: channel_parameters.channel_type_features().clone(),
keys,
built: BuiltCommitmentTransaction {
Expand All@@ -1558,7 +1558,7 @@ impl CommitmentTransaction {
fn internal_rebuild_transaction(&self, keys: &TxCreationKeys, channel_parameters: &DirectedChannelTransactionParameters) -> BuiltCommitmentTransaction {
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);

let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
let mut htlcs_with_aux = self.nondust_htlcs.iter().map(|h| (h.clone(), ())).collect();
let (outputs, _) = Self::internal_build_outputs(keys, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters);

let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
Expand DownExpand Up@@ -1653,7 +1653,7 @@ impl CommitmentTransaction {
}
}

let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
let mut nondust_htlcs = Vec::with_capacity(htlcs_with_aux.len());
for (htlc, _) in htlcs_with_aux {
let script = get_htlc_redeemscript(htlc, channel_type, keys);
let txout = TxOut {
Expand DownExpand Up@@ -1683,11 +1683,11 @@ impl CommitmentTransaction {
for (idx, out) in txouts.drain(..).enumerate() {
if let Some(htlc) = out.1 {
htlc.transaction_output_index = Some(idx as u32);
htlcs.push(htlc.clone());
nondust_htlcs.push(htlc.clone());
}
outputs.push(out.0);
}
(outputs, htlcs)
(outputs, nondust_htlcs)
}

fn internal_build_inputs(commitment_number: u64, channel_parameters: &DirectedChannelTransactionParameters) -> (u64, Vec<TxIn>) {
Expand DownExpand Up@@ -1746,8 +1746,8 @@ impl CommitmentTransaction {
///
/// This is not exported to bindings users as we cannot currently convert Vec references to/from C, though we should
/// expose a less effecient version which creates a Vec of references in the future.
pub fn htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.htlcs
pub fn nondust_htlcs(&self) -> &Vec<HTLCOutputInCommitment> {
&self.nondust_htlcs
}

/// Trust our pre-built transaction and derived transaction creation public keys.
Expand DownExpand Up@@ -1831,10 +1831,10 @@ impl<'a> TrustedCommitmentTransaction<'a> {
let inner = self.inner;
let keys = &inner.keys;
let txid = inner.built.txid;
let mut ret = Vec::with_capacity(inner.htlcs.len());
let mut ret = Vec::with_capacity(inner.nondust_htlcs.len());
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key);

for this_htlc in inner.htlcs.iter() {
for this_htlc in inner.nondust_htlcs.iter() {
assert!(this_htlc.transaction_output_index.is_some());
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);

Expand Down
Loading