Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes introduce support for querying events across both the forked origin chain and the local devnet in the Assessment against linked issues
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (10)
crates/starknet-devnet-core/src/starknet/events.rs(1 hunks)crates/starknet-devnet-core/src/starknet/mod.rs(1 hunks)crates/starknet-devnet-server/Cargo.toml(1 hunks)crates/starknet-devnet-server/src/api/json_rpc/endpoints.rs(3 hunks)crates/starknet-devnet-server/src/api/json_rpc/error.rs(1 hunks)crates/starknet-devnet-server/src/api/json_rpc/mod.rs(1 hunks)crates/starknet-devnet-server/src/api/json_rpc/origin_forwarder.rs(4 hunks)crates/starknet-devnet-types/src/rpc/emitted_event.rs(1 hunks)crates/starknet-devnet-types/src/rpc/transactions.rs(3 hunks)tests/integration/test_get_events.rs(2 hunks)
🔇 Additional comments (26)
crates/starknet-devnet-server/src/api/json_rpc/mod.rs (1)
234-234: Code improvement: Direct URL object usageThe change from converting the URL to a string to directly using the URL object is a good improvement. This avoids unnecessary string conversion and aligns with the updated
OriginForwarder::newconstructor which now accepts aurl::Urltype instead of aString.crates/starknet-devnet-server/src/api/json_rpc/error.rs (1)
252-259: Enhanced error forwarding for pagination supportMoving the
InvalidContinuationTokenerror variant to the forwardable errors list properly supports the enhanced event querying across both the forked origin chain and local devnet. This is crucial for pagination with continuation tokens to work correctly when querying events from dual sources.crates/starknet-devnet-core/src/starknet/events.rs (1)
27-28: Type consistency improvement: usize to u64Changing the parameter types from
usizetou64provides better type consistency across the codebase. This change:
- Ensures consistent behavior across different platforms and architectures
- Aligns with the refactored event querying that spans origin and local chains
- Provides fixed-width integer guarantees for pagination parameters
The change is appropriate and follows good API design practices.
crates/starknet-devnet-server/Cargo.toml (1)
38-42: Added required dependencies for forking functionalityThe dependencies have been properly organized with the addition of essential crates for the forking functionality:
starknet-rs-providers: Provides the JSON-RPC client for interacting with the origin chainurl: Supports proper URL handling in the refactoredOriginForwarderThese additions directly support the enhanced event querying feature that retrieves events from both forked origin and local chains.
crates/starknet-devnet-types/src/rpc/emitted_event.rs (1)
21-34: Implementation looks good.Clean implementation of the
Fromtrait to convert fromstarknet_rs_core::types::EmittedEventto the localEmittedEventstruct. The use ofexpectfor the address conversion is appropriate since this operation should never fail if both types are properly designed.crates/starknet-devnet-types/src/rpc/transactions.rs (2)
261-261: Type update fromusizetou64for better cross-platform consistency.This change ensures a fixed-width integer type is used for pagination, which is preferable to the platform-dependent
usizetype. This aligns with the changes in other parts of the codebase.
272-279: Clean implementation of the conversion between event pagination types.Good implementation of the
Fromtrait to convertEventsPagetoEventsChunk, which will help with integrating events from both local and forked sources.crates/starknet-devnet-core/src/starknet/mod.rs (1)
1170-1172: Type signature update fromusizetou64for pagination parameters.This method signature change ensures consistent types are used for pagination parameters, aligning with the changes in the
EventFilterstruct and theevents::get_eventsfunction it calls. This is a good practice for ensuring consistent behavior across different platforms.crates/starknet-devnet-server/src/api/json_rpc/origin_forwarder.rs (3)
25-25: Well-designed addition of the Starknet client field.The addition of a public
starknet_clientfield allows for direct JSON-RPC communication with the origin chain, which is essential for the enhanced event retrieval functionality.
29-36: Constructor signature change improves type safety.Changing the constructor to accept a
url::Urlinstead of a string is a good improvement for type safety, although it's a breaking change for any code that directly instantiates this struct.
38-40: Useful accessor method.Adding a getter for
fork_block_numberprovides a clean API to access this important value.crates/starknet-devnet-server/src/api/json_rpc/endpoints.rs (8)
3-3: Added Provider trait import for interacting with origin chain.This import is needed for the modified
get_eventsfunctionality that now needs to query the origin Starknet provider.
27-27: New constant for prefixing origin continuation tokens.Good naming convention for the prefix that helps distinguish continuation tokens coming from the origin chain versus the local devnet.
397-453: Well-structured helper method for determining block ranges across forked chains.The
split_block_rangehelper elegantly handles the complexity of splitting a requested block range between origin and local chains. The method properly handles different block ID types (number, hash, tag) and various range scenarios, with appropriate error handling.Some observations:
- Good early returns for edge cases
- Detailed comments explaining the logic and range boundaries
- Clear return type that provides all necessary information for the caller
455-456: Clippy allow directive is appropriate here.The
#[allow(clippy::expect_used)]annotation is justified as failure scenarios here would indicate implementation bugs rather than runtime errors.
458-460: Clean integration with the block range splitting logic.The function properly uses the helper method to determine which blocks need to be queried from the origin chain versus the local chain.
461-505: Well-implemented origin chain event fetching logic.This segment handles fetching events from the origin chain when applicable. The code:
- Correctly determines when to use the origin chain based on range and continuation token
- Properly strips/adds prefixes to continuation tokens to maintain origin context
- Handles errors from the origin client appropriately
- Ensures continuation token state is preserved for subsequent calls
506-535: Local event fetching logic with proper pagination.This segment handles local event fetching when either there's no origin range or we've exhausted the origin events. The implementation:
- Correctly parses the continuation token as a page number
- Calculates the appropriate skip (offset) based on pages read
- Properly handles error cases, particularly mapping NoBlock errors to BlockNotFound
- Generates the next continuation token based on whether more events exist
537-537: Clean response wrapping.The response is correctly wrapped in the
StarknetResponse::Eventsvariant to maintain API consistency.tests/integration/test_get_events.rs (7)
5-7: Updated imports for enhanced event handling.Added
EmittedEventto the imports fromstarknet_rs_core::types, which is necessary for the new helper function and test implementations.
12-12: Added constants for forking mainnet in tests.Including
MAINNET_URLandSTRK_ERC20_CONTRACT_ADDRESSconstants is essential for the new forking-related tests.
15-37: Well-implemented helper function for handling paginated event retrieval.The
get_events_follow_continuation_tokenfunction efficiently handles the complexity of paginated event retrieval by:
- Following continuation tokens until all events are retrieved
- Accumulating events from multiple pages
- Properly handling the completion condition (absence of continuation token)
- Maintaining the original filter parameters across calls
This helper significantly reduces code duplication in the test implementations and makes the test logic more readable.
205-205: Appropriate constant for fork block number.Defining the fork block as a constant improves maintainability and ensures consistency across tests.
207-238: Comprehensive test for querying events from origin chain only.This test validates that events can be correctly retrieved when the queried blocks are entirely on the origin chain. It:
- Sets up a forked devnet at a specific block number
- Verifies the fork was successful by checking the latest block number
- Uses a chunk size that forces pagination to test continuation token handling
- Queries events from a known contract with specific event keys
- Verifies the correct number of events are retrieved from the origin chain
This test is essential for validating the origin-side event fetching logic.
240-280: Thorough test for querying events from local devnet only.This test ensures events can be correctly retrieved when the queried blocks are entirely on the local devnet. It:
- Sets up a forked devnet
- Performs mint operations to generate events on the local chain
- Queries events specifically from blocks after the fork point
- Verifies the correct number of events are retrieved based on the minting operations
- Includes a helpful comment explaining the expected event count
Good test coverage for the local-only event querying scenario.
282-324: Comprehensive test for cross-boundary event querying.This test validates the most complex scenario where events are retrieved across both origin and local chains. It:
- Sets up a forked devnet
- Performs mint operations to generate events on the local chain
- Queries events from a block range that spans both the origin and local chains
- Verifies the total number of events matches the sum from both sources
- Includes helpful comments explaining the expected event counts from each source
This test is crucial for validating the seamless pagination across chain boundaries, which is a key feature of the implementation.
Usage related changes
Development related changes
get_eventsusizewithu64to avoidtry_fromconversionStringwithUrlto avoidtry_fromconversionexpectis used:Checklist:
./scripts/format.sh./scripts/clippy_check.sh./scripts/check_unused_deps.sh./scripts/check_spelling.sh./website/README.mdSummary by CodeRabbit