-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: master
Are you sure you want to change the base?
Conversation
The core binary search logic doesn't depend on the SpokePoolClient, so make a clean break.
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.
A few explanatory comments.
// 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. |
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.
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 }); |
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.
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.
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.
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); |
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.
This is a good call - I thought we did this previously. +1
The core binary search logic doesn't depend on the SpokePoolClient, so make a clean break.