Skip to content

Commit 8ed075f

Browse files
committed
Rename keys for OnchainTxHandler::claimable_outpoints map
1 parent 34b4820 commit 8ed075f

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

lightning/src/chain/onchaintx.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
251251
#[cfg(anchors)]
252252
pending_claim_events: HashMap<PackageID, ClaimEvent>,
253253

254-
// Used to link outpoints claimed in a connected block to a pending claim request.
255-
// Key is outpoint than monitor parsing has detected we have keys/scripts to claim
256-
// Value is (pending claim request identifier, confirmation_block), identifier
257-
// is txid of the initial claiming transaction and is immutable until outpoint is
258-
// post-anti-reorg-delay solved, confirmaiton_block is used to erase entry if
259-
// block with output gets disconnected.
254+
// Used to link outpoints claimed in a connected block to a pending claim request. The keys
255+
// represent the outpoints that our `ChannelMonitor` has detected we have keys/scripts to
256+
// claim. The values track the pending claim request identifier and the initial confirmation
257+
// block height, and are immutable until the outpoint has enough confirmations to meet our
258+
// [`ANTI_REORG_DELAY`]. The initial confirmation block height is used to remove the entry if
259+
// the block gets disconnected.
260260
#[cfg(test)] // Used in functional_test to verify sanitization
261261
pub claimable_outpoints: HashMap<BitcoinOutPoint, (PackageID, u32)>,
262262
#[cfg(not(test))]
@@ -494,12 +494,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
494494
// transaction is reorged out.
495495
let mut all_inputs_have_confirmed_spend = true;
496496
for outpoint in request_outpoints.iter() {
497-
if let Some(first_claim_txid_height) = self.claimable_outpoints.get(*outpoint) {
497+
if let Some((request_package_id, _)) = self.claimable_outpoints.get(*outpoint) {
498498
// We check for outpoint spends within claims individually rather than as a set
499499
// since requests can have outpoints split off.
500500
if !self.onchain_events_awaiting_threshold_conf.iter()
501501
.any(|event_entry| if let OnchainEvent::Claim { package_id } = event_entry.event {
502-
first_claim_txid_height.0 == package_id
502+
*request_package_id == package_id
503503
} else {
504504
// The onchain event is not a claim, keep seeking until we find one.
505505
false
@@ -744,9 +744,9 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
744744
// Scan all input to verify is one of the outpoint spent is of interest for us
745745
let mut claimed_outputs_material = Vec::new();
746746
for inp in &tx.input {
747-
if let Some(first_claim_txid_height) = self.claimable_outpoints.get(&inp.previous_output) {
747+
if let Some((package_id, _)) = self.claimable_outpoints.get(&inp.previous_output) {
748748
// If outpoint has claim request pending on it...
749-
if let Some(request) = self.pending_claim_requests.get_mut(&first_claim_txid_height.0) {
749+
if let Some(request) = self.pending_claim_requests.get_mut(package_id) {
750750
//... we need to verify equality between transaction outpoints and claim request
751751
// outpoints to know if transaction is the original claim or a bumped one issued
752752
// by us.
@@ -766,7 +766,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
766766
txid: tx.txid(),
767767
height: conf_height,
768768
block_hash: Some(conf_hash),
769-
event: OnchainEvent::Claim { package_id: first_claim_txid_height.0 }
769+
event: OnchainEvent::Claim { package_id: *package_id }
770770
};
771771
if !self.onchain_events_awaiting_threshold_conf.contains(&entry) {
772772
self.onchain_events_awaiting_threshold_conf.push(entry);
@@ -793,7 +793,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
793793
}
794794
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
795795
if at_least_one_drop {
796-
bump_candidates.insert(first_claim_txid_height.0.clone(), request.clone());
796+
bump_candidates.insert(*package_id, request.clone());
797797
}
798798
}
799799
break; //No need to iterate further, either tx is our or their
@@ -846,17 +846,17 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
846846
}
847847

848848
// Check if any pending claim request must be rescheduled
849-
for (first_claim_txid, ref request) in self.pending_claim_requests.iter() {
849+
for (package_id, request) in self.pending_claim_requests.iter() {
850850
if let Some(h) = request.timer() {
851851
if cur_height >= h {
852-
bump_candidates.insert(*first_claim_txid, (*request).clone());
852+
bump_candidates.insert(*package_id, request.clone());
853853
}
854854
}
855855
}
856856

857857
// Build, bump and rebroadcast tx accordingly
858858
log_trace!(logger, "Bumping {} candidates", bump_candidates.len());
859-
for (first_claim_txid, request) in bump_candidates.iter() {
859+
for (package_id, request) in bump_candidates.iter() {
860860
if let Some((new_timer, new_feerate, bump_claim)) = self.generate_claim(cur_height, &request, &*fee_estimator, &*logger) {
861861
match bump_claim {
862862
OnchainClaim::Tx(bump_tx) => {
@@ -866,10 +866,10 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
866866
#[cfg(anchors)]
867867
OnchainClaim::Event(claim_event) => {
868868
log_info!(logger, "Yielding RBF-bumped onchain event to spend inputs {:?}", request.outpoints());
869-
self.pending_claim_events.insert(*first_claim_txid, claim_event);
869+
self.pending_claim_events.insert(*package_id, claim_event);
870870
},
871871
}
872-
if let Some(request) = self.pending_claim_requests.get_mut(first_claim_txid) {
872+
if let Some(request) = self.pending_claim_requests.get_mut(package_id) {
873873
request.set_timer(new_timer);
874874
request.set_feerate(new_feerate);
875875
}
@@ -915,12 +915,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
915915
//- resurect outpoint back in its claimable set and regenerate tx
916916
match entry.event {
917917
OnchainEvent::ContentiousOutpoint { package } => {
918-
if let Some(ancestor_claimable_txid) = self.claimable_outpoints.get(package.outpoints()[0]) {
919-
if let Some(request) = self.pending_claim_requests.get_mut(&ancestor_claimable_txid.0) {
918+
if let Some(pending_claim) = self.claimable_outpoints.get(package.outpoints()[0]) {
919+
if let Some(request) = self.pending_claim_requests.get_mut(&pending_claim.0) {
920920
request.merge_package(package);
921921
// Using a HashMap guarantee us than if we have multiple outpoints getting
922922
// resurrected only one bump claim tx is going to be broadcast
923-
bump_candidates.insert(ancestor_claimable_txid.clone(), request.clone());
923+
bump_candidates.insert(pending_claim.clone(), request.clone());
924924
}
925925
}
926926
},
@@ -930,7 +930,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
930930
self.onchain_events_awaiting_threshold_conf.push(entry);
931931
}
932932
}
933-
for (_first_claim_txid_height, request) in bump_candidates.iter_mut() {
933+
for ((_package_id, _), request) in bump_candidates.iter_mut() {
934934
if let Some((new_timer, new_feerate, bump_claim)) = self.generate_claim(height, &request, fee_estimator, &&*logger) {
935935
request.set_timer(new_timer);
936936
request.set_feerate(new_feerate);
@@ -942,7 +942,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
942942
#[cfg(anchors)]
943943
OnchainClaim::Event(claim_event) => {
944944
log_info!(logger, "Yielding onchain event after reorg to spend inputs {:?}", request.outpoints());
945-
self.pending_claim_events.insert(_first_claim_txid_height.0, claim_event);
945+
self.pending_claim_events.insert(_package_id, claim_event);
946946
},
947947
}
948948
}

0 commit comments

Comments
 (0)