diff --git a/silkworm/silkrpc/commands/eth_api.cpp b/silkworm/silkrpc/commands/eth_api.cpp index e95f0bdb02..dcca116717 100644 --- a/silkworm/silkrpc/commands/eth_api.cpp +++ b/silkworm/silkrpc/commands/eth_api.cpp @@ -194,11 +194,12 @@ awaitable EthereumRpcApi::handle_eth_gas_price(const nlohmann::json& reque try { ethdb::TransactionDatabase tx_database{*tx}; + const auto chain_storage = tx->create_storage(tx_database, backend_); const auto latest_block_number = co_await core::get_block_number(core::kLatestBlockId, tx_database); SILK_INFO << "latest_block_number " << latest_block_number; - BlockProvider block_provider = [this, &tx_database](uint64_t block_number) { - return core::read_block_by_number(*block_cache_, tx_database, block_number); + BlockProvider block_provider = [this, &tx_database, &chain_storage](uint64_t block_number) { + return core::read_block_by_number(*block_cache_, *chain_storage, tx_database, block_number); }; GasPriceOracle gas_price_oracle{block_provider}; @@ -910,7 +911,6 @@ awaitable EthereumRpcApi::handle_eth_estimate_gas(const nlohmann::json& re const BlockNumberOrHash block_number_or_hash{core::kLatestBlockId}; ethdb::kv::CachedDatabase cached_database{block_number_or_hash, *tx, *state_cache_}; ethdb::TransactionDatabase tx_database{*tx}; - const auto chain_id = co_await core::rawdb::read_chain_id(tx_database); const auto chain_config_ptr = lookup_chain_config(chain_id); const auto latest_block_number = co_await core::get_block_number(core::kLatestBlockId, tx_database); @@ -919,7 +919,6 @@ awaitable EthereumRpcApi::handle_eth_estimate_gas(const nlohmann::json& re const auto latest_block_with_hash = co_await core::read_block_by_number(*block_cache_, tx_database, latest_block_number); const auto latest_block = latest_block_with_hash->block; StateReader state_reader(cached_database); - rpc::BlockHeaderProvider block_header_provider = [&cached_database](uint64_t block_number) { return core::rawdb::read_header_by_number(cached_database, block_number); }; @@ -1292,9 +1291,12 @@ awaitable EthereumRpcApi::handle_eth_create_access_list(const nlohmann::js ethdb::TransactionDatabase tx_database{*tx}; ethdb::kv::CachedDatabase cached_database{block_number_or_hash, *tx, *state_cache_}; - const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, tx_database, block_number_or_hash); - const auto chain_id = co_await core::rawdb::read_chain_id(tx_database); - const auto chain_config_ptr = lookup_chain_config(chain_id); + const auto chain_storage{tx->create_storage(tx_database, backend_)}; + const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, *chain_storage, tx_database, block_number_or_hash); + + const auto chain_id = co_await chain_storage->read_chain_id(); + ensure(chain_id.has_value(), "cannot read chain ID"); + const auto chain_config_ptr = lookup_chain_config(*chain_id); const bool is_latest_block = co_await core::get_latest_executed_block_number(tx_database) == block_with_hash->block.header.number; const core::rawdb::DatabaseReader& db_reader = @@ -1356,6 +1358,8 @@ awaitable EthereumRpcApi::handle_eth_create_access_list(const nlohmann::js } call.set_access_list(current_access_list); } while (!access_lists_match); + } catch (const std::invalid_argument& iv) { + reply = make_json_content(request["id"], {}); } catch (const std::exception& e) { SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump(); reply = make_json_error(request["id"], 100, e.what()); diff --git a/silkworm/silkrpc/core/cached_chain.cpp b/silkworm/silkrpc/core/cached_chain.cpp index 8a4d5ee8cf..1e66b503ea 100644 --- a/silkworm/silkrpc/core/cached_chain.cpp +++ b/silkworm/silkrpc/core/cached_chain.cpp @@ -101,6 +101,18 @@ awaitable> read_block_by_number_or_hash(BlockCach throw std::runtime_error{"invalid block_number_or_hash value"}; } +awaitable> read_block_by_number_or_hash(BlockCache& cache, const ChainStorage& storage, const rawdb::DatabaseReader& reader, const BlockNumberOrHash& bnoh) { + if (bnoh.is_number()) { // NOLINT(bugprone-branch-clone) + co_return co_await read_block_by_number(cache, storage, reader, bnoh.number()); + } else if (bnoh.is_hash()) { + co_return co_await read_block_by_hash(cache, storage, bnoh.hash()); + } else if (bnoh.is_tag()) { + auto [block_number, ignore] = co_await get_block_number(bnoh.tag(), reader, /*latest_required=*/false); + co_return co_await read_block_by_number(cache, storage, reader, block_number); + } + throw std::runtime_error{"invalid block_number_or_hash value"}; +} + awaitable read_block_by_transaction_hash(BlockCache& cache, const rawdb::DatabaseReader& reader, const evmc::bytes32& transaction_hash) { auto block_number = co_await rawdb::read_block_number_by_transaction_hash(reader, transaction_hash); auto block_by_hash = co_await read_block_by_number(cache, reader, block_number); diff --git a/silkworm/silkrpc/core/cached_chain.hpp b/silkworm/silkrpc/core/cached_chain.hpp index d52413c4de..ee1d096b58 100644 --- a/silkworm/silkrpc/core/cached_chain.hpp +++ b/silkworm/silkrpc/core/cached_chain.hpp @@ -36,6 +36,7 @@ awaitable> read_block_by_number(BlockCache& cache awaitable> read_block_by_hash(BlockCache& cache, const rawdb::DatabaseReader& reader, const evmc::bytes32& block_hash); awaitable> read_block_by_hash(BlockCache& cache, const ChainStorage& storage, const evmc::bytes32& block_hash); awaitable> read_block_by_number_or_hash(BlockCache& cache, const rawdb::DatabaseReader& reader, const BlockNumberOrHash& bnoh); +awaitable> read_block_by_number_or_hash(BlockCache& cache, const ChainStorage& storage, const rawdb::DatabaseReader& reader, const BlockNumberOrHash& bnoh); awaitable read_block_by_transaction_hash(BlockCache& cache, const rawdb::DatabaseReader& reader, const evmc::bytes32& transaction_hash); awaitable> read_transaction_by_hash(BlockCache& cache, const rawdb::DatabaseReader& reader, const evmc::bytes32& transaction_hash); diff --git a/tests/integration/goerly/eth_createAccessList/test_5.json b/tests/integration/goerly/eth_createAccessList/test_5.json new file mode 100644 index 0000000000..cde266f4b6 --- /dev/null +++ b/tests/integration/goerly/eth_createAccessList/test_5.json @@ -0,0 +1,25 @@ +[ + { + "request": { + "jsonrpc":"2.0", + "method":"eth_createAccessList", + "params":[ + { + "data": "0xdaa6d5560000000000000000000000000000000000000000000000000000000000000000", + "from": "0x52c24586c31cff0485a6208bb63859290fba5bce", + "to": "0xfffff7794a1dc8e42615f059dd6e406a6594651a", + "gas": "0xF4240", + "gasPrice": "0x10C388C00" + }, + "0xFFFFFF" + ], + "id":1 + }, + "response": { + "id":1, + "jsonrpc":"2.0", + "result": null + } + } +] +