-
Notifications
You must be signed in to change notification settings - Fork 0
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
As a Developer, I need to have a way to encode/decode Mina messages in Rust so I can implement an independent Mina peer #1
Comments
There are some crates available that take care of
Initially we can use one of these. |
It is possible to get sexp-based shapes for all versioned types used by Mina, by using the following command:
Here is the output of that command, and this one is pretty-printed version of |
ChainSafe uses this JSON file as a schema for block, or transition, message, but it might be out of date with actual data structure. |
I'm in the progress of code generation basing on JSON from above, but it looks like I need to use that sexp generated basing on up-to-date Mina sources instead. @tizoc do you know per chance how hard would it be to modify that command so sexp output includes more information, like type module name, and recursion markers? |
I think it should be possible to use the current structure of that shapes after all. The idea is like this: each type has the "whole" shape, extended up to primitive types (or ones without shape), but we need to detect what versioned type is used e.g. as a record field type. We can do that basing on the part of the shape representing that field type, by searching for a type with exactly the same shape. Consider the following shapes:
Here we can detect that the both fields of the |
If needed some extra processing can be added here to compare the shapes at each level to detect if some child is an already-seen shape https://github.com/MinaProtocol/mina/blob/1765ba6bdfd7c454e5ae836c49979fa076de1bea/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml#L1404 But in the end it is not very different from doing the same detection from the rendered result, there is really no extra information at this point that you don't have in the rendered version. |
Implementing RPC decoding. |
RPC |
The list of V1 RPCs:
|
V2 Gossip messages are done. Now working on RPCs for V2. |
For RPCs we can't have |
Adding bencmarking, for both native and wasm32. |
Implementing memory consumption benchmarks. |
Performance test Native:
Wasm32 (Firefox):
Wasm32 (Chrome):
Wasm32 (Node):
The summary is that there is a slight slow down when running as Wasm32, but it is less than x2. |
Memory Consumption TestDecoding of input messages, incoming RPCs captured during catch-up process in berkeleynet (~80M). Native:
Wasm32 (Firefox):
Still in-memory representation is 1.3-1.5 times bigger than encoded size. That is mostly because of enums with variants of different size -- all variants (even empty) require amount of memory suitable for the biggest variant. |
BTW, before this fix memory consumption ratio was ~8 (runtime representation was >8 times bigger than encoded size), and wasm32 tests were 50% slower. |
@akoptelov how did that change help? unless there is something I am missing, that code still allocates the same memory as before, plus space for the pointer to the bytes (which were inlined before), right? |
@tizoc For simplicity, imagine this: struct BigInt([u8;32]);
enum Option {
None,
Some(BigInt),
} Each instance of the struct BigInt(Box<[u8;32]>);
enum Option {
None,
Some(BigInt),
} the |
@akoptelov ahh I see. Thanks. |
An update: #19 (comment) |
V2 wire types are generated without parameters now. |
Here's the diff with boxed types: |
Heap allocations while decoding a Before boxing alts:
With boxed alts:
In a nutshell, the peaked (maximal allocated) size went from almost 200M down to 39M, what is only 2x times more than encoded size. With preallocated vectors in
|
Moved out security/safety items, they can be tracked elsewhere. |
The fully functional library for Mina types is developed. |
Definition of "done"
A Rust library developed that contains type definitions for all Mina gossip and RPC messages with possibility to encode/decode using
bin prot
schema.Bin_code
encoding for Mina types #7The text was updated successfully, but these errors were encountered: