Skip to content

Commit 18ef80f

Browse files
committed
Refer to top-level persistence namespaces as primary_namespace
This fixes a bindings build error as `namespace` is a C++ keyword which cannot be used as an argument, and while this could be fixed in the bindings rather than here, separating the term `namespace` between the concept (which refers to the primary and sub namespaces) and the primary namespace makes the documentation more readable.
1 parent 910a00e commit 18ef80f

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

lightning/src/util/persist.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,36 @@ pub const MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL: &[u8] = &[0xFF; 2];
7474
/// Provides an interface that allows storage and retrieval of persisted values that are associated
7575
/// with given keys.
7676
///
77-
/// In order to avoid collisions the key space is segmented based on the given `namespace`s and
78-
/// `sub_namespace`s. Implementations of this trait are free to handle them in different ways, as
79-
/// long as per-namespace key uniqueness is asserted.
77+
/// 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.
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-
/// namespaces and sub-namespaces (`""`) are assumed to be a valid, however, if `namespace` is
84-
/// empty, `sub_namespace` is required to be empty, too. This means that concerns should always be
85-
/// separated by namespace first, before sub-namespaces are used. While the number of namespaces
86-
/// will be relatively small and is determined at compile time, there may be many sub-namespaces
87-
/// per namespace. Note that per-namespace uniqueness needs to also hold for keys *and*
88-
/// namespaces/sub-namespaces in any given namespace/sub-namespace, i.e., conflicts between keys
89-
/// and equally named namespaces/sub-namespaces must be avoided.
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.
9090
///
9191
/// **Note:** Users migrating custom persistence backends from the pre-v0.0.117 `KVStorePersister`
92-
/// interface can use a concatenation of `[{namespace}/[{sub_namespace}/]]{key}` to recover a `key` compatible with the
93-
/// data model previously assumed by `KVStorePersister::persist`.
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`.
9494
pub trait KVStore {
95-
/// Returns the data stored for the given `namespace`, `sub_namespace`, and `key`.
95+
/// Returns the data stored for the given `primary_namespace`, `sub_namespace`, and `key`.
9696
///
9797
/// Returns an [`ErrorKind::NotFound`] if the given `key` could not be found in the given
98-
/// `namespace` and `sub_namespace`.
98+
/// `primary_namespace` and `sub_namespace`.
9999
///
100100
/// [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
101-
fn read(&self, namespace: &str, sub_namespace: &str, key: &str) -> Result<Vec<u8>, io::Error>;
101+
fn read(&self, primary_namespace: &str, sub_namespace: &str, key: &str) -> Result<Vec<u8>, io::Error>;
102102
/// Persists the given data under the given `key`.
103103
///
104-
/// Will create the given `namespace` and `sub_namespace` if not already present in the store.
105-
fn write(&self, namespace: &str, sub_namespace: &str, key: &str, buf: &[u8]) -> Result<(), io::Error>;
104+
/// Will create the given `primary_namespace` and `sub_namespace` if not already present in the
105+
/// store.
106+
fn write(&self, primary_namespace: &str, sub_namespace: &str, key: &str, buf: &[u8]) -> Result<(), io::Error>;
106107
/// Removes any data that had previously been persisted under the given `key`.
107108
///
108109
/// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
@@ -115,14 +116,16 @@ pub trait KVStore {
115116
/// potentially get lost on crash after the method returns. Therefore, this flag should only be
116117
/// set for `remove` operations that can be safely replayed at a later time.
117118
///
118-
/// Returns successfully if no data will be stored for the given `namespace`, `sub_namespace`, and
119-
/// `key`, independently of whether it was present before its invokation or not.
120-
fn remove(&self, namespace: &str, sub_namespace: &str, key: &str, lazy: bool) -> Result<(), io::Error>;
121-
/// Returns a list of keys that are stored under the given `sub_namespace` in `namespace`.
119+
/// 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
124+
/// `primary_namespace`.
122125
///
123126
/// Returns the keys in arbitrary order, so users requiring a particular order need to sort the
124-
/// returned keys. Returns an empty list if `namespace` or `sub_namespace` is unknown.
125-
fn list(&self, namespace: &str, sub_namespace: &str) -> Result<Vec<String>, io::Error>;
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>;
126129
}
127130

128131
/// Trait that handles persisting a [`ChannelManager`], [`NetworkGraph`], and [`WriteableScore`] to disk.
@@ -299,7 +302,7 @@ where
299302
///
300303
/// Each [`ChannelMonitorUpdate`] is stored in a dynamic sub-namespace, as follows:
301304
///
302-
/// - namespace: [`CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE`]
305+
/// - primary-namespace: [`CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE`]
303306
/// - sub-namespace: [the monitor's encoded outpoint name]
304307
///
305308
/// Under that sub-namespace, each update is stored with a number string, like `21`, which
@@ -314,7 +317,7 @@ where
314317
///
315318
/// `[CHANNEL_MONITOR_PERSISTENCE_NAMESPACE]/deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef_1`
316319
///
317-
/// Updates would be stored as follows (with `/` delimiting namespace/sub-namespace/key):
320+
/// Updates would be stored as follows (with `/` delimiting primary-namespace/sub-namespace/key):
318321
///
319322
/// ```text
320323
/// [CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE]/deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef_1/1

0 commit comments

Comments
 (0)