Skip to content

Commit 98ae8bf

Browse files
committed
Make all internal signatures accept LowerBoundedFeeEstimator
1 parent 67f7401 commit 98ae8bf

File tree

6 files changed

+62
-42
lines changed

6 files changed

+62
-42
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use ln::chan_utils::{CounterpartyCommitmentSecrets, HTLCOutputInCommitment, HTLC
4040
use ln::channelmanager::HTLCSource;
4141
use chain;
4242
use chain::{BestBlock, WatchedOutput};
43-
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
43+
use chain::chaininterface::{BroadcasterInterface, FeeEstimator, LowerBoundedFeeEstimator};
4444
use chain::transaction::{OutPoint, TransactionData};
4545
use chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, KeysInterface};
4646
use chain::onchaintx::OnchainTxHandler;
@@ -1099,7 +1099,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
10991099
payment_hash: &PaymentHash,
11001100
payment_preimage: &PaymentPreimage,
11011101
broadcaster: &B,
1102-
fee_estimator: &F,
1102+
fee_estimator: &LowerBoundedFeeEstimator<F>,
11031103
logger: &L,
11041104
) where
11051105
B::Target: BroadcasterInterface,
@@ -1295,8 +1295,9 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
12951295
F::Target: FeeEstimator,
12961296
L::Target: Logger,
12971297
{
1298+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
12981299
self.inner.lock().unwrap().transactions_confirmed(
1299-
header, txdata, height, broadcaster, fee_estimator, logger)
1300+
header, txdata, height, broadcaster, &bounded_fee_estimator, logger)
13001301
}
13011302

13021303
/// Processes a transaction that was reorganized out of the chain.
@@ -1316,8 +1317,9 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
13161317
F::Target: FeeEstimator,
13171318
L::Target: Logger,
13181319
{
1320+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
13191321
self.inner.lock().unwrap().transaction_unconfirmed(
1320-
txid, broadcaster, fee_estimator, logger);
1322+
txid, broadcaster, &bounded_fee_estimator, logger);
13211323
}
13221324

13231325
/// Updates the monitor with the current best chain tip, returning new outputs to watch. See
@@ -1340,8 +1342,9 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
13401342
F::Target: FeeEstimator,
13411343
L::Target: Logger,
13421344
{
1345+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
13431346
self.inner.lock().unwrap().best_block_updated(
1344-
header, height, broadcaster, fee_estimator, logger)
1347+
header, height, broadcaster, &bounded_fee_estimator, logger)
13451348
}
13461349

13471350
/// Returns the set of txids that should be monitored for re-organization out of the chain.
@@ -1877,7 +1880,9 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18771880

18781881
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
18791882
/// commitment_tx_infos which contain the payment hash have been revoked.
1880-
fn provide_payment_preimage<B: Deref, F: Deref, L: Deref>(&mut self, payment_hash: &PaymentHash, payment_preimage: &PaymentPreimage, broadcaster: &B, fee_estimator: &F, logger: &L)
1883+
fn provide_payment_preimage<B: Deref, F: Deref, L: Deref>(
1884+
&mut self, payment_hash: &PaymentHash, payment_preimage: &PaymentPreimage, broadcaster: &B,
1885+
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L)
18811886
where B::Target: BroadcasterInterface,
18821887
F::Target: FeeEstimator,
18831888
L::Target: Logger,
@@ -1975,7 +1980,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19751980
},
19761981
ChannelMonitorUpdateStep::PaymentPreimage { payment_preimage } => {
19771982
log_trace!(logger, "Updating ChannelMonitor with payment preimage");
1978-
self.provide_payment_preimage(&PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()), &payment_preimage, broadcaster, fee_estimator, logger)
1983+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
1984+
self.provide_payment_preimage(&PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()), &payment_preimage, broadcaster, &bounded_fee_estimator, logger)
19791985
},
19801986
ChannelMonitorUpdateStep::CommitmentSecret { idx, secret } => {
19811987
log_trace!(logger, "Updating ChannelMonitor with commitment secret");
@@ -2401,15 +2407,16 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
24012407
let block_hash = header.block_hash();
24022408
self.best_block = BestBlock::new(block_hash, height);
24032409

2404-
self.transactions_confirmed(header, txdata, height, broadcaster, fee_estimator, logger)
2410+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
2411+
self.transactions_confirmed(header, txdata, height, broadcaster, &bounded_fee_estimator, logger)
24052412
}
24062413

