You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Missing Logging The initialization of core components such as miner, executor, chain, and importer in the run function should be logged with all relevant configurations to ensure proper monitoring and debugging.
Use spawn_named Consider using spawn_named instead of tokio::spawn for better traceability and monitoring of background tasks.
Missing Error Logging When returning an error in the init_with_config method, ensure the original error is logged in a field called reason.
Missing Error Logging When returning an error in the init_with_config method, ensure the original error is logged in a field called reason.
if self.importer.is_some() {
// When importer is set, miner mode must be external.
- if self.miner.block_mode != MinerMode::External {- return Err(anyhow::anyhow!("miner mode must be external when importer config is set"));+ if let Some(miner) = &self.miner {+ if miner.block_mode != MinerMode::External {+ return Err(anyhow::anyhow!("miner mode must be external when importer config is set"));+ }
}
} else {
// When importer is not set, miner mode cannot be external.
- if self.miner.block_mode == MinerMode::External {- return Err(anyhow::anyhow!("miner mode must not be external when importer config is not set"));+ if let Some(miner) = &self.miner {+ if miner.block_mode == MinerMode::External {+ return Err(anyhow::anyhow!("miner mode must not be external when importer config is not set"));+ }
}
}
Suggestion importance[1-10]: 9
Why: This suggestion addresses a potential runtime error by ensuring that self.miner is not None before accessing its block_mode property, which is crucial for the stability of the code.
9
Add a check to handle the case where BlockchainClient::init_with_config returns None
To ensure that the chain variable is properly initialized, consider adding a check to handle the case where BlockchainClient::init_with_config returns None.
Why: This suggestion addresses a potential issue where BlockchainClient::init_with_config might return None, ensuring that the chain variable is properly initialized and preventing possible runtime errors.
9
Enhancement
Simplify error handling in the init_with_config function using the ? operator
To improve readability and maintainability, consider using the ? operator to simplify error handling in the init_with_config function.
if let Some(importer_config) = config.importer.as_ref() {
- if let Some(chain) = chain {- return Ok(Some(importer_config.init(- Arc::clone(executor),- Arc::clone(miner),- Arc::clone(storage),- chain,- )?));- } else {- return Err(anyhow::anyhow!("chain is not initialized"));- }+ let chain = chain.ok_or_else(|| anyhow::anyhow!("chain is not initialized"))?;+ return Ok(Some(importer_config.init(+ Arc::clone(executor),+ Arc::clone(miner),+ Arc::clone(storage),+ chain,+ )?));
}
Ok(None)
Suggestion importance[1-10]: 8
Why: This suggestion improves code readability and maintainability by simplifying error handling using the ? operator, making the code more concise and easier to understand.
8
Best practice
Rename the init_with_config function to init_with_stratus_config for better clarity
To improve code readability, consider renaming the init_with_config function to init_with_stratus_config to better reflect its purpose.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement, Configuration changes
Description
StratusMode
enum and related logic from the configuration.init_with_config
methods toImporterConfig
,MinerConfig
, andBlockchainClient
for initialization withStratusConfig
.ConfigChecks
implementation to include checks forMinerMode
based on the presence ofImporterConfig
.main
andrun
functions to use the new initialization methods.justfile
commands to remove--mode
flag and use--block-mode
instead.Changes walkthrough 📝
config.rs
Refactor configuration to remove
StratusMode
and addMinerMode
checkssrc/config.rs
StratusMode
enum and related logic.MinerMode
based on the presence ofImporterConfig
.ConfigChecks
implementation to reflect new logic.importer_config.rs
Add `init_with_config` method to `ImporterConfig`
src/eth/importer/importer_config.rs
init_with_config
method to initializeImporterConfig
withStratusConfig
.miner_config.rs
Add `init_with_config` method to `MinerConfig`
src/eth/miner/miner_config.rs
init_with_config
method to initializeMinerConfig
withStratusConfig
.MinerMode
enum to derivePartialEq
.blockchain_client.rs
Add `init_with_config` method to `BlockchainClient`
src/infra/blockchain_client/blockchain_client.rs
init_with_config
method to initializeBlockchainClient
withStratusConfig
.main.rs
Refactor main initialization logic to use new config methods
src/main.rs
main
andrun
functions to removeStratusMode
logic.init_with_config
methods.justfile
Update justfile commands to reflect new configuration
justfile
--mode
flag and use--block-mode
instead.