OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::parsec::agent::runner::evm_host Class Reference

Implementation of the evmc::Host interface using PARSEC as the backend database. More...

#include <host.hpp>

Inheritance diagram for cbdc::parsec::agent::runner::evm_host:
Collaboration diagram for cbdc::parsec::agent::runner::evm_host:

Public Types

using indexed_logs_type = std::unordered_map<evmc::address, std::vector<evm_log>>
 

Public Member Functions

 evm_host (std::shared_ptr< logging::log > log, interface::try_lock_callback_type try_lock_callback, evmc_tx_context tx_context, evm_tx tx, bool is_readonly_run, interface::ticket_number_type ticket_number)
 Constructs a new host instance.
 
auto account_exists (const evmc::address &addr) const noexcept -> bool override
 
auto get_storage (const evmc::address &addr, const evmc::bytes32 &key) const noexcept -> evmc::bytes32 override final
 
auto set_storage (const evmc::address &addr, const evmc::bytes32 &key, const evmc::bytes32 &value) noexcept -> evmc_storage_status override final
 
auto get_balance (const evmc::address &addr) const noexcept -> evmc::uint256be override final
 
auto get_code_size (const evmc::address &addr) const noexcept -> size_t override final
 
auto get_code_hash (const evmc::address &addr) const noexcept -> evmc::bytes32 override final
 
auto copy_code (const evmc::address &addr, size_t code_offset, uint8_t *buffer_data, size_t buffer_size) const noexcept -> size_t override final
 
auto selfdestruct (const evmc::address &addr, const evmc::address &beneficiary) noexcept -> bool override final
 
auto call (const evmc_message &msg) noexcept -> evmc::Result override final
 
auto get_tx_context () const noexcept -> evmc_tx_context override final
 
auto get_block_hash (int64_t number) const noexcept -> evmc::bytes32 override final
 
void emit_log (const evmc::address &addr, const uint8_t *data, size_t data_size, const evmc::bytes32 topics[], size_t topics_count) noexcept override final
 
auto access_account (const evmc::address &addr) noexcept -> evmc_access_status override final
 
auto access_storage (const evmc::address &addr, const evmc::bytes32 &key) noexcept -> evmc_access_status override final
 
auto get_log_index_keys () const -> std::vector< cbdc::buffer >
 Return the keys of the log indexes - these are sha256(addr, ticket) and will get value 1 - to indicate there are logs for the given address in the given ticket.
 
auto get_state_updates () const -> runtime_locking_shard::state_update_type
 Return the changes to the state resulting from transaction execution.
 
auto should_retry () const -> bool
 Returns whether the transaction needs to be retried due to a transient error.
 
void insert_account (const evmc::address &addr, const evm_account &acc)
 Inserts an account into the host.
 
void finalize (int64_t gas_left, int64_t gas_used)
 Finalizes the state updates resulting from the transaction.
 
void revert ()
 Set the state updates to revert the transaction changes due to a contract error.
 
auto ticket_number_key (std::optional< interface::ticket_number_type > tn=std::nullopt) const -> cbdc::buffer
 Return the key for the host's ticket number, which is the hash of the ticket number's serialized representation to uniformly distribute all ticket-to-tx mappings across the shards.
 
auto log_index_key (evmc::address addr, std::optional< interface::ticket_number_type > tn=std::nullopt) const -> cbdc::buffer
 Return the key for the indicator of the existence of logs for a particular address at a particular ticket.
 

Detailed Description

Implementation of the evmc::Host interface using PARSEC as the backend database.

Manages the cached state during contract execution to support committing the final state updates or reverting while still charging gas. Undocumented functions below are inhereted from evmc::Host and are documented upstream.

Definition at line 24 of file host.hpp.

Member Typedef Documentation

◆ indexed_logs_type

using cbdc::parsec::agent::runner::evm_host::indexed_logs_type = std::unordered_map<evmc::address, std::vector<evm_log>>

Definition at line 100 of file host.hpp.

Constructor & Destructor Documentation

