11
11
use core:: ops:: Deref ;
12
12
use bitcoin:: hashes:: hex:: ToHex ;
13
13
use crate :: io;
14
+ use crate :: prelude:: { Vec , String } ;
14
15
use crate :: routing:: scoring:: WriteableScore ;
15
16
16
17
use crate :: chain;
@@ -22,7 +23,58 @@ use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate};
22
23
use crate :: ln:: channelmanager:: ChannelManager ;
23
24
use crate :: routing:: router:: Router ;
24
25
use crate :: routing:: gossip:: NetworkGraph ;
25
- use super :: { logger:: Logger , ser:: Writeable } ;
26
+ use crate :: util:: logger:: Logger ;
27
+ use crate :: util:: ser:: Writeable ;
28
+
29
+ /// The namespace under which the [`ChannelManager`] will be persisted.
30
+ pub const CHANNEL_MANAGER_PERSISTENCE_NAMESPACE : & str = "" ;
31
+ /// The key under which the [`ChannelManager`] will be persisted.
32
+ pub const CHANNEL_MANAGER_PERSISTENCE_KEY : & str = "manager" ;
33
+
34
+ /// The namespace under which [`ChannelMonitor`]s will be persisted.
35
+ pub const CHANNEL_MONITOR_PERSISTENCE_NAMESPACE : & str = "monitors" ;
36
+
37
+ /// The namespace under which the [`NetworkGraph`] will be persisted.
38
+ pub const NETWORK_GRAPH_PERSISTENCE_NAMESPACE : & str = "" ;
39
+ /// The key under which the [`NetworkGraph`] will be persisted.
40
+ pub const NETWORK_GRAPH_PERSISTENCE_KEY : & str = "network_graph" ;
41
+
42
+ /// The namespace under which the [`WriteableScore`] will be persisted.
43
+ pub const SCORER_PERSISTENCE_NAMESPACE : & str = "" ;
44
+ /// The key under which the [`WriteableScore`] will be persisted.
45
+ pub const SCORER_PERSISTENCE_KEY : & str = "scorer" ;
46
+
47
+ /// Provides an interface that allows to store and retrieve persisted values that are associated
48
+ /// with given keys.
49
+ ///
50
+ /// In order to avoid collisions the key space is segmented based on the given `namespace`s.
51
+ /// Implementations of this trait are free to handle them in different ways, as long as
52
+ /// per-namespace key uniqueness is asserted.
53
+ ///
54
+ /// Keys and namespaces are required to be valid ASCII strings and the empty namespace (`""`) is
55
+ /// assumed to be valid namespace.
56
+ pub trait KVStore {
57
+ /// A reader as returned by [`Self::read`].
58
+ type Reader : io:: Read ;
59
+ /// Returns an [`io::Read`] for the given `namespace` and `key` from which [`Readable`]s may be
60
+ /// read.
61
+ ///
62
+ /// Returns an [`ErrorKind::NotFound`] if the given `key` could not be found in the given `namespace`.
63
+ ///
64
+ /// [`Readable`]: crate::util::ser::Readable
65
+ /// [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
66
+ fn read ( & self , namespace : & str , key : & str ) -> io:: Result < Self :: Reader > ;
67
+ /// Persists the given data under the given `key`.
68
+ ///
69
+ /// Will create the given `namespace` if not already present in the store.
70
+ fn write ( & self , namespace : & str , key : & str , buf : & [ u8 ] ) -> io:: Result < ( ) > ;
71
+ /// Removes any data that had previously been persisted under the given `key`.
72
+ fn remove ( & self , namespace : & str , key : & str ) -> io:: Result < ( ) > ;
73
+ /// Returns a list of keys that are stored under the given `namespace`.
74
+ ///
75
+ /// Will return an empty list if the `namespace` is unknown.
76
+ fn list ( & self , namespace : & str ) -> io:: Result < Vec < String > > ;
77
+ }
26
78
27
79
/// Trait for a key-value store for persisting some writeable object at some key
28
80
/// Implementing `KVStorePersister` provides auto-implementations for [`Persister`]
0 commit comments