24072414
fn best_block_updated<B: Deref, F: Deref, L: Deref>(
24082415
&mut self,
24092416
header: &BlockHeader,
24102417
height: u32,
24112418
broadcaster: B,
2412-
fee_estimator: F,
2419+
fee_estimator: &LowerBoundedFeeEstimator<F>,
24132420
logger: L,
24142421
) -> Vec<TransactionOutputs>
24152422
where
@@ -2436,7 +2443,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
24362443
txdata: &TransactionData,
24372444
height: u32,
24382445
broadcaster: B,
2439-
fee_estimator: F,
2446+
fee_estimator: &LowerBoundedFeeEstimator<F>,
24402447
logger: L,
24412448
) -> Vec<TransactionOutputs>
24422449
where
@@ -2533,7 +2540,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
25332540
mut watch_outputs: Vec<TransactionOutputs>,
25342541
mut claimable_outpoints: Vec<PackageTemplate>,
25352542
broadcaster: &B,
2536-
fee_estimator: &F,
2543+
fee_estimator: &LowerBoundedFeeEstimator<F>,
25372544
logger: &L,
25382545
) -> Vec<TransactionOutputs>
25392546
where
@@ -2671,7 +2678,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26712678
//- maturing spendable output has transaction paying us has been disconnected
26722679
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| entry.height < height);
26732680

2674-
self.onchain_tx_handler.block_disconnected(height, broadcaster, fee_estimator, logger);
2681+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
2682+
self.onchain_tx_handler.block_disconnected(height, broadcaster, &bounded_fee_estimator, logger);
26752683

26762684
self.best_block = BestBlock::new(header.prev_blockhash, height - 1);
26772685
}
@@ -2680,7 +2688,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
26802688
&mut self,
26812689
txid: &Txid,
26822690
broadcaster: B,
2683-
fee_estimator: F,
2691+
fee_estimator: &LowerBoundedFeeEstimator<F>,
26842692
logger: L,
26852693
) where
26862694
B::Target: BroadcasterInterface,
@@ -3420,6 +3428,8 @@ mod tests {
34203428

34213429
use hex;
34223430

3431+
use crate::chain::chaininterface::LowerBoundedFeeEstimator;
3432+
34233433
use super::ChannelMonitorUpdateStep;
34243434
use ::{check_added_monitors, check_closed_broadcast, check_closed_event, check_spends, get_local_commitment_txn, get_monitor, get_route_and_payment_hash, unwrap_send_err};
34253435
use chain::{BestBlock, Confirm};
@@ -3541,7 +3551,7 @@ mod tests {
35413551
let secp_ctx = Secp256k1::new();
35423552
let logger = Arc::new(TestLogger::new());
35433553
let broadcaster = Arc::new(TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new()), blocks: Arc::new(Mutex::new(Vec::new()))});
3544-
let fee_estimator = Arc::new(TestFeeEstimator { sat_per_kw: Mutex::new(253) });
3554+
let fee_estimator = TestFeeEstimator { sat_per_kw: Mutex::new(253) };
35453555

35463556
let dummy_key = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
35473557
let dummy_tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: Vec::new() };
@@ -3640,7 +3650,8 @@ mod tests {
36403650
monitor.provide_latest_counterparty_commitment_tx(dummy_txid, preimages_slice_to_htlc_outputs!(preimages[17..20]), 281474976710653, dummy_key, &logger);
36413651
monitor.provide_latest_counterparty_commitment_tx(dummy_txid, preimages_slice_to_htlc_outputs!(preimages[18..20]), 281474976710652, dummy_key, &logger);
36423652
for &(ref preimage, ref hash) in preimages.iter() {
3643-
monitor.provide_payment_preimage(hash, preimage, &broadcaster, &fee_estimator, &logger);
3653+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&fee_estimator);
3654+
monitor.provide_payment_preimage(hash, preimage, &broadcaster, &bounded_fee_estimator, &logger);
36443655
}
36453656

36463657
// Now provide a secret, pruning preimages 10-15

