pub struct StateDB { /* private fields */ }
Expand description
State database abstraction.
Manages shared global state cache which reflects the canonical
state as it is on the disk. All the entries in the cache are clean.
A clone of StateDB
may be created as canonical or not.
For canonical clones local cache is accumulated and applied
in sync_cache
For non-canonical clones local cache is dropped.
Global cache propagation.
After a State
object has been committed to the trie it
propagates its local cache into the StateDB
local cache
using add_to_account_cache
function.
Then, after the block has been added to the chain the local cache in the
StateDB
is propagated into the global cache.
Implementations
sourceimpl StateDB
impl StateDB
sourcepub fn new(db: Box<dyn JournalDB>, cache_size: usize) -> StateDB
pub fn new(db: Box<dyn JournalDB>, cache_size: usize) -> StateDB
Create a new instance wrapping JournalDB
and the maximum allowed size
of the LRU cache in bytes. Actual used memory may (read: will) be higher due to bookkeeping.
sourcepub fn journal_under(
&mut self,
batch: &mut DBTransaction,
now: u64,
id: &H256
) -> Result<u32>
pub fn journal_under(
&mut self,
batch: &mut DBTransaction,
now: u64,
id: &H256
) -> Result<u32>
Journal all recent operations under the given era and ID.
sourcepub fn mark_canonical(
&mut self,
batch: &mut DBTransaction,
end_era: u64,
canon_id: &H256
) -> Result<u32>
pub fn mark_canonical(
&mut self,
batch: &mut DBTransaction,
end_era: u64,
canon_id: &H256
) -> Result<u32>
Mark a given candidate from an ancient era as canonical, enacting its removals from the backing database and reverting any non-canonical historical commit’s insertions.
sourcepub fn sync_cache(
&mut self,
enacted: &[H256],
retracted: &[H256],
is_best: bool
)
pub fn sync_cache(
&mut self,
enacted: &[H256],
retracted: &[H256],
is_best: bool
)
the global cache with the best block state.
This function updates the global cache by removing entries
that are invalidated by chain reorganization. sync_cache
should be called after the block has been committed and the
blockchain route has ben calculated.
sourcepub fn as_hash_db(&self) -> &dyn HashDB<KeccakHasher, DBValue>
pub fn as_hash_db(&self) -> &dyn HashDB<KeccakHasher, DBValue>
Conversion method to interpret self as HashDB
reference
sourcepub fn as_hash_db_mut(&mut self) -> &mut dyn HashDB<KeccakHasher, DBValue>
pub fn as_hash_db_mut(&mut self) -> &mut dyn HashDB<KeccakHasher, DBValue>
Conversion method to interpret self as mutable HashDB
reference
sourcepub fn boxed_clone(&self) -> StateDB
pub fn boxed_clone(&self) -> StateDB
Clone the database.
sourcepub fn boxed_clone_canon(&self, parent: &H256) -> StateDB
pub fn boxed_clone_canon(&self, parent: &H256) -> StateDB
Clone the database for a canonical state.
sourcepub fn journal_db(&self) -> &dyn JournalDB
pub fn journal_db(&self) -> &dyn JournalDB
Returns underlying JournalDB
.
sourcepub fn cache_size(&self) -> usize
pub fn cache_size(&self) -> usize
Query how much memory is set aside for the accounts cache (in bytes).
Trait Implementations
sourceimpl Backend for StateDB
impl Backend for StateDB
sourcefn as_hash_db(&self) -> &dyn HashDB<KeccakHasher, DBValue>
fn as_hash_db(&self) -> &dyn HashDB<KeccakHasher, DBValue>
Treat the backend as a read-only hashdb.
sourcefn as_hash_db_mut(&mut self) -> &mut dyn HashDB<KeccakHasher, DBValue>
fn as_hash_db_mut(&mut self) -> &mut dyn HashDB<KeccakHasher, DBValue>
Treat the backend as a writeable hashdb.
sourcefn add_to_account_cache(
&mut self,
addr: Address,
data: Option<Account>,
modified: bool
)
fn add_to_account_cache(
&mut self,
addr: Address,
data: Option<Account>,
modified: bool
)
t_nb 9.4 Add an account entry to the cache.
sourcefn cache_code(&self, hash: H256, code: Arc<Vec<u8>>)
fn cache_code(&self, hash: H256, code: Arc<Vec<u8>>)
Add a global code cache entry. This doesn’t need to worry about canonicality because it simply maps hashes to raw code and will always be correct in the absence of hash collisions. Read more
sourcefn get_cached_account(&self, addr: &Address) -> Option<Option<Account>>
fn get_cached_account(&self, addr: &Address) -> Option<Option<Account>>
Get basic copy of the cached account. Not required to include storage. Returns ‘None’ if cache is disabled or if the account is not cached. Read more
Auto Trait Implementations
impl !RefUnwindSafe for StateDB
impl Send for StateDB
impl Sync for StateDB
impl Unpin for StateDB
impl !UnwindSafe for StateDB
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more