evm.db package

Submodules

evm.db.chain module

class evm.db.chain.BaseChainDB(db)

Bases: object

add_block_number_to_hash_lookup(header)
add_receipt(block_header, index_key, receipt)
add_transaction(block_header, index_key, transaction)
clear()
commit(checkpoint)
exists(key)
find_common_ancestor(header)

Returns the chain leading up from the given header until the first ancestor it has in common with our canonical chain.

get_block_header_by_hash(block_hash)

Returns the requested block header as specified by block hash.

Raises BlockNotFound if it is not present in the db.

get_block_transactions(block_header, transaction_class)
get_block_uncles(uncles_hash)
get_canonical_block_header_by_number(block_number)

Returns the block header with the given number in the canonical chain.

Raises BlockNotFound if there’s no block header with the given number in the canonical chain.

get_canonical_head()
get_receipts(header, receipt_class)
get_score(block_hash)
get_state_db(state_root, read_only)
header_exists(block_hash)

Returns True if the header with the given block hash is in our DB.

lookup_block_hash(block_number)

Return the block hash for the given block number.

persist_block_to_db(block)
persist_header_to_db(header)
revert(checkpoint)
set_as_canonical_chain_head(header)

Sets the header as the canonical chain HEAD.

snapshot()

evm.db.hash_trie module

class evm.db.hash_trie.HashTrie(trie)

Bases: object

root_hash

evm.db.immutable module

class evm.db.immutable.ImmutableDB(wrapped_db)

Bases: evm.db.backends.base.BaseDB

delete(key)
exists(key)
get(key)
set(key, value)

evm.db.journal module

class evm.db.journal.Journal

Bases: object

A Journal is an ordered list of checkpoints. A checkpoint is a dictionary of database keys and values. The values are the “original” value of that key at the time the checkpoint was created.

Checkpoints are referenced by a random uuid4.

add(key, value)

Adds the given key and value to the latest checkpoint.

checkpoints = None
commit_checkpoint(checkpoint_id)

Collapses all changes for the givent checkpoint into the previous checkpoint if it exists.

create_checkpoint()

Creates a new checkpoint. Checkpoints are referenced by a random uuid4 to prevent collisions between multiple checkpoints.

latest

Returns the dictionary of db keys and values for the latest checkpoint.

latest_id

Returns the checkpoint_id of the latest checkpoint

pop_checkpoint(checkpoint_id)

Returns all changes from the given checkpoint. This includes all of the changes from any subsequent checkpoints, giving precidence to earlier checkpoints.

class evm.db.journal.JournalDB(wrapped_db)

Bases: evm.db.backends.base.BaseDB

A wrapper around the basic DB objects that keeps a journal of all changes. Each time a snapshot is taken, the underlying journal creates a new checkpoint. The journal then keeps track of the original value for any keys changed. Reverting to a checkpoint involves merging the original key data from any subsequent checkpoints into the given checkpoint giving precidence earlier checkpoints. Then the keys from this merged data set are reset to their original values.

The added memory footprint for a JournalDB is one key/value stored per database key which is changed. Subsequent changes to the same key within the same checkpoint will not increase the journal size since we only need to track the original value for any given key within any given checkpoint.

clear()

Cleare the entire journal.

commit(checkpoint)

Commits a given checkpoint.

delete(key)
exists(key)
get(key)
journal = None
revert(checkpoint)

Reverts the database back to the checkpoint.

set(key, value)
  • replacing an existing value
  • setting a value that does not exist
snapshot()

Takes a snapshot of the database by creating a checkpoint.

wrapped_db = None

evm.db.state module

class evm.db.state.State(db, root_hash=b'Vxe8x1fx17x1bxccUxa6xffx83Exe6x92xc0xf8n[Hxe0x1bx99lxadxc0x01b/xb5xe3cxb4!', read_only=False)

Bases: object

High level API around account storage.

account_exists(address)
account_has_code_or_nonce(address)
account_is_empty(address)
db = None
delete_account(address)
delete_code(address)
delete_storage(address)
delta_balance(address, delta)
get_balance(address)
get_code(address)
get_code_hash(address)
get_nonce(address)
get_storage(address, slot)
increment_nonce(address)
logger = <logging.Logger object>
root_hash
set_balance(address, balance)
set_code(address, code)
set_nonce(address, nonce)
set_storage(address, slot, value)
touch_account(address)

Module contents

evm.db.get_db_backend(import_path=None, **init_kwargs)
evm.db.get_db_backend_class(import_path=None)