Skip to content

Commit

Permalink
rpcdaemon: use txn state for bundles in eth_callMany (#2602)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 authored Dec 16, 2024
1 parent bb62df8 commit 837331e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
31 changes: 10 additions & 21 deletions silkworm/rpc/core/call_many.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,16 @@ CallManyResult CallExecutor::executes_all_bundles(const silkworm::ChainConfig& c
const Bundles& bundles,
std::optional<std::uint64_t> opt_timeout,
const AccountsOverrides& accounts_overrides,
int32_t transaction_index,
TxnId txn_id,
boost::asio::any_io_executor& this_executor) {
CallManyResult result;
const auto& block = block_with_hash->block;
const auto& block_transactions = block.transactions;
auto state = execution::StateFactory{transaction_}.create_state(this_executor, storage, block.header.number);
auto state = execution::StateFactory{transaction_}.create_state_txn(this_executor, storage, txn_id);
EVMExecutor executor{block, config, workers_, std::make_shared<state::OverrideState>(*state, accounts_overrides)};

std::uint64_t timeout = opt_timeout.value_or(5000);
uint64_t timeout = opt_timeout.value_or(5000);
const auto start_time = clock_time::now();
for (auto idx{0}; idx < transaction_index; ++idx) {
silkworm::Transaction txn{block_transactions[static_cast<size_t>(idx)]};
auto exec_result = executor.call(block, txn);
if ((clock_time::since(start_time) / 1000000) > timeout) {
std::ostringstream oss;
oss << "execution aborted (timeout = " << static_cast<double>(timeout) / 1000.0 << "s)";
result.error = oss.str();
return result;
}
}
executor.reset();

// 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(bundles.size());
for (const auto& bundle : bundles) {
Expand Down Expand Up @@ -143,7 +132,7 @@ Task<CallManyResult> CallExecutor::execute(
std::optional<std::uint64_t> timeout) {
const auto chain_storage{transaction_.create_storage()};

std::uint16_t count{0};
uint16_t count{0};
bool empty = true;
for (const auto& bundle : bundles) {
SILK_DEBUG << "bundle[" << count++ << "]: " << bundle;
Expand All @@ -162,20 +151,20 @@ Task<CallManyResult> CallExecutor::execute(
if (!block_with_hash) {
throw std::invalid_argument("read_block_by_block_num_or_hash: block not found");
}
auto transaction_index = context.transaction_index;
if (transaction_index == -1) {
transaction_index = static_cast<std::int32_t>(block_with_hash->block.transactions.size());
}
const uint64_t transaction_index =
context.transaction_index == -1 ? block_with_hash->block.transactions.size() : static_cast<uint64_t>(context.transaction_index);

auto this_executor = co_await boost::asio::this_coro::executor;
const auto min_tx_num = co_await transaction_.first_txn_num_in_block(block_with_hash->block.header.number);
const auto txn_id = min_tx_num + transaction_index + 1; // for system txn in the beginning of block
result = co_await async_task(workers_.executor(), [&]() -> CallManyResult {
return executes_all_bundles(chain_config,
*chain_storage,
block_with_hash,
bundles,
timeout,
accounts_overrides,
transaction_index,
txn_id,
this_executor);
});

Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/core/call_many.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CallExecutor {
const Bundles& bundles,
std::optional<std::uint64_t> opt_timeout,
const AccountsOverrides& accounts_overrides,
int32_t transaction_index,
TxnId txn_id,
boost::asio::any_io_executor& executor);

private:
Expand Down

0 comments on commit 837331e

Please sign in to comment.