Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 11
Module DB Interface
Junha Yang(양준하) edited this page Jul 20, 2020
·
2 revisions
pubtraitDbContext{typeValue = Vec<u8>;typeKey = AsRef<[u8]>;fnget(storage_id:u16,key:Key) -> Option<Value>;fnset(storage_id:u16,key:Key,value:Value);fnhas(storage_id:u16,key:Key) -> bool;fndelete(storage_id:u16,key:Key);/// Create a recoverable checkpoint of this statefncreate_checkpoint();/// Revert to the last checkpoint and discard itfnrevert_to_the_checkpoint();/// Merge last checkpoint with previousfndiscard_checkpoint();}- DB subspace can be generated with key-prefix when connecting modules
getgo through the following steps- Context resolves the DB subspace corresponding to the
storage_id - If exists, fetch the byte expression of the corresponding
valuefrom DB subspace
- Context resolves the DB subspace corresponding to the
setgo through the following steps- Context resolves the DB subspace corresponding to the
storage_id - Set the value utilizing
setmethod in the subspace
- Context resolves the DB subspace corresponding to the
- Modules will execute transactions within a block following their own rules. Modules respond to the
deliverBlockonly once so thecheckpointandrevertfunctionality cannot be provided by the coordinator automatically. create_checkpoint- It creates a top level db check point in case of a reversion
revert_to_the_last_checkpoint- Revert a module state back to the last check point
- Called when runtime errors occur during a transaction execution
- DB subspace for modules are created by key-prefixing in a merkle-trie
setandgetcalculate actual db key(address) by prefixing after hashing- Coordinator level
StorageIdwill have a type ofu16and it is more convenient for applications to useStringtype forStorageId - Top-level database manages map from higher level
ModuleIds to lower levelModuleIds - Module DB occupies
ModuleIdprefixed subspace out of the wholeTrie
check_pointandrevert- Making check points and reverting are required for runtime-failing transactions
Cache layer- Before committing state transitions, the db operations are performed at the
Cache layer Cache layersupportcheck_pointandrevertfor tentative state transitions
- Before committing state transitions, the db operations are performed at the
Commit- persist state transitions to disk
application_state_root- Top Level state manages merkle root of each modules and renew the application merkle root to respond
Commitinabci.
- Top Level state manages merkle root of each modules and renew the application merkle root to respond