Open acolytec3 opened 3 years ago
thanks for giving this an initial try @acolytec3! agree with your reasoning that if the state access could be extracted with a put/get API, we could supply our own db and reduce the need for the rocksdb dependency (we use leveldb in ethereumjs in both Node and the browser)
edit: oh! rocksdb is an abstract-leveldown compliant store by level. i didn't know that! in that case could we simply pass you a leveldown compliant store as an arg? this is already how our trie, vm, and client packages handle their dbs so that would be simple.
https://github.com/crate-crypto/rust-verkle/blob/master/verkle-trie/src/database.rs If I'm reading the comments here, what would be needed is just an alternative implementation of the two methods exposed here declared as extern
and then we create methods on the JS side that provide the needed DB methods, right?
Hi, thanks for raising this issue. rust-verkle does not need rocksdb or verkle-db, so it should be put as optional.
rust-verkle only requires that you implement the methods in the file that you linked above. If you have a key-value database, then you can implement the methods in verkle-db and those methods in in database.rs will use default implementations.
thanks for giving this an initial try @acolytec3! agree with your reasoning that if the state access could be extracted with a put/get API, we could supply our own db and reduce the need for the rocksdb dependency (we use leveldb in ethereumjs in both Node and the browser)
edit: oh! rocksdb is an abstract-leveldown compliant store by level. i didn't know that! in that case could we simply pass you a leveldown compliant store as an arg? this is already how our trie, vm, and client packages handle their dbs so that would be simple.
Yep!, although instead of a put/get API, we have a "batch_put" and a get api, because we only ever write to the disk in batches/transactions.
This should be fixed now on main
, I tested the wasm-pack command you mentioned above and it produces a .wasm file along with accompanying typescript and javascript files.
Just to verify what I need, I just need to implement externs for the methods in this file, right?
Sorry I missed the last message.
I'm not familiar enough with WASM to comment on that part with 100% confidence, but I believe you are correct, because if you were using this library natively in Rust as a dependency, you would only need to implement those methods.
To test this hypothesis without the complexity of this codebase, you could have a simpler rust project with only the following trait:
pub trait Database {
fn put(key : [u8;32], value : [u8;32]);
fn get(key : [u8;32]) -> Option<[u8;32]>;
}
And provide bindings through WASM for these methods initially
Thanks! I'm a complete novice with Rust but can follow "how tos" okay so we'll see how far I can get. I can confirm I was able to compile the current master branch for WASM which is promising.
For anyone else trying to compile verkle-trie
for WASM, please note the following requirements to compile:
1) in Cargo.toml
, add the following two pieces.
[Dependencies]
...
[dependencies]
...
wasm-bindgen = "0.2"
getrandom = { version = "0.2", features = ["js"] }
...
[lib]
crate-type = ["cdylib", "rlib"]
2) Ensure you run rustup default nightly
3) Run wasm-pack build --target web
from [repo_root]/verkle-trie
to compile the module.
No problem :) let me know if anything else looks weird!
FYI - I've started a fork to work on a WASM compatible implementation attempting to implement a jsdb_impl
here.
It doesn't compile yet but I think that's at least as much ascribable to my ineptitude with Rust as anything.
Hi @kevaundray, thanks for giving this a start! 🙂
Here is the relevant repo which compiles the Rust code into Wasm and has an example js file which calls the generated wasm with js generated values: https://github.com/crate-crypto/rust-verkle-wasm
The root that is being returned is a stub until actual values can be taken received from the Go code
Hi @kevaundray, that's really great, thanks a lot! 🎉 😀
The
verkle-trie
module currently cannot be compiled to WASM because it depends on the rocksdb bindings which are from C (if I'm reading the logs correctly). I'm not sure if there's any direct way around this unless there is a pure Rust version of rocksdb that could be compiled to WASM as well. Would it be possible to separate out just the verkle verifier code into a standalone module that isn't dependent onrocksdb
so it could be used in the browser?By adding the below to
dependencies
and then
I was able to get to the point of the rocksdb failure that generates the below error by running
wasm-pack build --target web
in the root of theverkle-trie
package.