Skip to content

Commit a491200

Browse files
committed
Avoid blanket implementing FeeEstimator for Deref<FeeEstimator>
This simplifies things for bindings (and, to some extent, downstream users) by exploiting the fact that we can always "clone" a reference to a struct by dereferencing and then creating a new reference.
1 parent ca93571 commit a491200

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl chain::Watch<EnforcingSigner> for TestChainMonitor {
140140
};
141141
let deserialized_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingSigner>)>::
142142
read(&mut Cursor::new(&map_entry.get().1), &*self.keys).unwrap().1;
143-
deserialized_monitor.update_monitor(&update, &&TestBroadcaster{}, &&FuzzEstimator { ret_val: atomic::AtomicU32::new(253) }, &self.logger).unwrap();
143+
deserialized_monitor.update_monitor(&update, &&TestBroadcaster{}, &FuzzEstimator { ret_val: atomic::AtomicU32::new(253) }, &self.logger).unwrap();
144144
let mut ser = VecWriter(Vec::new());
145145
deserialized_monitor.write(&mut ser).unwrap();
146146
map_entry.insert((update.update_id, ser.0));

lightning/src/chain/chaininterface.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ pub trait FeeEstimator {
5252
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32;
5353
}
5454

55-
// We need `FeeEstimator` implemented so that in some places where we only have a shared
56-
// reference to a `Deref` to a `FeeEstimator`, we can still wrap it.
57-
impl<D: Deref> FeeEstimator for D where D::Target: FeeEstimator {
58-
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 {
59-
(**self).get_est_sat_per_1000_weight(confirmation_target)
60-
}
61-
}
62-
6355
/// Minimum relay fee as required by bitcoin network mempool policy.
6456
pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000;
6557
/// Minimum feerate that takes a sane approach to bitcoind weight-to-vbytes rounding.

lightning/src/chain/chainmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ where C::Target: chain::Filter,
636636
Some(monitor_state) => {
637637
let monitor = &monitor_state.monitor;
638638
log_trace!(self.logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor));
639-
let update_res = monitor.update_monitor(&update, &self.broadcaster, &self.fee_estimator, &self.logger);
639+
let update_res = monitor.update_monitor(&update, &self.broadcaster, &*self.fee_estimator, &self.logger);
640640
if update_res.is_err() {
641641
log_error!(self.logger, "Failed to update ChannelMonitor for channel {}.", log_funding_info!(monitor));
642642
}

lightning/src/chain/channelmonitor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
11341134
&self,
11351135
updates: &ChannelMonitorUpdate,
11361136
broadcaster: &B,
1137-
fee_estimator: &F,
1137+
fee_estimator: F,
11381138
logger: &L,
11391139
) -> Result<(), ()>
11401140
where
@@ -1944,10 +1944,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19441944
self.pending_monitor_events.push(MonitorEvent::CommitmentTxConfirmed(self.funding_info.0));
19451945
}
19461946

1947-
pub fn update_monitor<B: Deref, F: Deref, L: Deref>(&mut self, updates: &ChannelMonitorUpdate, broadcaster: &B, fee_estimator: &F, logger: &L) -> Result<(), ()>
1947+
pub fn update_monitor<B: Deref, F: Deref, L: Deref>(&mut self, updates: &ChannelMonitorUpdate, broadcaster: &B, fee_estimator: F, logger: &L) -> Result<(), ()>
19481948
where B::Target: BroadcasterInterface,
1949-
F::Target: FeeEstimator,
1950-
L::Target: Logger,
1949+
F::Target: FeeEstimator,
1950+
L::Target: Logger,
19511951
{
19521952
log_info!(logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} changes.",
19531953
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
@@ -1985,7 +1985,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19851985
},
19861986
ChannelMonitorUpdateStep::PaymentPreimage { payment_preimage } => {
19871987
log_trace!(logger, "Updating ChannelMonitor with payment preimage");
1988-
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(fee_estimator);
1988+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&*fee_estimator);
19891989
self.provide_payment_preimage(&PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()), &payment_preimage, broadcaster, &bounded_fee_estimator, logger)
19901990
},
19911991
ChannelMonitorUpdateStep::CommitmentSecret { idx, secret } => {
@@ -3534,7 +3534,7 @@ mod tests {
35343534

35353535
let broadcaster = TestBroadcaster::new(Arc::clone(&nodes[1].blocks));
35363536
assert!(
3537-
pre_update_monitor.update_monitor(&replay_update, &&broadcaster, &&chanmon_cfgs[1].fee_estimator, &nodes[1].logger)
3537+
pre_update_monitor.update_monitor(&replay_update, &&broadcaster, &chanmon_cfgs[1].fee_estimator, &nodes[1].logger)
35383538
.is_err());
35393539
// Even though we error'd on the first update, we should still have generated an HTLC claim
35403540
// transaction

0 commit comments

Comments
 (0)