Skip to content

Commit 4c3533d

Browse files
committed
Flatten Vec passed from channelmonitor to onchaintx block_connected
Instead of passing a Vec of Vecs drop them into one as we go in ChannelMonitor, hopefully avoiding a bit of memory fragmentation and improving readability.
1 parent 48549de commit 4c3533d

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

lightning/src/ln/channelmonitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
20102010
watch_outputs.push(new_outputs);
20112011
}
20122012
}
2013-
claimable_outpoints.push(new_outpoints);
2013+
claimable_outpoints.append(&mut new_outpoints);
20142014
}
20152015
if !funding_txo.is_none() && claimable_outpoints.is_empty() {
20162016
if let Some(spendable_output) = self.check_spend_closing_transaction(&tx) {
@@ -2020,7 +2020,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
20202020
} else {
20212021
if let Some(&(commitment_number, _)) = self.remote_commitment_txn_on_chain.get(&prevout.txid) {
20222022
let mut new_outpoints = self.check_spend_remote_htlc(&tx, commitment_number, height);
2023-
claimable_outpoints.push(new_outpoints);
2023+
claimable_outpoints.append(&mut new_outpoints);
20242024
}
20252025
}
20262026
}

lightning/src/ln/onchaintx.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ impl OnchainTxHandler {
478478
Some((new_timer, new_feerate, bumped_tx))
479479
}
480480

481-
pub(super) fn block_connected<B: Deref, F: Deref>(&mut self, txn_matched: &[&Transaction], claimable_outpoints: Vec<Vec<ClaimRequest>>, height: u32, broadcaster: B, fee_estimator: F) -> Vec<SpendableOutputDescriptor>
481+
pub(super) fn block_connected<B: Deref, F: Deref>(&mut self, txn_matched: &[&Transaction], claimable_outpoints: Vec<ClaimRequest>, height: u32, broadcaster: B, fee_estimator: F) -> Vec<SpendableOutputDescriptor>
482482
where B::Target: BroadcasterInterface,
483483
F::Target: FeeEstimator
484484
{
@@ -489,20 +489,18 @@ impl OnchainTxHandler {
489489

490490
// Try to aggregate outputs if they're 1) belong to same parent tx, 2) their
491491
// timelock expiration isn't imminent (<= CLTV_SHARED_CLAIM_BUFFER).
492-
for siblings_outpoints in claimable_outpoints {
493-
for req in siblings_outpoints {
494-
// Don't claim a outpoint twice that would be bad for privacy and may uselessly lock a CPFP input for a while
495-
if let Some(_) = self.claimable_outpoints.get(&req.outpoint) { log_trace!(self, "Bouncing off outpoint {}:{}, already registered its claiming request", req.outpoint.txid, req.outpoint.vout); } else {
496-
log_trace!(self, "Test if outpoint can be aggregated with expiration {} against {}", req.absolute_timelock, height + CLTV_SHARED_CLAIM_BUFFER);
497-
if req.absolute_timelock <= height + CLTV_SHARED_CLAIM_BUFFER || !req.aggregable { // Don't aggregate if outpoint absolute timelock is soon or marked as non-aggregable
498-
let mut single_input = HashMap::new();
499-
single_input.insert(req.outpoint, req.witness_data);
500-
new_claims.push((req.absolute_timelock, single_input));
501-
} else {
502-
aggregated_claim.insert(req.outpoint, req.witness_data);
503-
if req.absolute_timelock < aggregated_soonest {
504-
aggregated_soonest = req.absolute_timelock;
505-
}
492+
for req in claimable_outpoints {
493+
// Don't claim a outpoint twice that would be bad for privacy and may uselessly lock a CPFP input for a while
494+
if let Some(_) = self.claimable_outpoints.get(&req.outpoint) { log_trace!(self, "Bouncing off outpoint {}:{}, already registered its claiming request", req.outpoint.txid, req.outpoint.vout); } else {
495+
log_trace!(self, "Test if outpoint can be aggregated with expiration {} against {}", req.absolute_timelock, height + CLTV_SHARED_CLAIM_BUFFER);
496+
if req.absolute_timelock <= height + CLTV_SHARED_CLAIM_BUFFER || !req.aggregable { // Don't aggregate if outpoint absolute timelock is soon or marked as non-aggregable
497+
let mut single_input = HashMap::new();
498+
single_input.insert(req.outpoint, req.witness_data);
499+
new_claims.push((req.absolute_timelock, single_input));
500+
} else {
501+
aggregated_claim.insert(req.outpoint, req.witness_data);
502+
if req.absolute_timelock < aggregated_soonest {
503+
aggregated_soonest = req.absolute_timelock;
506504
}
507505
}
508506
}

0 commit comments

Comments
 (0)