Skip to content

Commit

Permalink
rpcdaemon: fix and improve perf in eth_getLogs (#2584)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixtysixter authored Dec 12, 2024
1 parent f7078cf commit a1a0807
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rpc-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Checkout RPC Tests Repository & Install Requirements
run: |
rm -rf ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v1.24.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v1.25.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
cd ${{runner.workspace}}/rpc-tests
pip3 install -r requirements.txt --break-system-packages
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ debug_traceTransaction/test_92.tar,\
debug_traceTransaction/test_96.json,\
trace_replayBlockTransactions/test_29,\
engine_,\
erigon_getLatestLogs,\
eth_getLogs
erigon_getLatestLogs

failed_test=$?

Expand Down
12 changes: 5 additions & 7 deletions silkworm/db/kv/txn_num.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,26 @@ Task<std::optional<TransactionNums>> PaginatedTransactionInfoIterator::next() {
}
const auto tnx_id = static_cast<TxnId>(next_id.value());

if (min_txn_num_ == 0 || (ascending_ && next_id > max_txn_num_) || (!ascending_ && next_id < min_txn_num_)) {
bool block_changed{false};
if (max_txn_num_ == 0 || (ascending_ && tnx_id > max_txn_num_) || (!ascending_ && tnx_id < min_txn_num_)) {
const auto block_num_opt = co_await db::txn::block_num_from_tx_num(tx_, tnx_id, provider_);
if (!block_num_opt) {
SILK_DEBUG << "No block found for txn_id " << tnx_id;
co_return std::nullopt;
}
block_num_ = block_num_opt.value();
block_changed_ = true;
}

if (block_changed_) {
max_txn_num_ = co_await db::txn::max_tx_num(tx_, block_num_, provider_);
min_txn_num_ = co_await db::txn::min_tx_num(tx_, block_num_, provider_);
block_changed_ = false;

block_changed = true;
}

const TransactionNums txn_nums{
.txn_id = tnx_id,
.block_num = block_num_,
.txn_index = tnx_id - min_txn_num_ - 1,
.final_txn = tnx_id == max_txn_num_,
.block_changed = block_changed_};
.block_changed = block_changed};

SILK_DEBUG << "txn_id: " << txn_nums.txn_id
<< ", block_num: " << txn_nums.block_num
Expand Down
1 change: 0 additions & 1 deletion silkworm/db/kv/txn_num.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class PaginatedTransactionInfoIterator : public kv::api::PaginatedIterator<Trans
BlockNum block_num_{0};
TxNum min_txn_num_{0};
TxNum max_txn_num_{0};
bool block_changed_{true};
};

kv::api::PaginatedStream<TransactionNums> make_txn_nums_stream(PaginatedTimestampStream stream,
Expand Down
14 changes: 5 additions & 9 deletions silkworm/rpc/core/logs_walker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ Task<void> LogsWalker::get_logs(BlockNum start,
paginated_stream = db::kv::api::make_range_stream(from_timestamp, to_timestamp);
}

std::map<evmc::bytes32, Receipt> receipts;

Receipts receipts;
uint64_t block_count{0};
uint64_t log_count{0};
Logs filtered_chunk_logs;
Expand All @@ -154,12 +153,8 @@ Task<void> LogsWalker::get_logs(BlockNum start,
SILK_DEBUG << "Not found block no. " << tnx_nums->block_num;
break;
}
auto rr = co_await core::get_receipts(tx_, *block_with_hash, *chain_storage, workers_);
SILK_DEBUG << "Read #" << rr.size() << " receipts from block " << tnx_nums->block_num;

std::for_each(rr.begin(), rr.end(), [&receipts](const auto& item) {
receipts[item.tx_hash] = std::move(item);
});
receipts = co_await core::get_receipts(tx_, *block_with_hash, *chain_storage, workers_);
SILK_DEBUG << "Read #" << receipts.size() << " receipts from block " << tnx_nums->block_num;

++block_count;
}
Expand All @@ -171,7 +166,8 @@ Task<void> LogsWalker::get_logs(BlockNum start,

SILK_DEBUG << "Got transaction: block_num: " << tnx_nums->block_num << ", txn_index: " << tnx_nums->txn_index;

const auto& receipt = receipts.at(transaction.value().hash());
SILKWORM_ASSERT(tnx_nums->txn_index < receipts.size());
const auto& receipt = receipts.at(tnx_nums->txn_index);

SILK_DEBUG << "#rawLogs: " << receipt.logs.size();
filtered_chunk_logs.clear();
Expand Down

0 comments on commit a1a0807

Please sign in to comment.