forked from lightningdevkit/ldk-node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmod.rs
More file actions
77 lines (66 loc) · 3.32 KB
/
mod.rs
File metadata and controls
77 lines (66 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pub(crate) mod fs_store;
pub(crate) mod utils;
use std::io::{Read, Write};
// The namespacs and keys LDK uses for persisting
pub(crate) const CHANNEL_MANAGER_PERSISTENCE_NAMESPACE: &str = "";
pub(crate) const CHANNEL_MANAGER_PERSISTENCE_KEY: &str = "manager";
pub(crate) const CHANNEL_MONITOR_PERSISTENCE_NAMESPACE: &str = "monitors";
pub(crate) const NETWORK_GRAPH_PERSISTENCE_NAMESPACE: &str = "";
pub(crate) const NETWORK_GRAPH_PERSISTENCE_KEY: &str = "network_graph";
pub(crate) const SCORER_PERSISTENCE_NAMESPACE: &str = "";
pub(crate) const SCORER_PERSISTENCE_KEY: &str = "scorer";
/// The event queue will be persisted under this key.
pub(crate) const EVENT_QUEUE_PERSISTENCE_NAMESPACE: &str = "";
pub(crate) const EVENT_QUEUE_PERSISTENCE_KEY: &str = "events";
/// The peer information will be persisted under this key.
pub(crate) const PEER_INFO_PERSISTENCE_NAMESPACE: &str = "";
pub(crate) const PEER_INFO_PERSISTENCE_KEY: &str = "peers";
/// The payment information will be persisted under this prefix.
pub(crate) const PAYMENT_INFO_PERSISTENCE_NAMESPACE: &str = "payments";
/// RapidGossipSync's `latest_sync_timestamp` will be persisted under this key.
pub(crate) const RGS_LATEST_SYNC_TIMESTAMP_NAMESPACE: &str = "";
pub(crate) const RGS_LATEST_SYNC_TIMESTAMP_KEY: &str = "rgs_latest_sync_timestamp";
/// Provides an interface that allows to store and retrieve persisted values that are associated
/// with given keys.
///
/// In order to avoid collisions the key space is segmented based on the given `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 and the empty namespace (`""`) is
/// assumed to be valid namespace.
pub trait KVStore {
type Reader: Read;
type Writer: TransactionalWrite;
/// Returns a [`Read`] for the given `namespace` and `key` from which [`Readable`]s may be
/// read.
///
/// Returns an `Err` if the given `key` could not be found in the given `namespace`.
///
/// [`Readable`]: lightning::util::ser::Readable
fn read(&self, namespace: &str, key: &str) -> std::io::Result<Self::Reader>;
/// Returns a [`TransactionalWrite`] for the given `key` to which [`Writeable`]s may be written.
///
/// Will create the given `namespace` if not already present in the store.
///
/// Note that [`TransactionalWrite::commit`] MUST be called to commit the written data, otherwise
/// the changes won't be persisted.
///
/// [`Writeable`]: lightning::util::ser::Writeable
fn write(&self, namespace: &str, key: &str) -> std::io::Result<Self::Writer>;
/// Removes any data that had previously been persisted under the given `key`.
///
/// Returns `true` if the `key` was present in the given `namespace`, and `false` otherwise.
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<bool>;
/// Returns a list of keys that are stored under the given `namespace`.
///
/// Will return an empty list if the `namespace` is unknown.
fn list(&self, namespace: &str) -> std::io::Result<Vec<String>>;
}
/// A [`Write`] asserting data consistency.
///
/// Note that any changes need to be `commit`ed for them to take effect, and are lost otherwise.
pub trait TransactionalWrite: Write {
/// Persist the previously made changes.
fn commit(&mut self) -> std::io::Result<()>;
}