-
Notifications
You must be signed in to change notification settings - Fork 182
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
refactor(katana): include config in the node struct #2742
Conversation
WalkthroughOhayo, sensei! This pull request introduces several modifications across multiple files, primarily focusing on the management of configuration structures. Key changes include the conversion of certain fields to use Changes
Possibly related PRs
Suggested labels
Suggested reviewers
🪧 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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
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 and nitpick comments (2)
crates/katana/node/src/config/mod.rs (1)
8-8
: Ohayo! Nice move to Arc!The transition to
Arc<ChainSpec>
is a good choice for shared ownership of the chain specification. This change aligns well with Rust's memory management best practices for shared, immutable data.Consider adding a doc comment explaining why
Arc
is used here, something like:/// The chain specification. + /// Uses Arc for shared ownership across multiple components. pub chain: Arc<ChainSpec>,
Also applies to: 25-25
crates/katana/node/src/lib.rs (1)
200-201
: Consider more concise gas price configurationThe gas price configuration could be simplified using struct update syntax.
- let gas_oracle = if let Some(fixed_prices) = &config.dev.fixed_gas_prices { - L1GasOracle::fixed(fixed_prices.gas_price.clone(), fixed_prices.data_gas_price.clone()) + let gas_oracle = if let Some(prices) = &config.dev.fixed_gas_prices { + L1GasOracle::fixed(prices.gas_price, prices.data_gas_price)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (5)
crates/dojo/test-utils/src/sequencer.rs
(1 hunks)crates/katana/cli/src/args.rs
(3 hunks)crates/katana/core/src/backend/mod.rs
(1 hunks)crates/katana/node/src/config/mod.rs
(2 hunks)crates/katana/node/src/lib.rs
(9 hunks)
🔇 Additional comments (6)
crates/dojo/test-utils/src/sequencer.rs (1)
129-129
: Ohayo sensei! Clean adaptation to Arc!
The use of .into()
for the chain field nicely handles the conversion to Arc<ChainSpec>
. The change maintains clean code structure while adapting to the new type requirement.
crates/katana/core/src/backend/mod.rs (1)
36-36
: Ohayo! Arc change looks good, but let's verify usage!
The transition to Arc<ChainSpec>
in the Backend struct is consistent with the changes in other files and appropriate for shared ownership.
Let's verify that all usages of chain_spec
in the Backend methods handle Arc correctly:
✅ Verification successful
Let me try a more specific pattern for ast-grep:
Ohayo! The Arc usage looks safe, sensei!
From the search results, we can see that chain_spec
is only accessed once in the Backend implementation through self.chain_spec.version.clone()
, which is the correct way to handle an Arc field. The other occurrences are just in type definitions and imports.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check all usages of chain_spec in Backend methods
# Look for any potential dereferencing or cloning that might need adjustment
ast-grep --pattern 'impl<$_> Backend<$_> {
$$$
chain_spec.$$$
$$$
}'
Length of output: 76
Script:
#!/bin/bash
# Let's try a different approach to find Backend implementations and chain_spec usage
# First find the file containing Backend implementations
rg -l "impl.*Backend" crates/katana/core/src/
# Then look at the actual implementations
rg -A 10 "impl.*Backend" crates/katana/core/src/
# Also search for direct chain_spec usage
rg "chain_spec" crates/katana/core/src/backend/
Length of output: 1958
Script:
#!/bin/bash
# Try with a more specific pattern focusing on method definitions
ast-grep --pattern 'impl Backend {
fn $_($$$) {
$$$
}
}'
# And another variation
ast-grep --pattern 'impl<$_> Backend<$_> {
fn $_($$$) {
$$$
}
}'
Length of output: 141
crates/katana/node/src/lib.rs (3)
91-91
: LGTM! Nice consolidation of config fields, sensei!
The change to use Arc<Config>
is a good optimization that reduces memory overhead and simplifies configuration management.
104-104
: Clean config access pattern!
The updated configuration access through self.config
is consistent and well-structured.
Also applies to: 131-131
181-183
: 🛠️ Refactor suggestion
Consider safer chain spec mutation approach
The Arc::get_mut
call assumes exclusive ownership. This could fail if there are other references to the Arc.
Consider using a builder pattern or constructing the chain spec before wrapping in Arc:
- let chain_spec = Arc::get_mut(&mut config.chain).expect("get mut Arc");
- let (bc, block_num) = Blockchain::new_from_forked(cfg.url.clone(), cfg.block, chain_spec).await?;
+ let mut chain_spec = (*config.chain).clone();
+ let (bc, block_num) = Blockchain::new_from_forked(cfg.url.clone(), cfg.block, &mut chain_spec).await?;
+ config.chain = Arc::new(chain_spec);
✅ Verification successful
Let me verify the usage of config.chain
further by checking how the Blockchain
type handles the chain spec.
Ohayo sensei! After analyzing the implementation, I can now provide the final response:
The Arc::get_mut usage is safe here
The new_from_forked
method needs mutable access to modify the chain spec with forked block data (timestamps, gas prices, etc). The Arc is only used for configuration and there are no other references to it at this point in the initialization flow.
Looking at the codebase:
- The chain spec is only used during initialization
- Other usages of
config.chain
are read-only accesses - The mutation is necessary to properly set up the forked chain state
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check for other potential references to chain_spec
rg -A 3 "config\.chain"
Length of output: 5049
Script:
#!/bin/bash
# Check Blockchain implementation and chain spec usage
ast-grep --pattern 'impl Blockchain {
$$$
}'
# Also check the new_from_forked implementation specifically
ast-grep --pattern 'fn new_from_forked($$$) {
$$$
}'
Length of output: 17582
crates/katana/cli/src/args.rs (1)
Line range hint 207-233
: Ohayo! Clean Arc implementation for chain spec!
The change to return Arc<ChainSpec>
aligns well with the overall memory optimization strategy while maintaining the existing functionality.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2742 +/- ##
==========================================
+ Coverage 56.31% 56.36% +0.04%
==========================================
Files 423 425 +2
Lines 54159 54269 +110
==========================================
+ Hits 30499 30588 +89
- Misses 23660 23681 +21 ☔ View full report in Codecov by Sentry. |
Summary by CodeRabbit
Release Notes
New Features
Improvements
Node
struct, simplifying access to various configurations.Arc<ChainSpec>
, improving efficiency and shared ownership.Bug Fixes
These changes streamline the application's configuration handling and memory management, improving overall performance and maintainability.