Skip to content

Commit ff64247

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 650fd19 commit ff64247

File tree

22 files changed

+1971
-50
lines changed

22 files changed

+1971
-50
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
@@ -55,6 +55,12 @@ enum WordCount {
5555
"Words24",
5656
};
5757

58+
dictionary RetryConfig {
59+
u16 initial_retry_delay_ms;
60+
u16 maximum_delay_secs;
61+
f32 backoff_multiplier;
62+
};
63+
5864
enum LogLevel {
5965
"Gossip",
6066
"Trace",
@@ -76,6 +82,56 @@ interface LogWriter {
7682
void log(LogRecord record);
7783
};
7884

85+
interface DynStore {
86+
[Name=from_store]
87+
constructor(SyncAndAsyncKVStore store);
88+
};
89+
90+
[Trait, WithForeign]
91+
interface SyncAndAsyncKVStore {
92+
// KVStoreSync versions
93+
[Throws=IOError]
94+
sequence<u8> read_sync(string primary_namespace, string secondary_namespace, string key);
95+
[Throws=IOError]
96+
void write_sync(string primary_namespace, string secondary_namespace, string key, sequence<u8> buf);
97+
[Throws=IOError]
98+
void remove_sync(string primary_namespace, string secondary_namespace, string key, boolean lazy);
99+
[Throws=IOError]
100+
sequence<string> list_sync(string primary_namespace, string secondary_namespace);
101+
102+
// KVStore versions
103+
[Throws=IOError, Async]
104+
sequence<u8> read_async(string primary_namespace, string secondary_namespace, string key);
105+
[Throws=IOError, Async]
106+
void write_async(string primary_namespace, string secondary_namespace, string key, sequence<u8> buf);
107+
[Throws=IOError, Async]
108+
void remove_async(string primary_namespace, string secondary_namespace, string key, boolean lazy);
109+
[Throws=IOError, Async]
110+
sequence<string> list_async(string primary_namespace, string secondary_namespace);
111+
};
112+
113+
[Error]
114+
enum IOError {
115+
"NotFound",
116+
"PermissionDenied",
117+
"ConnectionRefused",
118+
"ConnectionReset",
119+
"ConnectionAborted",
120+
"NotConnected",
121+
"AddrInUse",
122+
"AddrNotAvailable",
123+
"BrokenPipe",
124+
"AlreadyExists",
125+
"WouldBlock",
126+
"InvalidInput",
127+
"InvalidData",
128+
"TimedOut",
129+
"WriteZero",
130+
"Interrupted",
131+
"UnexpectedEof",
132+
"Other",
133+
};
134+
79135
interface Builder {
80136
constructor();
81137
[Name=from_config]
@@ -104,6 +160,9 @@ interface Builder {
104160
void set_announcement_addresses(sequence<SocketAddress> announcement_addresses);
105161
[Throws=BuildError]
106162
void set_node_alias(string node_alias);
163+
void set_tier_store_retry_config(RetryConfig retry_config);
164+
void set_tier_store_backup(DynStore backup_store);
165+
void set_tier_store_ephemeral(DynStore ephemeral_store);
107166
[Throws=BuildError]
108167
void set_async_payments_role(AsyncPaymentsRole? role);
109168
[Throws=BuildError]
@@ -116,6 +175,8 @@ interface Builder {
116175
Node build_with_vss_store_and_fixed_headers(string vss_url, string store_id, record<string, string> fixed_headers);
117176
[Throws=BuildError]
118177
Node build_with_vss_store_and_header_provider(string vss_url, string store_id, VssHeaderProvider header_provider);
178+
[Throws=BuildError]
179+
Node build_with_tier_store(DynStore primary_store);
119180
};
120181

121182
interface Node {

0 commit comments

Comments
 (0)