-
Notifications
You must be signed in to change notification settings - Fork 103
Make KVStore
configurable
#101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5d0abd7
to
98b4bc1
Compare
Rebased after #85 landed. |
Rebased on main after #85 landed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM!
Previously `KVStore::write` would return a `TransactionalWrite` that would allow `Writeables` to be written directly and only be persisted upon calling `TransactionalWrite::commit()`. We however received feedback from implementors that this API is considered unnecessarily complex for a K-V store. Therefore we here refactor `KVStore::write` to take a `buf: &[u8]` directly and serialize the data into corresponding buffers before calling `KVStore::write`, thereby reducing the complexity for any implementation of the `KVStore` interface.
854f935
to
fa6f0d9
Compare
Rebased on current main and addressed all feedback. Let me know when I can squash the fixups. |
58fc84d
to
cd9b51f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to squash
Previously, we had `Node` take a concrete `FilesystemStore` struct. Here we switch to a generic `KVStore` type parameter. To this end we switched from `K: Deref` to concrete `Arc<K>` in all of the modules to avoid confusion of the type paramters or requirements to track `Arc`-ed and non-`Arc`ed version of the `K: KVStore` paramter. Moreover, as Uniffi doesn't support exposing generics we now expose a concretized `LDKNode` type alias in bindings, which will use `SqliteStore` in the future. Note that going the generic route was necessary as `dyn KVStore` wasn't an opion due to the incompatibility of `dyn` with associated types. In this case the incompatibility is in regard to `KVStore::Reader` and I opted to go this route over forcing any implementation of the trait to allocating and returning the same concrete value (e.g., `Vec<u8>`) which could potentially have significant performance impacts over returning a buffered reader for example.
cd9b51f
to
f482d45
Compare
Squashed fixups and included a new cleanup commit, as it touches unrelated code parts. |
/// Builds a [`Node`] instance according to the options previously configured. | ||
pub fn build(&self) -> Arc<Node> { | ||
pub fn build_with_store<K: KVStore + Sync + Send + 'static>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we do similar to set_esplora_server_url ?
and use similar builder pattern for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's one more related or unrelated item.
some KVStore's like Vss might need a runtime,
Current process of build_with_store assumes kvstore will be provided externally, but we will have no way to inject common runtime without something like set_runtime.
any thoughts or solutions to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we do similar to set_esplora_server_url ? and use similar builder pattern for this.
No, we need different build
methods as KVStore
is a type parameter, i.e., we need to build objects with the concretized type.
there's one more related or unrelated item. some KVStore's like Vss might need a runtime,
Current process of build_with_store assumes kvstore will be provided externally, but we will have no way to inject common runtime without something like set_runtime. any thoughts or solutions to that?
Mh, good point. I think unfortunately there is no way around injecting a runtime, as there will be no runtime loaded at initialization time. This in turn means that VssClient needs to be able to handle the absence of a runtime. Perhaps you'll need to write a KVStore
adapter object anyways which could handle the runtime injection and init/reload the actual client as needed?
Firstly, we simplify the
KVStore
interface: in the first commit we refactorKVStore::write
to take abuf: &[u8]
directly and serialize the data into corresponding buffers before callingKVStore::write
, thereby reducing the complexity for anyimplementation of the
KVStore
interface.Furthermore, we previously had
Node
take a concreteFilesystemStore
struct. In the second commit we switch to a genericKVStore
type parameter. To this end we switched fromK: Deref
to concreteArc<K>
in all of the modules to avoid confusion of the type parameters or requirements to trackArc
-ed and non-Arc
ed version of theK: KVStore
paramter. Moreover, as UniFFI doesn't support exposing generics we now expose a concretizedLDKNode
type alias in bindings, which will use
SqliteStore
in the future.