lightning/src/chain/onchaintx.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use bitcoin::secp256k1;
2424
use ln::msgs::DecodeError;
2525
use ln::PaymentPreimage;
2626
use ln::chan_utils::{ChannelTransactionParameters, HolderCommitmentTransaction};
27-
use chain::chaininterface::{FeeEstimator, BroadcasterInterface};
27+
use chain::chaininterface::{FeeEstimator, BroadcasterInterface, LowerBoundedFeeEstimator};
2828
use chain::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER};
2929
use chain::keysinterface::{Sign, KeysInterface};
3030
use chain::package::PackageTemplate;
@@ -377,7 +377,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
377377
/// (CSV or CLTV following cases). In case of high-fee spikes, claim tx may stuck in the mempool, so you need to bump its feerate quickly using Replace-By-Fee or Child-Pay-For-Parent.
378378
/// Panics if there are signing errors, because signing operations in reaction to on-chain events
379379
/// are not expected to fail, and if they do, we may lose funds.
380-
fn generate_claim_tx<F: Deref, L: Deref>(&mut self, cur_height: u32, cached_request: &PackageTemplate, fee_estimator: &F, logger: &L) -> Option<(Option<u32>, u64, Transaction)>
380+
fn generate_claim_tx<F: Deref, L: Deref>(&mut self, cur_height: u32, cached_request: &PackageTemplate, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> Option<(Option<u32>, u64, Transaction)>
381381
where F::Target: FeeEstimator,
382382
L::Target: Logger,
383383
{
@@ -415,7 +415,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
415415
/// `conf_height` represents the height at which the transactions in `txn_matched` were
416416
/// confirmed. This does not need to equal the current blockchain tip height, which should be
417417
/// provided via `cur_height`, however it must never be higher than `cur_height`.
418-
pub(crate) fn update_claims_view<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], requests: Vec<PackageTemplate>, conf_height: u32, cur_height: u32, broadcaster: &B, fee_estimator: &F, logger: &L)
418+
pub(crate) fn update_claims_view<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], requests: Vec<PackageTemplate>, conf_height: u32, cur_height: u32, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L)
419419
where B::Target: BroadcasterInterface,
420420
F::Target: FeeEstimator,
421421
L::Target: Logger,
@@ -617,7 +617,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
617617
&mut self,
618618
txid: &Txid,
619619
broadcaster: B,
620-
fee_estimator: F,
620+
fee_estimator: &LowerBoundedFeeEstimator<F>,
621621
logger: L,
622622
) where
623623
B::Target: BroadcasterInterface,
@@ -637,7 +637,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
637637
}
638638
}
639639

