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

rpcdaemon: ots_searchTransactionsAfter for e3 #2527

Merged
merged 3 commits into from
Nov 22, 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
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.17.1 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v1.18.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
64 changes: 20 additions & 44 deletions silkworm/rpc/commands/ots_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <silkworm/core/common/empty_hashes.hpp>
#include <silkworm/core/protocol/ethash_rule_set.hpp>
#include <silkworm/core/types/evmc_bytes32.hpp>
#include <silkworm/db/access_layer.hpp>
#include <silkworm/db/datastore/mdbx/bitmap.hpp>
#include <silkworm/db/kv/api/endpoint/key_value.hpp>
#include <silkworm/db/kv/txn_num.hpp>
Expand Down Expand Up @@ -763,54 +762,22 @@ Task<void> OtsRpcApi::handle_ots_search_transactions_after(const nlohmann::json&
auto tx = co_await database_->begin();

try {
auto call_from_cursor = co_await tx->cursor(table::kCallFromIndexName);
auto call_to_cursor = co_await tx->cursor(table::kCallToIndexName);

bool is_last_page = false;
auto provider = ethdb::kv::canonical_body_for_storage_provider(backend_);

if (block_number == 0) {
is_last_page = true;
} else {
// Internal search code considers blockNum [including], so adjust the value
++block_number;
db::kv::api::Timestamp from_timestamp{-1};
if (block_number > 0) {
const auto max_tx_num = co_await db::txn::min_tx_num(*tx, block_number + 1, provider);
from_timestamp = static_cast<db::kv::api::Timestamp>(max_tx_num);
SILK_DEBUG << "block_number: " << block_number << " max_tx_num: " << max_tx_num;
}

ForwardBlockProvider from_provider{call_from_cursor.get(), address, block_number};
ForwardBlockProvider to_provider{call_to_cursor.get(), address, block_number};
FromToBlockProvider from_to_provider{true, &from_provider, &to_provider};

uint64_t result_count = 0;
bool has_more = true;

TransactionsWithReceipts results{
.last_page = is_last_page};

while (result_count < page_size && has_more) {
std::vector<TransactionsWithReceipts> transactions_with_receipts_vec;

has_more = co_await trace_blocks(from_to_provider, *tx, address, page_size, result_count, transactions_with_receipts_vec);
auto results = co_await collect_transactions_with_receipts(*tx, provider, block_number, address, from_timestamp, true, page_size);

for (const auto& item : transactions_with_receipts_vec) {
results.receipts.insert(results.receipts.end(), item.receipts.begin(), item.receipts.end());
results.transactions.insert(results.transactions.end(), item.transactions.begin(), item.transactions.end());
results.blocks.insert(results.blocks.end(), item.blocks.begin(), item.blocks.end());

result_count += item.transactions.size();

if (result_count >= page_size) {
break;
}
}
}

// Reverse results
std::reverse(results.transactions.begin(), results.transactions.end());
std::reverse(results.receipts.begin(), results.receipts.end());
std::reverse(results.blocks.begin(), results.blocks.end());

results.first_page = !has_more;
reply = make_json_content(request, results);

} catch (const std::invalid_argument& iv) {
SILK_WARN << "invalid_argument: " << iv.what() << " processing request: " << request.dump();
reply = make_json_content(request, nlohmann::detail::value_t::null);
Expand Down Expand Up @@ -852,9 +819,14 @@ Task<TransactionsWithReceipts> OtsRpcApi::collect_transactions_with_receipts(
auto it_from = co_await paginated_result_from.begin();
auto it_to = co_await paginated_result_to.begin();

TransactionsWithReceipts results{
.first_page = block_number == 0,
.last_page = true};
TransactionsWithReceipts results;
if (ascending) {
results.first_page = true;
results.last_page = block_number == 0;
} else {
results.first_page = block_number == 0;
results.last_page = true;
}

std::map<std::string, Receipt> receipts;
std::optional<BlockInfo> block_info;
Expand Down Expand Up @@ -916,7 +888,11 @@ Task<TransactionsWithReceipts> OtsRpcApi::collect_transactions_with_receipts(
}

if (results.transactions.size() >= page_size && block_num_changed) {
results.last_page = false;
if (ascending) {
results.first_page = false;
} else {
results.last_page = false;
}
break;
}

Expand Down
Loading