1
- //! Logic for persisting data from ChannelMonitors on-disk. Per-platform data
1
+ //! Logic for persisting data from ChannelMonitors on-disk. Sample data
2
2
//! persisters are separated into the lightning-persist-data crate. These
3
3
//! objects mainly interface with the ChainMonitor when a channel monitor is
4
4
//! added or updated, and when they are all synced on startup.
@@ -8,7 +8,7 @@ use chain::transaction::OutPoint;
8
8
use std:: collections:: HashMap ;
9
9
10
10
/// ChannelDataPersister is responsible for persisting channel data: this could
11
- /// mean writing once to disk, and/or uploading to several backup services.
11
+ /// mean writing once to disk, and/or uploading to one or more backup services.
12
12
///
13
13
/// Note that for every new monitor, you **must** persist the new ChannelMonitor
14
14
/// to disk/backups. And, on every update, you **must** persist either the
@@ -19,33 +19,22 @@ use std::collections::HashMap;
19
19
/// are toxic, so it's important that whatever channel state is persisted is
20
20
/// kept up-to-date.
21
21
///
22
- /// Upon calls to update_channel_data, implementers of this trait should either
23
- /// persist the ChannelMonitorUpdate or the ChannelMonitor. If an implementer
24
- /// chooses to persist the updates only, they need to make sure that all the
25
- /// updates are applied to the ChannelMonitors *before* the set of channel
26
- /// monitors is given to the ChainMonitor at startup time (e.g., all monitors
27
- /// returned by `load_channel_data` must be up-to-date). If full ChannelMonitors
28
- /// are persisted, then there is no need to persist individual updates.
29
- ///
30
- /// Note that there could be a performance tradeoff between persisting complete
31
- /// channel monitors on every update vs. persisting only updates and applying
32
- /// them in batches.
33
- ///
34
22
/// Given multiple backups, situations may arise where one or more backup sources
35
23
/// have fallen behind or disagree on the current state. Because these backup
36
24
/// sources don't have any transaction signing/broadcasting duties and are only
37
25
/// supposed to be persisting bytes of data, backup sources may be considered
38
26
/// "in consensus" if a majority of them agree on the current state and are on
39
- /// the highest known commitment number. See individual methods for more info.
27
+ /// the highest known commitment number.
40
28
pub trait ChannelDataPersister : Send + Sync {
41
29
/// The concrete type which signs for transactions and provides access to our channel public
42
30
/// keys.
43
31
type Keys : ChannelKeys ;
44
32
45
- /// Persist a new channel's data. The majority of backups should agree on a
46
- /// channel's state and be on the latest [`update_id`]. The data
47
- /// can be stored with any file name/path, but the identifier provided is the
48
- /// channel's outpoint.
33
+ /// Persist a new channel's data. The data can be stored with any file
34
+ /// name/path, but the identifier provided is the channel's outpoint.
35
+ /// Note that you **must** persist every new monitor to disk. See the
36
+ /// ChannelDataPersister trait documentation for more details, and for
37
+ /// information on consensus between backups.
49
38
///
50
39
/// See [`ChannelMonitor::write_for_disk`] for writing out a ChannelMonitor.
51
40
///
@@ -58,11 +47,8 @@ pub trait ChannelDataPersister: Send + Sync {
58
47
///
59
48
/// Note that on every update, you **must** persist either the
60
49
/// ChannelMonitorUpdate or the updated monitor itself to disk/backups.
61
- /// Otherwise, there is risk of situations such as revoking a transaction,
62
- /// then crashing before this revocation can be persisted, then
63
- /// unintentionally broadcasting a revoked transaction and losing money. This
64
- /// is a risk because previous channel states are toxic, so it's important
65
- /// that whatever channel state is persisted is kept up-to-date.
50
+ /// See the ChannelDataPersister trait documentation for more details, and
51
+ /// for information on consensus between backups.
66
52
///
67
53
/// If an implementer chooses to persist the updates only, they need to make
68
54
/// sure that all the updates are applied to the ChannelMonitors *before* the
@@ -71,23 +57,24 @@ pub trait ChannelDataPersister: Send + Sync {
71
57
/// If full ChannelMonitors are persisted, then there is no need to persist
72
58
/// individual updates.
73
59
///
74
- /// In the case where one or more backups fail, it's likely safe to only
75
- /// require that the majority of backups succeed and agree on the latest
76
- /// [`update_id`] to succeed this method .
60
+ /// Note that there could be a performance tradeoff between persisting complete
61
+ /// channel monitors on every update vs. persisting only updates and applying
62
+ /// them in batches .
77
63
///
78
64
/// See [`ChannelMonitor::write_for_disk`] for writing out a ChannelMonitor
79
65
/// and [`ChannelMonitorUpdate::write`] for writing out an update.
80
66
///
81
67
/// [`load_channel_data`]: trait.ChannelDataPersister.html#tymethod.load_channel_data
82
- /// [`update_id`]: struct.ChannelMonitorUpdate.html#structfield.update_id
83
68
/// [`ChannelMonitor::write_for_disk`]: struct.ChannelMonitor.html#method.write_for_disk
84
69
/// [`ChannelMonitorUpdate::write`]: struct.ChannelMonitorUpdate.html#method.write
85
70
fn update_channel_data ( & self , id : OutPoint , update : & ChannelMonitorUpdate , data : & ChannelMonitor < Self :: Keys > ) -> Result < ( ) , ChannelMonitorUpdateErr > ;
86
71
87
72
/// Load the data for all channels. Generally only called on startup. You must
88
73
/// ensure that the ChannelMonitors returned are on the latest [`update_id`],
89
- /// with all of the updates given in [`update_channel_data`] applied. Otherwise,
90
- /// there is a risk of broadcasting a revoked transaction and losing money.
74
+ /// with all of the updates given in [`update_channel_data`] applied.
75
+ ///
76
+ /// See the ChannelDataPersister trait documentation for more details, and
77
+ /// for information on consensus between backups.
91
78
///
92
79
/// See [`ChannelMonitor::read`] for deserializing a ChannelMonitor.
93
80
///
0 commit comments