Skip to content

Commit ec8bfb3

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 eaad8f5 commit ec8bfb3

File tree

22 files changed

+1970
-49
lines changed

22 files changed

+1970
-49
lines changed

Cargo.toml

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

92+
async-trait = {version = "0.1.89"}
9293
base64 = { version = "0.22.1", default-features = false, features = ["std"] }
9394
rand = "0.8.5"
9495
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
@@ -46,6 +46,12 @@ dictionary LSPS2ServiceConfig {
4646
u64 max_payment_size_msat;
4747
};
4848

49+
dictionary RetryConfig {
50+
u16 initial_retry_delay_ms;
51+
u16 maximum_delay_secs;
52+
f32 backoff_multiplier;
53+
};
54+
4955
enum LogLevel {
5056
"Gossip",
5157
"Trace",
@@ -67,6 +73,56 @@ interface LogWriter {
6773
void log(LogRecord record);
6874
};
6975

76+
interface DynStore {
77+
[Name=from_store]
78+
constructor(SyncAndAsyncKVStore store);
79+
};
80+
81+
[Trait, WithForeign]
82+
interface SyncAndAsyncKVStore {
83+
// KVStoreSync versions
84+
[Throws=IOError]
85+
sequence<u8> read_sync(string primary_namespace, string secondary_namespace, string key);
86+
[Throws=IOError]
87+
void write_sync(string primary_namespace, string secondary_namespace, string key, sequence<u8> buf);
88+
[Throws=IOError]
89+
void remove_sync(string primary_namespace, string secondary_namespace, string key, boolean lazy);
90+
[Throws=IOError]
91+
sequence<string> list_sync(string primary_namespace, string secondary_namespace);
92+
93+
// KVStore versions
94+
[Throws=IOError, Async]
95+
sequence<u8> read_async(string primary_namespace, string secondary_namespace, string key);
96+
[Throws=IOError, Async]
97+
void write_async(string primary_namespace, string secondary_namespace, string key, sequence<u8> buf);
98+
[Throws=IOError, Async]
99+
void remove_async(string primary_namespace, string secondary_namespace, string key, boolean lazy);
100+
[Throws=IOError, Async]
101+
sequence<string> list_async(string primary_namespace, string secondary_namespace);
102+
};
103+
104+
[Error]
105+
enum IOError {
106+
"NotFound",
107+
"PermissionDenied",
108+
"ConnectionRefused",
109+
"ConnectionReset",
110+
"ConnectionAborted",
111+
"NotConnected",
112+
"AddrInUse",
113+
"AddrNotAvailable",
114+
"BrokenPipe",
115+
"AlreadyExists",
116+
"WouldBlock",
117+
"InvalidInput",
118+
"InvalidData",
119+
"TimedOut",
120+
"WriteZero",
121+
"Interrupted",
122+
"UnexpectedEof",
123+
"Other",
124+
};
125+
70126
interface Builder {
71127
constructor();
72128
[Name=from_config]
@@ -95,6 +151,9 @@ interface Builder {
95151
void set_announcement_addresses(sequence<SocketAddress> announcement_addresses);
96152
[Throws=BuildError]
97153
void set_node_alias(string node_alias);
154+
void set_tier_store_retry_config(RetryConfig retry_config);
155+
void set_tier_store_backup(DynStore backup_store);
156+
void set_tier_store_ephemeral(DynStore ephemeral_store);
98157
[Throws=BuildError]
99158
void set_async_payments_role(AsyncPaymentsRole? role);
100159
[Throws=BuildError]
@@ -107,6 +166,8 @@ interface Builder {
107166
Node build_with_vss_store_and_fixed_headers(string vss_url, string store_id, record<string, string> fixed_headers);
108167
[Throws=BuildError]
109168
Node build_with_vss_store_and_header_provider(string vss_url, string store_id, VssHeaderProvider header_provider);
169+
[Throws=BuildError]
170+
Node build_with_tier_store(DynStore primary_store);
110171
};
111172

112173
interface Node {

0 commit comments

Comments
 (0)