Move state storage to IndexedDB/LevelDB #2044
Labels
20
enhancement
New feature or request
optimization ⚡
Optimizations for the implementation or protocol
Ready 🎬
Issues which are ready to be pulled into the iteration
refactor
sdk 🖥
Description
Fixes #1933 #1831
The above issues seems to be caused by client losing state, as we've feared for long, or client crashing before persisting state after a critical state change took place (like new BalanceProof created). This is a tricky problem, due to the ephemeral nature of in-browser storage keeping.
Current
RaidenState
is stored by default like this:localStorage
instance is received byRaiden.create
state$
observable, which by default serialize and store the state after1s
without a new state being generated, and at most every5s
if new states keep going through.serialize
part can be quite CPU intensive, and both the serialize and state saving onLocalStorage
currently are synchronous operations which can take time and block other more important events processing.The proposed solution is to move the state to the
IndexedDB
or even directly aLevelDB
:put
operations are asynchronousBigNumber
, but IndexedDB is able to encode them as{"_hex": "0x1234"}
objects which, as long as we're able to decode (and we already are), should allow us to persist the state directly, without an expensive encoding stepsent
&received
transfers, on a separate object store, or key prefix, for higher efficiency on storing of the general state, although requiring async access (shouldn't be a problem for the async epics, may require some thinking for the reducers)secrethash
list on the in-memory state, for synchronous check of used secrethashes, but we should avoid duplicating this if possibleAcceptance criteria
Tasks
The text was updated successfully, but these errors were encountered: