Skip to content

Commit

Permalink
#827: Implement a configuration option for the system call buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
sgerbino committed Oct 17, 2023
1 parent 3b0277c commit a43e155
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
15 changes: 9 additions & 6 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ std::string format_time( int64_t time )
class controller_impl final
{
public:
controller_impl( uint64_t read_compute_bandwith_limit );
controller_impl( uint64_t read_compute_bandwith_limit, uint32_t syscall_bufsize );
~controller_impl();

void open( const std::filesystem::path& p, const genesis_data& data, fork_resolution_algorithm algo, bool reset );
Expand Down Expand Up @@ -110,6 +110,7 @@ class controller_impl final
std::shared_ptr< vm_manager::vm_backend > _vm_backend;
std::shared_ptr< mq::client > _client;
uint64_t _read_compute_bandwidth_limit;
uint32_t _syscall_bufsize;
std::shared_mutex _cached_head_block_mutex;
std::shared_ptr< const protocol::block > _cached_head_block;

Expand All @@ -119,7 +120,9 @@ class controller_impl final
fork_data get_fork_data( state_db::shared_lock_ptr db_lock );
};

controller_impl::controller_impl( uint64_t read_compute_bandwidth_limit ) : _read_compute_bandwidth_limit( read_compute_bandwidth_limit )
controller_impl::controller_impl( uint64_t read_compute_bandwidth_limit, uint32_t syscall_bufsize ) :
_read_compute_bandwidth_limit( read_compute_bandwidth_limit ),
_syscall_bufsize( syscall_bufsize )
{
_vm_backend = vm_manager::get_vm_backend(); // Default is fizzy
KOINOS_ASSERT( _vm_backend, unknown_backend_exception, "could not get vm backend" );
Expand Down Expand Up @@ -870,11 +873,10 @@ rpc::chain::invoke_system_call_response controller_impl::invoke_system_call( con

koinos::chain::host_api hapi( ctx );

const int32_t bufsize = 1000000;
std::vector< char > buffer( bufsize, 0 );
std::vector< char > buffer( _syscall_bufsize, 0 );
uint32_t bytes_written;

hapi.call( syscall_id, &buffer[0], bufsize, request.args().c_str(), uint32_t( request.args().size() ), &bytes_written );
hapi.call( syscall_id, &buffer[0], _syscall_bufsize, request.args().c_str(), uint32_t( request.args().size() ), &bytes_written );

koinos::chain::execution_result exec_result;

Expand All @@ -888,7 +890,8 @@ rpc::chain::invoke_system_call_response controller_impl::invoke_system_call( con

} // detail

controller::controller( uint64_t read_compute_bandwith_limit ) : _my( std::make_unique< detail::controller_impl >( read_compute_bandwith_limit ) ) {}
controller::controller( uint64_t read_compute_bandwith_limit, uint32_t syscall_bufsize ) :
_my( std::make_unique< detail::controller_impl >( read_compute_bandwith_limit, syscall_bufsize ) ) {}

controller::~controller() = default;

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/koinos/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum class fork_resolution_algorithm
class controller final
{
public:
controller( uint64_t read_compute_bandwith_limit = 0 );
controller( uint64_t read_compute_bandwith_limit = 0, uint32_t syscall_bufsize = 0 );
~controller();

void open( const std::filesystem::path& p, const chain::genesis_data& data, fork_resolution_algorithm algo, bool reset );
Expand Down
7 changes: 6 additions & 1 deletion programs/koinos_chain/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
#define GENESIS_DATA_FILE_DEFAULT "genesis_data.json"
#define READ_COMPUTE_BANDWITH_LIMIT_OPTION "read-compute-bandwidth-limit"
#define READ_COMPUTE_BANDWITH_LIMIT_DEFAULT 10'000'000
#define SYSTEM_CALL_BUFFER_SIZE_OPTION "system-call-buffer-size"
#define SYSTEM_CALL_BUFFER_SIZE_DEFAULT 64'000
#define FORK_ALGORITHM_OPTION "fork-algorithm"
#define FORK_ALGORITHM_DEFAULT FIFO_ALGORITHM

Expand All @@ -81,6 +83,7 @@ int main( int argc, char** argv )
std::string amqp_url, log_level, log_dir, instance_id, fork_algorithm_option;
std::filesystem::path statedir, genesis_data_file;
uint64_t jobs, read_compute_limit;
int32_t syscall_bufsize;
chain::genesis_data genesis_data;
bool reset, log_color, log_datetime;
chain::fork_resolution_algorithm fork_algorithm;
Expand All @@ -105,7 +108,8 @@ int main( int argc, char** argv )
(FORK_ALGORITHM_OPTION ",f", program_options::value< std::string >(), "The fork resolution algorithm to use. Can be 'fifo', 'pob', or 'block-time'. (Default: 'fifo')")
(LOG_DIR_OPTION , program_options::value< std::string >(), "The logging directory")
(LOG_COLOR_OPTION , program_options::value< bool >(), "Log color toggle")
(LOG_DATETIME_OPTION , program_options::value< bool >(), "Log datetime on console toggle");
(LOG_DATETIME_OPTION , program_options::value< bool >(), "Log datetime on console toggle")
(SYSTEM_CALL_BUFFER_SIZE_OPTION , program_options::value< uint32_t >(), "System call RPC invocation buffer size");

program_options::variables_map args;
program_options::store( program_options::parse_command_line( argc, argv, options ), args );
Expand Down Expand Up @@ -157,6 +161,7 @@ int main( int argc, char** argv )
jobs = util::get_option< uint64_t >( JOBS_OPTION, std::max( JOBS_DEFAULT, uint64_t( std::thread::hardware_concurrency() ) ), args, chain_config, global_config );
read_compute_limit = util::get_option< uint64_t >( READ_COMPUTE_BANDWITH_LIMIT_OPTION, READ_COMPUTE_BANDWITH_LIMIT_DEFAULT, args, chain_config, global_config );
fork_algorithm_option = util::get_option< std::string >( FORK_ALGORITHM_OPTION, FORK_ALGORITHM_DEFAULT, args, chain_config, global_config );
syscall_bufsize = util::get_option< uint32_t >( SYSTEM_CALL_BUFFER_SIZE_OPTION, SYSTEM_CALL_BUFFER_SIZE_DEFAULT, args, chain_config, global_config );

std::optional< std::filesystem::path > logdir_path;
if ( !log_dir.empty() )
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/controller_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct controller_fixture
{ "verify_vrf_proof", 144067 },
};

controller_fixture() : _controller( 10'000'000 )
controller_fixture() : _controller( 10'000'000, 64'000 )
{
initialize_logging( "koinos_test", {}, "info" );

Expand Down

0 comments on commit a43e155

Please sign in to comment.