Skip to content

Commit

Permalink
Add deadline height to UrgentOnChainSweep
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Jan 27, 2025
1 parent 3718da0 commit faa33f1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl FeeEstimator for FuzzEstimator {
// always return a HighPriority feerate here which is >= the maximum Normal feerate and a
// Background feerate which is <= the minimum Normal feerate.
match conf_target {
ConfirmationTarget::MaximumFeeEstimate | ConfirmationTarget::UrgentOnChainSweep => {
ConfirmationTarget::MaximumFeeEstimate | ConfirmationTarget::UrgentOnChainSweep(_) => {
MAX_FEE
},
ConfirmationTarget::ChannelCloseMinimum
Expand Down
4 changes: 3 additions & 1 deletion lightning/src/chain/chaininterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ pub enum ConfirmationTarget {
/// Generally we have in the high tens to low hundreds of blocks to get our transaction
/// on-chain (it doesn't have to happen in the next few blocks!), but we shouldn't risk too low
/// a fee - this should be a relatively high priority feerate.
UrgentOnChainSweep,
///
/// If a target confirmation height is known, it can be set as the parameter.
UrgentOnChainSweep(Option<u32>),
/// This is the lowest feerate we will allow our channel counterparty to have in an anchor
/// channel in order to close the channel if a channel party goes away.
///
Expand Down
25 changes: 19 additions & 6 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2744,19 +2744,32 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
// Treat the sweep as urgent as long as there is at least one HTLC which is pending on a
// valid commitment transaction.
if !self.current_holder_commitment_tx.htlc_outputs.is_empty() {
return ConfirmationTarget::UrgentOnChainSweep;
let minimum_expiry = self.current_holder_commitment_tx.htlc_outputs
.iter()
.map(|o| o.0.cltv_expiry)
.min();
return ConfirmationTarget::UrgentOnChainSweep(minimum_expiry);
}
if self.prev_holder_signed_commitment_tx.as_ref().map(|t| !t.htlc_outputs.is_empty()).unwrap_or(false) {
return ConfirmationTarget::UrgentOnChainSweep;
let minimum_expiry = self.prev_holder_signed_commitment_tx.as_ref().map(|t| t.htlc_outputs
.iter()
.map(|o| o.0.cltv_expiry)
.min()
).flatten();
return ConfirmationTarget::UrgentOnChainSweep(minimum_expiry);
}
if let Some(txid) = self.current_counterparty_commitment_txid {
if !self.counterparty_claimable_outpoints.get(&txid).unwrap().is_empty() {
return ConfirmationTarget::UrgentOnChainSweep;
let claimable_outpoints = self.counterparty_claimable_outpoints.get(&txid).unwrap();
if !claimable_outpoints.is_empty() {
let minimum_expiry = claimable_outpoints.iter().map(|o|o.0.cltv_expiry).min();
return ConfirmationTarget::UrgentOnChainSweep(minimum_expiry);
}
}
if let Some(txid) = self.prev_counterparty_commitment_txid {
if !self.counterparty_claimable_outpoints.get(&txid).unwrap().is_empty() {
return ConfirmationTarget::UrgentOnChainSweep;
let claimable_outpoints = self.counterparty_claimable_outpoints.get(&txid).unwrap();
if !claimable_outpoints.is_empty() {
let minimum_expiry = claimable_outpoints.iter().map(|o|o.0.cltv_expiry).min();
return ConfirmationTarget::UrgentOnChainSweep(minimum_expiry);
}
}
ConfirmationTarget::OutputSpendingFee
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ mod tests {
1,
1,
&&broadcaster,
ConfirmationTarget::UrgentOnChainSweep,
ConfirmationTarget::UrgentOnChainSweep(Some(2)),
&fee_estimator,
&logger,
);
Expand All @@ -1440,7 +1440,7 @@ mod tests {
2,
2,
&&broadcaster,
ConfirmationTarget::UrgentOnChainSweep,
ConfirmationTarget::UrgentOnChainSweep(Some(3)),
&fee_estimator,
&logger,
);
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/chain/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ mod tests {
let test_fee_estimator = &TestFeeEstimator { sat_per_kw };
let fee_estimator = LowerBoundedFeeEstimator::new(test_fee_estimator);
let fee_rate_strategy = FeerateStrategy::ForceBump;
let confirmation_target = ConfirmationTarget::UrgentOnChainSweep;
let confirmation_target = ConfirmationTarget::UrgentOnChainSweep(None);

{
// Check underflow doesn't occur
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/monitor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2556,7 +2556,7 @@ fn do_test_yield_anchors_events(have_htlcs: bool) {
// Note that if we use the wrong target, we will immediately broadcast the commitment
// transaction as no bump is required.
if have_htlcs {
nodes[0].fee_estimator.target_override.lock().unwrap().insert(ConfirmationTarget::UrgentOnChainSweep, 500);
nodes[0].fee_estimator.target_override.lock().unwrap().insert(ConfirmationTarget::UrgentOnChainSweep(Some(81)), 500);
} else {
nodes[0].fee_estimator.target_override.lock().unwrap().insert(ConfirmationTarget::OutputSpendingFee, 500);
}
Expand Down

0 comments on commit faa33f1

Please sign in to comment.