OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
parsec/agent/runners/interface.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_RUNNERS_INTERFACE_H_
7#define OPENCBDC_TX_SRC_PARSEC_AGENT_RUNNERS_INTERFACE_H_
8
12#include "parsec/util.hpp"
15
16#include <memory>
17
21 class interface {
22 public:
48
51
58 using run_callback_type = std::function<void(run_return_type)>;
59
64 = std::function<bool(broker::key_type,
69 using factory_type = std::function<std::unique_ptr<interface>(
70 std::shared_ptr<logging::log> logger,
71 const cbdc::parsec::config& cfg,
73 parameter_type param,
74 bool is_readonly_run,
77 std::shared_ptr<secp256k1_context>,
78 std::shared_ptr<thread_pool> t_pool,
79 ticket_number_type ticket_number)>;
80
96 interface(std::shared_ptr<logging::log> logger,
97 const cbdc::parsec::config& cfg,
99 parameter_type param,
100 bool is_readonly_run,
101 run_callback_type result_callback,
102 try_lock_callback_type try_lock_callback,
103 std::shared_ptr<secp256k1_context> secp,
104 std::shared_ptr<thread_pool> t_pool,
105 ticket_number_type ticket_number);
106
107 virtual ~interface() = default;
109 interface(const interface&) = delete;
110 auto operator=(const interface&) -> interface& = delete;
111 interface(interface&&) = delete;
112 auto operator=(interface&&) -> interface& = delete;
113
117 [[nodiscard]] virtual auto run() -> bool = 0;
119 friend class lua_runner;
120 friend class evm_runner;
121
122 private:
123 std::shared_ptr<logging::log> m_log;
124 const cbdc::parsec::config& m_cfg;
126 parameter_type m_param;
127 bool m_is_readonly_run;
128 run_callback_type m_result_callback;
129 try_lock_callback_type m_try_lock_callback;
130 std::shared_ptr<secp256k1_context> m_secp;
131 std::shared_ptr<thread_pool> m_threads;
132 ticket_number_type m_ticket_number;
133 };
134
138 template<class T>
139 class factory {
140 public:
143 static auto
144 create(std::shared_ptr<logging::log> logger,
147 parameter_type param,
148 bool is_readonly_run,
151 std::shared_ptr<secp256k1_context> secp,
152 std::shared_ptr<thread_pool> t_pool,
154 -> std::unique_ptr<runner::interface> {
155 return std::make_unique<T>(std::move(logger),
156 std::move(cfg),
157 std::move(function),
158 std::move(param),
159 is_readonly_run,
160 std::move(result_callback),
161 std::move(try_lock_callback),
162 std::move(secp),
163 std::move(t_pool),
164 ticket_number);
165 }
166 };
167}
168
169#endif
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
Executes EVM transactions, implementing the runner interface.
Runner factory for agents to intiantiate new runners of a particular type while only worrying about t...
static auto create(std::shared_ptr< logging::log > logger, cbdc::parsec::config cfg, runtime_locking_shard::value_type function, parameter_type param, bool is_readonly_run, runner::interface::run_callback_type result_callback, runner::interface::try_lock_callback_type try_lock_callback, std::shared_ptr< secp256k1_context > secp, std::shared_ptr< thread_pool > t_pool, runner::interface::ticket_number_type ticket_number) -> std::unique_ptr< runner::interface >
Construct a new runner of type T.
std::function< void(run_return_type)> run_callback_type
Callback type for function execution.
std::function< std::unique_ptr< interface >( std::shared_ptr< logging::log > logger, const cbdc::parsec::config &cfg, runtime_locking_shard::value_type function, parameter_type param, bool is_readonly_run, runner::interface::run_callback_type result_callback, runner::interface::try_lock_callback_type try_lock_callback, std::shared_ptr< secp256k1_context >, std::shared_ptr< thread_pool > t_pool, ticket_number_type ticket_number)> factory_type
Factory function type for instantiating new runners.
virtual auto run() -> bool=0
Begins 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.
auto operator=(const interface &) -> interface &=delete
std::variant< runtime_locking_shard::state_update_type, error_code > run_return_type
Return type from executing a function.
auto operator=(interface &&) -> interface &=delete
parsec::ticket_machine::ticket_number_type ticket_number_type
Type alias for a ticket number.
error_code
Error codes return during function execution.
@ yield_count
Function yielded more than one key to lock.
@ wounded
Ticket wounded during execution.
@ result_count
Function more than one result.
@ result_value_type
Function did not return a string value.
@ yield_type
Function yielded a invalid datatype.
@ function_load
Error loading function bytecode.
@ result_type
Function did not return a map.
@ result_key_type
Function did not return a string key.
@ exec_error
Runner error during function execution.
interface(std::shared_ptr< logging::log > logger, const cbdc::parsec::config &cfg, runtime_locking_shard::value_type function, parameter_type param, bool is_readonly_run, run_callback_type result_callback, try_lock_callback_type try_lock_callback, std::shared_ptr< secp256k1_context > secp, std::shared_ptr< thread_pool > t_pool, ticket_number_type ticket_number)
Constructor.
std::function< void(try_lock_return_type)> try_lock_callback_type
Callback function type for a try lock operation.
std:: unordered_map< key_type, value_type, hashing::const_sip_hash< key_type > > state_update_type
Type for state updates to a shard. A map of keys and their new values.
uint64_t ticket_number_type
Type alias for a ticket number.
Configuration parameters for a phase two system.