Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcdaemon: remove base fee from to_transaction #2305

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions silkworm/rpc/commands/eth_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ Task<void> EthereumRpcApi::handle_eth_call(const nlohmann::json& request, std::s
co_await tx->close(); // RAII not (yet) available with coroutines
co_return;
}
silkworm::Transaction txn{call.to_transaction(block_with_hash->block.header.base_fee_per_gas)};
silkworm::Transaction txn{call.to_transaction()};

const auto execution_result = co_await EVMExecutor::call(
chain_config, *chain_storage, workers_, block_with_hash->block, txn, [&](auto& io_executor, auto block_num, auto& storage) {
Expand Down Expand Up @@ -1304,7 +1304,7 @@ Task<void> EthereumRpcApi::handle_eth_create_access_list(const nlohmann::json& r
auto tracer = std::make_shared<AccessListTracer>();

Tracers tracers{tracer};
auto txn = call.to_transaction(block_with_hash->block.header.base_fee_per_gas, std::nullopt, nonce);
auto txn = call.to_transaction(std::nullopt, nonce);
AccessList saved_access_list = call.access_list;
while (true) {
const auto execution_result = co_await EVMExecutor::call(
Expand All @@ -1331,7 +1331,7 @@ Task<void> EthereumRpcApi::handle_eth_create_access_list(const nlohmann::json& r
reply = make_json_content(request, access_list_result);
break;
}
txn = call.to_transaction(block_with_hash->block.header.base_fee_per_gas, current_access_list, nonce);
txn = call.to_transaction(current_access_list, nonce);
saved_access_list = current_access_list;
}
} catch (const std::invalid_argument& iv) {
Expand Down
4 changes: 2 additions & 2 deletions silkworm/rpc/commands/eth_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ TEST_CASE_METHOD(test_util::RpcApiE2ETest, "unit: eth_feeHistory succeeds if req
})"_json);
}

TEST_CASE_METHOD(test_util::RpcApiE2ETest, "fuzzy: eth_call invalid params", "[rpc][api]") {
TEST_CASE_METHOD(test_util::RpcApiE2ETest, "eth_call without params on gas", "[rpc][api]") {
const auto request = R"({"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{}, "latest"]})"_json;
std::string reply;
run<&test_util::RequestHandlerForTest::request_and_create_reply>(request, reply);
CHECK(nlohmann::json::parse(reply) == R"({
"jsonrpc":"2.0",
"id":1,
"error":{"code":-32000,"message":"insufficient funds for gas * price + value: address 0x0000000000000000000000000000000000000000 have 0 want 15240199550000000"}
"result":"0x"
})"_json);
}

Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/core/call_many.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ CallManyResult CallExecutor::executes_all_bundles(const silkworm::ChainConfig& c
// Don't call reserve here to preallocate result.results - since json value is dynamic it doesn't know yet how much it should allocate!
// -> Don't uncomment this line result.results.reserve(bundle.transactions.size());
for (const auto& call : bundle.transactions) {
silkworm::Transaction txn{call.to_transaction(block.header.base_fee_per_gas)};
silkworm::Transaction txn{call.to_transaction()};

auto call_execution_result = executor.call(blockContext.block_with_hash->block, txn);

Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/core/estimate_gas_oracle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Task<intx::uint256> EstimateGasOracle::estimate_gas(const Call& call, const silk
auto state = transaction_.create_state(this_executor, storage_, block_number);

ExecutionResult result{evmc_status_code::EVMC_SUCCESS};
silkworm::Transaction transaction{call.to_transaction(block.header.base_fee_per_gas)};
silkworm::Transaction transaction{call.to_transaction()};
while (lo + 1 < hi) {
EVMExecutor executor{config_, workers_, state};
auto mid = (hi + lo) / 2;
Expand Down
6 changes: 3 additions & 3 deletions silkworm/rpc/core/evm_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ Task<void> DebugExecutor::trace_call(json::Stream& stream, const BlockNumberOrHa
if (!block_with_hash) {
co_return;
}
rpc::Transaction transaction{call.to_transaction(block_with_hash->block.header.base_fee_per_gas)};
rpc::Transaction transaction{call.to_transaction()};

const auto& block = block_with_hash->block;
const auto number = block.header.number;
Expand Down Expand Up @@ -549,7 +549,7 @@ Task<void> DebugExecutor::execute(json::Stream& stream, const ChainStorage& stor
}

Task<void> DebugExecutor::execute(json::Stream& stream, const ChainStorage& storage, const silkworm::Block& block, const Call& call) {
rpc::Transaction transaction{call.to_transaction(block.header.base_fee_per_gas)};
rpc::Transaction transaction{call.to_transaction()};
co_await execute(stream, storage, block.header.number, block, transaction, -1);
co_return;
}
Expand Down Expand Up @@ -656,7 +656,7 @@ Task<void> DebugExecutor::execute(
stream.open_array();

for (const auto& call : bundle.transactions) {
silkworm::Transaction txn{call.to_transaction(block.header.base_fee_per_gas)};
silkworm::Transaction txn{call.to_transaction()};

stream.open_object();
stream.write_field("structLogs");
Expand Down
4 changes: 2 additions & 2 deletions silkworm/rpc/core/evm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ Task<std::vector<TraceCallResult>> TraceCallExecutor::trace_block_transactions(c
}

Task<TraceCallResult> TraceCallExecutor::trace_call(const silkworm::Block& block, const Call& call, const TraceConfig& config) {
rpc::Transaction transaction{call.to_transaction(block.header.base_fee_per_gas)};
rpc::Transaction transaction{call.to_transaction()};
auto result = co_await execute(block.header.number, block, transaction, -1, config);
co_return result;
}
Expand All @@ -1535,7 +1535,7 @@ Task<TraceManyCallResult> TraceCallExecutor::trace_calls(const silkworm::Block&
for (size_t index{0}; index < calls.size(); index++) {
const auto& config = calls[index].trace_config;

silkworm::Transaction transaction{calls[index].call.to_transaction(block.header.base_fee_per_gas)};
silkworm::Transaction transaction{calls[index].call.to_transaction()};

Tracers tracers;
TraceCallTraces traces;
Expand Down
5 changes: 2 additions & 3 deletions silkworm/rpc/types/call.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ struct Call {
std::optional<uint64_t> nonce;
AccessList access_list;

[[nodiscard]] silkworm::Transaction to_transaction(const std::optional<intx::uint256>& base_fee_per_gas,
const std::optional<AccessList>& override_access_list = std::nullopt,
[[nodiscard]] silkworm::Transaction to_transaction(const std::optional<AccessList>& override_access_list = std::nullopt,
const std::optional<uint64_t> override_nonce = std::nullopt) const {
silkworm::Transaction txn{};
txn.set_sender(from ? *from : evmc::address{});
Expand Down Expand Up @@ -78,7 +77,7 @@ struct Call {
// SILKWORM_ASSERT(!gas_price);
txn.type = TransactionType::kDynamicFee;
txn.max_priority_fee_per_gas = max_priority_fee_per_gas.value_or(intx::uint256{0});
txn.max_fee_per_gas = max_fee_per_gas.value_or(base_fee_per_gas.value_or(intx::uint256{0}));
txn.max_fee_per_gas = max_fee_per_gas.value_or(intx::uint256{0});
}

txn.value = value.value_or(intx::uint256{0});
Expand Down
24 changes: 12 additions & 12 deletions silkworm/rpc/types/call_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TEST_CASE("call with gas price", "[rpc][types][call]") {
1, // nonce
{},
};
silkworm::Transaction txn = call.to_transaction(std::nullopt);
silkworm::Transaction txn = call.to_transaction();
CHECK(txn.gas_limit == 235);
CHECK(txn.max_fee_per_gas == 21000);
CHECK(txn.max_priority_fee_per_gas == 21000);
Expand All @@ -78,7 +78,7 @@ TEST_CASE("call w/o gas price and max_fee_per_gas & max_priority_fee_per_gas not
1, // nonce
{},
};
silkworm::Transaction txn = call.to_transaction(18000);
silkworm::Transaction txn = call.to_transaction();
CHECK(txn.gas_limit == 235);
CHECK(txn.max_fee_per_gas == 18000);
CHECK(txn.max_priority_fee_per_gas == 18000);
Expand All @@ -98,7 +98,7 @@ TEST_CASE("call w/o gas price, max_fee_per_gas & max_priority_fee_per_gas", "[rp
1, // nonce
{},
};
silkworm::Transaction txn = call.to_transaction(std::nullopt);
silkworm::Transaction txn = call.to_transaction();
CHECK(txn.gas_limit == 235);
CHECK(txn.max_fee_per_gas == 0);
CHECK(txn.max_priority_fee_per_gas == 0);
Expand All @@ -118,9 +118,9 @@ TEST_CASE("call w/o gas price with base_fee", "[rpc][types][call]") {
1, // nonce
{},
};
silkworm::Transaction txn = call.to_transaction(23500);
silkworm::Transaction txn = call.to_transaction();
CHECK(txn.gas_limit == 235);
CHECK(txn.max_fee_per_gas == 23500);
CHECK(txn.max_fee_per_gas == 0);
CHECK(txn.max_priority_fee_per_gas == 0);
CHECK(txn.nonce == 1);
}
Expand All @@ -138,7 +138,7 @@ TEST_CASE("call with gas price and base_fee", "[rpc][types][call]") {
1, // nonce
{},
};
silkworm::Transaction txn = call.to_transaction(23500);
silkworm::Transaction txn = call.to_transaction();
CHECK(txn.gas_limit == 235);
CHECK(txn.max_fee_per_gas == 21000);
CHECK(txn.max_priority_fee_per_gas == 21000);
Expand Down Expand Up @@ -166,7 +166,7 @@ TEST_CASE("call with no gas price and no max_fee_per_gas and max_priority_fee_pe
std::nullopt,
23,
};
silkworm::Transaction txn = call.to_transaction(std::nullopt);
silkworm::Transaction txn = call.to_transaction();
CHECK(txn.gas_limit == 235);
CHECK(txn.max_fee_per_gas == 0);
CHECK(txn.nonce == 23);
Expand All @@ -183,7 +183,7 @@ TEST_CASE("call with no gas price and valid max_fee_per_gas and max_priority_fee
10000, // max_priority_fee_per_gas
31337, // value
silkworm::from_hex("001122aabbcc")};
silkworm::Transaction txn = call.to_transaction(10000);
silkworm::Transaction txn = call.to_transaction();
CHECK(txn.sender() == 0x99f9b87991262f6ba471f09758cde1c0fc1de734_address);
CHECK(txn.to == 0x5df9b87991262f6ba471f09758cde1c0fc1de734_address);
CHECK(txn.gas_limit == 235);
Expand All @@ -195,7 +195,7 @@ TEST_CASE("call with no gas price and valid max_fee_per_gas and max_priority_fee

TEST_CASE("call with no gas", "[rpc][types][call]") {
Call call;
silkworm::Transaction txn = call.to_transaction(std::nullopt);
silkworm::Transaction txn = call.to_transaction();
CHECK(txn.gas_limit == 50000000);
CHECK(txn.value == 0);
CHECK(txn.data.empty());
Expand All @@ -213,7 +213,7 @@ TEST_CASE("call with AccessList", "[rpc][types][call]") {
{}, // data
1, // nonce
access_list};
silkworm::Transaction txn = call.to_transaction(std::nullopt);
silkworm::Transaction txn = call.to_transaction();
CHECK(txn.gas_limit == 235);
CHECK(txn.max_fee_per_gas == 21000);
CHECK(txn.max_priority_fee_per_gas == 21000);
Expand All @@ -233,7 +233,7 @@ TEST_CASE("call with no AccessList and pass it to_transaction", "[rpc][types][ca
31337, // value
{}, // data
1}; // nonce
silkworm::Transaction txn = call.to_transaction(std::nullopt, access_list);
silkworm::Transaction txn = call.to_transaction(access_list);
CHECK(txn.gas_limit == 235);
CHECK(txn.max_fee_per_gas == 21000);
CHECK(txn.max_priority_fee_per_gas == 21000);
Expand All @@ -254,7 +254,7 @@ TEST_CASE("call with no nonce and pass it to_transaction", "[rpc][types][call]")
31337, // value
{}, // data
std::nullopt}; // nonce
silkworm::Transaction txn = call.to_transaction(std::nullopt, std::nullopt, nonce);
silkworm::Transaction txn = call.to_transaction(std::nullopt, nonce);
CHECK(txn.gas_limit == 235);
CHECK(txn.max_fee_per_gas == 21000);
CHECK(txn.max_priority_fee_per_gas == 21000);
Expand Down
Loading