Skip to content

Commit faa33f1

Browse files
committed
Add deadline height to UrgentOnChainSweep
1 parent 3718da0 commit faa33f1

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

fuzz/src/chanmon_consistency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl FeeEstimator for FuzzEstimator {
9898
// always return a HighPriority feerate here which is >= the maximum Normal feerate and a
9999
// Background feerate which is <= the minimum Normal feerate.
100100
match conf_target {
101-
ConfirmationTarget::MaximumFeeEstimate | ConfirmationTarget::UrgentOnChainSweep => {
101+
ConfirmationTarget::MaximumFeeEstimate | ConfirmationTarget::UrgentOnChainSweep(_) => {
102102
MAX_FEE
103103
},
104104
ConfirmationTarget::ChannelCloseMinimum

lightning/src/chain/chaininterface.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ pub enum ConfirmationTarget {
6161
/// Generally we have in the high tens to low hundreds of blocks to get our transaction
6262
/// on-chain (it doesn't have to happen in the next few blocks!), but we shouldn't risk too low
6363
/// a fee - this should be a relatively high priority feerate.
64-
UrgentOnChainSweep,
64+
///
65+
/// If a target confirmation height is known, it can be set as the parameter.
66+
UrgentOnChainSweep(Option<u32>),
6567
/// This is the lowest feerate we will allow our channel counterparty to have in an anchor
6668
/// channel in order to close the channel if a channel party goes away.
6769
///

lightning/src/chain/channelmonitor.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -2744,19 +2744,32 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
27442744
// Treat the sweep as urgent as long as there is at least one HTLC which is pending on a
27452745
// valid commitment transaction.
27462746
if !self.current_holder_commitment_tx.htlc_outputs.is_empty() {
2747-
return ConfirmationTarget::UrgentOnChainSweep;
2747+
let minimum_expiry = self.current_holder_commitment_tx.htlc_outputs
2748+
.iter()
2749+
.map(|o| o.0.cltv_expiry)
2750+
.min();
2751+
return ConfirmationTarget::UrgentOnChainSweep(minimum_expiry);
27482752
}
27492753
if self.prev_holder_signed_commitment_tx.as_ref().map(|t| !t.htlc_outputs.is_empty()).unwrap_or(false) {
2750-
return ConfirmationTarget::UrgentOnChainSweep;
2754+
let minimum_expiry = self.prev_holder_signed_commitment_tx.as_ref().map(|t| t.htlc_outputs
2755+
.iter()
2756+
.map(|o| o.0.cltv_expiry)
2757+
.min()
2758+
).flatten();
2759+
return ConfirmationTarget::UrgentOnChainSweep(minimum_expiry);
27512760
}
27522761
if let Some(txid) = self.current_counterparty_commitment_txid {
2753-
if !self.counterparty_claimable_outpoints.get(&txid).unwrap().is_empty() {
2754-
return ConfirmationTarget::UrgentOnChainSweep;
2762+
let claimable_outpoints = self.counterparty_claimable_outpoints.get(&txid).unwrap();
2763+
if !claimable_outpoints.is_empty() {
2764+
let minimum_expiry = claimable_outpoints.iter().map(|o|o.0.cltv_expiry).min();
2765+
return ConfirmationTarget::UrgentOnChainSweep(minimum_expiry);
27552766
}
27562767
}
27572768
if let Some(txid) = self.prev_counterparty_commitment_txid {
2758-
if !self.counterparty_claimable_outpoints.get(&txid).unwrap().is_empty() {
2759-
return ConfirmationTarget::UrgentOnChainSweep;
2769+
let claimable_outpoints = self.counterparty_claimable_outpoints.get(&txid).unwrap();
2770+
if !claimable_outpoints.is_empty() {
2771+
let minimum_expiry = claimable_outpoints.iter().map(|o|o.0.cltv_expiry).min();
2772+
return ConfirmationTarget::UrgentOnChainSweep(minimum_expiry);
27602773
}
27612774
}
27622775
ConfirmationTarget::OutputSpendingFee

lightning/src/chain/onchaintx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ mod tests {
14171417
1,
14181418
1,
14191419
&&broadcaster,
1420-
ConfirmationTarget::UrgentOnChainSweep,
1420+
ConfirmationTarget::UrgentOnChainSweep(Some(2)),
14211421
&fee_estimator,
14221422
&logger,
14231423
);
@@ -1440,7 +1440,7 @@ mod tests {
14401440
2,
14411441
2,
14421442
&&broadcaster,
1443-
ConfirmationTarget::UrgentOnChainSweep,
1443+
ConfirmationTarget::UrgentOnChainSweep(Some(3)),
14441444
&fee_estimator,
14451445
&logger,
14461446
);

lightning/src/chain/package.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ mod tests {
16891689
let test_fee_estimator = &TestFeeEstimator { sat_per_kw };
16901690
let fee_estimator = LowerBoundedFeeEstimator::new(test_fee_estimator);
16911691
let fee_rate_strategy = FeerateStrategy::ForceBump;
1692-
let confirmation_target = ConfirmationTarget::UrgentOnChainSweep;
1692+
let confirmation_target = ConfirmationTarget::UrgentOnChainSweep(None);
16931693

16941694
{
16951695
// Check underflow doesn't occur

lightning/src/ln/monitor_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ fn do_test_yield_anchors_events(have_htlcs: bool) {
25562556
// Note that if we use the wrong target, we will immediately broadcast the commitment
25572557
// transaction as no bump is required.
25582558
if have_htlcs {
2559-
nodes[0].fee_estimator.target_override.lock().unwrap().insert(ConfirmationTarget::UrgentOnChainSweep, 500);
2559+
nodes[0].fee_estimator.target_override.lock().unwrap().insert(ConfirmationTarget::UrgentOnChainSweep(Some(81)), 500);
25602560
} else {
25612561
nodes[0].fee_estimator.target_override.lock().unwrap().insert(ConfirmationTarget::OutputSpendingFee, 500);
25622562
}

0 commit comments

Comments
 (0)