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

feat: enhanced eth_getLogs with timestamp range validation and new error handling #3431

Merged
Prev Previous commit
Next Next commit
chore: explained the logic behind MISSING_FROM_BLOCK_PARAM error
Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
  • Loading branch information
quiet-node committed Jan 28, 2025
commit f28342f046e3a18c08a3a31b94f15de57894df1d
Original file line number Diff line number Diff line change
@@ -114,13 +114,16 @@ export class CommonService implements ICommonService {
) {
if (this.blockTagIsLatestOrPending(toBlock)) {
toBlock = CommonService.blockLatest;
}

const latestBlockNumber: string = await this.getLatestBlockNumber(requestDetails);

// toBlock is a number and is less than the current block number and fromBlock is not defined
if (Number(toBlock) < Number(latestBlockNumber) && !fromBlock) {
throw predefined.MISSING_FROM_BLOCK_PARAM;
} else {
const latestBlockNumber: string = await this.getLatestBlockNumber(requestDetails);

// - When `fromBlock` is not explicitly provided, it defaults to `latest`.
// - Then if `toBlock` equals `latestBlockNumber`, it means both `toBlock` and `fromBlock` essentially refer to the latest block, so the `MISSING_FROM_BLOCK_PARAM` error is not necessary.
// - If `toBlock` is explicitly provided and does not equals to `latestBlockNumber`, it establishes a solid upper bound.
// - If `fromBlock` is missing, indicating the absence of a lower bound, throw the `MISSING_FROM_BLOCK_PARAM` error.
if (Number(toBlock) !== Number(latestBlockNumber) && !fromBlock) {
throw predefined.MISSING_FROM_BLOCK_PARAM;
}
}

if (this.blockTagIsLatestOrPending(fromBlock)) {