Skip to content

Parallel block ingest with connection-pooled RPC client - #565

Open
emersonian wants to merge 1 commit into
zcash:masterfrom
zecrocks:be/sync-speed
Open

Parallel block ingest with connection-pooled RPC client#565
emersonian wants to merge 1 commit into
zcash:masterfrom
zecrocks:be/sync-speed

Conversation

@emersonian

Copy link
Copy Markdown
Contributor

Speeds up initial sync by fetching blocks concurrently instead of one at a time.

This fix allowed us to scale out lightwalletd quickly to new nodes during the 5.0.0 upgrade last week to meet unprecedented demand without slow initial sync times, it is running in production now.

ValarDragon added a commit to valargroup/lightwalletd that referenced this pull request Jun 12, 2026
…ingest

Backport upstream zcash#565: Parallel block ingest with connection-pooled RPC client
BlockIngestor fetched one block at a time and issued a getbestblockhash
before each one, so initial sync was bounded by round-trip latency rather
than by the backend's throughput.

Fetch a window of blocks concurrently (LWD_INGEST_WORKERS, default 8;
LWD_INGEST_WINDOW, default 64) and commit them to the cache in strict
height order, so cache and reorg semantics are unchanged. Refresh the tip
only once we reach the last known tip instead of polling per block. Any
error, missing block, or chain mismatch stops the batch and the outer loop
re-evaluates from the (possibly rewound) next block, matching the serial
path's recovery behaviour. Unit tests (rep != 0) and darkside keep the
serial path.

Concurrency alone was not enough: NewContextRawRequest set
httpReq.Close = true, mirroring btcd's rpcclient, and configured no
connection pool, so every request paid for a fresh TCP (and, with TLS, a
full handshake) connection and the fetch workers serialized on connection
setup rather than on the backend's actual work. Size the transport's
idle/total connection pool from the ingest worker count, with headroom for
frontend gRPC traffic (LWD_RPC_POOL overrides), and stop closing the
connection after each request. Response bodies were already drained before
Close, so connections were already eligible for reuse.
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