Skip to content

esplora: fetch address histories concurrently - #37

Open
albertodeluigi wants to merge 1 commit into
sequentiafrom
fix/esplora-concurrent-history
Open

albertodeluigi wants to merge 1 commit into
sequentiafrom
fix/esplora-concurrent-history

Conversation

@albertodeluigi

Copy link
Copy Markdown
Collaborator

What was wrong

get_scripts_history_esplora (lwk_wollet/src/clients/asyncr/esplora.rs) walked each batch with a for loop, one address at a time. The client's concurrency setting reached only get_transactions and get_headers.

A wallet's scan is mostly address histories: every used address plus the 20-address gap, on each chain. A fresh testnet web wallet made about 44 of these requests in strict sequence, and as many again for the covenant order-payout wallet. That is ~7 s each behind a 120 ms round trip, whether the web wallet asked for a concurrency of 1 or of 8.

What changes

The batch goes through the same stream as get_transactions, with up to concurrency requests in flight. It uses buffered, not buffer_unordered, so the results stay in address order, which get_history relies on to find the last used index. Error handling and the paging TODO are unchanged.

With the default concurrency of 1, behaviour is identical.

Verified

  • wasm-pack build --target web --release of lwk_wasm from this branch, on the testnet box (Rust 1.85.0, wasm-pack 0.13.1).
  • The web wallet ran on that build with concurrency 8 (sequentia-web-wallet fix/faster-sync) against the testnet indexer:
    • a wallet holding GOLD and USDX did a full sync in 4 s, against 16 s on the current build;
    • it found the same balances (10 GOLD, 500,000 USDX) and both history entries;
    • the browser showed address requests overlapping, against strictly one at a time before.

Not verified

  • cargo test was not run. No suite covers this path against a live esplora, and the native build was not exercised here. The esplora client tests (cargo test -p lwk_wollet --features esplora, needs the test environment) would.
  • Ambra uses lwk_wollet as a path dependency. If it builds an async esplora client with concurrency above 1, its scans speed up the same way; with 1, nothing changes.

get_scripts_history_esplora walked each batch one address at a time, so
the concurrency the caller sets reached only transactions and headers. A
wallet's scan is mostly address histories: every used address plus the
20-address gap on each chain. For a fresh testnet web wallet that was 44
requests in strict sequence, about 7 s behind a 120 ms round trip, with
concurrency set to 8 or to 1 alike.

The batch now goes through the same stream as get_transactions, up to
`concurrency` requests in flight. `buffered` keeps the results in address
order, which get_history needs to find the last used index. With the
default concurrency of 1 nothing changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant