Skip to content

Commit 4c2fbff

Browse files
committed
[rpc] Collect metrics in eth_simulate
This patch enables the collection of fiber group execution metrics in `submit_eth_simulate_to_pool`.
1 parent 066e208 commit 4c2fbff

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

category/rpc/monad_executor.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <category/execution/ethereum/evmc_host.hpp>
4545
#include <category/execution/ethereum/execute_block.hpp>
4646
#include <category/execution/ethereum/execute_transaction.hpp>
47+
#include <category/execution/ethereum/rlp/decode.hpp>
4748
#include <category/execution/ethereum/state2/block_state.hpp>
4849
#include <category/execution/ethereum/state3/state.hpp>
4950
#include <category/execution/ethereum/trace/call_frame.hpp>
@@ -78,7 +79,6 @@
7879
#include <cstring>
7980
#include <filesystem>
8081
#include <format>
81-
#include <iostream>
8282
#include <memory>
8383
#include <optional>
8484
#include <span>
@@ -535,10 +535,10 @@ namespace
535535
std::vector<std::unique_ptr<trace::StateTracer>>{};
536536
state_tracers.reserve(calls[block_idx].size());
537537

538-
for (auto tx_idx = 0u; tx_idx < calls[block_idx].size(); ++tx_idx) {
538+
for (Transaction const &tx : calls[block_idx]) {
539539
call_frames.emplace_back();
540-
call_tracers.emplace_back(std::make_unique<CallTracer>(
541-
calls[block_idx][tx_idx], call_frames.back()));
540+
call_tracers.emplace_back(
541+
std::make_unique<CallTracer>(tx, call_frames.back()));
542542
state_tracers.emplace_back(
543543
std::make_unique<trace::StateTracer>());
544544
}
@@ -1613,8 +1613,15 @@ struct monad_executor
16131613
complete = complete,
16141614
result = result,
16151615
user = user]() {
1616-
// TODO(BSC): fiber group
1617-
(void)fiber_group;
1616+
fiber_group->queued_count.fetch_sub(
1617+
1, std::memory_order_relaxed);
1618+
fiber_group->executing_count.fetch_add(
1619+
1, std::memory_order_relaxed);
1620+
BOOST_SCOPE_EXIT_ALL(&fiber_group)
1621+
{
1622+
fiber_group->executing_count.fetch_sub(
1623+
1, std::memory_order_relaxed);
1624+
};
16181625

16191626
auto const res = [&]() -> Result<nlohmann::json> {
16201627
auto authorities = std::vector<
@@ -1658,7 +1665,7 @@ struct monad_executor
16581665
MONAD_ASSERT(false);
16591666
}();
16601667

1661-
LazyBlockHash block_hash_buffer{db, block_number};
1668+
LazyBlockHash const block_hash_buffer{db, block_number};
16621669
TrieRODb tdb{db};
16631670

16641671
if (chain_config == CHAIN_CONFIG_ETHEREUM_MAINNET) {
@@ -1938,13 +1945,13 @@ void monad_executor_eth_simulate_submit(
19381945
auto const maybe_senders =
19391946
decode_nested_items<rlp::decode_address, false>(rlp_senders_view);
19401947
MONAD_ASSERT(maybe_senders.has_value());
1941-
auto const senders = maybe_senders.assume_value();
1948+
auto const &senders = maybe_senders.assume_value();
19421949

19431950
byte_string_view rlp_calls_view{rlp_calls, rlp_calls_len};
19441951
auto const maybe_txns =
19451952
decode_nested_items<rlp::decode_transaction, true>(rlp_calls_view);
19461953
MONAD_ASSERT(maybe_txns.has_value());
1947-
auto const txns = maybe_txns.assume_value();
1954+
auto const &txns = maybe_txns.assume_value();
19481955

19491956
MONAD_ASSERT(senders.size() == txns.size());
19501957
MONAD_ASSERT(n_state_overrides == txns.size());
@@ -1963,8 +1970,8 @@ void monad_executor_eth_simulate_submit(
19631970

19641971
executor->submit_eth_simulate_to_pool(
19651972
chain_config,
1966-
std::move(txns),
1967-
std::move(senders),
1973+
txns,
1974+
senders,
19681975
std::span{state_overrides, n_state_overrides},
19691976
block_header,
19701977
block_number,

category/rpc/monad_executor_test.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4312,8 +4312,11 @@ TEST_F(EthCallFixture, eth_simulate_v1)
43124312
// .value();
43134313
auto const rlp_block_id = to_vec(rlp_finalized_id);
43144314

4315-
auto const state_overrides =
4316-
std::vector<monad_state_override const *>{5, nullptr};
4315+
std::vector<monad_state_override *> state_overrides{};
4316+
state_overrides.reserve(2);
4317+
for (size_t i = 0; i < 2; i++) {
4318+
state_overrides.push_back(monad_state_override_create());
4319+
}
43174320

43184321
struct callback_context ctx;
43194322
boost::fibers::future<void> f = ctx.promise.get_future();
@@ -4336,5 +4339,9 @@ TEST_F(EthCallFixture, eth_simulate_v1)
43364339
(void *)&ctx);
43374340
f.get();
43384341

4342+
for (auto *override : state_overrides) {
4343+
monad_state_override_destroy(override);
4344+
}
4345+
43394346
monad_executor_destroy(executor);
43404347
}

0 commit comments

Comments
 (0)