Skip to content

Commit 583e101

Browse files
committed
Avoid a few useless clone() calls in onchaintx.rs
3d640da looped over a new HashMap new_claims, clone()ing entries out of it right before droppng the whole thing. This is an obvious candidate for drain(..).
1 parent 01db259 commit 583e101

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lightning/src/ln/onchaintx.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,17 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
585585

586586
// Generate claim transactions and track them to bump if necessary at
587587
// height timer expiration (i.e in how many blocks we're going to take action).
588-
for claim in new_claims {
589-
let mut claim_material = ClaimTxBumpMaterial { height_timer: None, feerate_previous: 0, soonest_timelock: claim.0, per_input_material: claim.1.clone() };
588+
for (soonest_timelock, claim) in new_claims.drain(..) {
589+
let mut claim_material = ClaimTxBumpMaterial { height_timer: None, feerate_previous: 0, soonest_timelock, per_input_material: claim };
590590
if let Some((new_timer, new_feerate, tx)) = self.generate_claim_tx(height, &claim_material, &*fee_estimator) {
591591
claim_material.height_timer = new_timer;
592592
claim_material.feerate_previous = new_feerate;
593593
let txid = tx.txid();
594-
self.pending_claim_requests.insert(txid, claim_material);
595-
for k in claim.1.keys() {
594+
for k in claim_material.per_input_material.keys() {
596595
log_trace!(self, "Registering claiming request for {}:{}", k.txid, k.vout);
597596
self.claimable_outpoints.insert(k.clone(), (txid, height));
598597
}
598+
self.pending_claim_requests.insert(txid, claim_material);
599599
log_trace!(self, "Broadcast onchain {}", log_tx!(tx));
600600
broadcaster.broadcast_transaction(&tx);
601601
}

0 commit comments

Comments
 (0)