Skip to content

Commit 817448b

Browse files
committed
traits: No persist_[manager,monitor] default impls
Since these impls aren't actually shared, it would be too easy to just modify the logic in the provided impl without being aware of the node method override.
1 parent ec4510b commit 817448b

File tree

3 files changed

+8
-37
lines changed

3 files changed

+8
-37
lines changed

lexe-ln/src/channel_monitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async fn handle_update<PS: LexePersister>(
133133
// Persist the monitor.
134134
let funding_txo = OutPoint::from(update.funding_txo);
135135
persister
136-
.persist_monitor(chain_monitor, &update.funding_txo)
136+
.persist_channel_monitor(chain_monitor, &update.funding_txo)
137137
.await
138138
.context("persist_monitor failed")?;
139139

lexe-ln/src/traits.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{future::Future, ops::Deref, str::FromStr};
22

3-
use anyhow::{anyhow, Context};
3+
use anyhow::Context;
44
use async_trait::async_trait;
55
use common::{
66
api::{
@@ -63,45 +63,18 @@ pub trait LexeInnerPersister: Vfs + Persist<SignerType> {
6363
index: PaymentIndex,
6464
) -> anyhow::Result<Option<Payment>>;
6565

66-
// --- Provided methods --- //
67-
6866
async fn persist_manager<CM: Writeable + Send + Sync>(
6967
&self,
7068
channel_manager: &CM,
71-
) -> anyhow::Result<()> {
72-
let file_id = VfsFileId::new(
73-
constants::SINGLETON_DIRECTORY,
74-
constants::CHANNEL_MANAGER_FILENAME,
75-
);
76-
let file = self.encrypt_ldk_writeable(file_id, channel_manager);
77-
self.persist_file(&file, constants::IMPORTANT_PERSIST_RETRIES)
78-
.await
79-
}
69+
) -> anyhow::Result<()>;
8070

81-
async fn persist_monitor<PS: LexePersister>(
71+
async fn persist_channel_monitor<PS: LexePersister>(
8272
&self,
8373
chain_monitor: &LexeChainMonitorType<PS>,
8474
funding_txo: &LxOutPoint,
85-
) -> anyhow::Result<()> {
86-
let file = {
87-
let locked_monitor =
88-
chain_monitor.get_monitor((*funding_txo).into()).map_err(
89-
|e| anyhow!("No monitor for this funding_txo: {e:?}"),
90-
)?;
91-
92-
// NOTE: The VFS filename uses the `ToString` impl of `LxOutPoint`
93-
// rather than `lightning::chain::transaction::OutPoint` or
94-
// `bitcoin::OutPoint`! `LxOutPoint`'s FromStr/Display impls are
95-
// guaranteed to roundtrip, and will be stable across LDK versions.
96-
let filename = funding_txo.to_string();
97-
let file_id =
98-
VfsFileId::new(constants::CHANNEL_MONITORS_DIR, filename);
99-
self.encrypt_ldk_writeable(file_id, &*locked_monitor)
100-
};
101-
102-
self.persist_file(&file, constants::IMPORTANT_PERSIST_RETRIES)
103-
.await
104-
}
75+
) -> anyhow::Result<()>;
76+
77+
// --- Provided methods --- //
10578

10679
/// Reads all persisted events, along with their event IDs.
10780
async fn read_events(&self) -> anyhow::Result<Vec<(EventId, Event)>> {

node/src/persister/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,6 @@ impl LexeInnerPersister for NodePersister {
747747
Ok(maybe_payment)
748748
}
749749

750-
/// Override the default since we want multi-upsert.
751750
async fn persist_manager<CM: Writeable + Send + Sync>(
752751
&self,
753752
channel_manager: &CM,
@@ -770,8 +769,7 @@ impl LexeInnerPersister for NodePersister {
770769
.context("multi::upsert failed")
771770
}
772771

773-
/// Override the default since we want multi-upsert.
774-
async fn persist_monitor<PS: LexePersister>(
772+
async fn persist_channel_monitor<PS: LexePersister>(
775773
&self,
776774
chain_monitor: &LexeChainMonitorType<PS>,
777775
funding_txo: &LxOutPoint,

0 commit comments

Comments
 (0)