-
Notifications
You must be signed in to change notification settings - Fork 12
Module DB Interface
Junha Yang(양준하) edited this page Jul 20, 2020
·
2 revisions
pub trait DbContext {
type Value = Vec<u8>;
type Key = AsRef<[u8]>;
fn get(storage_id: u16, key: Key) -> Option<Value>;
fn set(storage_id: u16, key: Key, value: Value);
fn has(storage_id: u16, key: Key) -> bool;
fn delete(storage_id: u16, key: Key);
/// Create a recoverable checkpoint of this state
fn create_checkpoint();
/// Revert to the last checkpoint and discard it
fn revert_to_the_checkpoint();
/// Merge last checkpoint with previous
fn discard_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