Skip to content

Commit

Permalink
fix: add missing check of the to_block number in LogFilter::match_all
Browse files Browse the repository at this point in the history
  • Loading branch information
kstdl committed Aug 6, 2024
1 parent 3517f00 commit b0ad898
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ std::shared_ptr<const FinalizationResult> FinalChainImpl::finalize_(PeriodData&&
for (const auto& r : exec_results) {
LogEntries logs;
logs.reserve(r.logs.size());
std::transform(r.logs.cbegin(), r.logs.cend(), std::back_inserter(logs), [](const auto& l) {
return LogEntry{l.address, l.topics, l.data};
});
std::transform(r.logs.cbegin(), r.logs.cend(), std::back_inserter(logs),
[](const auto& l) { return LogEntry{l.address, l.topics, l.data}; });
transactions_gas_used.push_back(r.gas_used);
receipts.emplace_back(TransactionReceipt{
r.code_err.empty() && r.consensus_err.empty(),
Expand Down
13 changes: 10 additions & 3 deletions libraries/core_libs/network/rpc/eth/LogFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,23 @@ void LogFilter::match_one(const ExtendedTransactionLocation& trx_loc, const Tran

std::vector<LocalisedLogEntry> LogFilter::match_all(const FinalChain& final_chain) const {
std::vector<LocalisedLogEntry> ret;

// to_block can't be greater than the last executed block number
const auto last_block_number = final_chain.last_block_number();
auto to_blk_n = to_block_ ? *to_block_ : last_block_number;
if (to_blk_n > last_block_number) {
to_blk_n = last_block_number;
}

auto action = [&, this](EthBlockNumber blk_n) {
ExtendedTransactionLocation trx_loc{{{blk_n}, *final_chain.block_hash(blk_n)}};
ExtendedTransactionLocation trx_loc{{{blk_n}, final_chain.block_hash(blk_n).value()}};
auto hashes = final_chain.transaction_hashes(trx_loc.period);
for (const auto& hash : *hashes) {
trx_loc.trx_hash = hash;
match_one(trx_loc, *final_chain.transaction_receipt(hash), [&](const auto& lle) { ret.push_back(lle); });
match_one(trx_loc, final_chain.transaction_receipt(hash).value(), [&](const auto& lle) { ret.push_back(lle); });
++trx_loc.position;
}
};
auto to_blk_n = to_block_ ? *to_block_ : final_chain.last_block_number();
if (is_range_only_) {
for (auto blk_n = from_block_; blk_n <= to_blk_n; ++blk_n) {
action(blk_n);
Expand Down

0 comments on commit b0ad898

Please sign in to comment.