Skip to content

Commit 90f719d

Browse files
committed
feat: introduce and configure node with tiered KVStore
Introduces TierStore, a KVStore implementation that manages data across three storage layers: - Primary: Main/remote data store - Ephemeral: Secondary store for non-critical, easily-rebuildable data (e.g., network graph) with fast local access - Backup: Tertiary store for disaster recovery with async/lazy operations to avoid blocking primary store Adds four configuration methods to NodeBuilder: - set_tier_store_backup: Configure backup data store - set_tier_store_ephemeral: Configure ephemeral data store - set_tier_store_retry_config: Configure retry parameters with exponential backoff - build_with_tier_store: Build node with primary data store These methods are exposed to the foreign interface via additions in ffi/types.rs: - ffi::SyncAndAsyncKVStore: Composed of KVStore and KVStoreSync methods to handle the types::SyncAndAsyncKVStore supertrait across FFI - ffi::ForeignKVStoreAdapter and ffi::DynStore: Adapt/translate between foreign language store and native Rust store - Conditional compilation for DynStore: ffi::DynStore with uniffi, types::DynStore without, with selection aided by the wrap_store!() macro
1 parent 198ff30 commit 90f719d

File tree

22 files changed

+1960
-51
lines changed

22 files changed

+1960
-51
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ bitcoin = "0.32.7"
6363
bip39 = { version = "2.0.0", features = ["rand"] }
6464
bip21 = { version = "0.5", features = ["std"], default-features = false }
6565

66+
async-trait = {version = "0.1.89"}
6667
base64 = { version = "0.22.1", default-features = false, features = ["std"] }
6768
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
6869
chrono = { version = "0.4", default-features = false, features = ["clock"] }

bindings/ldk_node.udl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ enum WordCount {
6969
"Words24",
7070
};
7171

72+
dictionary RetryConfig {
73+
u16 initial_retry_delay_ms;
74+
u16 maximum_delay_secs;
75+
f32 backoff_multiplier;
76+
};
77+
7278
enum LogLevel {
7379
"Gossip",
7480
"Trace",
@@ -90,6 +96,56 @@ interface LogWriter {
9096
void log(LogRecord record);
9197
};
9298

99+
interface DynStore {
100+
[Name=from_store]
101+
constructor(SyncAndAsyncKVStore store);
102+
};
103+
104+
[Trait, WithForeign]
105+
interface SyncAndAsyncKVStore {
106+
// KVStoreSync versions
107+
[Throws=IOError]
108+
sequence<u8> read_sync(string primary_namespace, string secondary_namespace, string key);
109+
[Throws=IOError]
110+
void write_sync(string primary_namespace, string secondary_namespace, string key, sequence<u8> buf);
111+
[Throws=IOError]
112+
void remove_sync(string primary_namespace, string secondary_namespace, string key, boolean lazy);
113+
[Throws=IOError]
114+
sequence<string> list_sync(string primary_namespace, string secondary_namespace);
115+
116+
// KVStore versions
117+
[Throws=IOError, Async]
118+
sequence<u8> read_async(string primary_namespace, string secondary_namespace, string key);
119+
[Throws=IOError, Async]
120+
void write_async(string primary_namespace, string secondary_namespace, string key, sequence<u8> buf);
121+
[Throws=IOError, Async]
122+
void remove_async(string primary_namespace, string secondary_namespace, string key, boolean lazy);
123+
[Throws=IOError, Async]
124+
sequence<string> list_async(string primary_namespace, string secondary_namespace);
125+
};
126+
127+
[Error]
128+
enum IOError {
129+
"NotFound",
130+
"PermissionDenied",
131+
"ConnectionRefused",
132+
"ConnectionReset",
133+
"ConnectionAborted",
134+
"NotConnected",
135+
"AddrInUse",
136+
"AddrNotAvailable",
137+
"BrokenPipe",
138+
"AlreadyExists",
139+
"WouldBlock",
140+
"InvalidInput",
141+
"InvalidData",
142+
"TimedOut",
143+
"WriteZero",
144+
"Interrupted",
145+
"UnexpectedEof",
146+
"Other",
147+
};
148+
93149
interface Builder {
94150
constructor();
95151
[Name=from_config]
@@ -114,6 +170,9 @@ interface Builder {
114170
void set_announcement_addresses(sequence<SocketAddress> announcement_addresses);
115171
[Throws=BuildError]
116172
void set_node_alias(string node_alias);
173+
void set_tier_store_retry_config(RetryConfig retry_config);
174+
void set_tier_store_backup(DynStore backup_store);
175+
void set_tier_store_ephemeral(DynStore ephemeral_store);
117176
[Throws=BuildError]
118177
void set_async_payments_role(AsyncPaymentsRole? role);
119178
[Throws=BuildError]
@@ -126,6 +185,8 @@ interface Builder {
126185
Node build_with_vss_store_and_fixed_headers(NodeEntropy node_entropy, string vss_url, string store_id, record<string, string> fixed_headers);
127186
[Throws=BuildError]
128187
Node build_with_vss_store_and_header_provider(NodeEntropy node_entropy, string vss_url, string store_id, VssHeaderProvider header_provider);
188+
[Throws=BuildError]
189+
Node build_with_tier_store(NodeEntropy node_entropy, DynStore primary_store);
129190
};
130191

131192
interface Node {

0 commit comments

Comments
 (0)