Copy async docs from async KVStore to sync one
What changed, and why it matters
This commit only copies documentation comments from the asynchronous version of a key-value storage trait to its synchronous wrapper. It fixes broken documentation links for language bindings but does not change any code behavior, logic, or security properties.
No security action required. Treat as a normal documentation maintenance commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff updates doc comments in lightning/src/util/persist.rs. It copies the full trait and method-level documentation from the async KVStore trait to the sync KVStoreSync trait, and adds cross-references and a maintenance note. No function signatures, implementations, or runtime behavior are modified.
Changed components
lightning/src/util/persist.rs documentation onlyInspect captured patch +62 / −5
diff --git a/lightning/src/util/persist.rs b/lightning/src/util/persist.rs
index 7be957a..d00e29e 100644
--- a/lightning/src/util/persist.rs
+++ b/lightning/src/util/persist.rs
@@ -118,21 +118,75 @@ pub const OUTPUT_SWEEPER_PERSISTENCE_KEY: &str = "output_sweeper";
/// updates applied to be current) with another implementation.
pub const MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL: &[u8] = &[0xFF; 2];
-/// A synchronous version of the [`KVStore`] trait.
+/// Provides an interface that allows storage and retrieval of persisted values that are associated
+/// with given keys.
+///
+/// In order to avoid collisions the key space is segmented based on the given `primary_namespace`s
+/// and `secondary_namespace`s. Implementations of this trait are free to handle them in different
+/// ways, as long as per-namespace key uniqueness is asserted.
+///
+/// Keys and namespaces are required to be valid ASCII strings in the range of
+/// [`KVSTORE_NAMESPACE_KEY_ALPHABET`] and no longer than [`KVSTORE_NAMESPACE_KEY_MAX_LEN`]. Empty
+/// primary namespaces and secondary namespaces (`""`) are assumed to be a valid, however, if
+/// `primary_namespace` is empty, `secondary_namespace` is required to be empty, too. This means
+/// that concerns should always be separated by primary namespace first, before secondary
+/// namespaces are used. While the number of primary namespaces will be relatively small and is
+/// determined at compile time, there may be many secondary namespaces per primary namespace. Note
+/// that per-namespace uniqueness needs to also hold for keys *and* namespaces in any given
+/// namespace, i.e., conflicts between keys and equally named
+/// primary namespaces/secondary namespaces must be avoided.
+///
+/// **Note:** Users migrating custom persistence backends from the pre-v0.0.117 `KVStorePersister`
+/// interface can use a concatenation of `[{primary_namespace}/[{secondary_namespace}/]]{key}` to
+/// recover a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
+///
+/// For an asynchronous version of this trait, see [`KVStore`].
+// Note that updates to documentation on this trait should be copied to the asynchronous version.
pub trait KVStoreSync {
- /// A synchronous version of the [`KVStore::read`] method.
+ /// Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
+ /// `key`.
+ ///
+ /// Returns an [`ErrorKind::NotFound`] if the given `key` could not be found in the given
+ /// `primary_namespace` and `secondary_namespace`.
+ ///
+ /// [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
fn read(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
) -> Result<Vec<u8>, io::Error>;
- /// A synchronous version of the [`KVStore::write`] method.
+ /// Persists the given data under the given `key`.
+ ///
+ /// Will create the given `primary_namespace` and `secondary_namespace` if not already present in the store.
fn write(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
) -> Result<(), io::Error>;
- /// A synchronous version of the [`KVStore::remove`] method.
+ /// Removes any data that had previously been persisted under the given `key`.
+ ///
+ /// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
+ /// remove the given `key` at some point in time after the method returns, e.g., as part of an
+ /// eventual batch deletion of multiple keys. As a consequence, subsequent calls to
+ /// [`KVStoreSync::list`] might include the removed key until the changes are actually persisted.
+ ///
+ /// Note that while setting the `lazy` flag reduces the I/O burden of multiple subsequent
+ /// `remove` calls, it also influences the atomicity guarantees as lazy `remove`s could
+ /// potentially get lost on crash after the method returns. Therefore, this flag should only be
+ /// set for `remove` operations that can be safely replayed at a later time.
+ ///
+ /// All removal operations must complete in a consistent total order with [`Self::write`]s
+ /// to the same key. Whether a removal operation is `lazy` or not, [`Self::write`] operations
+ /// to the same key which occur before a removal completes must cancel/overwrite the pending
+ /// removal.
+ ///
+ /// Returns successfully if no data will be stored for the given `primary_namespace`,
+ /// `secondary_namespace`, and `key`, independently of whether it was present before its
+ /// invokation or not.
fn remove(
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
) -> Result<(), io::Error>;
- /// A synchronous version of the [`KVStore::list`] method.
+ /// Returns a list of keys that are stored under the given `secondary_namespace` in
+ /// `primary_namespace`.
+ ///
+ /// Returns the keys in arbitrary order, so users requiring a particular order need to sort the
+ /// returned keys. Returns an empty list if `primary_namespace` or `secondary_namespace` is unknown.
fn list(
&self, primary_namespace: &str, secondary_namespace: &str,
) -> Result<Vec<String>, io::Error>;
@@ -215,7 +269,10 @@ where
/// interface can use a concatenation of `[{primary_namespace}/[{secondary_namespace}/]]{key}` to
/// recover a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
///
+/// For a synchronous version of this trait, see [`KVStoreSync`].
+///
/// This is not exported to bindings users as async is only supported in Rust.
+// Note that updates to documentation on this trait should be copied to the synchronous version.
pub trait KVStore {
/// Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
/// `key`.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.