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

rpcdameon: fix getLatestLogs with logCount #2007

Merged
merged 3 commits into from
May 9, 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
25 changes: 15 additions & 10 deletions silkworm/rpc/core/logs_walker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Task<void> LogsWalker::get_logs(std::uint64_t start, std::uint64_t end,
std::reverse(matching_block_numbers.begin(), matching_block_numbers.end());
}

std::uint64_t logCount{0};
std::uint64_t blockCount{0};
std::uint64_t log_count{0};
std::uint64_t block_count{0};

Logs chunk_logs;
Logs filtered_chunk_logs;
Expand All @@ -133,19 +133,19 @@ Task<void> LogsWalker::get_logs(std::uint64_t start, std::uint64_t end,
SILK_DEBUG << "chunk_logs.size(): " << chunk_logs.size();

filtered_chunk_logs.clear();
filter_logs(std::move(chunk_logs), addresses, topics, filtered_chunk_logs);
filter_logs(std::move(chunk_logs), addresses, topics, filtered_chunk_logs, options.log_count == 0 ? 0 : options.log_count - log_count);

if (!filtered_chunk_logs.empty()) {
const auto tx_index = boost::endian::load_big_u32(&k[sizeof(uint64_t)]);
SILK_TRACE << "Transaction index: " << tx_index;
for (auto& log : filtered_chunk_logs) {
log.tx_index = tx_index;
}
logCount += filtered_chunk_logs.size();
SILK_TRACE << "logCount: " << logCount;
log_count += filtered_chunk_logs.size();
SILK_TRACE << "log_count: " << log_count;
filtered_block_logs.insert(filtered_block_logs.end(), filtered_chunk_logs.rbegin(), filtered_chunk_logs.rend());
}
return options.log_count == 0 || options.log_count > logCount;
return options.log_count == 0 || options.log_count > log_count;
});
SILK_DEBUG << "filtered_block_logs.size(): " << filtered_block_logs.size();

Expand All @@ -166,11 +166,11 @@ Task<void> LogsWalker::get_logs(std::uint64_t start, std::uint64_t end,
}
logs.insert(logs.end(), filtered_block_logs.begin(), filtered_block_logs.end());
}
blockCount++;
if (options.log_count != 0 && options.log_count <= logCount) {
block_count++;
if (options.log_count != 0 && options.log_count <= log_count) {
break;
}
if (options.block_count != 0 && options.block_count == blockCount) {
if (options.block_count != 0 && options.block_count == block_count) {
break;
}
}
Expand All @@ -179,8 +179,10 @@ Task<void> LogsWalker::get_logs(std::uint64_t start, std::uint64_t end,
co_return;
}

void LogsWalker::filter_logs(const std::vector<Log>&& logs, const FilterAddresses& addresses, const FilterTopics& topics, std::vector<Log>& filtered_logs) {
void LogsWalker::filter_logs(const std::vector<Log>&& logs, const FilterAddresses& addresses, const FilterTopics& topics, std::vector<Log>& filtered_logs,
size_t max_logs) {
SILK_DEBUG << "filter_logs: addresses: " << addresses << ", topics: " << topics;
size_t log_count = 0;
for (auto& log : logs) {
SILK_DEBUG << "log: " << log;
if (!addresses.empty() && std::find(addresses.begin(), addresses.end(), log.address) == addresses.end()) {
Expand Down Expand Up @@ -217,6 +219,9 @@ void LogsWalker::filter_logs(const std::vector<Log>&& logs, const FilterAddresse
if (matches) {
filtered_logs.push_back(log);
}
if (max_logs != 0 && ++log_count >= max_logs) {
return;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/core/logs_walker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LogsWalker {
std::vector<Log>& logs);

private:
void filter_logs(const std::vector<Log>&& logs, const FilterAddresses& addresses, const FilterTopics& topics, std::vector<Log>& filtered_logs);
void filter_logs(const std::vector<Log>&& logs, const FilterAddresses& addresses, const FilterTopics& topics, std::vector<Log>& filtered_logs, size_t max_logs);

ethbackend::BackEnd* backend_;
BlockCache& block_cache_;
Expand Down
Loading