Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

arcoraven
Copy link
Contributor

@arcoraven arcoraven commented May 1, 2024

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

  • Added dedupeArray utility function to remove duplicates in arrays for cleaner code.
  • Replaced array deduplication logic with dedupeArray function in removeUrlToCorsConfiguration, addUrlToCorsConfiguration, setUrlsToCorsConfiguration, and chainIndexer.ts files.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

zeet-co bot commented May 1, 2024

We're building your pull request over on Zeet.
Click me for more info about your build and deployment.
Once built, this branch can be tested at: https://web3-api-akbv-ph-fixlatestblocksu-a7fff2.chainsaw-dev.zeet.app before merging 😉

@@ -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;
Copy link
Contributor Author

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.

Comment on lines +289 to +294
// 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;
Copy link
Contributor Author

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,
Copy link
Contributor Author

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

Comment on lines +286 to +288
if (lastIndexedBlock > 0) {
lastIndexedBlock -= NUM_BLOCKS_TO_RECHECK;
}
Copy link
Contributor Author

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.

Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants