Comments (3)
I think the main problem is that kvdb
exposes sync API like fn get(&self, col: Option<u32>, key: &[u8]) -> io::Result<Option<DBValue>>
, whereas IndexedDB provides an async API with js-style callbacks.
From https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStoreSync:
Important: The synchronous version of the IndexedDB API was originally intended for use only with Web Workers, and was eventually removed from the spec because its need was questionable. It may however be reintroduced in the future if there is enough demand from web developers.
from parity-common.
Oh, I see.
Maybe a better approach is simply to keep the database in memory (like kvdb-memory
), and save a serialized version in the local storage from time to time and on shutdown.
The use case is a light client whose database is probably very small. I imagine that the light client will somehow warp-sync in the future, and storing the database is mostly an optimization.
from parity-common.
While trying to make this work, I've encountered a bunch of issues:
Some problems of localStorage:
- The API allows you to use only JS string (UTF-16) as keys and values
- It usually has a limit of 10MB (https://arty.name/localstorage.html)
- localStorage API is not available in WebWorkers, meaning it's not possible to save a serialized version in a background thread.
IndexDB API is not ready yet
- one can access low-level API via
web_sys
, but it's really ugly - Hopefully this will be resolved by rustwasm/gloo#68
I'm not sure what is the expected size of of the substrate light client db, but we could implement it with localStorage first and migrate to IndexDB later (I imagine having an in-memory hashmap in both cases, reading the whole db into the memory on startup and writing async in case of indexdb).
wasm-bindgen limitations
- it doesn't (and probably won't) support lifetimes in returned values (rustwasm/wasm-bindgen#423) (we have
iter
anditer_from_prefix
methods onKeyValueDB
) - only supports c-style enums (we have a rusty enum
DBOp
in kvdb) - [minor] wasm-bindgen provides a proc macro to generate all the js shims, which means it can't be used as an optional dependency on kvdb due to rust-lang/rust#29642, unless I'm missing something?
This means that kvdb KeyValueDB
interface would need some breaking changes. Alternatively, we could create another (async?) interface just for the browser use-case.
EDIT: the wasm-bindgen limitations are only relevant if we want to expose the KeyValueDB
interface to JS, but looks like we don't.
from parity-common.
Related Issues (20)
- U256 type does not support `num_traits::int::PrimInt` HOT 3
- Could we have a new crates release for primitive-types please? HOT 1
- [rlp] `RlpIterator::len()` does not update when the iterator is consumed. HOT 1
- From<i64> impl is invalid HOT 2
- ethereum-types: Consider depending on uint v0.9.4 or above
- rlp: handling extra data HOT 1
- rlp: list length and contents are not validated
- Where is patricia-trie? HOT 1
- Implement BoundedVec with bound on both end HOT 2
- Implement `Serialize / Deserialize` for `BoundedBtreeSet` HOT 3
- Implement BoundedVec::try_with_capacity
- Is it possible to use unit in no_std projects? HOT 1
- Is there a corresponding library in Go for Rust's primitive-types package? HOT 1
- num-traits feature on primitive-types could use a FromPrimitive impl
- [uint] conversion between uint types HOT 2
- rlp - test failures on 32-bit HOT 1
- Missing I256 HOT 2
- fixed-hash: allow opting out `rand` when `std` enabled
- uint bench doesn't compile anymore?
- Default RocksDB WAL log size settings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parity-common.