From 14b65b117d5e05d409f55a7c7a82f9c32eef8418 Mon Sep 17 00:00:00 2001 From: yarkin Date: Fri, 9 Aug 2024 10:08:37 +0800 Subject: [PATCH 1/2] Backport fix for mdbx --- external/silkworm | 2 +- src/engine_plugin.cpp | 7 +++---- src/rpc_plugin.cpp | 31 ++++--------------------------- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/external/silkworm b/external/silkworm index dced0ac..646d5e9 160000 --- a/external/silkworm +++ b/external/silkworm @@ -1 +1 @@ -Subproject commit dced0ac962c1d33e9dcbd648ee5126165314f233 +Subproject commit 646d5e9c6694cda9ebc13a83b85576cb5b391a3b diff --git a/src/engine_plugin.cpp b/src/engine_plugin.cpp index 0dfcbde..84ab9ac 100644 --- a/src/engine_plugin.cpp +++ b/src/engine_plugin.cpp @@ -73,12 +73,11 @@ class engine_plugin_impl : std::enable_shared_from_this { tid = std::this_thread::get_id(); const auto data_path = std::filesystem::path(node_settings.data_directory->chaindata().path().string()); - if ( std::filesystem::exists(data_path) ) { - node_settings.chaindata_env_config.shared = true; - } else { + // We do not set shared flag as node suppose to be the only writter to the db. + // There should be any valid case to use the shared flag here with our current design. + if ( !std::filesystem::exists(data_path) ) { node_settings.chaindata_env_config.create = true; } - db_env = silkworm::db::open_env(node_settings.chaindata_env_config); SILK_INFO << "Created DB environment at location : " << node_settings.data_directory->chaindata().path().string(); diff --git a/src/rpc_plugin.cpp b/src/rpc_plugin.cpp index 03bc2c1..1eceab3 100644 --- a/src/rpc_plugin.cpp +++ b/src/rpc_plugin.cpp @@ -36,7 +36,8 @@ void rpc_plugin::set_program_options( appbase::options_description& cli, appbase "number of threads for use with rpc") ("chaindata", boost::program_options::value()->default_value("./"), "directory of chaindata") - ("rpc-max-readers", boost::program_options::value()->default_value(16), + // use the value of silkworm::rpc::kDatabaseMaxReaders so we have the same setting between and after the fix + ("rpc-max-readers", boost::program_options::value()->default_value(32000), "maximum number of rpc readers") ("api-spec", boost::program_options::value()->default_value("eth"), "comma separated api spec, possible values: debug,engine,eth,net,parity,erigon,txpool,trace,web3") @@ -87,31 +88,6 @@ void rpc_plugin::plugin_initialize( const appbase::variables_map& options ) try const auto& data_dir = options.at("chaindata").as(); auto log_level = appbase::app().get_plugin().get_verbosity(); - using evmc::operator""_bytes32; - - uint32_t chain_id = options.at("chain-id").as(); - const auto chain_info = silkworm::lookup_known_chain(chain_id); - if (!chain_info) { - throw std::runtime_error{"unknown chain ID: " + std::to_string(chain_id)}; - } - silkworm::ChainConfig config = *(chain_info->second); - - silkworm::NodeSettings node_settings; - node_settings.data_directory = std::make_unique(data_dir, false); - node_settings.network_id = config.chain_id; - node_settings.etherbase = silkworm::to_evmc_address(silkworm::from_hex("").value()); // TODO determine etherbase name - node_settings.chaindata_env_config = {node_settings.data_directory->chaindata().path().string(), false, true, false, false, true}; - - // bool create{false}; // Whether db file must be created - // bool readonly{false}; // Whether db should be opened in RO mode - // bool exclusive{false}; // Whether this process has exclusive access - // bool inmemory{false}; // Whether this db is in memory - // bool shared{false}; // Whether this process opens a db already opened by another process - // bool read_ahead{false}; // Whether to enable mdbx read ahead - // bool write_map{false}; // Whether to enable mdbx write map - - node_settings.chaindata_env_config.max_readers = max_readers; - node_settings.chain_config = config; silkworm::log::Settings log_settings{ .log_verbosity = log_level @@ -129,7 +105,8 @@ void rpc_plugin::plugin_initialize( const appbase::variables_map& options ) try .private_api_addr = node_port, .num_workers = threads, .skip_protocol_check = true, - .rpc_quirk_flag = rpc_quirk_flag + .rpc_quirk_flag = rpc_quirk_flag, + .max_readers = max_readers }; my.reset(new rpc_plugin_impl(settings)); From dbe78bd9efd847475eb536dcf673455104b4d892 Mon Sep 17 00:00:00 2001 From: yarkin Date: Fri, 9 Aug 2024 15:38:09 +0800 Subject: [PATCH 2/2] update submodule --- external/silkworm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/silkworm b/external/silkworm index 646d5e9..ee66c64 160000 --- a/external/silkworm +++ b/external/silkworm @@ -1 +1 @@ -Subproject commit 646d5e9c6694cda9ebc13a83b85576cb5b391a3b +Subproject commit ee66c64204dbaf921057992a9a277a1fcaceefd3