Skip to content

Commit 34f36d5

Browse files
committed
Drop various bounds on types passed to MonitorUpdatingPersister
The new `MonitorUpdatingPersister` has a few redundant type bounds (re-specified on functions after having been specified on the struct itself), which we remove here. Further, it requires a `Deref<FeeEstimator>` which is `Clone`able. This is generally fine in rust, but annoying in bindings, so we simply elide it in favor if a `&Deref<FeeEstimator>`.
1 parent 07205a2 commit 34f36d5

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl chain::Watch<TestChannelSigner> for TestChainMonitor {
155155
};
156156
let deserialized_monitor = <(BlockHash, channelmonitor::ChannelMonitor<TestChannelSigner>)>::
157157
read(&mut Cursor::new(&map_entry.get().1), (&*self.keys, &*self.keys)).unwrap().1;
158-
deserialized_monitor.update_monitor(update, &&TestBroadcaster{}, &FuzzEstimator { ret_val: atomic::AtomicU32::new(253) }, &self.logger).unwrap();
158+
deserialized_monitor.update_monitor(update, &&TestBroadcaster{}, &&FuzzEstimator { ret_val: atomic::AtomicU32::new(253) }, &self.logger).unwrap();
159159
let mut ser = VecWriter(Vec::new());
160160
deserialized_monitor.write(&mut ser).unwrap();
161161
map_entry.insert((update.update_id, ser.0));

lightning/src/chain/chainmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ where C::Target: chain::Filter,
767767
Some(monitor_state) => {
768768
let monitor = &monitor_state.monitor;
769769
log_trace!(self.logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor));
770-
let update_res = monitor.update_monitor(update, &self.broadcaster, &*self.fee_estimator, &self.logger);
770+
let update_res = monitor.update_monitor(update, &self.broadcaster, &self.fee_estimator, &self.logger);
771771

772772
let update_id = MonitorUpdateId::from_monitor_update(update);
773773
let mut pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap();

lightning/src/chain/channelmonitor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
13111311
&self,
13121312
updates: &ChannelMonitorUpdate,
13131313
broadcaster: &B,
1314-
fee_estimator: F,
1314+
fee_estimator: &F,
13151315
logger: &L,
13161316
) -> Result<(), ()>
13171317
where
@@ -2615,7 +2615,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
26152615
self.pending_monitor_events.push(MonitorEvent::HolderForceClosed(self.funding_info.0));
26162616
}
26172617

