-
Notifications
You must be signed in to change notification settings - Fork 91
fix: Use latest eth_getLogs block as toBlock #512
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
Conversation
We're building your pull request over on Zeet. |
@@ -168,7 +165,9 @@ export const getSubscribedContractsLogs = async ( | |||
} | |||
} | |||
|
|||
const block = blockCache[log.blockNumber]; | |||
// Block may be null if the RPC does not yet have block details. Fall back to current time. | |||
const block = blockCache[log.blockNumber] as ethers.providers.Block | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential fix 1: Handle if block is not found by falling back on timestamp.
// Get latest block with logs. This should be the maxBlock to query up to. | ||
const logs = await provider.getLogs({ fromBlock: "latest" }); | ||
if (logs.length === 0) { | ||
return; | ||
} | ||
const currentBlockNumber = logs[0].blockNumber; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential fix 2: Use latest log block instead of RPC's block height
indexContractEvents({ | ||
pgtx, | ||
chainId, | ||
fromBlockNumber: lastIndexedBlock + 1, | ||
fromBlockNumber: lastIndexedBlock, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential fix 3: Overlap the "boundary" blocks just in case there's incomplete data from RPC
if (lastIndexedBlock > 0) { | ||
lastIndexedBlock -= NUM_BLOCKS_TO_RECHECK; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential fix 4: Recheck the last 2 blocks to capture incomplete data from the last check.
This PR is stale because it has been open for 7 days with no activity. Remove stale label or comment or this PR will be closed in 3 days. |
PR-Codex overview
This PR introduces a
dedupeArray
utility function to remove duplicates in arrays across multiple files for improved code readability and maintenance.Detailed summary
dedupeArray
utility function to remove duplicates in arrays for cleaner code.dedupeArray
function inremoveUrlToCorsConfiguration
,addUrlToCorsConfiguration
,setUrlsToCorsConfiguration
, andchainIndexer.ts
files.