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>`.
This commit is contained in:
Matt Corallo 2023-09-27 23:02:50 +00:00
parent 07205a2869
commit 34f36d5ffe
4 changed files with 21 additions and 29 deletions

View file

@ -155,7 +155,7 @@ impl chain::Watch<TestChannelSigner> for TestChainMonitor {
}; };
let deserialized_monitor = <(BlockHash, channelmonitor::ChannelMonitor<TestChannelSigner>)>:: let deserialized_monitor = <(BlockHash, channelmonitor::ChannelMonitor<TestChannelSigner>)>::
read(&mut Cursor::new(&map_entry.get().1), (&*self.keys, &*self.keys)).unwrap().1; read(&mut Cursor::new(&map_entry.get().1), (&*self.keys, &*self.keys)).unwrap().1;
deserialized_monitor.update_monitor(update, &&TestBroadcaster{}, &FuzzEstimator { ret_val: atomic::AtomicU32::new(253) }, &self.logger).unwrap(); deserialized_monitor.update_monitor(update, &&TestBroadcaster{}, &&FuzzEstimator { ret_val: atomic::AtomicU32::new(253) }, &self.logger).unwrap();
let mut ser = VecWriter(Vec::new()); let mut ser = VecWriter(Vec::new());
deserialized_monitor.write(&mut ser).unwrap(); deserialized_monitor.write(&mut ser).unwrap();
map_entry.insert((update.update_id, ser.0)); map_entry.insert((update.update_id, ser.0));

View file

@ -767,7 +767,7 @@ where C::Target: chain::Filter,
Some(monitor_state) => { Some(monitor_state) => {
let monitor = &monitor_state.monitor; let monitor = &monitor_state.monitor;
log_trace!(self.logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor)); log_trace!(self.logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor));
let update_res = monitor.update_monitor(update, &self.broadcaster, &*self.fee_estimator, &self.logger); let update_res = monitor.update_monitor(update, &self.broadcaster, &self.fee_estimator, &self.logger);
let update_id = MonitorUpdateId::from_monitor_update(update); let update_id = MonitorUpdateId::from_monitor_update(update);
let mut pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap(); let mut pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap();

View file

@ -1311,7 +1311,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
&self, &self,
updates: &ChannelMonitorUpdate, updates: &ChannelMonitorUpdate,
broadcaster: &B, broadcaster: &B,
fee_estimator: F, fee_estimator: &F,
logger: &L, logger: &L,
) -> Result<(), ()> ) -> Result<(), ()>
where where
@ -2615,7 +2615,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
self.pending_monitor_events.push(MonitorEvent::HolderForceClosed(self.funding_info.0)); self.pending_monitor_events.push(MonitorEvent::HolderForceClosed(self.funding_info.0));
} }
pub fn update_monitor<B: Deref, F: Deref, L: Deref>(&mut self, updates: &ChannelMonitorUpdate, broadcaster: &B, fee_estimator: F, logger: &L) -> Result<(), ()> pub fn update_monitor<B: Deref, F: Deref, L: Deref>(&mut self, updates: &ChannelMonitorUpdate, broadcaster: &B, fee_estimator: &F, logger: &L) -> Result<(), ()>
where B::Target: BroadcasterInterface, where B::Target: BroadcasterInterface,
F::Target: FeeEstimator, F::Target: FeeEstimator,
L::Target: Logger, L::Target: Logger,
@ -2655,7 +2655,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
panic!("Attempted to apply ChannelMonitorUpdates out of order, check the update_id before passing an update to update_monitor!"); panic!("Attempted to apply ChannelMonitorUpdates out of order, check the update_id before passing an update to update_monitor!");
} }
let mut ret = Ok(()); let mut ret = Ok(());
let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&*fee_estimator); let bounded_fee_estimator = LowerBoundedFeeEstimator::new(&**fee_estimator);
for update in updates.updates.iter() { for update in updates.updates.iter() {
match update { match update {
ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, claimed_htlcs, nondust_htlc_sources } => { ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, claimed_htlcs, nondust_htlc_sources } => {
@ -4581,7 +4581,7 @@ mod tests {
let broadcaster = TestBroadcaster::with_blocks(Arc::clone(&nodes[1].blocks)); let broadcaster = TestBroadcaster::with_blocks(Arc::clone(&nodes[1].blocks));
assert!( assert!(
pre_update_monitor.update_monitor(&replay_update, &&broadcaster, &chanmon_cfgs[1].fee_estimator, &nodes[1].logger) pre_update_monitor.update_monitor(&replay_update, &&broadcaster, &&chanmon_cfgs[1].fee_estimator, &nodes[1].logger)
.is_err()); .is_err());
// Even though we error'd on the first update, we should still have generated an HTLC claim // Even though we error'd on the first update, we should still have generated an HTLC claim
// transaction // transaction

View file

@ -397,11 +397,7 @@ where
pub fn new( pub fn new(
kv_store: K, logger: L, maximum_pending_updates: u64, entropy_source: ES, kv_store: K, logger: L, maximum_pending_updates: u64, entropy_source: ES,
signer_provider: SP, signer_provider: SP,
) -> Self ) -> Self {
where
ES::Target: EntropySource + Sized,
SP::Target: SignerProvider + Sized,
{
MonitorUpdatingPersister { MonitorUpdatingPersister {
kv_store, kv_store,
logger, logger,
@ -416,12 +412,10 @@ where
/// It is extremely important that your [`KVStore::read`] implementation uses the /// It is extremely important that your [`KVStore::read`] implementation uses the
/// [`io::ErrorKind::NotFound`] variant correctly. For more information, please see the /// [`io::ErrorKind::NotFound`] variant correctly. For more information, please see the
/// documentation for [`MonitorUpdatingPersister`]. /// documentation for [`MonitorUpdatingPersister`].
pub fn read_all_channel_monitors_with_updates<B: Deref, F: Deref + Clone>( pub fn read_all_channel_monitors_with_updates<B: Deref, F: Deref>(
&self, broadcaster: B, fee_estimator: F, &self, broadcaster: &B, fee_estimator: &F,
) -> Result<Vec<(BlockHash, ChannelMonitor<<SP::Target as SignerProvider>::Signer>)>, io::Error> ) -> Result<Vec<(BlockHash, ChannelMonitor<<SP::Target as SignerProvider>::Signer>)>, io::Error>
where where
ES::Target: EntropySource + Sized,
SP::Target: SignerProvider + Sized,
B::Target: BroadcasterInterface, B::Target: BroadcasterInterface,
F::Target: FeeEstimator, F::Target: FeeEstimator,
{ {
@ -432,8 +426,8 @@ where
let mut res = Vec::with_capacity(monitor_list.len()); let mut res = Vec::with_capacity(monitor_list.len());
for monitor_key in monitor_list { for monitor_key in monitor_list {
res.push(self.read_channel_monitor_with_updates( res.push(self.read_channel_monitor_with_updates(
&broadcaster, broadcaster,
fee_estimator.clone(), fee_estimator,
monitor_key, monitor_key,
)?) )?)
} }
@ -457,12 +451,10 @@ where
/// ///
/// Loading a large number of monitors will be faster if done in parallel. You can use this /// Loading a large number of monitors will be faster if done in parallel. You can use this
/// function to accomplish this. Take care to limit the number of parallel readers. /// function to accomplish this. Take care to limit the number of parallel readers.
pub fn read_channel_monitor_with_updates<B: Deref, F: Deref + Clone>( pub fn read_channel_monitor_with_updates<B: Deref, F: Deref>(
&self, broadcaster: &B, fee_estimator: F, monitor_key: String, &self, broadcaster: &B, fee_estimator: &F, monitor_key: String,
) -> Result<(BlockHash, ChannelMonitor<<SP::Target as SignerProvider>::Signer>), io::Error> ) -> Result<(BlockHash, ChannelMonitor<<SP::Target as SignerProvider>::Signer>), io::Error>
where where
ES::Target: EntropySource + Sized,
SP::Target: SignerProvider + Sized,
B::Target: BroadcasterInterface, B::Target: BroadcasterInterface,
F::Target: FeeEstimator, F::Target: FeeEstimator,
{ {
@ -484,7 +476,7 @@ where
Err(err) => return Err(err), Err(err) => return Err(err),
}; };
monitor.update_monitor(&update, broadcaster, fee_estimator.clone(), &self.logger) monitor.update_monitor(&update, broadcaster, fee_estimator, &self.logger)
.map_err(|e| { .map_err(|e| {
log_error!( log_error!(
self.logger, self.logger,
@ -949,17 +941,17 @@ mod tests {
// Check that the persisted channel data is empty before any channels are // Check that the persisted channel data is empty before any channels are
// open. // open.
let mut persisted_chan_data_0 = persister_0.read_all_channel_monitors_with_updates( let mut persisted_chan_data_0 = persister_0.read_all_channel_monitors_with_updates(
broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap(); &broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
assert_eq!(persisted_chan_data_0.len(), 0); assert_eq!(persisted_chan_data_0.len(), 0);
let mut persisted_chan_data_1 = persister_1.read_all_channel_monitors_with_updates( let mut persisted_chan_data_1 = persister_1.read_all_channel_monitors_with_updates(
broadcaster_1, &chanmon_cfgs[1].fee_estimator).unwrap(); &broadcaster_1, &&chanmon_cfgs[1].fee_estimator).unwrap();
assert_eq!(persisted_chan_data_1.len(), 0); assert_eq!(persisted_chan_data_1.len(), 0);
// Helper to make sure the channel is on the expected update ID. // Helper to make sure the channel is on the expected update ID.
macro_rules! check_persisted_data { macro_rules! check_persisted_data {
($expected_update_id: expr) => { ($expected_update_id: expr) => {
persisted_chan_data_0 = persister_0.read_all_channel_monitors_with_updates( persisted_chan_data_0 = persister_0.read_all_channel_monitors_with_updates(
broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap(); &broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
// check that we stored only one monitor // check that we stored only one monitor
assert_eq!(persisted_chan_data_0.len(), 1); assert_eq!(persisted_chan_data_0.len(), 1);
for (_, mon) in persisted_chan_data_0.iter() { for (_, mon) in persisted_chan_data_0.iter() {
@ -978,7 +970,7 @@ mod tests {
} }
} }
persisted_chan_data_1 = persister_1.read_all_channel_monitors_with_updates( persisted_chan_data_1 = persister_1.read_all_channel_monitors_with_updates(
broadcaster_1, &chanmon_cfgs[1].fee_estimator).unwrap(); &broadcaster_1, &&chanmon_cfgs[1].fee_estimator).unwrap();
assert_eq!(persisted_chan_data_1.len(), 1); assert_eq!(persisted_chan_data_1.len(), 1);
for (_, mon) in persisted_chan_data_1.iter() { for (_, mon) in persisted_chan_data_1.iter() {
assert_eq!(mon.get_latest_update_id(), $expected_update_id); assert_eq!(mon.get_latest_update_id(), $expected_update_id);
@ -1043,7 +1035,7 @@ mod tests {
check_persisted_data!(CLOSED_CHANNEL_UPDATE_ID); check_persisted_data!(CLOSED_CHANNEL_UPDATE_ID);
// Make sure the expected number of stale updates is present. // Make sure the expected number of stale updates is present.
let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap(); let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(&broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
let (_, monitor) = &persisted_chan_data[0]; let (_, monitor) = &persisted_chan_data[0];
let monitor_name = MonitorName::from(monitor.get_funding_txo().0); let monitor_name = MonitorName::from(monitor.get_funding_txo().0);
// The channel should have 0 updates, as it wrote a full monitor and consolidated. // The channel should have 0 updates, as it wrote a full monitor and consolidated.
@ -1151,7 +1143,7 @@ mod tests {
// Check that the persisted channel data is empty before any channels are // Check that the persisted channel data is empty before any channels are
// open. // open.
let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap(); let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(&broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
assert_eq!(persisted_chan_data.len(), 0); assert_eq!(persisted_chan_data.len(), 0);
// Create some initial channel // Create some initial channel
@ -1162,7 +1154,7 @@ mod tests {
send_payment(&nodes[1], &vec![&nodes[0]][..], 4_000_000); send_payment(&nodes[1], &vec![&nodes[0]][..], 4_000_000);
// Get the monitor and make a fake stale update at update_id=1 (lowest height of an update possible) // Get the monitor and make a fake stale update at update_id=1 (lowest height of an update possible)
let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(broadcaster_0, &chanmon_cfgs[0].fee_estimator).unwrap(); let persisted_chan_data = persister_0.read_all_channel_monitors_with_updates(&broadcaster_0, &&chanmon_cfgs[0].fee_estimator).unwrap();
let (_, monitor) = &persisted_chan_data[0]; let (_, monitor) = &persisted_chan_data[0];
let monitor_name = MonitorName::from(monitor.get_funding_txo().0); let monitor_name = MonitorName::from(monitor.get_funding_txo().0);
persister_0 persister_0