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)); diff --git a/tests/nodeos_eos_evm_ws_test_basic.py b/tests/nodeos_eos_evm_ws_test_basic.py index 103f161..ab267b7 100755 --- a/tests/nodeos_eos_evm_ws_test_basic.py +++ b/tests/nodeos_eos_evm_ws_test_basic.py @@ -89,6 +89,12 @@ eosEvmMinerPOpen = None wsproxy = None +def get_raw_transaction(signed_trx): + if hasattr(signed_trx, 'raw_transaction'): + return signed_trx.raw_transaction + else: + return signed_trx.rawTransaction + def interact_with_storage_contract(dest, nonce): for i in range(1, 5): # execute a few Utils.Print("Execute ETH contract") @@ -105,7 +111,7 @@ def interact_with_storage_contract(dest, nonce): chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name)) assert retValue[0], "pushtx to ETH contract failed." Utils.Print("\tBlock#", retValue[1]["processed"]["block_num"]) @@ -359,7 +365,7 @@ def makeReservedEvmAddress(account): chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name)) prodNode.waitForTransBlockIfNeeded(trans[1], True) @@ -385,7 +391,7 @@ def makeReservedEvmAddress(account): chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} Utils.Print("Send balance again, with correct nonce") retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True) assert retValue[0], f"push trx should have succeeded: {retValue}" @@ -404,7 +410,7 @@ def makeReservedEvmAddress(account): chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} Utils.Print("Send balance again, with invalid chainid") retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True) assert not retValue[0], f"push trx should have failed: {retValue}" @@ -437,7 +443,7 @@ def makeReservedEvmAddress(account): chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True) assert retValue[0], f"push trx should have succeeded: {retValue}" contract_addr = makeContractAddress(fromAdd, nonce) @@ -560,7 +566,7 @@ def makeReservedEvmAddress(account): data=b'', chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True) prodNode.waitForTransBlockIfNeeded(trans[1], True) row4=prodNode.getTableRow(evmAcc.name, evmAcc.name, "account", 4) # 4th balance of this integration test @@ -643,10 +649,11 @@ def makeReservedEvmAddress(account): for line in lines: Utils.Print("wsStdOutlog:", line) - time.sleep(3.0) + time.sleep(5.0) ws = websocket.WebSocket() - ws.connect("ws://127.0.0.1:3333", origin="nodeos_eos_evm_test.py") + Utils.Print("start to connect ws://localhost:3333") + ws.connect("ws://localhost:3333") ws.send("{\"method\":\"eth_blockNumber\",\"params\":[\"0x1\",false],\"id\":123}") Utils.Print("send eth_blockNumber to websocket proxy") @@ -774,6 +781,8 @@ def makeReservedEvmAddress(account): ws.close() testSuccessful= not foundErr +except Exception as ex: + Utils.Print("Exception:" + str(ex)) finally: TestHelper.shutdown(cluster, walletMgr, testSuccessful=testSuccessful, dumpErrorDetails=dumpErrorDetails) if killEosInstances: diff --git a/tests/nodeos_eos_evm_ws_test_fork.py b/tests/nodeos_eos_evm_ws_test_fork.py index 3c74175..633c1c0 100755 --- a/tests/nodeos_eos_evm_ws_test_fork.py +++ b/tests/nodeos_eos_evm_ws_test_fork.py @@ -57,6 +57,12 @@ Print=Utils.Print errorExit=Utils.errorExit +def get_raw_transaction(signed_trx): + if hasattr(signed_trx, 'raw_transaction'): + return signed_trx.raw_transaction + else: + return signed_trx.rawTransaction + def analyzeBPs(bps0, bps1, expectDivergence): start=0 index=None @@ -198,7 +204,7 @@ def interact_with_storage_contract(dest, nonce): chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name)) assert retValue[0], "pushtx to ETH contract failed." Utils.Print("\tBlock#", retValue[1]["processed"]["block_num"]) @@ -483,7 +489,7 @@ def makeReservedEvmAddress(account): chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name)) prodNode.waitForTransBlockIfNeeded(trans[1], True) @@ -509,7 +515,7 @@ def makeReservedEvmAddress(account): chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} Utils.Print("Send balance again, with correct nonce") retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True) time.sleep(1.0) @@ -529,7 +535,7 @@ def makeReservedEvmAddress(account): chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} Utils.Print("Send balance again, with invalid chainid") retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True) time.sleep(1.0) @@ -562,7 +568,7 @@ def makeReservedEvmAddress(account): data=Web3.to_bytes(hexstr='608060405234801561001057600080fd5b506101b6806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b604051610050919061013f565b60405180910390f35b610073600480360381019061006e9190610103565b61007e565b005b60008054905090565b806000819055503373ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516100e3919061013f565b60405180910390a350565b6000813590506100fd81610169565b92915050565b60006020828403121561011957610118610164565b5b6000610127848285016100ee565b91505092915050565b6101398161015a565b82525050565b60006020820190506101546000830184610130565b92915050565b6000819050919050565b600080fd5b6101728161015a565b811461017d57600080fd5b5056fea264697066735822122061ba78daf70a6edb2db7cbb1dbac434da1ba14ec0e009d4df8907b8c6ee4d63264736f6c63430008070033'), chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} retValue = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True) time.sleep(1.0) assert retValue[0], f"push trx should have succeeded: {retValue}" @@ -690,7 +696,7 @@ def makeReservedEvmAddress(account): data=b'', chainId=evmChainId ), evmSendKey) - actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]} + actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(get_raw_transaction(signed_trx))[2:]} trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True) time.sleep(1.0) prodNode.waitForTransBlockIfNeeded(trans[1], True) @@ -776,10 +782,11 @@ def makeReservedEvmAddress(account): for line in lines: Utils.Print("wsStdOutlog:", line) - time.sleep(3.0) + time.sleep(5.0) ws = websocket.WebSocket() - ws.connect("ws://127.0.0.1:3333", origin="nodeos_eos_evm_test.py") + Utils.Print("start to connect ws://localhost:3333") + ws.connect("ws://localhost:3333") ws.send("{\"method\":\"eth_blockNumber\",\"params\":[\"0x1\",false],\"id\":123}") Utils.Print("send eth_blockNumber to websocket proxy") @@ -1080,6 +1087,8 @@ def makeReservedEvmAddress(account): ws.close() testSuccessful= not foundErr +except Exception as ex: + Utils.Print("Exception:" + str(ex)) finally: TestHelper.shutdown(cluster, walletMgr, testSuccessful=testSuccessful, dumpErrorDetails=dumpErrorDetails) if killEosInstances: