This repository was archived by the owner on Nov 11, 2026. It is now read-only.
Repository navigation
Conversation
…le scan four copies of the same query aggregate every row of bridges.transactions to find where each adapter should resume. the cron job runs one of them every cycle, and /lastblocks serves another. MIN(tx_block) is in all four and nothing reads it: getBlocksForRunningAdapter only looks at endBlock. on a 10m row copy of the schema the query is a parallel seq scan, 285,715 buffers and 609ms, and it grows with the table. the same values come back from two ORDER BY ... LIMIT 1 lookups per config row against (bridge_id, tx_block) WHERE origin_chain IS NULL AND tx_block IS NOT NULL, as an index only scan with no heap fetches: 12,858 buffers and 23ms, 0 of 1607 bridge ids disagreeing. two of the four copies were also missing the origin_chain filter, so they could report portal's solana slots as an evm chain's last block. they now share one query, which takes an optional bridge name so running a single adapter no longer loads every bridge's progress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #539
One
getLastRecordedBlocks(bridgeName?)inquery.tsreplaces the four copies of the full table aggregate. It reads the first and lasttx_blockper config row with twoORDER BY tx_block LIMIT 1lookups instead ofMIN/MAXover every row, and takes an optional bridge name sorunAdapterByNamestops loading every bridge's progress to run one.The index it needs is declared in
sql/data.sql:This has to exist before the code ships. Without it the lookups fall back to a bitmap heap scan per bridge, which is slower than what they replace. In production that means
CREATE INDEX CONCURRENTLYfirst, then deploy.Measured on postgres 16 with this schema, 1,607 config rows and 10m transactions:
Driven through the function itself against that database rather than just as SQL: 28 ms against 502 ms, 1,607 keys both ways, 0 entries differing in either
startBlockorendBlock.Two behaviour changes, both deliberate:
getLastBlocksandrunAdapterByNamenow applyWHERE origin_chain IS NULLlike the other two call sites, so portal's solana slots stop being reported as an EVM chain's last recorded block.querySql, which is where the rest of the reads live.startBlockis kept in the result even thoughgetBlocksForRunningAdapterignores it, becauseGET /lastblocksputs it in the response and the index serves both ends anyway.npm run test:serverpasses (170 tests) andtsc --noEmitreports the same 11 pre-existing errors as master, no more.