OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
agent/runners/evm/impl.hpp
Go to the documentation of this file.
1// Copyright (c) 2022 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef OPENCBDC_TX_SRC_PARSEC_AGENT_EVM_RUNNER_H_
7#define OPENCBDC_TX_SRC_PARSEC_AGENT_EVM_RUNNER_H_
8
9#include "host.hpp"
11#include "parsec/util.hpp"
12
13#include <evmc/evmc.h>
14#include <secp256k1.h>
15#include <thread>
16
45
47 class evm_runner : public interface {
48 public:
50 evm_runner(std::shared_ptr<logging::log> logger,
51 const cbdc::parsec::config& cfg,
53 parameter_type param,
54 bool is_readonly_run,
55 run_callback_type result_callback,
56 try_lock_callback_type try_lock_callback,
57 std::shared_ptr<secp256k1_context> secp,
58 std::shared_ptr<thread_pool> t_pool,
59 ticket_number_type ticket_number);
60
63 ~evm_runner() override;
64
65 evm_runner(const evm_runner&) = delete;
66 auto operator=(const evm_runner&) -> evm_runner& = delete;
68 auto operator=(evm_runner&&) -> evm_runner& = delete;
69
73 [[nodiscard]] auto run() -> bool override;
74
77 static constexpr auto initial_lock_type = broker::lock_type::write;
78
79 private:
80 std::vector<std::thread> m_evm_threads;
81
82 std::unique_ptr<evm_host> m_host;
83 evm_tx m_tx;
84 evmc_message m_msg{};
85
86 void exec();
87 auto run_execute_real_transaction() -> bool;
88 auto run_execute_dryrun_transaction() -> bool;
89 auto run_get_account_code() -> bool;
90 auto run_get_transaction() -> bool;
91 auto run_get_transaction_receipt() -> bool;
92 auto run_execute_transaction(const evmc::address& from,
93 bool is_readonly_run) -> bool;
94 auto run_get_account() -> bool;
95 auto run_get_block() -> bool;
96 auto run_get_logs() -> bool;
97 auto run_get_block_number() -> bool;
98 [[nodiscard]] static auto check_base_gas(const evm_tx& tx,
99 bool is_readonly_run)
100 -> std::pair<evmc::uint256be, bool>;
101 [[nodiscard]] static auto make_tx_context(const evmc::address& from,
102 const evm_tx& tx,
103 bool is_readonly_run)
104 -> evmc_tx_context;
105 static auto make_message(const evmc::address& from,
106 const evm_tx& tx,
107 bool is_readonly_run)
108 -> std::pair<evmc_message, bool>;
109
110 void handle_lock_from_account(
112
113 void lock_ticket_number_key();
114 void lock_index_keys(const std::function<void()>& callback);
115 void schedule_exec();
116
117 void schedule(const std::function<void()>& fn);
118
119 void schedule_run();
120 void do_run();
121 static auto make_pretend_block(interface::ticket_number_type tn)
123
124 void handle_get_logs_try_lock_response(
125 const evm_log_query& qry,
126 const std::shared_ptr<std::vector<evm_log_index>>& log_indexes,
127 const std::shared_ptr<std::atomic<size_t>>& acquired,
128 const std::shared_ptr<std::mutex>& log_indexes_mut,
129 size_t key_count,
131
132 void handle_complete_get_logs(
133 const evm_log_query& qry,
134 const std::shared_ptr<std::mutex>& log_indexes_mut,
135 const std::shared_ptr<std::vector<evm_log_index>>& log_indexes);
136
137 void lock_tx_receipt(const broker::value_type& value,
138 const ticket_number_type& ticket_number);
139 };
140}
141
142#endif
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
Executes EVM transactions, implementing the runner interface.
evm_runner(const evm_runner &)=delete
auto operator=(const evm_runner &) -> evm_runner &=delete
auto run() -> bool override
Begin executing the transaction asynchronously.
static constexpr auto initial_lock_type
Initial lock type for the agent to request when retrieving the function key.
~evm_runner() override
Blocks until the transaction has completed and all processing threads have ended.
auto operator=(evm_runner &&) -> evm_runner &=delete
std::function< void(run_return_type)> run_callback_type
Callback type for function execution.
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::variant< value_type, error_code, runtime_locking_shard::shard_error > try_lock_return_type
Return type from a try lock operation.
evm_runner_function
Commands accepted by the EVM contract runner.
@ get_transaction_receipt
Return the receipt for a transaction.
@ get_block_number
Return just the ticket number to simulate getting the latest block.
@ read_account_code
Read the contract code of an account.
@ get_transaction
Return a previously completed transaction.
@ get_logs
Query the logs for a particular address, block range and topic filter.
@ get_block
Return a pretend block that is based on the ticket number, and the transaction (potentially) correspo...
@ execute_transaction
Execute a normal transaction.
@ read_account_storage
Read a specific key of an account's storage.
@ read_account
Read the metadata of an account.
@ dryrun_transaction
Execute a transaction without applying any changes.
Describes the parameters of a query on EVM logs - used to transfer these parameters from the getLogs ...
EVM pretend block is a pairing of the blocknumber (equal to the ticket number) and the transactions (...
Configuration parameters for a phase two system.