-
-
Notifications
You must be signed in to change notification settings - Fork 26
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: Add getBlockByTag to Chain package #1315
✨ Feat: Add getBlockByTag to Chain package #1315
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: 68082c3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Warning Rate limit exceeded@roninjin10 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 11 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe recent changes introduce new dependencies to the blockchain package, enhance block retrieval functionality, and add error handling. The key addition is the Changes
Possibly related issues
Poem
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 Configration File (
|
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @roninjin10 and the rest of your teammates on Graphite |
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 ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
Files selected for processing (4)
- packages/blockchain/package.json (1 hunks)
- packages/blockchain/src/Chain.ts (2 hunks)
- packages/blockchain/src/actions/getBlockByTag.js (1 hunks)
- packages/blockchain/src/createChain.js (2 hunks)
Additional comments not posted (7)
packages/blockchain/src/actions/getBlockByTag.js (2)
1-5
: LGTM! Import statements are appropriate.The imported utilities and dependencies are necessary for the function's operations.
7-10
: LGTM! JSDoc comment block is well-written.The type annotations and descriptions are clear and helpful.
packages/blockchain/src/createChain.js (2)
Line range hint
1-11
:
LGTM! Import statements are appropriate.The imported actions and utilities are necessary for the chain creation and decoration.
21-22
: LGTM!decorate
function integratesgetBlockByTag
correctly.The function properly integrates the
getBlockByTag
function into the chain object.packages/blockchain/package.json (1)
68-68
: LGTM! Addition of@tevm/errors
dependency is appropriate.The new dependency is necessary for handling block-related errors.
packages/blockchain/src/Chain.ts (2)
3-3
: LGTM! Expanded import statement is appropriate.The additional imports are necessary for the
getBlockByTag
method.
44-56
: LGTM!getBlockByTag
method addition is well-written.The method and the JSDoc comment provide clear and necessary information.
export const getBlockByTag = (baseChain) => async (blockId) => { | ||
const _getBlock = getBlock(baseChain) | ||
if (isHex(blockId)) { | ||
return blockId.length === 66 ? _getBlock(hexToBytes(blockId)) : _getBlock(hexToNumber(blockId)) | ||
} | ||
if (typeof blockId === 'number' || typeof blockId === 'bigint' || blockId instanceof Uint8Array) { | ||
return _getBlock(blockId) | ||
} | ||
const block = baseChain.blocksByTag.get(blockId) | ||
if (!block && baseChain.options.fork?.transport) { | ||
const block = await getBlockFromRpc( | ||
{ | ||
transport: baseChain.options.fork.transport, | ||
blockTag: blockId, | ||
}, | ||
baseChain.common, | ||
) | ||
await putBlock(baseChain)(block) | ||
return block | ||
} | ||
if (!block) { | ||
throw new UnknownBlockError(blockId) | ||
} | ||
return block |
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.
Potential issue with re-declared variable block
.
The block
variable is re-declared within the if
block starting at line 20. This can cause confusion and potential issues.
- const block = await getBlockFromRpc(
+ const fetchedBlock = await getBlockFromRpc(
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.
export const getBlockByTag = (baseChain) => async (blockId) => { | |
const _getBlock = getBlock(baseChain) | |
if (isHex(blockId)) { | |
return blockId.length === 66 ? _getBlock(hexToBytes(blockId)) : _getBlock(hexToNumber(blockId)) | |
} | |
if (typeof blockId === 'number' || typeof blockId === 'bigint' || blockId instanceof Uint8Array) { | |
return _getBlock(blockId) | |
} | |
const block = baseChain.blocksByTag.get(blockId) | |
if (!block && baseChain.options.fork?.transport) { | |
const block = await getBlockFromRpc( | |
{ | |
transport: baseChain.options.fork.transport, | |
blockTag: blockId, | |
}, | |
baseChain.common, | |
) | |
await putBlock(baseChain)(block) | |
return block | |
} | |
if (!block) { | |
throw new UnknownBlockError(blockId) | |
} | |
return block | |
export const getBlockByTag = (baseChain) => async (blockId) => { | |
const _getBlock = getBlock(baseChain) | |
if (isHex(blockId)) { | |
return blockId.length === 66 ? _getBlock(hexToBytes(blockId)) : _getBlock(hexToNumber(blockId)) | |
} | |
if (typeof blockId === 'number' || typeof blockId === 'bigint' || blockId instanceof Uint8Array) { | |
return _getBlock(blockId) | |
} | |
const block = baseChain.blocksByTag.get(blockId) | |
if (!block && baseChain.options.fork?.transport) { | |
const fetchedBlock = await getBlockFromRpc( | |
{ | |
transport: baseChain.options.fork.transport, | |
blockTag: blockId, | |
}, | |
baseChain.common, | |
) | |
await putBlock(baseChain)(fetchedBlock) | |
return fetchedBlock | |
} | |
if (!block) { | |
throw new UnknownBlockError(blockId) | |
} | |
return block |
2ebeb69
to
0759704
Compare
9c67b80
to
58c5717
Compare
58c5717
to
08c2b43
Compare
97fabad
to
bfc4df2
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: 0
Outside diff range, codebase verification and nitpick comments (1)
packages/blockchain/src/utils/getBlockFromRpc.js (1)
68-68
: Add more context to the error message.The error message "No block found" could be more descriptive to aid debugging.
- throw new UnknownBlockError('No block found') + throw new UnknownBlockError(`No block found for blockTag ${blockTag}`)
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
packages/blockchain/src/utils/__snapshots__/getBlockFromRpc.spec.ts.snap
is excluded by!**/*.snap
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
Files selected for processing (20)
- .changeset/tall-phones-appear.md (1 hunks)
- docs/src/content/docs/reference/@tevm/blockchain/functions/createChain.md (1 hunks)
- docs/src/content/docs/reference/@tevm/blockchain/functions/getBlockFromRpc.md (2 hunks)
- docs/src/content/docs/reference/@tevm/blockchain/type-aliases/Chain.md (1 hunks)
- packages/blockchain/docs/functions/createChain.md (1 hunks)
- packages/blockchain/docs/functions/getBlockFromRpc.md (2 hunks)
- packages/blockchain/docs/type-aliases/Chain.md (1 hunks)
- packages/blockchain/package.json (1 hunks)
- packages/blockchain/src/Chain.ts (2 hunks)
- packages/blockchain/src/actions/getBlock.js (1 hunks)
- packages/blockchain/src/actions/getBlockByTag.js (1 hunks)
- packages/blockchain/src/createBaseChain.js (1 hunks)
- packages/blockchain/src/createChain.js (2 hunks)
- packages/blockchain/src/utils/getBlockFromRpc.js (6 hunks)
- packages/blockchain/src/utils/getBlockFromRpc.spec.ts (1 hunks)
- packages/blockchain/src/utils/warnOnce.js (1 hunks)
- packages/procedures/src/utils/blockToJsonRpcBlock.spec.ts (1 hunks)
- packages/procedures/src/utils/txToJsonRpcTx.spec.ts (1 hunks)
- tevm/docs/blockchain/functions/getBlockFromRpc.md (1 hunks)
- tevm/docs/blockchain/type-aliases/Chain.md (1 hunks)
Files skipped from review due to trivial changes (2)
- docs/src/content/docs/reference/@tevm/blockchain/functions/createChain.md
- packages/blockchain/docs/functions/createChain.md
Files skipped from review as they are similar to previous changes (3)
- packages/blockchain/src/Chain.ts
- packages/blockchain/src/actions/getBlockByTag.js
- packages/blockchain/src/createChain.js
Additional comments not posted (21)
.changeset/tall-phones-appear.md (1)
1-5
: Changeset description looks good.The changeset description clearly explains the addition of the
getBlockByTag
method and its functionality.packages/blockchain/docs/functions/getBlockFromRpc.md (1)
9-14
: Documentation update forgetBlockFromRpc
looks good.The documentation accurately reflects the addition of the
baseChain
parameter and provides clear descriptions of the parameters and return type.Also applies to: 31-31
packages/blockchain/src/utils/warnOnce.js (1)
1-22
: NewwarnOnce
function looks good.The
warnOnce
function is well-documented and ensures that the warning is logged only once.tevm/docs/blockchain/functions/getBlockFromRpc.md (1)
9-14
: Documentation update forgetBlockFromRpc
looks good.The documentation accurately reflects the addition of the
baseChain
parameter and provides clear descriptions of the parameters and return type.docs/src/content/docs/reference/@tevm/blockchain/functions/getBlockFromRpc.md (2)
8-8
: Documentation update for function signature looks good.The function signature now correctly includes the
baseChain
parameter.
12-12
: Documentation forbaseChain
parameter looks good.The new parameter
baseChain
is clearly described.packages/procedures/src/utils/blockToJsonRpcBlock.spec.ts (1)
11-15
: Update togetBlockFromRpc
function call looks good.The function call now correctly includes the
baseChain
parameter, ensuring the test remains valid.packages/procedures/src/utils/txToJsonRpcTx.spec.ts (1)
29-33
: Update togetBlockFromRpc
function call looks good.The function call now correctly includes the
baseChain
parameter, ensuring the test remains valid.packages/blockchain/src/createBaseChain.js (1)
71-71
: Update togetBlockFromRpc
function call looks good.The function call now correctly includes the
baseChain
parameter, ensuring the function remains valid.packages/blockchain/src/actions/getBlock.js (1)
41-43
: LGTM! But verify the function usage in the codebase.The code changes are approved.
However, ensure that all function calls to
getBlock
correctly pass thebaseChain
parameter.packages/blockchain/package.json (1)
68-75
: LGTM! But verify the dependency usage in the codebase.The addition of new dependencies
@tevm/errors
and@tevm/test-utils
is approved.However, ensure that these dependencies are correctly used in the codebase.
packages/blockchain/src/utils/getBlockFromRpc.js (1)
2-2
: LGTM! But verify the error handling and warning function usage.The code changes are approved.
However, ensure that the new error handling and warning function are correctly implemented and used.
Verification successful
The error handling and warning function are correctly implemented and used.
The
UnknownBlockError
,InvalidBlockError
, andwarnOnce
functions are used appropriately within the codebase.
UnknownBlockError
andInvalidBlockError
are thrown in various places to handle specific error conditions.warnOnce
is used to log warnings once for specific conditions.The implementation aligns with the intended error handling and warning mechanisms.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of new error handling and warning function. # Test: Search for the usage of the new error handling and warning function. Expect: Occurances of the new error handling and warning function. rg --type javascript -A 5 $'UnknownBlockError' rg --type javascript -A 5 $'InvalidBlockError' rg --type javascript -A 5 $'warnOnce'Length of output: 233
Script:
#!/bin/bash # Description: Verify the usage of new error handling and warning function. # Test: Search for the usage of the new error handling and warning function. Expect: Occurrences of the new error handling and warning function. rg -A 5 'UnknownBlockError' rg -A 5 'InvalidBlockError' rg -A 5 'warnOnce'Length of output: 91988
packages/blockchain/docs/type-aliases/Chain.md (1)
70-95
: LGTM! But verify the documentation accuracy.The documentation for the
getBlockByTag
method is clear and accurate.However, ensure that the method description and parameters are correctly documented.
Verification successful
Let's re-run the search for the
getBlockByTag
method by specifying common JavaScript file extensions directly.
The
rg
command successfully found multiple occurrences of thegetBlockByTag
method, including its implementation inpackages/blockchain/src/actions/getBlockByTag.js
. Let's verify that the parameters and description in the documentation match the implementation.
The documentation for the
getBlockByTag
method is accurate.The implementation handles the specified parameter types and throws errors as documented.
packages/blockchain/docs/type-aliases/Chain.md
(lines 70-95)packages/blockchain/src/actions/getBlockByTag.js
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the accuracy of the documentation for the `getBlockByTag` method. # Test: Search for the usage of the `getBlockByTag` method. Expect: Occurances of the method usage. rg --type javascript -A 5 $'getBlockByTag'Length of output: 76
Script:
#!/bin/bash # Description: Verify the accuracy of the documentation for the `getBlockByTag` method. # Test: Search for the usage of the `getBlockByTag` method in JavaScript files. rg --type-add 'js:*.{js,jsx,ts,tsx}' -A 5 'getBlockByTag'Length of output: 3883
Script:
#!/bin/bash # Description: Verify the implementation of the `getBlockByTag` method to ensure the documentation is accurate. # Extract the implementation of the `getBlockByTag` method. rg --type-add 'js:*.{js,jsx,ts,tsx}' -A 10 'export const getBlockByTag' packages/blockchain/src/actions/getBlockByTag.jsLength of output: 622
tevm/docs/blockchain/type-aliases/Chain.md (1)
70-95
: Documentation forgetBlockByTag
looks good.The method description, parameters, return type, and exceptions are clearly documented.
docs/src/content/docs/reference/@tevm/blockchain/type-aliases/Chain.md (1)
69-94
: Documentation forgetBlockByTag
looks good.The method description, parameters, return type, and exceptions are clearly documented.
packages/blockchain/src/utils/getBlockFromRpc.spec.ts (6)
12-19
: Test case for fetching the latest block looks good.The test case checks if the latest block is fetched correctly and validates the expected behavior.
26-36
: Test case for fetching a block by number looks good.The test case checks if a block is fetched correctly by its number and validates the expected behavior.
38-48
: Test case for fetching a block by hash looks good.The test case checks if a block is fetched correctly by its hash and validates the expected behavior.
50-60
: Test case for handling invalid block tag looks good.The test case checks if an invalid block tag is handled correctly and validates the expected behavior.
62-73
: Test case for handling non-existing block number looks good.The test case checks if a non-existing block number is handled correctly and validates the expected behavior.
75-83
: Test case for handling non-existing block hash looks good.The test case checks if a non-existing block hash is handled correctly and validates the expected behavior.
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ `main` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `main`.⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ # Releases ## @tevm/[email protected] ### Minor Changes - [#1311](#1311) [`de2a2ab`](de2a2ab) Thanks [@roninjin10](https://github.com/roninjin10)! - Added support for all blocktags to eth_getCode actions and json-rpc - [#1311](#1311) [`de2a2ab`](de2a2ab) Thanks [@roninjin10](https://github.com/roninjin10)! - Added blockTag to `tevmGetAccount` action ### Patch Changes - Updated dependencies \[[`a8c810b`](a8c810b), [`c71445a`](c71445a)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Minor Changes - [#1312](#1312) [`a8c810b`](a8c810b) Thanks [@roninjin10](https://github.com/roninjin10)! - Add deepCopy method to BaseClient ReceiptManager and TxPool ### Patch Changes - Updated dependencies \[[`a8c810b`](a8c810b), [`c71445a`](c71445a)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Minor Changes - [#1315](#1315) [`c71445a`](c71445a) Thanks [@roninjin10](https://github.com/roninjin10)! - Added new getBlockByTag method to Chain. It gets blocks by hash or number just like getBlock but also accepts a named tag such as 'latest', 'pending', or 'forked' ## @tevm/[email protected] ### Minor Changes - [#1311](#1311) [`de2a2ab`](de2a2ab) Thanks [@roninjin10](https://github.com/roninjin10)! - Added support for all blocktags to eth_getCode actions and json-rpc ### Patch Changes - Updated dependencies \[[`de2a2ab`](de2a2ab), [`a8c810b`](a8c810b), [`c71445a`](c71445a), [`de2a2ab`](de2a2ab)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Minor Changes - [#1312](#1312) [`a8c810b`](a8c810b) Thanks [@roninjin10](https://github.com/roninjin10)! - Add deepCopy method to BaseClient ReceiptManager and TxPool ### Patch Changes - Updated dependencies \[[`c71445a`](c71445a)]: - @tevm/[email protected] ## @tevm/[email protected] ### Minor Changes - [#1312](#1312) [`a8c810b`](a8c810b) Thanks [@roninjin10](https://github.com/roninjin10)! - Add deepCopy method to BaseClient ReceiptManager and TxPool ### Patch Changes - Updated dependencies \[[`c71445a`](c71445a)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[[`de2a2ab`](de2a2ab), [`a8c810b`](a8c810b)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[[`a8c810b`](a8c810b)]: - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[[`de2a2ab`](de2a2ab), [`a8c810b`](a8c810b), [`de2a2ab`](de2a2ab)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[[`c71445a`](c71445a)]: - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[]: - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[[`de2a2ab`](de2a2ab), [`a8c810b`](a8c810b), [`de2a2ab`](de2a2ab)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[]: - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[]: - @tevm/[email protected] - @tevm/[email protected] ## @tevm/[email protected] ### Patch Changes - Updated dependencies \[[`c71445a`](c71445a)]: - @tevm/[email protected] - @tevm/[email protected] ## [email protected] ### Patch Changes - Updated dependencies \[[`de2a2ab`](de2a2ab), [`a8c810b`](a8c810b), [`c71445a`](c71445a), [`de2a2ab`](de2a2ab)]: - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] - @tevm/[email protected] Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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
getBlockByTag
functionality to retrieve blocks using block hash, block number, or block tag.Bug Fixes
UnknownBlockError
,InvalidBlockError
).Documentation
Tests
getBlockFromRpc
to cover various scenarios and improve reliability.