◆ evm_host()

cbdc::parsec::agent::runner::evm_host::evm_host ( std::shared_ptr< logging::log > log,
interface::try_lock_callback_type try_lock_callback,
evmc_tx_context tx_context,
evm_tx tx,
bool is_readonly_run,
interface::ticket_number_type ticket_number )

Constructs a new host instance.

Parameters
loglog instance.
try_lock_callbackfunction for requesting locks on keys.
tx_contextevmc context in which the transaction will execute.
txtransaction to execute.
is_readonly_runtrue if no state changes should be applied.
ticket_numberticket number for transaction.

Definition at line 23 of file host.cpp.

References cbdc::parsec::agent::runner::evm_tx_receipt::m_ticket_number, and cbdc::parsec::agent::runner::evm_tx_receipt::m_tx.

Member Function Documentation

◆ access_account()

auto cbdc::parsec::agent::runner::evm_host::access_account ( const evmc::address & addr) -> evmc_access_status
finaloverridenoexcept

Definition at line 404 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex().

Here is the call graph for this function:

◆ access_storage()

auto cbdc::parsec::agent::runner::evm_host::access_storage ( const evmc::address & addr,
const evmc::bytes32 & key ) -> evmc_access_status
finaloverridenoexcept

Definition at line 414 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex().

Here is the call graph for this function:

◆ account_exists()

auto cbdc::parsec::agent::runner::evm_host::account_exists ( const evmc::address & addr) const -> bool
nodiscardoverridenoexcept

Definition at line 83 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex().

Here is the call graph for this function:

◆ call()

auto cbdc::parsec::agent::runner::evm_host::call ( const evmc_message & msg) -> evmc::Result
finaloverridenoexcept

Definition at line 308 of file host.cpp.

References cbdc::buffer, cbdc::parsec::agent::runner::to_hex(), and cbdc::parsec::transfer.

Here is the call graph for this function:

◆ copy_code()

auto cbdc::parsec::agent::runner::evm_host::copy_code ( const evmc::address & addr,
size_t code_offset,
uint8_t * buffer_data,
size_t buffer_size ) const -> size_t
finaloverridenoexcept

Definition at line 192 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex().

Here is the call graph for this function:

◆ emit_log()

void cbdc::parsec::agent::runner::evm_host::emit_log ( const evmc::address & addr,
const uint8_t * data,
size_t data_size,
const evmc::bytes32 topics[],
size_t topics_count )
finaloverridenoexcept

Definition at line 386 of file host.cpp.

◆ finalize()

void cbdc::parsec::agent::runner::evm_host::finalize ( int64_t gas_left,
int64_t gas_used )

Finalizes the state updates resulting from the transaction.

Parameters
gas_leftremaining unspent gas.
gas_usedtotal gas consumed by the transaction.

Definition at line 576 of file host.cpp.

References cbdc::parsec::agent::runner::evm_tx_receipt::m_gas_used, and cbdc::parsec::agent::runner::evm_tx_receipt::m_timestamp.

◆ get_balance()

auto cbdc::parsec::agent::runner::evm_host::get_balance ( const evmc::address & addr) const -> evmc::uint256be
nodiscardfinaloverridenoexcept

Definition at line 150 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex().

Here is the call graph for this function:

◆ get_block_hash()

auto cbdc::parsec::agent::runner::evm_host::get_block_hash ( int64_t number) const -> evmc::bytes32
nodiscardfinaloverridenoexcept

Definition at line 379 of file host.cpp.

◆ get_code_hash()

auto cbdc::parsec::agent::runner::evm_host::get_code_hash ( const evmc::address & addr) const -> evmc::bytes32
nodiscardfinaloverridenoexcept

Definition at line 175 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex().

Here is the call graph for this function:

◆ get_code_size()

auto cbdc::parsec::agent::runner::evm_host::get_code_size ( const evmc::address & addr) const -> size_t
nodiscardfinaloverridenoexcept

Definition at line 162 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex().

