Fix messaging bridge when using forked network#882
Conversation
WalkthroughThe PR modifies Ethereum message handling in two key areas. First, it changes Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
crates/starknet-devnet-core/src/messaging/ethereum.rs(2 hunks)crates/starknet-devnet-core/src/messaging/mod.rs(2 hunks)
🔇 Additional comments (3)
crates/starknet-devnet-core/src/messaging/ethereum.rs (1)
119-136: LGTM! Initialization optimization for forked networks.The change to initialize
last_fetched_blockfrom the current block number effectively prevents scanning from genesis on forked networks, which addresses the large block range issue mentioned in the PR objectives. This meansfetch_messages(line 176) will start from the current block + 1 instead of block 1, significantly reducing RPC load on forked networks.crates/starknet-devnet-core/src/messaging/mod.rs (2)
124-126: LGTM! API corrected to match naming convention.The signature change from a getter to a setter is semantically correct - the
set_prefix should indicate a setter method. This allows external callers to explicitly update the last processed block number.Note: This is a breaking API change.
137-148: Edge case is properly handled—no issues found.The edge case you identified (when
to_block < from_block) is explicitly tested and handled correctly. The test at lines 607-613 confirms thatget_blocks(Some(BlockId::Number(10)), Some(BlockId::Number(2)))returns an empty result without error. The range check inis_block_number_in_range(line 159-160) ensures no blocks pass the filter whenstart > end, resulting in a valid emptyVec. The messaging code will safely handle this by receiving an empty block collection.
|
Thanks, LGTM! There are 6 commits in the main branch after your fork. Please rebase/merge and we are good to go to run tests. |
In case of a forked environment, fetching from zero can cause getBlocks RPC calls with a range too big to be handled. Instead, start fetching messages for blocks created after the devnet was launched.
5c03c20 to
81d5162
Compare
Done, thank you ! |
* Do not fetch from messages from genesis In case of a forked environment, fetching from zero can cause getBlocks RPC calls with a range too big to be handled. Instead, start fetching messages for blocks created after the devnet was launched. * Do not include L2->L1 messages from pre-confirmed block * fix: only collect L2->L1 messages if there are L2 accepted blocks to process --------- Co-authored-by: Kelvyne <lakhdar@argent.xyz>
Usage related changes
When using the messaging, devnet has to scan L1 for messages to include on L2. On forked network, it results in a
eth_getBlockscall with a very large range, which is problematic for most (if not all) RPC.Also, pre confirmed block can cause some messages to be missed, because they are marked as scanned when flushing. But subsequent transactions can be included in the same block number, which will cause the logic to miss messages in those transactions. I don't think it makes sense to include messages from the pre confirmed block anyway, because realistically only mined block's messages can be included on L1. I patched the logic to never include the pre confirmed block.
Development related changes
None
Checklist:
./scripts/format.sh./scripts/clippy_check.sh./scripts/check_unused_deps.sh./scripts/check_spelling.sh./website/README.mdSummary by CodeRabbit