2618-
pub fn update_monitor<B: Deref, F: Deref, L: Deref>(&mut self, updates: &ChannelMonitorUpdate, broadcaster: &B, fee_estimator: F, logger: &L) -> Result<(), ()>
2618+
pub fn update_monitor<B: Deref, F: Deref, L: Deref>(&mut self, updates: &ChannelMonitorUpdate, broadcaster: &B, fee_estimator: &F, logger: &L) -> Result<(), ()>
26192619
where B::Target: BroadcasterInterface,
26202620
F::Target: FeeEstimator,
26212621
L::Target: Logger,
@@ -2655,7 +2655,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
26552655
panic!("Attempted to apply ChannelMonitorUpdates out of order, check the update_id before passing an update to update_monitor!");
26562656
}
26572657
let mut ret = Ok(());
2658-
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&*fee_estimator);
2658+
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&**fee_estimator);
26592659
for update in updates.updates.iter() {
26602660
match update {
26612661
ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, claimed_htlcs, nondust_htlc_sources } => {
@@ -4581,7 +4581,7 @@ mod tests {
45814581

45824582
let broadcaster = TestBroadcaster::with_blocks(Arc::clone(&nodes[1].blocks));
45834583
assert!(
4584-
pre_update_monitor.update_monitor(&replay_update, &&broadcaster, &chanmon_cfgs[1].fee_estimator, &nodes[1].logger)
4584+
pre_update_monitor.update_monitor(&replay_update, &&broadcaster, &&chanmon_cfgs[1].fee_estimator, &nodes[1].logger)
45854585
.is_err());
45864586
// Even though we error'd on the first update, we should still have generated an HTLC claim
45874587
// transaction

lightning/src/util/persist.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,7 @@ where
397397
pub fn new(
398398
kv_store: K, logger: L, maximum_pending_updates: u64, entropy_source: ES,
399399
signer_provider: SP,
400-
) -> Self
401-
where
402-
ES::Target: EntropySource + Sized,
403-
SP::Target: SignerProvider + Sized,
404-
{
400+
) -> Self {
405401
MonitorUpdatingPersister {
406402
kv_store,
407403
logger,
@@ -416,12 +412,10 @@ where
416412
/// It is extremely important that your [`KVStore::read`] implementation uses the
417413
/// [`io::ErrorKind::NotFound`] variant correctly. For more information, please see the
418414
/// documentation for [`MonitorUpdatingPersister`].
419-
pub fn read_all_channel_monitors_with_updates<B: Deref, F: Deref + Clone>(
420-
&self, broadcaster: B, fee_estimator: F,
415+
pub fn read_all_channel_monitors_with_updates<B: Deref, F: Deref>(
416+
&self, broadcaster: &B, fee_estimator: &F,
421417
) -> Result<Vec<(BlockHash, ChannelMonitor<<SP::Target as SignerProvider>::Signer>)>, io::Error>
422418
where
423-
ES::Target: EntropySource + Sized,
424-
SP::Target: SignerProvider + Sized,
425419
B::Target: BroadcasterInterface,
426420
F::Target: FeeEstimator,
427421
{
@@ -432,8 +426,8 @@ where
432426
let mut res = Vec::with_capacity(monitor_list.len());
433427
for monitor_key in monitor_list {
434428
res.push(self.read_channel_monitor_with_updates(
435-
&broadcaster,
436-
fee_estimator.clone(),
429+
broadcaster,
430+
fee_estimator,
437431
monitor_key,
438432
)?)
439433
}
@@ -457,12 +451,10 @@ where
457451
///
458452
/// Loading a large number of monitors will be faster if done in parallel. You can use this
459453
/// function to accomplish this. Take care to limit the number of parallel readers.
460-
pub fn read_channel_monitor_with_updates<B: Deref, F: Deref + Clone>(
461-
&self, broadcaster: &B, fee_estimator: F, monitor_key: String,
454+
pub fn read_channel_monitor_with_updates<B: Deref, F: Deref>(
455+
&self, broadcaster: &B, fee_estimator: &F, monitor_key: String,
462456
) -> Result<(BlockHash, ChannelMonitor<<SP::Target as SignerProvider>::Signer>), io::Error>
463457
where
464-
ES::Target: EntropySource + Sized,
465-
SP::Target: SignerProvider + Sized,
466458
B::Target: BroadcasterInterface,
467459
F::Target: FeeEstimator,
468460
{
@@ -484,7 +476,7 @@ where
484476
Err(err) => return Err(err),
485477
};
486478

487-
monitor.update_monitor(&update, broadcaster, fee_estimator.clone(), &self.logger)
479+
monitor.update_monitor(&update, broadcaster, fee_estimator, &self.logger)
488480
.map_err(|e| {
489481
log_error!(
490482
self.logger,
@@ -949,17 +941,17 @@ mod tests {
949941
// Check that the persisted channel data is empty before any channels are
950942
// open.
951943
let mut persisted_chan_data_0 = persister_0.read_all_channel_monitors_with_updates(
952-
broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap();
944+
&broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
953945
assert_eq!(persisted_chan_data_0.len(), 0);
954946
let mut persisted_chan_data_1 = persister_1.read_all_channel_monitors_with_updates(
955-
broadcaster_1, &chanmon_cfgs[1].fee_estimator).unwrap();
947+
&broadcaster_1, &&chanmon_cfgs[1].fee_estimator).unwrap();
956948
assert_eq!(persisted_chan_data_1.len(), 0);
957949

958950
// Helper to make sure the channel is on the expected update ID.
959951
macro_rules! check_persisted_data {
960952
($expected_update_id: expr) => {
961953
persisted_chan_data_0 = persister_0.read_all_channel_monitors_with_updates(
962-
broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap();
954+
&broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
963955
// check that we stored only one monitor
964956
assert_eq!(persisted_chan_data_0.len(), 1);
965957
for (_, mon) in persisted_chan_data_0.iter() {
@@ -978,7 +970,7 @@ mod tests {
978970
}
979971
}
980972
persisted_chan_data_1 = persister_1.read_all_channel_monitors_with_updates(
981-
broadcaster_1, &chanmon_cfgs[1].fee_estimator).unwrap();
973+
&broadcaster_1, &&chanmon_cfgs[1].fee_estimator).unwrap();
982974
assert_eq!(persisted_chan_data_1.len(), 1);
983975
for (_, mon) in persisted_chan_data_1.iter() {
984976
assert_eq!(mon.get_latest_update_id(), $expected_update_id);
@@ -1043,7 +1035,7 @@ mod tests {
10431035
check_persisted_data!(CLOSED_CHANNEL_UPDATE_ID);
10441036

10451037
// Make sure the expected number of stale updates is present.
1046-
let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap();
1038+
let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(&broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
10471039
let (_, monitor) = &persisted_chan_data[0];
10481040
let monitor_name = MonitorName::from(monitor.get_funding_txo().0);
10491041
// The channel should have 0 updates, as it wrote a full monitor and consolidated.
@@ -1151,7 +1143,7 @@ mod tests {
11511143

11521144
// Check that the persisted channel data is empty before any channels are
11531145
// open.
1154-
let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap();
1146+
let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(&broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
11551147
assert_eq!(persisted_chan_data.len(), 0);
11561148

11571149
// Create some initial channel
@@ -1162,7 +1154,7 @@ mod tests {
11621154
send_payment(&nodes[1], &vec![&nodes[0]][..], 4_000_000);
11631155

11641156
// Get the monitor and make a fake stale update at update_id=1 (lowest height of an update possible)
1165-
let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap();
1157+
let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(&broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
11661158
let (_, monitor) = &persisted_chan_data[0];
11671159
let monitor_name = MonitorName::from(monitor.get_funding_txo().0);
11681160
persister_0

0 commit comments

Comments
 (0)