@@ -36,6 +36,7 @@ use crate::sign::ecdsa::EcdsaChannelSigner;
36
36
use crate :: events:: { self , Event , EventHandler , ReplayEvent } ;
37
37
use crate :: util:: logger:: { Logger , WithContext } ;
38
38
use crate :: util:: errors:: APIError ;
39
+ use crate :: util:: persist:: MonitorName ;
39
40
use crate :: util:: wakers:: { Future , Notifier } ;
40
41
use crate :: ln:: channel_state:: ChannelDetails ;
41
42
@@ -102,11 +103,13 @@ use bitcoin::secp256k1::PublicKey;
102
103
/// [`TrustedCommitmentTransaction::build_to_local_justice_tx`]: crate::ln::chan_utils::TrustedCommitmentTransaction::build_to_local_justice_tx
103
104
pub trait Persist < ChannelSigner : EcdsaChannelSigner > {
104
105
/// Persist a new channel's data in response to a [`chain::Watch::watch_channel`] call. This is
105
- /// called by [`ChannelManager`] for new channels, or may be called directly, e.g. on startup.
106
+ /// called by [`ChannelManager`] for new channels, or may be called directly, e.g. on startup,
107
+ /// with the `monitor_name` returned by [`ChannelMonitor::persistence_key`].
106
108
///
107
- /// The data can be stored any way you want, but the identifier provided by LDK is the
108
- /// channel's outpoint (and it is up to you to maintain a correct mapping between the outpoint
109
- /// and the stored channel data). Note that you **must** persist every new monitor to disk.
109
+ /// The data can be stored any way you want, so long as `monitor_name` is used to maintain a
110
+ /// correct mapping with the stored channel data (i.e., calls to `update_persisted_channel` with
111
+ /// the same `monitor_name` must be applied to or overwrite this data). Note that you **must**
112
+ /// persist every new monitor to disk.
110
113
///
111
114
/// The [`ChannelMonitor::get_latest_update_id`] uniquely links this call to [`ChainMonitor::channel_monitor_updated`].
112
115
/// For [`Persist::persist_new_channel`], it is only necessary to call [`ChainMonitor::channel_monitor_updated`]
@@ -117,7 +120,7 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
117
120
///
118
121
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
119
122
/// [`Writeable::write`]: crate::util::ser::Writeable::write
120
- fn persist_new_channel ( & self , channel_funding_outpoint : OutPoint , monitor : & ChannelMonitor < ChannelSigner > ) -> ChannelMonitorUpdateStatus ;
123
+ fn persist_new_channel ( & self , monitor_name : MonitorName , monitor : & ChannelMonitor < ChannelSigner > ) -> ChannelMonitorUpdateStatus ;
121
124
122
125
/// Update one channel's data. The provided [`ChannelMonitor`] has already applied the given
123
126
/// update.
@@ -156,7 +159,7 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
156
159
/// [`ChannelMonitorUpdateStatus`] for requirements when returning errors.
157
160
///
158
161
/// [`Writeable::write`]: crate::util::ser::Writeable::write
159
- fn update_persisted_channel ( & self , channel_funding_outpoint : OutPoint , monitor_update : Option < & ChannelMonitorUpdate > , monitor : & ChannelMonitor < ChannelSigner > ) -> ChannelMonitorUpdateStatus ;
162
+ fn update_persisted_channel ( & self , monitor_name : MonitorName , monitor_update : Option < & ChannelMonitorUpdate > , monitor : & ChannelMonitor < ChannelSigner > ) -> ChannelMonitorUpdateStatus ;
160
163
/// Prevents the channel monitor from being loaded on startup.
161
164
///
162
165
/// Archiving the data in a backup location (rather than deleting it fully) is useful for
@@ -168,7 +171,7 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
168
171
/// the archive process. Additionally, because the archive operation could be retried on
169
172
/// restart, this method must in that case be idempotent, ensuring it can handle scenarios where
170
173
/// the monitor already exists in the archive.
171
- fn archive_persisted_channel ( & self , channel_funding_outpoint : OutPoint ) ;
174
+ fn archive_persisted_channel ( & self , monitor_name : MonitorName ) ;
172
175
}
173
176
174
177
struct MonitorHolder < ChannelSigner : EcdsaChannelSigner > {
@@ -342,8 +345,7 @@ where C::Target: chain::Filter,
342
345
// `ChannelMonitorUpdate` after a channel persist for a channel with the same
343
346
// `latest_update_id`.
344
347
let _pending_monitor_updates = monitor_state. pending_monitor_updates . lock ( ) . unwrap ( ) ;
345
- let funding_txo = monitor. get_funding_txo ( ) ;
346
- match self . persister . update_persisted_channel ( funding_txo, None , monitor) {
348
+ match self . persister . update_persisted_channel ( monitor. persistence_key ( ) , None , monitor) {
347
349
ChannelMonitorUpdateStatus :: Completed =>
348
350
log_trace ! ( logger, "Finished syncing Channel Monitor for channel {} for block-data" ,
349
351
log_funding_info!( monitor)
@@ -642,7 +644,7 @@ where C::Target: chain::Filter,
642
644
have_monitors_to_prune = true ;
643
645
}
644
646
if needs_persistence {
645
- self . persister . update_persisted_channel ( monitor_holder. monitor . get_funding_txo ( ) , None , & monitor_holder. monitor ) ;
647
+ self . persister . update_persisted_channel ( monitor_holder. monitor . persistence_key ( ) , None , & monitor_holder. monitor ) ;
646
648
}
647
649
}
648
650
if have_monitors_to_prune {
@@ -655,7 +657,7 @@ where C::Target: chain::Filter,
655
657
"Archiving fully resolved ChannelMonitor for channel ID {}" ,
656
658
channel_id
657
659
) ;
658
- self . persister . archive_persisted_channel ( monitor_holder. monitor . get_funding_txo ( ) ) ;
660
+ self . persister . archive_persisted_channel ( monitor_holder. monitor . persistence_key ( ) ) ;
659
661
false
660
662
} else {
661
663
true
@@ -769,7 +771,7 @@ where C::Target: chain::Filter,
769
771
log_trace ! ( logger, "Got new ChannelMonitor for channel {}" , log_funding_info!( monitor) ) ;
770
772
let update_id = monitor. get_latest_update_id ( ) ;
771
773
let mut pending_monitor_updates = Vec :: new ( ) ;
772
- let persist_res = self . persister . persist_new_channel ( monitor. get_funding_txo ( ) , & monitor) ;
774
+ let persist_res = self . persister . persist_new_channel ( monitor. persistence_key ( ) , & monitor) ;
773
775
match persist_res {
774
776
ChannelMonitorUpdateStatus :: InProgress => {
775
777
log_info ! ( logger, "Persistence of new ChannelMonitor for channel {} in progress" , log_funding_info!( monitor) ) ;
@@ -825,17 +827,16 @@ where C::Target: chain::Filter,
825
827
let update_res = monitor. update_monitor ( update, & self . broadcaster , & self . fee_estimator , & self . logger ) ;
826
828
827
829
let update_id = update. update_id ;
828
- let funding_txo = monitor. get_funding_txo ( ) ;
829
830
let persist_res = if update_res. is_err ( ) {
830
831
// Even if updating the monitor returns an error, the monitor's state will
831
832
// still be changed. Therefore, we should persist the updated monitor despite the error.
832
833
// We don't want to persist a `monitor_update` which results in a failure to apply later
833
834
// while reading `channel_monitor` with updates from storage. Instead, we should persist
834
835
// the entire `channel_monitor` here.
835
836
log_warn ! ( logger, "Failed to update ChannelMonitor for channel {}. Going ahead and persisting the entire ChannelMonitor" , log_funding_info!( monitor) ) ;
836
- self . persister . update_persisted_channel ( funding_txo , None , monitor)
837
+ self . persister . update_persisted_channel ( monitor . persistence_key ( ) , None , monitor)
837
838
} else {
838
- self . persister . update_persisted_channel ( funding_txo , Some ( update) , monitor)
839
+ self . persister . update_persisted_channel ( monitor . persistence_key ( ) , Some ( update) , monitor)
839
840
} ;
840
841
match persist_res {
841
842
ChannelMonitorUpdateStatus :: InProgress => {
0 commit comments