Skip to content

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

Merged
merged 4 commits into from
May 25, 2023
Merged

Conversation

tnull
Copy link
Collaborator

@tnull tnull commented May 19, 2023

Firstly, we simplify the KVStore interface: in the first commit we 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.

Furthermore, we previously had Node take a concrete FilesystemStore struct. In the second commit 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 parameters or requirements to track Arc-ed and non-Arced 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.

@tnull tnull requested review from G8XSU and jkczyz May 19, 2023 06:49
@tnull tnull mentioned this pull request May 19, 2023
@tnull tnull force-pushed the 2023-05-generic-kvstore branch from 5d0abd7 to 98b4bc1 Compare May 23, 2023 17:48
@tnull
Copy link
Collaborator Author

tnull commented May 23, 2023

Rebased after #85 landed.

@tnull
Copy link
Collaborator Author

tnull commented May 23, 2023

Rebased on main after #85 landed.

Copy link
Contributor

@G8XSU G8XSU left a 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.
@tnull tnull force-pushed the 2023-05-generic-kvstore branch 2 times, most recently from 854f935 to fa6f0d9 Compare May 24, 2023 18:59
@tnull
Copy link
Collaborator Author

tnull commented May 24, 2023

Rebased on current main and addressed all feedback. Let me know when I can squash the fixups.

@tnull tnull force-pushed the 2023-05-generic-kvstore branch 3 times, most recently from 58fc84d to cd9b51f Compare May 24, 2023 19:21
Copy link
Contributor

@jkczyz jkczyz left a 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

tnull added 3 commits May 24, 2023 22:21
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.
@tnull tnull force-pushed the 2023-05-generic-kvstore branch from cd9b51f to f482d45 Compare May 24, 2023 20:22
@tnull
Copy link
Collaborator Author

tnull commented May 24, 2023

Feel free to squash

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>(
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants