Skip to content

Commit 8edede0

Browse files
committed
f - use MontiorName as archive_persisted_channel param
1 parent 681f587 commit 8edede0

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

fuzz/src/utils/test_persister.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use lightning::chain;
22
use lightning::chain::{chainmonitor, channelmonitor};
3+
use lightning::util::persist::MonitorName;
34
use lightning::util::test_channel_signer::TestChannelSigner;
45

56
use std::sync::Mutex;
@@ -21,5 +22,5 @@ impl chainmonitor::Persist<TestChannelSigner> for TestPersister {
2122
self.update_ret.lock().unwrap().clone()
2223
}
2324

24-
fn archive_persisted_channel(&self, _: &channelmonitor::ChannelMonitor<TestChannelSigner>) {}
25+
fn archive_persisted_channel(&self, _monitor_name: MonitorName) {}
2526
}

lightning/src/chain/chainmonitor.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::sign::ecdsa::EcdsaChannelSigner;
3636
use crate::events::{self, Event, EventHandler, ReplayEvent};
3737
use crate::util::logger::{Logger, WithContext};
3838
use crate::util::errors::APIError;
39+
use crate::util::persist::MonitorName;
3940
use crate::util::wakers::{Future, Notifier};
4041
use crate::ln::channel_state::ChannelDetails;
4142

@@ -168,7 +169,7 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
168169
/// the archive process. Additionally, because the archive operation could be retried on
169170
/// restart, this method must in that case be idempotent, ensuring it can handle scenarios where
170171
/// the monitor already exists in the archive.
171-
fn archive_persisted_channel(&self, monitor: &ChannelMonitor<ChannelSigner>);
172+
fn archive_persisted_channel(&self, monitor_name: MonitorName);
172173
}
173174

174175
struct MonitorHolder<ChannelSigner: EcdsaChannelSigner> {
@@ -654,7 +655,7 @@ where C::Target: chain::Filter,
654655
"Archiving fully resolved ChannelMonitor for channel ID {}",
655656
channel_id
656657
);
657-
self.persister.archive_persisted_channel(&monitor_holder.monitor);
658+
self.persister.archive_persisted_channel(monitor_holder.monitor.persistence_key());
658659
false
659660
} else {
660661
true

lightning/src/util/persist.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ impl<ChannelSigner: EcdsaChannelSigner, K: KVStore + ?Sized> Persist<ChannelSign
290290
}
291291
}
292292

293-
fn archive_persisted_channel(&self, monitor: &ChannelMonitor<ChannelSigner>) {
294-
let monitor_name = monitor.persistence_key();
293+
fn archive_persisted_channel(&self, monitor_name: MonitorName) {
295294
let monitor = match self.read(
296295
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
297296
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
@@ -821,8 +820,7 @@ where
821820
}
822821
}
823822

824-
fn archive_persisted_channel(&self, monitor: &ChannelMonitor<ChannelSigner>) {
825-
let monitor_name = monitor.persistence_key();
823+
fn archive_persisted_channel(&self, monitor_name: MonitorName) {
826824
let monitor_key = monitor_name.as_str().to_string();
827825
let monitor = match self.read_channel_monitor_with_updates(monitor_key) {
828826
Ok((_block_hash, monitor)) => monitor,
@@ -920,7 +918,7 @@ where
920918
/// // Using MonitorName to generate a storage key
921919
/// let storage_key = format!("channel_monitors/{}", monitor_name.as_str());
922920
/// ```
923-
#[derive(Debug)]
921+
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
924922
pub struct MonitorName(String);
925923

926924
/// The source of the [`MonitorName`], either an [`OutPoint`] for V1 channels or a [`ChannelId`] for

lightning/src/util/test_utils.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use crate::sync::RwLock;
5151
use crate::types::features::{ChannelFeatures, InitFeatures, NodeFeatures};
5252
use crate::util::config::UserConfig;
5353
use crate::util::logger::{Logger, Record};
54-
use crate::util::persist::KVStore;
54+
use crate::util::persist::{KVStore, MonitorName};
5555
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
5656
use crate::util::test_channel_signer::{EnforcementState, TestChannelSigner};
5757

@@ -663,8 +663,11 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for WatchtowerPers
663663
res
664664
}
665665

666-
fn archive_persisted_channel(&self, data: &ChannelMonitor<Signer>) {
667-
self.persister.archive_persisted_channel(data);
666+
fn archive_persisted_channel(&self, monitor_name: MonitorName) {
667+
<TestPersister as Persist<TestChannelSigner>>::archive_persisted_channel(
668+
&self.persister,
669+
monitor_name,
670+
);
668671
}
669672
}
670673

@@ -674,10 +677,10 @@ pub struct TestPersister {
674677
pub update_rets: Mutex<VecDeque<chain::ChannelMonitorUpdateStatus>>,
675678
/// When we get an update_persisted_channel call *with* a ChannelMonitorUpdate, we insert the
676679
/// [`ChannelMonitor::get_latest_update_id`] here.
677-
pub offchain_monitor_updates: Mutex<HashMap<ChannelId, HashSet<u64>>>,
680+
pub offchain_monitor_updates: Mutex<HashMap<MonitorName, HashSet<u64>>>,
678681
/// When we get an update_persisted_channel call with no ChannelMonitorUpdate, we insert the
679682
/// monitor's funding outpoint here.
680-
pub chain_sync_monitor_persistences: Mutex<VecDeque<ChannelId>>,
683+
pub chain_sync_monitor_persistences: Mutex<VecDeque<MonitorName>>,
681684
}
682685
impl TestPersister {
683686
pub fn new() -> Self {
@@ -710,23 +713,24 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for TestPersister
710713
ret = update_ret;
711714
}
712715

716+
let monitor_name = data.persistence_key();
713717
if let Some(update) = update {
714718
self.offchain_monitor_updates
715719
.lock()
716720
.unwrap()
717-
.entry(data.channel_id())
721+
.entry(monitor_name)
718722
.or_insert(new_hash_set())
719723
.insert(update.update_id);
720724
} else {
721-
self.chain_sync_monitor_persistences.lock().unwrap().push_back(data.channel_id());
725+
self.chain_sync_monitor_persistences.lock().unwrap().push_back(monitor_name);
722726
}
723727
ret
724728
}
725729

726-
fn archive_persisted_channel(&self, data: &ChannelMonitor<Signer>) {
730+
fn archive_persisted_channel(&self, monitor_name: MonitorName) {
727731
// remove the channel from the offchain_monitor_updates and chain_sync_monitor_persistences.
728-
self.offchain_monitor_updates.lock().unwrap().remove(&data.channel_id());
729-
self.chain_sync_monitor_persistences.lock().unwrap().retain(|x| x != &data.channel_id());
732+
self.offchain_monitor_updates.lock().unwrap().remove(&monitor_name);
733+
self.chain_sync_monitor_persistences.lock().unwrap().retain(|x| x != &monitor_name);
730734
}
731735
}
732736

0 commit comments

Comments
 (0)