Skip to content

Commit daa0652

Browse files
committed
Rename the persistence sub_namespace to secondary_namespace
With the top-level namespace now called "primary", "secondary" makes more sense than "sub".
1 parent 18ef80f commit daa0652

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

lightning/src/util/persist.rs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,28 @@ pub const KVSTORE_NAMESPACE_KEY_MAX_LEN: usize = 120;
3939

4040
/// The namespace under which the [`ChannelManager`] will be persisted.
4141
pub const CHANNEL_MANAGER_PERSISTENCE_NAMESPACE: &str = "";
42-
/// The sub-namespace under which the [`ChannelManager`] will be persisted.
42+
/// The secondary-namespace under which the [`ChannelManager`] will be persisted.
4343
pub const CHANNEL_MANAGER_PERSISTENCE_SUB_NAMESPACE: &str = "";
4444
/// The key under which the [`ChannelManager`] will be persisted.
4545
pub const CHANNEL_MANAGER_PERSISTENCE_KEY: &str = "manager";
4646

4747
/// The namespace under which [`ChannelMonitor`]s will be persisted.
4848
pub const CHANNEL_MONITOR_PERSISTENCE_NAMESPACE: &str = "monitors";
49-
/// The sub-namespace under which [`ChannelMonitor`]s will be persisted.
49+
/// The secondary-namespace under which [`ChannelMonitor`]s will be persisted.
5050
pub const CHANNEL_MONITOR_PERSISTENCE_SUB_NAMESPACE: &str = "";
5151
/// The namespace under which [`ChannelMonitorUpdate`]s will be persisted.
5252
pub const CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE: &str = "monitor_updates";
5353

5454
/// The namespace under which the [`NetworkGraph`] will be persisted.
5555
pub const NETWORK_GRAPH_PERSISTENCE_NAMESPACE: &str = "";
56-
/// The sub-namespace under which the [`NetworkGraph`] will be persisted.
56+
/// The secondary-namespace under which the [`NetworkGraph`] will be persisted.
5757
pub const NETWORK_GRAPH_PERSISTENCE_SUB_NAMESPACE: &str = "";
5858
/// The key under which the [`NetworkGraph`] will be persisted.
5959
pub const NETWORK_GRAPH_PERSISTENCE_KEY: &str = "network_graph";
6060

