-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
🐛 Fix: getFilterLog issue #1337
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
|
WalkthroughThis update introduces significant enhancements to the Ethereum log filtering mechanism. A new Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FilterHandler
participant LogManager
participant BlockManager
Client->>FilterHandler: createFilter(topics, address, fromBlock, toBlock)
FilterHandler->>BlockManager: resolveBlocks(fromBlock, toBlock)
BlockManager-->>FilterHandler: return resolved blocks
FilterHandler->>LogManager: setupListener()
LogManager-->>FilterHandler: return filter ID
FilterHandler-->>Client: return filter ID
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @roninjin10 and the rest of your teammates on Graphite |
2a17445
to
af8205a
Compare
af8205a
to
d140058
Compare
d140058
to
0b15e07
Compare
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.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- packages/actions/src/eth/ethNewFilterHandler.js (1 hunks)
- packages/actions/src/eth/index.ts (1 hunks)
- packages/actions/src/eth/utils/generateRandomId.js (1 hunks)
- packages/actions/src/eth/utils/generateRandomId.spec.ts (1 hunks)
- packages/actions/src/eth/utils/parseBlockTag.js (1 hunks)
- packages/actions/src/eth/utils/parseBlockTag.spec.ts (1 hunks)
- packages/procedures/src/eth/ethGetFilterLogsProcedure.js (1 hunks)
- packages/procedures/src/eth/ethGetFilterLogsProcedure.spec.ts (1 hunks)
- packages/procedures/src/eth/ethNewFilterProcedure.js (2 hunks)
Additional comments not posted (22)
packages/actions/src/eth/utils/generateRandomId.js (1)
1-8
: LGTM! But verify the usage ofcrypto.getRandomValues
.The code changes are approved.
However, ensure that
crypto.getRandomValues
is supported in all target environments.packages/actions/src/eth/utils/generateRandomId.spec.ts (1)
1-15
: LGTM! But verify the test coverage.The code changes are approved.
However, ensure that the tests cover all edge cases and potential issues.
packages/actions/src/eth/utils/parseBlockTag.js (1)
1-14
: LGTM! But verify the usage ofhexToBigInt
.The code changes are approved.
However, ensure that
hexToBigInt
is correctly used and tested.Verification successful
The usage of
hexToBigInt
is correct and well-tested.
- The function
hexToBigInt
is correctly defined and exported in@tevm/utils
.- It is used consistently across various files in the codebase.
- There are sufficient test cases covering its functionality.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `hexToBigInt` in the codebase. # Test: Search for the usage of `hexToBigInt`. Expect: Only valid usages. rg --type js --type ts $'hexToBigInt'Length of output: 34564
Script:
#!/bin/bash # 1. Verify the definition and export of `hexToBigInt` in `@tevm/utils`. ast-grep --lang javascript --pattern 'export function hexToBigInt($_) { $$$ }' # 2. Check the usage of `hexToBigInt` in various files to ensure it is used correctly. # We will search for the function calls to `hexToBigInt` across the codebase. rg --type js --type ts 'hexToBigInt(' -A 3 # 3. Verify that there are sufficient test cases for `hexToBigInt`. # We will look for test cases that involve `hexToBigInt`. rg --type js --type ts 'hexToBigInt' | grep -i 'test'Length of output: 5799
packages/actions/src/eth/index.ts (1)
4-4
: LGTM!The new export statement for
ethNewFilterHandler.js
is correctly added and enhances the module's functionality.packages/procedures/src/eth/ethNewFilterProcedure.js (3)
1-1
: Import statement is correct.The import statement correctly brings in
ethNewFilterHandler
from@tevm/actions
.
11-16
: Function implementation is streamlined and efficient.The function implementation is streamlined, utilizing
ethNewFilterHandler
to handle the request. This improves readability and maintainability.
18-28
: Error handling is robust.The error handling is robust, logging the error and returning a structured error response in JSON-RPC format.
packages/actions/src/eth/utils/parseBlockTag.spec.ts (7)
1-3
: Import statements are correct.The import statements correctly bring in required modules and functions.
5-10
: Test case for parsing hex block numbers to bigint is correct.The test case correctly verifies that hex block numbers are parsed to bigint.
12-16
: Test case for returning block hash as is correct.The test case correctly verifies that block hashes are returned as is.
18-24
: Test case for returning special block tags as is correct.The test case correctly verifies that special block tags are returned as is.
26-30
: Test case for returning block number as bigint for valid hex strings is correct.The test case correctly verifies that valid hex strings are parsed to bigint.
32-36
: Test case for handling block tag as a number string correctly is correct.The test case correctly verifies that block tags as number strings are parsed correctly.
38-42
: Test case for returning blockTag unchanged if it is a non-hex string is correct.The test case correctly verifies that non-hex strings are returned unchanged.
packages/procedures/src/eth/ethGetFilterLogsProcedure.spec.ts (3)
1-9
: Good use of imports and setup.The imports cover necessary utilities and components for the test. The setup is clear and prepares the environment for testing.
11-46
: Well-structured test setup.The
beforeEach
block ensures that the client is created and the initial conditions are set up before each test. This promotes test isolation and reliability.
48-83
: Comprehensive test case for log retrieval.The test case verifies the creation of a filter, execution of a transaction, mining of a block, and retrieval of logs. The use of inline snapshots for result verification is a good practice.
packages/actions/src/eth/ethNewFilterHandler.js (5)
1-5
: Good use of imports and utility functions.The imports cover necessary utilities and error classes. The use of utility functions like
generateRandomId
andparseBlockTag
promotes code reuse and readability.
7-9
: Clear type definition for errors.The type definition for
EthNewFilterError
is clear and helps in understanding the possible errors that can be thrown by the handler.
11-15
: Well-defined handler function signature.The handler function signature is clear and includes the necessary type annotations, which improve code readability and maintainability.
17-49
: Robust block retrieval logic.The logic for retrieving blocks based on the tag is robust and handles various block tags, including special tags like 'latest' and 'earliest'. The error handling for invalid and unknown block tags is appropriate.
51-104
: Comprehensive filter creation and log handling.The handler creates a filter, registers a listener for new logs, and populates the filter with past logs. This comprehensive approach ensures that the filter is correctly set up and ready to use.
@@ -50,6 +50,7 @@ export const ethGetFilterLogsProcedure = (client) => { | |||
result: jsonRpcResult, | |||
} | |||
} catch (e) { | |||
console.log(e) |
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.
Avoid using console.log
for error logging in production code.
Using console.log
for error logging is not recommended in production environments as it can expose sensitive information and is not a robust logging solution. Consider using a proper logging library that supports different log levels and better error tracking.
- console.log(e)
+ // Consider using a proper logging library, e.g., winston or pino.
+ logger.error(e)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
console.log(e) | |
// Consider using a proper logging library, e.g., winston or pino. | |
logger.error(e) |
0b15e07
to
31ece76
Compare
3205da2
to
044e7a1
Compare
Description
Concise description of proposed changes
Testing
Explain the quality checks that have been done on the code changes
Additional Information
Your ENS/address:
Summary by CodeRabbit
New Features
Bug Fixes
Tests