6#ifndef OPENCBDC_TX_SRC_PARSEC_AGENT_EVM_HOST_H_
7#define OPENCBDC_TX_SRC_PARSEC_AGENT_EVM_HOST_H_
13#include <evmc/evmc.hpp>
34 evm_host(std::shared_ptr<logging::log> log,
36 evmc_tx_context tx_context,
45 [[nodiscard]]
auto get_storage(
const evmc::address& addr,
46 const evmc::bytes32& key)
const noexcept
47 -> evmc::bytes32
override final;
50 const evmc::bytes32& key,
51 const evmc::bytes32& value)
noexcept
52 -> evmc_storage_status
override final;
55 get_balance(
const evmc::address& addr)
const noexcept
56 -> evmc::uint256be
override final;
60 ->
size_t override final;
64 -> evmc::bytes32
override final;
69 size_t buffer_size)
const noexcept
70 ->
size_t override final;
73 const evmc::address& beneficiary)
noexcept
74 ->
bool override final;
76 auto call(
const evmc_message& msg)
noexcept
77 -> evmc::Result
override final;
80 -> evmc_tx_context
override final;
83 -> evmc::bytes32
override final;
86 const evmc::address& addr,
90 const evmc::bytes32 topics[],
91 size_t topics_count)
noexcept override final;
94 -> evmc_access_status
override final;
97 const evmc::bytes32& key)
noexcept
98 -> evmc_access_status
override final;
101 = std::unordered_map<evmc::address, std::vector<evm_log>>;
114 -> runtime_locking_shard::state_update_type;
130 void finalize(int64_t gas_left, int64_t gas_used);
146 std::optional<
interface::ticket_number_type> tn
150 std::shared_ptr<logging::log> m_log;
151 runner::
interface::try_lock_callback_type m_try_lock_callback;
152 mutable std::map<evmc::address,
157 std::map<evmc::bytes32,
158 std::pair<std::optional<evmc::bytes32>,
bool>>>
160 mutable std::map<evmc::address,
163 evmc_tx_context m_tx_context;
164 std::unique_ptr<evmc::VM> m_vm;
166 bool m_is_readonly_run;
168 mutable std::set<evmc::address> m_accessed_addresses;
169 std::set<std::pair<evmc::address, evmc::bytes32>>
170 m_accessed_storage_keys;
172 mutable
bool m_retry{
false};
174 std::map<evmc::address, std::pair<std::optional<evm_account>,
bool>>
182 [[nodiscard]]
auto get_account(
const evmc::address& addr,
184 -> std::optional<evm_account>;
186 [[nodiscard]]
auto get_account_storage(
const evmc::address& addr,
187 const evmc::bytes32& key,
189 -> std::optional<evmc::bytes32>;
191 [[nodiscard]]
auto get_account_code(
const evmc::address& addr,
193 -> std::optional<evm_account_code>;
195 auto get_sorted_logs() const
196 -> std::unordered_map<evmc::address, std::vector<
evm_log>>;
198 void transfer(const evmc::address& from,
199 const evmc::address& to,
200 const evmc::uint256be& value);
202 static auto is_precompile(const evmc::address& addr) ->
bool;
204 [[nodiscard]] auto get_key(const
cbdc::
buffer& key,
bool write) const
205 -> std::optional<broker::value_type>;
207 auto create(const evmc_message& msg) noexcept -> evmc::Result;
209 auto execute(const evmc_message& msg,
211 size_t code_size) -> evmc::Result;
Buffer to store and retrieve byte data.
Implementation of the evmc::Host interface using PARSEC as the backend database.
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 indicat...
auto should_retry() const -> bool
Returns whether the transaction needs to be retried due to a transient error.
auto get_balance(const evmc::address &addr) const noexcept -> evmc::uint256be override final
auto get_code_hash(const evmc::address &addr) const noexcept -> evmc::bytes32 override final
auto get_tx_context() const noexcept -> evmc_tx_context override final
void finalize(int64_t gas_left, int64_t gas_used)
Finalizes the state updates resulting from the transaction.
void insert_account(const evmc::address &addr, const evm_account &acc)
Inserts an account into the host.
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 repr...
auto get_storage(const evmc::address &addr, const evmc::bytes32 &key) const noexcept -> evmc::bytes32 override final
auto account_exists(const evmc::address &addr) const noexcept -> bool override
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 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 access_storage(const evmc::address &addr, const evmc::bytes32 &key) noexcept -> evmc_access_status override final
auto call(const evmc_message &msg) noexcept -> evmc::Result 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 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 ti...
auto set_storage(const evmc::address &addr, const evmc::bytes32 &key, const evmc::bytes32 &value) noexcept -> evmc_storage_status override final
auto selfdestruct(const evmc::address &addr, const evmc::address &beneficiary) noexcept -> bool override final
auto get_code_size(const evmc::address &addr) const noexcept -> size_t override final
auto access_account(const evmc::address &addr) noexcept -> evmc_access_status override final
auto get_state_updates() const -> runtime_locking_shard::state_update_type
Return the changes to the state resulting from transaction execution.
std::unordered_map< evmc::address, std::vector< evm_log > > indexed_logs_type
Interface for a contract runner.
std::function< bool(broker::key_type, broker::lock_type, broker::interface::try_lock_callback_type)> try_lock_callback_type
Callback function type for acquiring locks during function execution.
parsec::ticket_machine::ticket_number_type ticket_number_type
Type alias for a ticket number.
std::vector< uint8_t > evm_account_code
Type alias for EVM account code.
@ transfer
Base token transfer.
EVM transaction receipt type.