6161
/// The namespace under which the [`WriteableScore`] will be persisted.
6262
pub const SCORER_PERSISTENCE_NAMESPACE: &str = "";
63-
/// The sub-namespace under which the [`WriteableScore`] will be persisted.
63+
/// The secondary-namespace under which the [`WriteableScore`] will be persisted.
6464
pub const SCORER_PERSISTENCE_SUB_NAMESPACE: &str = "";
6565
/// The key under which the [`WriteableScore`] will be persisted.
6666
pub const SCORER_PERSISTENCE_KEY: &str = "scorer";
@@ -75,35 +75,37 @@ pub const MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL: &[u8] = &[0xFF; 2];
7575
/// with given keys.
7676
///
7777
/// In order to avoid collisions the key space is segmented based on the given `primary_namespace`s
78-
/// and `sub_namespace`s. Implementations of this trait are free to handle them in different ways,
79-
/// as long as per-namespace key uniqueness is asserted.
78+
/// and `secondary_namespace`s. Implementations of this trait are free to handle them in different
79+
/// ways, as long as per-namespace key uniqueness is asserted.
8080
///
8181
/// Keys and namespaces are required to be valid ASCII strings in the range of
8282
/// [`KVSTORE_NAMESPACE_KEY_ALPHABET`] and no longer than [`KVSTORE_NAMESPACE_KEY_MAX_LEN`]. Empty
83-
/// primary namespaces and sub-namespaces (`""`) are assumed to be a valid, however, if
84-
/// `primary_namespace` is empty, `sub_namespace` is required to be empty, too. This means that
85-
/// concerns should always be separated by primary namespace first, before sub-namespaces are used.
86-
/// While the number of primary namespaces will be relatively small and is determined at compile
87-
/// time, there may be many sub-namespaces per primary namespace. Note that per-namespace
88-
/// uniqueness needs to also hold for keys *and* namespaces in any given namespace, i.e., conflicts
89-
/// between keys and equally named primary-namespaces/sub-namespaces must be avoided.
83+
/// primary namespaces and secondary-namespaces (`""`) are assumed to be a valid, however, if
84+
/// `primary_namespace` is empty, `secondary_namespace` is required to be empty, too. This means
85+
/// that concerns should always be separated by primary namespace first, before secondary
86+
/// namespaces are used. While the number of primary namespaces will be relatively small and is
87+
/// determined at compile time, there may be many secondary namespaces per primary namespace. Note
88+
/// that per-namespace uniqueness needs to also hold for keys *and* namespaces in any given
89+
/// namespace, i.e., conflicts between keys and equally named
90+
/// primary-namespaces/secondary-namespaces must be avoided.
9091
///
9192
/// **Note:** Users migrating custom persistence backends from the pre-v0.0.117 `KVStorePersister`
92-
/// interface can use a concatenation of `[{primary_namespace}/[{sub_namespace}/]]{key}` to recover
93-
/// a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
93+
/// interface can use a concatenation of `[{primary_namespace}/[{secondary_namespace}/]]{key}` to
94+
/// recover a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
9495
pub trait KVStore {
95-
/// Returns the data stored for the given `primary_namespace`, `sub_namespace`, and `key`.
96+
/// Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
97+
/// `key`.
9698
///
9799
/// Returns an [`ErrorKind::NotFound`] if the given `key` could not be found in the given
98-
/// `primary_namespace` and `sub_namespace`.
100+
/// `primary_namespace` and `secondary_namespace`.
99101
///
100102
/// [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
101-
fn read(&self, primary_namespace: &str, sub_namespace: &str, key: &str) -> Result<Vec<u8>, io::Error>;
103+
fn read(&self, primary_namespace: &str, secondary_namespace: &str, key: &str) -> Result<Vec<u8>, io::Error>;
102104
/// Persists the given data under the given `key`.
103105
///
104-
/// Will create the given `primary_namespace` and `sub_namespace` if not already present in the
106+
/// Will create the given `primary_namespace` and `secondary_namespace` if not already present in the
105107
/// store.
106-
fn write(&self, primary_namespace: &str, sub_namespace: &str, key: &str, buf: &[u8]) -> Result<(), io::Error>;
108+
fn write(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: &[u8]) -> Result<(), io::Error>;
107109
/// Removes any data that had previously been persisted under the given `key`.
108110
///
109111
/// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
@@ -117,15 +119,15 @@ pub trait KVStore {
117119
/// set for `remove` operations that can be safely replayed at a later time.
118120
///
119121
/// Returns successfully if no data will be stored for the given `primary_namespace`,
120-
/// `sub_namespace`, and `key`, independently of whether it was present before its invokation
121-
/// or not.
122-
fn remove(&self, primary_namespace: &str, sub_namespace: &str, key: &str, lazy: bool) -> Result<(), io::Error>;
123-
/// Returns a list of keys that are stored under the given `sub_namespace` in
122+
/// `secondary_namespace`, and `key`, independently of whether it was present before its
123+
/// invokation or not.
124+
fn remove(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool) -> Result<(), io::Error>;
125+
/// Returns a list of keys that are stored under the given `secondary_namespace` in
124126
/// `primary_namespace`.
125127
///
126128
/// Returns the keys in arbitrary order, so users requiring a particular order need to sort the
127-
/// returned keys. Returns an empty list if `primary_namespace` or `sub_namespace` is unknown.
128-
fn list(&self, primary_namespace: &str, sub_namespace: &str) -> Result<Vec<String>, io::Error>;
129+
/// returned keys. Returns an empty list if `primary_namespace` or `secondary_namespace` is unknown.
130+
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> Result<Vec<String>, io::Error>;
129131
}
130132

131133
/// Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk.
@@ -300,12 +302,12 @@ where
300302
/// Whole [`ChannelMonitor`]s are stored in the [`CHANNEL_MONITOR_PERSISTENCE_NAMESPACE`], using the
301303
/// familiar encoding of an [`OutPoint`] (for example, `[SOME-64-CHAR-HEX-STRING]_1`).
302304
///
303-
/// Each [`ChannelMonitorUpdate`] is stored in a dynamic sub-namespace, as follows:
305+
/// Each [`ChannelMonitorUpdate`] is stored in a dynamic secondary namespace, as follows:
304306
///
305-
/// - primary-namespace: [`CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE`]
306-
/// - sub-namespace: [the monitor's encoded outpoint name]
307+
/// - primary namespace: [`CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE`]
308+
/// - secondary namespace: [the monitor's encoded outpoint name]
307309
///
308-
/// Under that sub-namespace, each update is stored with a number string, like `21`, which
310+
/// Under that secondary namespace, each update is stored with a number string, like `21`, which
309311
/// represents its `update_id` value.
310312
///
311313
/// For example, consider this channel, named for its transaction ID and index, or [`OutPoint`]:
@@ -317,7 +319,7 @@ where
317319
///
318320
/// `[CHANNEL_MONITOR_PERSISTENCE_NAMESPACE]/deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef_1`
319321
///
320-
/// Updates would be stored as follows (with `/` delimiting primary-namespace/sub-namespace/key):
322+
/// Updates would be stored as follows (with `/` delimiting primary_namespace/secondary_namespace/key):
321323
///
322324
/// ```text
323325
/// [CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE]/deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef_1/1

0 commit comments

Comments
 (0)