Skip to content
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

refactor: Remove SpokePoolClient dependency from depositId search #476

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pxrl
Copy link
Contributor

@pxrl pxrl commented Dec 17, 2023

The core binary search logic doesn't depend on the SpokePoolClient, so make a clean break.

The core binary search logic doesn't depend on the SpokePoolClient, so
make a clean break.
Copy link
Contributor Author

@pxrl pxrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few explanatory comments.

Comment on lines -40 to -52
// Sanity check to ensure that the spoke pool client is updated
[spokePool.isUpdated, "Spoke pool client is not updated"],
// Sanity check to ensure that initHigh is greater than or equal to initLow.
[initLow <= initHigh, "Binary search failed because low > high"],
// Sanity check to ensure that init Low is greater than or equal to zero.
[initLow >= deploymentBlock, "Binary search failed because low must be >= deploymentBlock"],
// Sanity check to ensure that maxSearches is greater than zero.
[maxSearches > 0, "maxSearches must be > 0"],
// Sanity check to ensure that deploymentBlock is greater than or equal to zero.
[deploymentBlock >= 0, "deploymentBlock must be >= 0"],
] as [boolean, string][]
).forEach(([condition, errorMessage]) => {
// If the condition is false, then we will throw an error.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments were just 100% mirroring what the code does (and what the error messages said the code was doing), so I opportunistically deleted them but wanted to flag it just in case.

queriedIds[blockNumber] ??= await spokePool._getDepositIdAtBlock(blockNumber);
return queriedIds[blockNumber];
const getDepositIdAtBlock = async (blockTag: number): Promise<number> => {
return queriedIds[blockTag] ??= await spokePool.numberOfDeposits({ blockTag });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intuitively this implementation is wrong to me, since numberOfDeposits != "highest depositId". I'd expect that we should be doing something like:

const nDeposits = await spokePoolClient.numberOfDeposits({ blockTag });
return Math.max(nDeposits - 1, 0);

nb. the above ignores the in-memory cache, but it's implied that that is used.

Copy link
Contributor

@james-a-morris james-a-morris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - +1

initLow: number,
initHigh: number,
maxSearches: number
): Promise<{
low: number;
high: number;
}> {
return getBlockRangeForDepositId(targetDepositId, initLow, initHigh, maxSearches, this);
return getBlockRangeForDepositId(depositId, initLow, initHigh, maxSearches, this.spokePool, this.deploymentBlock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good call - I thought we did this previously. +1

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.

2 participants