Skip to content

Commit 0ab997b

Browse files
committed
Rename keys for OnchainTxHandler::claimable_outpoints map
1 parent b4d26a6 commit 0ab997b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

lightning/src/chain/onchaintx.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
255255
#[cfg(anchors)]
256256
pending_claim_events: HashMap<PackageID, ClaimEvent>,
257257

258-
// Used to link outpoints claimed in a connected block to a pending claim request.
259-
// Key is outpoint than monitor parsing has detected we have keys/scripts to claim
260-
// Value is (pending claim request identifier, confirmation_block), identifier
261-
// is txid of the initial claiming transaction and is immutable until outpoint is
262-
// post-anti-reorg-delay solved, confirmaiton_block is used to erase entry if
263-
// block with output gets disconnected.
258+
// Used to link outpoints claimed in a connected block to a pending claim request. The keys
259+
// represent the outpoints that our `ChannelMonitor` has detected we have keys/scripts to claim.
260+
// The values track the pending claim request identifier and the initial confirmation block
261+
// height, and are immutable until the outpoint is has enough confirmations to meet our
262+
// [`ANTI_REORG_DELAY`]. The initial confirmation block height is used to remove the entry if
263+
// the block gets disconnected.
264264
#[cfg(test)] // Used in functional_test to verify sanitization
265265
pub claimable_outpoints: HashMap<BitcoinOutPoint, (PackageID, u32)>,
266266
#[cfg(not(test))]
@@ -498,12 +498,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
498498
// transaction is reorged out.
499499
let mut all_inputs_have_confirmed_spend = true;
500500
for outpoint in request_outpoints.iter() {
501-
if let Some(first_claim_txid_height) = self.claimable_outpoints.get(*outpoint) {
501+
if let Some((request_package_id, _)) = self.claimable_outpoints.get(*outpoint) {
502502
// We check for outpoint spends within claims individually rather than as a set
503503
// since requests can have outpoints split off.
504504
if !self.onchain_events_awaiting_threshold_conf.iter()
505505
.any(|event_entry| if let OnchainEvent::Claim { package_id } = event_entry.event {
506-
first_claim_txid_height.0 == package_id
506+
*request_package_id == package_id
507507
} else {
508508
// The onchain event is not a claim, keep seeking until we find one.
509509
false
@@ -748,9 +748,9 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
748748
// Scan all input to verify is one of the outpoint spent is of interest for us
749749
let mut claimed_outputs_material = Vec::new();
750750
for inp in &tx.input {
751-
if let Some(first_claim_txid_height) = self.claimable_outpoints.get(&inp.previous_output) {
751+
if let Some((package_id, _)) = self.claimable_outpoints.get(&inp.previous_output) {
752752
// If outpoint has claim request pending on it...
753-
if let Some(request) = self.pending_claim_requests.get_mut(&first_claim_txid_height.0) {
753+
if let Some(request) = self.pending_claim_requests.get_mut(package_id) {
754754
//... we need to verify equality between transaction outpoints and claim request
755755
// outpoints to know if transaction is the original claim or a bumped one issued
756756
// by us.
@@ -770,7 +770,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
770770
txid: tx.txid(),
771771
height: conf_height,
772772
block_hash: Some(conf_hash),
773-
event: OnchainEvent::Claim { package_id: first_claim_txid_height.0 }
773+
event: OnchainEvent::Claim { package_id: *package_id }
774774
};
775775
if !self.onchain_events_awaiting_threshold_conf.contains(&entry) {
776776
self.onchain_events_awaiting_threshold_conf.push(entry);
@@ -797,7 +797,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
797797
}
798798
//TODO: recompute soonest_timelock to avoid wasting a bit on fees
799799
if at_least_one_drop {
800-
bump_candidates.insert(first_claim_txid_height.0.clone(), request.clone());
800+
bump_candidates.insert(*package_id, request.clone());
801801
}
802802
}
803803
break; //No need to iterate further, either tx is our or their
@@ -850,17 +850,17 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
850850
}
851851

852852
// Check if any pending claim request must be rescheduled
853-
for (first_claim_txid, ref request) in self.pending_claim_requests.iter() {
853+
for (package_id, request) in self.pending_claim_requests.iter() {
854854
if let Some(h) = request.timer() {
855855
if cur_height >= h {
856-
bump_candidates.insert(*first_claim_txid, (*request).clone());
856+
bump_candidates.insert(*package_id, request.clone());
857857
}
858858
}
859859
}
860860

861861
// Build, bump and rebroadcast tx accordingly
862862
log_trace!(logger, "Bumping {} candidates", bump_candidates.len());
863-
for (first_claim_txid, request) in bump_candidates.iter() {
863+
for (package_id, request) in bump_candidates.iter() {
864864
if let Some((new_timer, new_feerate, bump_claim)) = self.generate_claim(cur_height, &request, &*fee_estimator, &*logger) {
865865
match bump_claim {
866866
OnchainClaim::Tx(bump_tx) => {
@@ -870,10 +870,10 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
870870
#[cfg(anchors)]
871871
OnchainClaim::Event(claim_event) => {
872872
log_info!(logger, "Yielding RBF-bumped onchain event to spend inputs {:?}", request.outpoints());
873-
self.pending_claim_events.insert(*first_claim_txid, claim_event);
873+
self.pending_claim_events.insert(*package_id, claim_event);
874874
},
875875
}
876-
if let Some(request) = self.pending_claim_requests.get_mut(first_claim_txid) {
876+
if let Some(request) = self.pending_claim_requests.get_mut(package_id) {
877877
request.set_timer(new_timer);
878878
request.set_feerate(new_feerate);
879879
}
@@ -934,7 +934,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
934934
self.onchain_events_awaiting_threshold_conf.push(entry);
935935
}
936936
}
937-
for (_first_claim_txid_height, request) in bump_candidates.iter_mut() {
937+
for ((_package_id, _), request) in bump_candidates.iter_mut() {
938938
if let Some((new_timer, new_feerate, bump_claim)) = self.generate_claim(height, &request, fee_estimator, &&*logger) {
939939
request.set_timer(new_timer);
940940
request.set_feerate(new_feerate);
@@ -946,7 +946,7 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
946946
#[cfg(anchors)]
947947
OnchainClaim::Event(claim_event) => {
948948
log_info!(logger, "Yielding onchain event after reorg to spend inputs {:?}", request.outpoints());
949-
self.pending_claim_events.insert(_first_claim_txid_height.0, claim_event);
949+
self.pending_claim_events.insert(_package_id, claim_event);
950950
},
951951
}
952952
}

0 commit comments

Comments
 (0)