640-
pub(crate) fn block_disconnected<B: Deref, F: Deref, L: Deref>(&mut self, height: u32, broadcaster: B, fee_estimator: F, logger: L)
640+
pub(crate) fn block_disconnected<B: Deref, F: Deref, L: Deref>(&mut self, height: u32, broadcaster: B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: L)
641641
where B::Target: BroadcasterInterface,
642642
F::Target: FeeEstimator,
643643
L::Target: Logger,
@@ -667,7 +667,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
667667
}
668668
}
669669
for (_, request) in bump_candidates.iter_mut() {
670-
if let Some((new_timer, new_feerate, bump_tx)) = self.generate_claim_tx(height, &request, &&*fee_estimator, &&*logger) {
670+
if let Some((new_timer, new_feerate, bump_tx)) = self.generate_claim_tx(height, &request, &fee_estimator, &&*logger) {
671671
request.set_timer(new_timer);
672672
request.set_feerate(new_feerate);
673673
log_info!(logger, "Broadcasting onchain {}", log_tx!(bump_tx));

lightning/src/chain/package.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ use core::mem;
3838
use core::ops::Deref;
3939
use bitcoin::Witness;
4040

41+
use super::chaininterface::LowerBoundedFeeEstimator;
42+
4143
const MAX_ALLOC_SIZE: usize = 64*1024;
4244

4345

@@ -665,7 +667,7 @@ impl PackageTemplate {
665667
/// Returns value in satoshis to be included as package outgoing output amount and feerate
666668
/// which was used to generate the value. Will not return less than `dust_limit_sats` for the
667669
/// value.
668-
pub(crate) fn compute_package_output<F: Deref, L: Deref>(&self, predicted_weight: usize, dust_limit_sats: u64, fee_estimator: &F, logger: &L) -> Option<(u64, u64)>
670+
pub(crate) fn compute_package_output<F: Deref, L: Deref>(&self, predicted_weight: usize, dust_limit_sats: u64, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> Option<(u64, u64)>
669671
where F::Target: FeeEstimator,
670672
L::Target: Logger,
671673
{
@@ -772,7 +774,7 @@ impl Readable for PackageTemplate {
772774
/// If the proposed fee is less than the available spent output's values, we return the proposed
773775
/// fee and the corresponding updated feerate. If the proposed fee is equal or more than the
774776
/// available spent output's values, we return nothing
775-
fn compute_fee_from_spent_amounts<F: Deref, L: Deref>(input_amounts: u64, predicted_weight: usize, fee_estimator: &F, logger: &L) -> Option<(u64, u64)>
777+
fn compute_fee_from_spent_amounts<F: Deref, L: Deref>(input_amounts: u64, predicted_weight: usize, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> Option<(u64, u64)>
776778
where F::Target: FeeEstimator,
777779
L::Target: Logger,
778780
{
@@ -808,7 +810,7 @@ fn compute_fee_from_spent_amounts<F: Deref, L: Deref>(input_amounts: u64, predic
808810
/// attempt, use them. Otherwise, blindly bump the feerate by 25% of the previous feerate. We also
809811
/// verify that those bumping heuristics respect BIP125 rules 3) and 4) and if required adjust
810812
/// the new fee to meet the RBF policy requirement.
811-
fn feerate_bump<F: Deref, L: Deref>(predicted_weight: usize, input_amounts: u64, previous_feerate: u64, fee_estimator: &F, logger: &L) -> Option<(u64, u64)>
813+
fn feerate_bump<F: Deref, L: Deref>(predicted_weight: usize, input_amounts: u64, previous_feerate: u64, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) -> Option<(u64, u64)>
812814
where F::Target: FeeEstimator,
813815
L::Target: Logger,
814816
{

lightning/src/ln/channel.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use ln::channelmanager::{CounterpartyForwardingInfo, PendingHTLCStatus, HTLCSour
3131
use ln::chan_utils::{CounterpartyCommitmentSecrets, TxCreationKeys, HTLCOutputInCommitment, htlc_success_tx_weight, htlc_timeout_tx_weight, make_funding_redeemscript, ChannelPublicKeys, CommitmentTransaction, HolderCommitmentTransaction, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, MAX_HTLCS, get_commitment_transaction_number_obscure_factor, ClosingTransaction};
3232
use ln::chan_utils;
3333
use chain::BestBlock;
34-
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
34+
use chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBoundedFeeEstimator};
3535
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
3636
use chain::transaction::{OutPoint, TransactionData};
3737
use chain::keysinterface::{Sign, KeysInterface};
@@ -917,7 +917,7 @@ impl<Signer: Sign> Channel<Signer> {
917917
return Err(APIError::APIMisuseError { err: format!("Holder selected channel reserve below implemention limit dust_limit_satoshis {}", holder_selected_channel_reserve_satoshis) });
918918
}
919919

920-
let feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
920+
let feerate = LowerBoundedFeeEstimator::new(fee_estimator).get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
921921

922922
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
923923
let commitment_tx_fee = Self::commit_tx_fee_msat(feerate, MIN_AFFORDABLE_HTLC_COUNT, opt_anchors);
@@ -1056,7 +1056,7 @@ impl<Signer: Sign> Channel<Signer> {
10561056
})
10571057
}
10581058

1059-
fn check_remote_fee<F: Deref>(fee_estimator: &F, feerate_per_kw: u32) -> Result<(), ChannelError>
1059+
fn check_remote_fee<F: Deref>(fee_estimator: &LowerBoundedFeeEstimator<F>, feerate_per_kw: u32) -> Result<(), ChannelError>
10601060
where F::Target: FeeEstimator
10611061
{
10621062
// We only bound the fee updates on the upper side to prevent completely absurd feerates,
@@ -1160,7 +1160,7 @@ impl<Signer: Sign> Channel<Signer> {
11601160
if msg.htlc_minimum_msat >= full_channel_value_msat {
11611161
return Err(ChannelError::Close(format!("Minimum htlc value ({}) was larger than full channel value ({})", msg.htlc_minimum_msat, full_channel_value_msat)));
11621162
}
1163-
Channel::<Signer>::check_remote_fee(fee_estimator, msg.feerate_per_kw)?;
1163+
Channel::<Signer>::check_remote_fee(&LowerBoundedFeeEstimator::new(fee_estimator), msg.feerate_per_kw)?;
11641164

11651165
let max_counterparty_selected_contest_delay = u16::min(config.channel_handshake_limits.their_to_self_delay, MAX_LOCAL_BREAKDOWN_TIMEOUT);
11661166
if msg.to_self_delay > max_counterparty_selected_contest_delay {
@@ -3696,7 +3696,7 @@ impl<Signer: Sign> Channel<Signer> {
36963696
if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {
36973697
return Err(ChannelError::Close("Peer sent update_fee when we needed a channel_reestablish".to_owned()));
36983698
}
3699-
Channel::<Signer>::check_remote_fee(fee_estimator, msg.feerate_per_kw)?;
3699+
Channel::<Signer>::check_remote_fee(&LowerBoundedFeeEstimator::new(fee_estimator), msg.feerate_per_kw)?;
37003700
let feerate_over_dust_buffer = msg.feerate_per_kw > self.get_dust_buffer_feerate(None);
37013701

37023702
self.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
@@ -4013,7 +4013,8 @@ impl<Signer: Sign> Channel<Signer> {
40134013
/// Calculates and returns our minimum and maximum closing transaction fee amounts, in whole
40144014
/// satoshis. The amounts remain consistent unless a peer disconnects/reconnects or we restart,
40154015
/// at which point they will be recalculated.
4016-
fn calculate_closing_fee_limits<F: Deref>(&mut self, fee_estimator: &F) -> (u64, u64)
4016+
fn calculate_closing_fee_limits<F: Deref>(&mut self, fee_estimator: &LowerBoundedFeeEstimator<F>)
4017+
-> (u64, u64)
40174018
where F::Target: FeeEstimator
40184019
{
40194020
if let Some((min, max)) = self.closing_fee_limits { return (min, max); }
@@ -4097,12 +4098,13 @@ impl<Signer: Sign> Channel<Signer> {
40974098

40984099
if !self.is_outbound() {
40994100
if let Some(msg) = &self.pending_counterparty_closing_signed.take() {
4100-
return self.closing_signed(fee_estimator, &msg);
4101+
return self.closing_signed(&fee_estimator, &msg);
41014102
}
41024103
return Ok((None, None));
41034104
}
41044105

4105-
let (our_min_fee, our_max_fee) = self.calculate_closing_fee_limits(fee_estimator);
4106+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
4107+
let (our_min_fee, our_max_fee) = self.calculate_closing_fee_limits(&bounded_fee_estimator);
41064108

41074109
assert!(self.shutdown_scriptpubkey.is_some());
41084110
let (closing_tx, total_fee_satoshis) = self.build_closing_transaction(our_min_fee, false);
@@ -4300,7 +4302,8 @@ impl<Signer: Sign> Channel<Signer> {
43004302
}
43014303
}
43024304

4303-
let (our_min_fee, our_max_fee) = self.calculate_closing_fee_limits(fee_estimator);
4305+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
4306+
let (our_min_fee, our_max_fee) = self.calculate_closing_fee_limits(&bounded_fee_estimator);
43044307

43054308
macro_rules! propose_fee {
43064309
($new_fee: expr) => {
@@ -6572,7 +6575,7 @@ mod tests {
65726575
use ln::chan_utils;
65736576
use ln::chan_utils::{htlc_success_tx_weight, htlc_timeout_tx_weight};
65746577
use chain::BestBlock;
6575-
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
6578+
use chain::chaininterface::{FeeEstimator, LowerBoundedFeeEstimator, ConfirmationTarget};
65766579
use chain::keysinterface::{InMemorySigner, Recipient, KeyMaterial, KeysInterface};
65776580
use chain::transaction::OutPoint;
65786581
use util::config::UserConfig;
@@ -6611,7 +6614,9 @@ mod tests {
66116614
fn test_no_fee_check_overflow() {
66126615
// Previously, calling `check_remote_fee` with a fee of 0xffffffff would overflow in
66136616
// arithmetic, causing a panic with debug assertions enabled.
6614-
assert!(Channel::<InMemorySigner>::check_remote_fee(&&TestFeeEstimator { fee_est: 42 }, u32::max_value()).is_err());
6617+
let fee_est = TestFeeEstimator { fee_est: 42 };
6618+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&fee_est);
6619+
assert!(Channel::<InMemorySigner>::check_remote_fee(&bounded_fee_estimator, u32::max_value()).is_err());
66156620
}
66166621

66176622
struct Keys {
@@ -6661,11 +6666,10 @@ mod tests {
66616666
returns: non_v0_segwit_shutdown_script.clone(),
66626667
});
66636668

6664-
let fee_estimator = TestFeeEstimator { fee_est: 253 };
66656669
let secp_ctx = Secp256k1::new();
66666670
let node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
66676671
let config = UserConfig::default();
6668-
match Channel::<EnforcingSigner>::new_outbound(&&fee_estimator, &&keys_provider, node_id, &features, 10000000, 100000, 42, &config, 0, 42) {
6672+
match Channel::<EnforcingSigner>::new_outbound(&&TestFeeEstimator { fee_est: 253 }, &&keys_provider, node_id, &features, 10000000, 100000, 42, &config, 0, 42) {
66696673
Err(APIError::IncompatibleShutdownScript { script }) => {
66706674
assert_eq!(script.into_inner(), non_v0_segwit_shutdown_script.into_inner());
66716675
},

0 commit comments

Comments
 (0)