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

Lua function executor. More...

#include <impl.hpp>

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

Public Member Functions

 lua_runner (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.
 
auto run () -> bool override
 Begins function execution.
 
- Public Member Functions inherited from cbdc::parsec::agent::runner::interface
 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.
 
virtual ~interface ()=default
 
 interface (const interface &)=delete
 
auto operator= (const interface &) -> interface &=delete
 
 interface (interface &&)=delete
 
auto operator= (interface &&) -> interface &=delete
 

Static Public Attributes

static constexpr auto initial_lock_type = broker::lock_type::read
 Lock type to acquire when requesting the function code.
 

Additional Inherited Members

- Public Types inherited from cbdc::parsec::agent::runner::interface
enum class  error_code {
  result_value_type , result_key_type , result_type , result_count ,
  exec_error , function_load , internal_error , yield_count ,
  yield_type , lock_error , wounded
}
 Error codes return during function execution. More...
 
using ticket_number_type = parsec::ticket_machine::ticket_number_type
 Type alias for a ticket number.
 
using run_return_type
 Return type from executing a function.
 
using run_callback_type = std::function<void(run_return_type)>
 Callback type for function execution.
 
using try_lock_callback_type
 Callback function type for acquiring locks during function execution.
 
using factory_type
 Factory function type for instantiating new runners.
 

Detailed Description

Lua function executor.

Provides an environment for contracts to execute in. Manages retrieval of function bytecode, locking keys during function execution, signature checking and commiting execution results. Class cannot be re-used for different functions/transactions, manages the lifecycle of a single transaction. NOTE: When writing contracts, to pass data between the Lua environment and the C++ environment, use coroutine.yield(). To request a read-lock use coroutine.yield(<data>, 0). To request a write-lock use coroutine.yield(<data>, 1) or coroutine.yield(<data>).

Definition at line 25 of file agent/runners/lua/impl.hpp.

Constructor & Destructor Documentation

◆ lua_runner()

cbdc::parsec::agent::runner::lua_runner::lua_runner ( 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.

Parameters
loggerlog instance.
cfgconfig reference.
functionkey of function bytecode to execute.
paramparameter to pass to function.
is_readonly_runtrue if runner execution should not result in state changes.
result_callbackfunction to call with function execution result.
try_lock_callbackfunction to call for the function to request key locks.
secpshared context for libsecp256k1.
t_poolshared thread pool between agents.
ticket_numberticket number for the ticket managed by this runner instance.

Definition at line 23 of file agent/runners/lua/impl.cpp.

Member Function Documentation

◆ run()

auto cbdc::parsec::agent::runner::lua_runner::run ( ) -> bool
nodiscardoverridevirtual

Begins function execution.

Retrieves the function bytecode using a read lock and executes it with the given parameter.

Returns
true unless a internal system error has occurred

Implements cbdc::parsec::agent::runner::interface.

Definition at line 44 of file agent/runners/lua/impl.cpp.

Field Documentation

◆ initial_lock_type

auto cbdc::parsec::agent::runner::lua_runner::initial_lock_type = broker::lock_type::read
staticconstexpr

Lock type to acquire when requesting the function code.

Definition at line 45 of file agent/runners/lua/impl.hpp.


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