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

feat(plugin-keychain-memory-wasm): add WebAssmebly PoC #1463

Merged
merged 3 commits into from
Oct 25, 2021

Conversation

petermetz
Copy link
Contributor

Adding a new keychain in-memory plugin that has it's implementation
written in Rust that is then compiled down to WebAssmebly via wasm-pack
and used by the wrapper Typescript code.

This is NOT meant for production because it stores everything in plain
text and also provides zero durability/persistence guarantees given that
it's only storing everything in memory.

The actual news here is that we have a plugin now written in Rust which
is the pre-cursor to us being able to do something similar with the
Weaver relay component as the next phase of a bigger PoC.

The reason why not the entire plugin is implemented in Rust is because
we are unable to hook up ExpressJS request handlers from the Rust code
as far as I could determine. See this link for further details on this:
https://rustwasm.github.io/book/reference/js-ffi.html#from-the-rust-side

Because of the above, the way it works is this:

    +--------+ API Request   +----------+
    | HTTP   |-------------->| ExpressJS|
    | Client |               +----------+
    +--------+               Method|
                             Call  |
                                   v
    +---------+ Method Call  +----------+
    | Calling |------------->|JS Plugin |
    | Module  |              |Module    |
    +---------+              +----------+
                               |get()
                               |set()
                               |has()
                               |delete()
            +-------------+    |
            | Wasm Plugin |<---+
            | Module      |
            +-------------+
                    ^
                    |
                    |
                    v
       +------------------------+
       |Rust Native             |
       |HashMap<String, String> |
       +------------------------+

Resolves #1281

Signed-off-by: Peter Somogyvari [email protected]

Adding a new keychain in-memory plugin that has it's implementation
written in Rust that is then compiled down to WebAssmebly via wasm-pack
and used by the wrapper Typescript code.

This is NOT meant for production because it stores everything in plain
text and also provides zero durability/persistence guarantees given that
it's only storing everything in memory.

The actual news here is that we have a plugin now written in Rust which
is the pre-cursor to us being able to do something similar with the
Weaver relay component as the next phase of a bigger PoC.

The reason why not the entire plugin is implemented in Rust is because
we are unable to hook up ExpressJS request handlers from the Rust code
as far as I could determine. See this link for further details on this:
https://rustwasm.github.io/book/reference/js-ffi.html#from-the-rust-side

Because of the above, the way it works is this:

        +--------+ API Request   +----------+
        | HTTP   |-------------->| ExpressJS|
        | Client |               +----------+
        +--------+               Method|
                                 Call  |
                                       v
        +---------+ Method Call  +----------+
        | Calling |------------->|JS Plugin |
        | Module  |              |Module    |
        +---------+              +----------+
                                   |get()
                                   |set()
                                   |has()
                                   |delete()
                +-------------+    |
                | Wasm Plugin |<---+
                | Module      |
                +-------------+
                        ^
                        |
                        |
                        v
           +------------------------+
           |Rust Native             |
           |HashMap<String, String> |
           +------------------------+

Resolves hyperledger-cacti#1281

Signed-off-by: Peter Somogyvari <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Oct 19, 2021

Codecov Report

Merging #1463 (157077b) into main (305171b) will decrease coverage by 0.61%.
The diff coverage is 57.62%.

❗ Current head 157077b differs from pull request most recent head 0a419f8. Consider uploading reports for the commit 0a419f8 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1463      +/-   ##
==========================================
- Coverage   71.82%   71.20%   -0.62%     
==========================================
  Files         317      331      +14     
  Lines       11568    12080     +512     
  Branches     1416     1455      +39     
==========================================
+ Hits         8309     8602     +293     
- Misses       2477     2675     +198     
- Partials      782      803      +21     
Impacted Files Coverage Δ
...enerated/openapi/typescript-axios/configuration.ts 9.09% <9.09%> (ø)
...pescript/generated/openapi/typescript-axios/api.ts 29.54% <29.54%> (ø)
...asm/src/main/typescript/plugin-factory-keychain.ts 41.66% <41.66%> (ø)
...cript/generated/openapi/typescript-axios/common.ts 42.85% <42.85%> (ø)
...ed/wasm-pack/cactus_plugin_keychain_memory_wasm.js 57.87% <57.87%> (ø)
...escript/generated/openapi/typescript-axios/base.ts 58.33% <58.33%> (ø)
...ript/webservices/get-keychain-entry-endpoint-v1.ts 63.88% <63.88%> (ø)
...t/webservices/delete-keychain-entry-endpoint-v1.ts 69.69% <69.69%> (ø)
...ript/webservices/set-keychain-entry-endpoint-v1.ts 69.69% <69.69%> (ø)
...src/main/typescript/plugin-keychain-memory-wasm.ts 82.60% <82.60%> (ø)
... and 48 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 305171b...0a419f8. Read the comment docs.

Copy link
Contributor

@jonathan-m-hamilton jonathan-m-hamilton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@izuru0 izuru0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petermetz am I correct in assuming that this is a refactoring of existing plugin, not a totally new plugin?

@petermetz
Copy link
Contributor Author

@petermetz am I correct in assuming that this is a refactoring of existing plugin, not a totally new plugin?

@izuru0 Yup, that's right.

Copy link
Contributor

@izuru0 izuru0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@petermetz petermetz merged commit df94397 into hyperledger-cacti:main Oct 25, 2021
@petermetz petermetz deleted the feat-1281 branch October 25, 2021 19:38
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.

feat(cmd-api-server): web assembly plugin modules
4 participants