Here is the call graph for this function:

◆ get_log_index_keys()

auto cbdc::parsec::agent::runner::evm_host::get_log_index_keys ( ) const -> std::vector<cbdc::buffer>

Return the keys of the log indexes - these are sha256(addr, ticket) and will get value 1 - to indicate there are logs for the given address in the given ticket.

The logs for the specific ticket can then be fetched and filtered on topic and address.

Returns
list of keys to set to 1 for the log index

Definition at line 460 of file host.cpp.

References log_index_key().

Here is the call graph for this function:

◆ get_state_updates()

auto cbdc::parsec::agent::runner::evm_host::get_state_updates ( ) const -> runtime_locking_shard::state_update_type

Return the changes to the state resulting from transaction execution.

Returns
list of updates keys and values.

Definition at line 481 of file host.cpp.

References cbdc::buffer, log_index_key(), cbdc::make_buffer(), ticket_number_key(), and cbdc::parsec::agent::runner::tx_id().

Here is the call graph for this function:

◆ get_storage()

auto cbdc::parsec::agent::runner::evm_host::get_storage ( const evmc::address & addr,
const evmc::bytes32 & key ) const -> evmc::bytes32
nodiscardfinaloverridenoexcept

Definition at line 95 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex().

Here is the call graph for this function:

◆ get_tx_context()

auto cbdc::parsec::agent::runner::evm_host::get_tx_context ( ) const -> evmc_tx_context
nodiscardfinaloverridenoexcept

Definition at line 375 of file host.cpp.

◆ insert_account()

void cbdc::parsec::agent::runner::evm_host::insert_account ( const evmc::address & addr,
const evm_account & acc )

Inserts an account into the host.

The host will assume the lock is already held on the account metadata.

Parameters
addraccount address.
accaccount metadata.

Definition at line 541 of file host.cpp.

◆ log_index_key()

auto cbdc::parsec::agent::runner::evm_host::log_index_key ( evmc::address addr,
std::optional< interface::ticket_number_type > tn = std::nullopt ) const -> cbdc::buffer

Return the key for the indicator of the existence of logs for a particular address at a particular ticket.

Definition at line 443 of file host.cpp.

References cbdc::make_buffer().

Referenced by get_log_index_keys(), and get_state_updates().

Here is the call graph for this function:

◆ revert()

void cbdc::parsec::agent::runner::evm_host::revert ( )

Set the state updates to revert the transaction changes due to a contract error.

Definition at line 594 of file host.cpp.

◆ selfdestruct()

auto cbdc::parsec::agent::runner::evm_host::selfdestruct ( const evmc::address & addr,
const evmc::address & beneficiary ) -> bool
finaloverridenoexcept

Definition at line 217 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex(), and cbdc::parsec::transfer.

Here is the call graph for this function:

◆ set_storage()

auto cbdc::parsec::agent::runner::evm_host::set_storage ( const evmc::address & addr,
const evmc::bytes32 & key,
const evmc::bytes32 & value ) -> evmc_storage_status
finaloverridenoexcept

Definition at line 104 of file host.cpp.

References cbdc::parsec::agent::runner::to_hex().

Here is the call graph for this function:

◆ should_retry()

auto cbdc::parsec::agent::runner::evm_host::should_retry ( ) const -> bool

Returns whether the transaction needs to be retried due to a transient error.

Returns
true if the transaction needs to be re-executed.

Definition at line 537 of file host.cpp.

◆ ticket_number_key()

auto cbdc::parsec::agent::runner::evm_host::ticket_number_key ( std::optional< interface::ticket_number_type > tn = std::nullopt) const -> cbdc::buffer

Return the key for the host's ticket number, which is the hash of the ticket number's serialized representation to uniformly distribute all ticket-to-tx mappings across the shards.

Returns
ticket number key

Definition at line 427 of file host.cpp.

References cbdc::make_buffer().

Referenced by get_state_updates().

Here is the call graph for this function:

The documentation for this class was generated from the following files: