Skip to content
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

wRPC binary serialization with data structure versioning support #480

Closed
wants to merge 29 commits into from

Conversation

aspect
Copy link
Collaborator

@aspect aspect commented May 31, 2024

This PR implements support for "wRPC serialization versioning".

This is accomplished using a set of primitives and macros added to workflow-rs (workflow-serializer crate) that implements Serializer trait and a helper Serializable<T>(T) struct (https://github.com/workflow-rs/workflow-rs/tree/serializer/serializer/src).

wRPC calls require BorshSerialize and BorshDeserialize. These traits have been removed form RK RPC data structures. Instead they now implement Serializer trait to perform binary serialization. The Serializable<T>(T) where T: Serializer struct implements BorshSerialize and BorshDeserialize and is #[repr(transparent)], effectively converting data structures that implement Serializer trait to BorshSerialize and BorshDeserialize invocations.

Each RPC (and related) data structure that opts-in for versioning now manually serializes it's fields, where the first field is always a version number (currently u32). By checking the version number on deserialization, structures can opt-in to deserialize old or new binary layouts.

This is a "future compatible" implementation that allows newer clients/nodes to understand older requests, but will not allow older clients/nodes to understand newer requests. (each structure can implement forward compatibility internally if desired by pre-buffering and storing the size of the binary payload and ignoring (while skipping) additional data; this is not really a common approach as it poses other issues where field types can change, breaking serialization).

By augmenting Kaspa wRPC client and server interfaces with these traits, the constraints on these interfaces change requiring all RPC data structures to implement the Serializer trait, which is now implemented for each such struct.

The implementation of serialization is done beside each RPC data structure. A new rpc/core/src/test.rs file implements serialization unit tests designed to catch basic data misalignments.

IMPORTANT: When this PR is merged, we will need to make a new node release as well as the corresponding WASM SDK and KNG releases as this will break wRPC Borsh encoding compatibility (this PR addresses that very problem, allowing us to perform protocol upgrades in the future without breaking such compatibility).

aspect and others added 29 commits May 31, 2024 18:37
* range support added for transactions pagination

* cargo fmt/clippy
* provisional RpcConnection propagation via RpcApi methods

* lints
@aspect
Copy link
Collaborator Author

aspect commented Jul 22, 2024

Merged into #506

@aspect aspect closed this Jul 22, 2024
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.

2 participants