Skip to content

Commit

Permalink
Merge pull request #271 from eosnetworkfoundation/kayan_port_mdbx_fix
Browse files Browse the repository at this point in the history
[0.7] Kayan port mdbx fix
  • Loading branch information
yarkinwho authored Aug 9, 2024
2 parents 00a14cf + 871c9ee commit 0694c35
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion external/silkworm
7 changes: 3 additions & 4 deletions src/engine_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ class engine_plugin_impl : std::enable_shared_from_this<engine_plugin_impl> {
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();

Expand Down
31 changes: 4 additions & 27 deletions src/rpc_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>()->default_value("./"),
"directory of chaindata")
("rpc-max-readers", boost::program_options::value<uint32_t>()->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<uint32_t>()->default_value(32000),
"maximum number of rpc readers")
("api-spec", boost::program_options::value<std::string>()->default_value("eth"),
"comma separated api spec, possible values: debug,engine,eth,net,parity,erigon,txpool,trace,web3")
Expand Down Expand Up @@ -87,31 +88,6 @@ void rpc_plugin::plugin_initialize( const appbase::variables_map& options ) try
const auto& data_dir = options.at("chaindata").as<std::string>();

auto log_level = appbase::app().get_plugin<sys_plugin>().get_verbosity();
using evmc::operator""_bytes32;

uint32_t chain_id = options.at("chain-id").as<uint32_t>();
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<silkworm::DataDirectory>(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
Expand All @@ -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));
Expand Down
25 changes: 17 additions & 8 deletions tests/nodeos_eos_evm_ws_test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"])
Expand Down Expand Up @@ -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)

Expand All @@ -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}"
Expand All @@ -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}"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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:
Expand Down
25 changes: 17 additions & 8 deletions tests/nodeos_eos_evm_ws_test_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0694c35

Please sign in to comment.