-
Notifications
You must be signed in to change notification settings - Fork 39
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: start network with latest version if genesis version not set #2206
feat: start network with latest version if genesis version not set #2206
Conversation
WalkthroughThe changes in this pull request involve significant updates to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 8
🧹 Outside diff range and nitpick comments (11)
packages/rs-drive-abci/src/test/fixture/abci.rs (1)
16-17
: LGTM: Implementation changes align with PR objectives. Minor clarification needed.The updates to the function implementation correctly use the
protocol_version
parameter to set theplatform_version
andapp_version
. This change addresses the issue of waiting for two epochs before switching to the latest version, as mentioned in the PR objectives.For improved clarity, consider adding a brief comment explaining why
protocol_version
is cast tou64
on line 26:version: Some(VersionParams { - app_version: protocol_version as u64, + // Cast protocol_version to u64 to match the expected type for app_version + app_version: protocol_version as u64, consensus_version: platform_version.consensus.tenderdash_consensus_version as i32, }),Also applies to: 26-26
packages/dashmate/configs/defaults/getMainnetConfigFactory.js (1)
Line range hint
1-89
: Summary: Changes partially address PR objectives, but further clarification needed.The addition of
consensus_params
with a specificapp_version
in the genesis configuration is a step towards addressing the PR's goal. However, it's not entirely clear how this change alone ensures that the network starts with the latest version when the genesis version is not set.Consider the following points for the overall implementation:
- How does this change interact with the removal of the default protocol version for local networks mentioned in the PR objectives?
- Is there additional logic elsewhere in the codebase that uses this
app_version
to determine the latest version?- How does this change in the mainnet configuration relate to the behavior in devnet or local network scenarios mentioned in the PR objectives?
To fully address the PR objectives, you might need to implement additional logic that:
- Detects when the genesis version is not set (protocol version 0).
- Dynamically determines the latest desired version.
- Updates the
app_version
accordingly.This logic might be better placed in a separate function or module that handles network initialization, rather than hardcoding a version in the configuration file.
packages/rs-platform-version/src/version/protocol_version.rs (1)
155-157
: LGTM! Consider adding documentation.The
desired
method is a good addition that aligns with the PR objectives. It provides a clear way to access the desired platform version, which can be used to start the network with the latest version when the genesis version is not set.Consider adding a doc comment to explain the purpose of this method and its relationship to the
DESIRED_PLATFORM_VERSION
constant. For example:/// Returns a reference to the desired platform version. /// This is currently set to the latest platform version. pub fn desired<'a>() -> &'a Self { DESIRED_PLATFORM_VERSION }packages/rs-platform-version/src/version/v3.rs (1)
623-624
: LGTM! Consider adding more context to the comment.The increment of
consensus_params_update
version and the added comment align well with the PR objectives. This change will allow the network to start with the latest version when the genesis version is not set.Consider expanding the comment to provide more context:
-// Update app version if changed as well +// Update app version if changed, allowing the network to start with the latest version when genesis version is not setpackages/rs-drive-abci/tests/strategy_tests/execution.rs (1)
837-837
: Unnecessary use ofdrop(platform_state)
In Rust, values are automatically dropped when they go out of scope. Explicitly calling
drop(platform_state);
might be redundant unless you need to release resources immediately. Consider removing this line for cleaner code.Apply this diff to remove the unnecessary
drop
:- drop(platform_state);
packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs (6)
Line range hint
29-31
: Increase stack size configuration comment clarity.Consider adding a comment explaining why the stack size is increased to 4MB. This will help other developers understand the necessity of this adjustment.
Line range hint
213-215
: Handle potential panics when joining threads.In the
handler.join().expect("Thread has panicked");
call, consider handling panics more gracefully or providing additional context. This will aid in debugging if the thread does panic.
Line range hint
1030-1042
: Consolidate repeated setup code into a helper function.The setup code for
strategy
andconfig
is repeated across multiple tests. Refactoring this into a common helper function will improve maintainability and reduce duplication.
Line range hint
1200-1206
: Adjust logging level only when necessary.In
run_chain_version_upgrade_slow_upgrade_quick_reversion_after_lock_in
, the logging level is set toSilent
. Ensure that this change is necessary, as it might suppress important debug information during test failures.
Line range hint
1800-1805
: Consider handling potential overflow in time calculations.When calculating
block_spacing_ms
, ensure that multiplying large numbers doesn't cause integer overflows, which could lead to unexpected behavior.
PATCHES are not being reset after tests.
The shell script confirmed that
PATCHES.reset()
is not present in the following test files:
packages/rs-drive-abci/tests/strategy_tests/patch_platform_tests.rs
packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs
This may lead to unintended side effects on other tests. Please ensure that
PATCHES
are properly cleaned up after each test to maintain test isolation.🔗 Analysis chain
Line range hint
678-680
: Ensure protocol version patch is properly cleaned up after tests.After modifying the global
PATCHES
, it's important to reset them to avoid side effects on other tests.Confirm that the
PATCHES
are cleared by running:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Ensure that PATCHES are reset after tests. # Test: Search for patches assignments outside the current test. rg --type rust 'PATCHES.write\(\)' --files-with-matchesLength of output: 191
Script:
#!/bin/bash # Description: Check if PATCHES are reset after tests. # Test: Search for PATCHES.reset() in the identified test files. rg --type rust 'PATCHES.reset\(\)' packages/rs-drive-abci/tests/strategy_tests/patch_platform_tests.rs packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rsLength of output: 170
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
.yarn/cache/fsevents-patch-19706e7e35-10.zip
is excluded by!**/.yarn/**
,!**/*.zip
📒 Files selected for processing (18)
- packages/dashmate/configs/defaults/getBaseConfigFactory.js (0 hunks)
- packages/dashmate/configs/defaults/getMainnetConfigFactory.js (1 hunks)
- packages/dashmate/configs/defaults/getTestnetConfigFactory.js (1 hunks)
- packages/rs-drive-abci/src/config.rs (0 hunks)
- packages/rs-drive-abci/src/execution/engine/consensus_params_update/mod.rs (2 hunks)
- packages/rs-drive-abci/src/execution/engine/consensus_params_update/v1/mod.rs (1 hunks)
- packages/rs-drive-abci/src/execution/engine/initialization/init_chain/mod.rs (2 hunks)
- packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs (3 hunks)
- packages/rs-drive-abci/src/test/fixture/abci.rs (2 hunks)
- packages/rs-drive-abci/tests/strategy_tests/execution.rs (1 hunks)
- packages/rs-drive-abci/tests/strategy_tests/main.rs (4 hunks)
- packages/rs-drive-abci/tests/strategy_tests/patch_platform_tests.rs (2 hunks)
- packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs (1 hunks)
- packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs (4 hunks)
- packages/rs-platform-version/src/version/mocks/v3_test.rs (1 hunks)
- packages/rs-platform-version/src/version/protocol_version.rs (1 hunks)
- packages/rs-platform-version/src/version/v3.rs (1 hunks)
- packages/rs-platform-version/src/version/v4.rs (1 hunks)
💤 Files with no reviewable changes (2)
- packages/dashmate/configs/defaults/getBaseConfigFactory.js
- packages/rs-drive-abci/src/config.rs
🔇 Additional comments (28)
packages/rs-drive-abci/src/test/fixture/abci.rs (2)
6-6
: LGTM: New import aligns with function signature change.The addition of
use dpp::version::ProtocolVersion;
is necessary and consistent with the changes made to thestatic_init_chain_request
function signature.
12-15
: LGTM: Function signature update aligns with PR objectives.The addition of the
protocol_version: ProtocolVersion
parameter enhances the flexibility of thestatic_init_chain_request
function, allowing it to use the latest version when starting a network. This change is consistent with the PR objectives.To ensure this change is properly implemented across the codebase, let's verify its usage:
✅ Verification successful
All instances of
static_init_chain_request
have been updated to include theprotocol_version
parameter as required. The function signature changes align with the PR objectives and are consistently implemented across the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the updated function signature usage across the codebase. # Test: Search for function calls to static_init_chain_request # Expect: All calls should now include a protocol_version argument rg --type rust -A 3 'static_init_chain_request\s*\('Length of output: 834
packages/rs-drive-abci/src/execution/engine/consensus_params_update/mod.rs (2)
10-10
: LGTM: New module addition for versioning.The addition of the
v1
module aligns with the PR objectives and provides a clean way to implement new versions of the consensus params update logic. This modular approach enhances maintainability and allows for easy future upgrades.
Line range hint
1-43
: Summary: Changes align well with PR objectives.The modifications in this file effectively implement the new version of consensus params update logic, aligning well with the PR objectives. The modular approach and versioning system allow for easy future upgrades and maintain backward compatibility.
Key points:
- New
v1
module added for the updated logic.consensus_params_update
function updated to handle the new version.- Error handling needs a minor update to include version 1 as a known version.
These changes contribute to enhancing the process of starting a development or local network by allowing the use of the latest version when specified.
To ensure the new
v1
module is properly implemented, run the following script:packages/dashmate/configs/defaults/getMainnetConfigFactory.js (1)
69-73
: Approved: Addition of consensus parameters aligns with PR objectives.The addition of
consensus_params
with a specificapp_version
in the genesis configuration is a step towards addressing the PR's goal of starting the network with the latest version. However, I have a few points for consideration:
Could you clarify how setting
app_version
to '1' ensures that the network starts with the latest version? Is '1' always considered the latest version, or should this be a dynamic value?To improve code maintainability, consider adding a comment explaining the significance of the
app_version
setting and how it relates to the network initialization process.To ensure this change doesn't conflict with other parts of the codebase, let's verify the usage of
app_version
:✅ Verification successful
Verified: No conflicting usages of
app_version
found in the main codebase.The search results indicate that
app_version
is consistently set to'1'
in bothgetMainnetConfigFactory.js
andgetTestnetConfigFactory.js
, as well as within test fixtures. There are no conflicting or differing usages detected elsewhere in the main codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for other occurrences of app_version in the codebase # Expected: No conflicting usages of app_version rg --type js 'app_version'Length of output: 622
packages/rs-drive-abci/tests/strategy_tests/patch_platform_tests.rs (3)
21-21
: LGTM: New import aligns with PR objectives.The addition of
PROTOCOL_VERSION_1
import is appropriate for setting the initial protocol version in the test. This change supports the PR's goal of starting the network with the latest version when the genesis version is not specified.
109-109
: LGTM: Setting initial protocol version enhances test precision.The addition of
.with_initial_protocol_version(PROTOCOL_VERSION_1)
ensures that the test platform starts with a specific protocol version. This change is crucial for accurately testing version-related behavior and aligns with the PR's objective of controlling the initial network version.
21-21
: Changes enhance test precision and align with PR objectives.The addition of
PROTOCOL_VERSION_1
import and its use in setting the initial protocol version for the test platform provides a more controlled and explicit starting point for the test. This change aligns well with the PR's objective of enhancing the process of starting a network with a specific version.The test function
test_patch_version
remains comprehensive, covering multiple scenarios including applying patches and upgrading to version 2. The changes do not alter the core logic of the test but provide a more precise initial state.To further improve the test:
- Consider adding assertions to verify the initial protocol version immediately after platform creation.
- It might be beneficial to add a test case that explicitly checks the behavior when starting with a genesis version of 0 (not set) to fully cover the PR's main objective.
To ensure the changes don't introduce any regressions, please run the following command:
Also applies to: 109-109
packages/rs-drive-abci/src/execution/engine/initialization/init_chain/mod.rs (3)
27-32
: Appropriate error handling for missing consensus parametersThe code correctly checks for the presence of
consensus_params
in the request and returns aBadRequest
error with a clear message if it is missing.
34-43
: Proper extraction and validation of protocol versionThe code appropriately extracts
protocol_version
from theconsensus_params.version
and handles the case whereversion
is missing by returning aBadRequest
error with a clear message.
44-51
: Correct initialization of platform versionThe logic for determining the
platform_version
is correctly implemented. It uses the desired platform version when theprotocol_version
is 0 and retrieves the version from the genesis when it is not.packages/rs-drive-abci/src/execution/engine/consensus_params_update/v1/mod.rs (1)
51-73
: Ensure accurate version comparison logicThe condition checking if versions have changed compares both the consensus version and the protocol version. Confirm that this logic aligns with the intended behavior, especially regarding type casting and equality checks.
Run the following script to verify the version comparison:
Ensure that the versions are compared appropriately throughout the codebase and that any necessary type conversions are handled correctly.
packages/rs-drive-abci/src/execution/engine/initialization/init_chain/v0/mod.rs (6)
10-10
: Import ofconsensus_params_update
is appropriateThe added import statement correctly brings
consensus_params_update
into scope, ensuring that the function can be used later in the code.
12-13
: Imports forEpochInfoV0
andEpochInfo
are necessaryThe new imports of
EpochInfoV0
andEpochInfo
are required for calculating the epoch information during chain initialization.
135-138
: Usage ofPlatformVersion::first()
aligns with Tenderdash requirementsAssigning
first_platform_version
usingPlatformVersion::first()
ensures compatibility with Tenderdash's expectation of starting genesis with the first protocol versions by default.
139-145
: Epoch information calculated correctlyThe epoch information is properly calculated using
EpochInfoV0::calculate
, which will accurately set up epoch-related parameters for the initialization process.
147-152
: Verify parameters inconsensus_params_update
function callIn the
consensus_params_update
function call, bothfirst_platform_version
andplatform_version
are being passed. Please confirm that this is intentional and that the function correctly utilizes both versions to update the consensus parameters as required.Run the following script to review the implementation of
consensus_params_update
:#!/bin/bash # Description: Inspect `consensus_params_update` function to verify parameter usage. # Test: Display the definition of `consensus_params_update` for examination. rg --type rust -A 20 'fn consensus_params_update\('
74-75
: Verify the initialization of protocol versionsThe
default_with_protocol_versions
function is called withplatform_version.protocol_version
for both the current and next protocol versions. Please confirm that setting both versions to the same value is intentional and aligns with the expected initialization behavior.Run the following script to check how
default_with_protocol_versions
is used elsewhere:✅ Verification successful
Initialization of Protocol Versions Verified
The use of
default_with_protocol_versions
with identicalprotocol_version
values is consistent across the codebase and appears to be intentional.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify usage of `default_with_protocol_versions` in the codebase. # Test: Search for calls to `default_with_protocol_versions` and display parameter usage. rg --type rust -A 5 'default_with_protocol_versions\('Length of output: 2355
Script:
#!/bin/bash # Description: Verify usage of `default_with_protocol_versions` in the codebase. # Test: Search for calls to `default_with_protocol_versions` and display parameter usage. rg --type rust 'default_with_protocol_versions\(' -A 5Length of output: 5237
packages/rs-drive-abci/tests/strategy_tests/execution.rs (2)
832-836
: Retrievingprotocol_version
fromplatform_state
The code correctly retrieves
protocol_version
fromplatform_state
and prepares it for use in the chain initialization. This aligns with the PR objectives to ensure the latest version is utilized when the genesis version is not specified.
840-840
: Updatingstatic_init_chain_request
withprotocol_version
Passing
protocol_version
tostatic_init_chain_request
properly integrates the protocol version into the chain initialization process.packages/rs-platform-version/src/version/v4.rs (1)
618-618
: Method version update forconsensus_params_update
is appropriateThe method version for
consensus_params_update
has been incremented from0
to1
, which aligns with the changes introduced in handling consensus parameters. This update appears consistent with the PR objectives to ensure the latest version is utilized when the genesis version is not specified.packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs (3)
Line range hint
86-96
: Avoid unnecessary cloning of configuration.In the calls to
run_chain_for_strategy
,config.clone()
is passed multiple times. If the configuration is not modified within these functions, consider passing a reference instead to avoid unnecessary cloning and improve performance.[performance]
Apply this diff to pass references:
- run_chain_for_strategy( - &mut platform, - 1300, - strategy.clone(), - config.clone(), - 13, - &mut None, - ); + run_chain_for_strategy( + &mut platform, + 1300, + &strategy, + &config, + 13, + &mut None, + );
Line range hint
1500-1505
: Validate test scenarios for real-world applicability.The
run_chain_version_upgrade_multiple_versions
test introduces multiple protocol versions. Verify that this scenario aligns with expected real-world upgrade paths and doesn't introduce unrealistic cases.
631-631
:⚠️ Potential issueRemove unused variable
config
.On line 631, the variable
config
is redefined but not used afterwards. This might lead to confusion.Apply this diff to remove the unused variable:
- let mut platform = TestPlatformBuilder::new() - .with_config(config.clone()) - .with_initial_protocol_version(PROTOCOL_VERSION_1) - .build_with_mock_rpc(); + let mut platform = TestPlatformBuilder::new() + .with_initial_protocol_version(PROTOCOL_VERSION_1) + .build_with_mock_rpc();Likely invalid or redundant comment.
packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs (4)
103-103
: Correct usage of.with_initial_protocol_version
The addition of
.with_initial_protocol_version(TEST_PLATFORM_V3.protocol_version)
correctly sets the initial protocol version for the test platform after removinginitial_protocol_version
fromPlatformConfig
.
784-784
: Correct usage of.with_initial_protocol_version
The method
.with_initial_protocol_version(TEST_PLATFORM_V3.protocol_version)
is appropriately used to set the initial protocol version for the test platform.
2204-2204
: Correct usage of.with_initial_protocol_version
The addition of
.with_initial_protocol_version(TEST_PLATFORM_V3.protocol_version)
appropriately sets the initial protocol version for the test platform.
1487-1489
: Verify the order of builder method callsThe
.with_initial_protocol_version(TEST_PLATFORM_V3.protocol_version)
method is called before.with_config(config.clone())
. Typically, configuration methods are called prior to setting the initial protocol version. Please ensure that the order of these method calls does not affect the configuration, and that all parameters are set as intended.To check the order of builder method calls across the codebase, run the following script:
This script searches for instances where
TestPlatformBuilder::new()
is followed by.with_initial_protocol_version
before.with_config
. Review the results to ensure that the order of method calls is consistent and appropriate.
packages/rs-drive-abci/src/execution/engine/consensus_params_update/mod.rs
Show resolved
Hide resolved
packages/rs-drive-abci/src/execution/engine/consensus_params_update/v1/mod.rs
Show resolved
Hide resolved
packages/rs-drive-abci/src/execution/engine/consensus_params_update/v1/mod.rs
Show resolved
Hide resolved
…rotocol-version' into feat/start-network-with-latest-protocol-version
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
🧹 Outside diff range and nitpick comments (1)
packages/dashmate/configs/getConfigFileMigrationsFactory.js (1)
Line range hint
916-1066
: Reduce duplication in 'consensusParams' definitions across networksThe
consensusParams
object for each network repeats the same parameters, leading to redundant code. Refactoring to use a shared base configuration with network-specific overrides enhances readability and maintainability.You can apply a similar refactoring as suggested for the
genesis
configurations:+const commonConsensusParams = { + block: { + max_bytes: '2097152', + max_gas: '57631392000', + time_iota_ms: '5000', + }, + evidence: { + max_age: '100000', + max_age_num_blocks: '100000', + max_age_duration: '172800000000000', + }, + validator: { + pub_key_types: ['bls12381'], + }, + timeout: { + propose: '50000000000', + propose_delta: '5000000000', + vote: '10000000000', + vote_delta: '1000000000', + }, + synchrony: { + message_delay: '70000000000', + precision: '1000000000', + }, + abci: { + recheck_tx: true, + }, + version: { + app_version: '1', + }, +}; const consensusParams = { base: commonConsensusParams, local: commonConsensusParams, testnet: commonConsensusParams, mainnet: commonConsensusParams, };This refactoring centralizes the common parameters and simplifies the configuration structure.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- packages/dashmate/configs/getConfigFileMigrationsFactory.js (4 hunks)
🔇 Additional comments (1)
packages/dashmate/configs/getConfigFileMigrationsFactory.js (1)
1184-1196
: LGTMThe changes correctly remove the
version
parameter fromconsensus_params
for thebase
andlocal
configurations and set it fortestnet
, aligning with the PR objectives to ensure the latest version is used when the genesis version is not set.
…rotocol-version' into feat/start-network-with-latest-protocol-version
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 (4)
packages/dashmate/configs/getConfigFileMigrationsFactory.js (4)
1001-1013
: Implement version-specific consensus parameter updatesThe changes in the '1.4.0-dev.4' migration function align with the PR objective of starting the network with the latest version when the genesis version is not set. Here's a breakdown of the changes:
- For 'base' and 'local' configurations, the
version
field is removed fromconsensus_params
.- For the testnet network, a specific
version
withapp_version: '1'
is set.- The mainnet network is not explicitly handled, which implies it will use the default behavior.
These changes support the goal of using the latest version when not specified, while still allowing for explicit version setting in certain cases (e.g., testnet).
Consider adding a comment explaining the rationale behind these version-specific changes, especially for future maintainers who might not be familiar with the context of this update.
451-507
: Standardize consensus parameters across network typesThis change introduces a standardized
consensusParams
object and applies it to different network types (base, local, testnet, mainnet) through thegenesis
object. This standardization is a good practice as it ensures consistency across different network configurations while still allowing for network-specific overrides.While this standardization is beneficial, consider the following suggestions:
- Add comments explaining the purpose and impact of each consensus parameter for better maintainability.
- Consider extracting the
consensusParams
andgenesis
objects into separate configuration files if they grow larger or need to be reused elsewhere in the codebase.
Line range hint
828-883
: Refine consensus parameter applicationThis change updates the consensus parameters and applies them more selectively. The new approach only applies the
consensusParams
to configurations that exist indefaultConfigs
. This is a more nuanced approach compared to the previous migration, allowing for better control over which configurations receive these parameters.To improve code maintainability and reduce duplication, consider the following:
Extract the
consensusParams
object into a separate, reusable constant or configuration file. This object is defined twice (in '1.0.0-dev.2' and '1.1.0-dev.1') with identical values, which could lead to inconsistencies if one is updated and the other is not.Create a helper function to apply consensus parameters. This function could take the configuration and the consensus parameters as arguments, and handle the logic of when and how to apply them. This would centralize the logic and make it easier to update in the future.
Example:
function applyConsensusParams(config, consensusParams, defaultConfigs) { if (defaultConfigs.has(config.name)) { config.platform.drive.tenderdash.genesis.consensus_params = consensusParams; } } // Usage in migration function Object.entries(configFile.configs).forEach(([name, options]) => { applyConsensusParams(options, consensusParams, defaultConfigs); // ... other configuration updates ... });This refactoring would make the code more DRY (Don't Repeat Yourself) and easier to maintain.
Line range hint
1-1013
: Overall assessment of changesThe modifications in this file successfully implement the PR objectives of enhancing the network startup process and version management. The changes across different migration functions (1.0.0-dev.2, 1.1.0-dev.1, and 1.4.0-dev.4) work together to create a more flexible and consistent configuration system.
Key improvements:
- Standardized consensus parameters across network types.
- More nuanced application of consensus parameters based on configuration type.
- Version-specific updates that allow for using the latest version by default while still supporting explicit version setting.
While the functionality appears correct, there are opportunities to improve code quality:
- Reduce duplication by extracting repeated objects (like
consensusParams
) into reusable constants or configuration files.- Enhance maintainability by adding comments explaining the rationale behind version-specific changes and the purpose of consensus parameters.
- Consider creating helper functions for common operations to centralize logic and make future updates easier.
As the configuration system grows more complex, consider implementing a more robust configuration management system. This could involve:
- Creating a configuration schema to validate configuration objects.
- Implementing a plugin system for network-specific configurations.
- Developing a comprehensive test suite for configuration migrations to ensure backwards compatibility and correct application of changes across different network types.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- .yarnrc.yml (1 hunks)
- packages/dashmate/configs/getConfigFileMigrationsFactory.js (4 hunks)
🔇 Additional comments (2)
.yarnrc.yml (2)
Line range hint
6-6
: Indentation correction approvedThe indentation for the '@humanwhocodes/config-array' entry has been corrected, improving the file's readability and consistency.
18-18
:⚠️ Potential issueTemporary exclusion of eslint from npm audit checks
Adding 'eslint' to
npmAuditExcludePackages
excludes it from npm audit checks, which could potentially hide security vulnerabilities. While this appears to be a temporary measure, it's important to prioritize the eslint update to ensure the project's security.To verify the status of the eslint update, please run the following script:
Please ensure that the eslint update is completed as soon as possible to remove this exclusion.
✅ Verification successful
Confirming Temporary Exclusion of eslint from npm audit
The exclusion of 'eslint' from
npmAuditExcludePackages
remains necessary as the issue to update eslint (Issue #2212) is still open. Please prioritize updating eslint to address the deprecation and re-enable it in npm audit checks to maintain the project's security.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check the status of the eslint update issue # Test: Fetch the issue status gh issue view 2212 --json title,state,body # Expected output: The issue should be open and actively being worked onLength of output: 1030
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: 2
🧹 Outside diff range and nitpick comments (1)
packages/dashmate/configs/getConfigFileMigrationsFactory.js (1)
Line range hint
1-1013
: Consider refactoring migration functions for better maintainabilityThe current structure of having separate migration functions for each version works, but it leads to some code duplication and might make it difficult to maintain as the number of versions grows. Consider the following suggestions to improve the overall structure:
- Extract common operations into helper functions to reduce duplication across migration functions.
- Use a more declarative approach for defining migrations, possibly using a configuration object that describes the changes for each version.
- Implement a mechanism to chain migrations, ensuring that all necessary updates are applied when migrating across multiple versions.
Here's a conceptual example of how this could be implemented:
const migrationOperations = { updateDockerImage: (config, path, newImage) => { lodash.set(config, path, newImage); }, updateConsensusParams: (config, newParams) => { // Logic to update consensus params }, // ... other common operations }; const migrations = [ { version: '1.0.0-dev.2', operations: [ { op: 'updateConsensusParams', params: [/* ... */] }, { op: 'updateDockerImage', params: ['platform.drive.tenderdash.docker.image', 'newImage'] }, // ... other operations ], }, // ... other migrations ]; function applyMigration(config, targetVersion) { let currentVersion = config.version; for (const migration of migrations) { if (semver.gt(migration.version, currentVersion) && semver.lte(migration.version, targetVersion)) { for (const operation of migration.operations) { migrationOperations[operation.op](config, ...operation.params); } } } config.version = targetVersion; return config; }This approach would make it easier to add new migrations, reduce code duplication, and ensure that all necessary updates are applied when migrating across multiple versions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- packages/dashmate/configs/getConfigFileMigrationsFactory.js (4 hunks)
🔇 Additional comments (1)
packages/dashmate/configs/getConfigFileMigrationsFactory.js (1)
1001-1013
:⚠️ Potential issueConsider handling the mainnet configuration explicitly
The current implementation removes the
consensus_params.version
for 'base' and 'local' configurations and sets it for the testnet. However, it doesn't explicitly handle the mainnet configuration. This might lead to unexpected behavior if the mainnet configuration is different from the base configuration.Consider adding an explicit condition for the mainnet configuration to ensure consistent behavior across all network types.
Here's a suggested improvement:
'1.4.0-dev.4': (configFile) => { Object.entries(configFile.configs) .forEach(([name, options]) => { if (name === 'base' || name === 'local') { delete options.platform.drive.tenderdash.genesis.consensus_params.version; } else if (options.network === NETWORK_TESTNET) { options.platform.drive.tenderdash.genesis.consensus_params.version = { app_version: '1', }; + } else if (options.network === NETWORK_MAINNET) { + // Handle mainnet configuration explicitly + // You may want to set a specific version or remove it, depending on your requirements + delete options.platform.drive.tenderdash.genesis.consensus_params.version; } }); return configFile; },To verify the current state of the mainnet configuration, you can run the following script:
This will help ensure that the mainnet configuration is handled correctly and consistently with other network types.
Issue being fixed or feature implemented
When we start devnet or local network we need to wait 2 epochs until we switch to latest version. It doesn't work at all with CI when we want to run tests against latest functionality.
What was done?
...genesis.consensus_params.version.app_version
) is not set (protocol version 0)How Has This Been Tested?
Breaking Changes
None
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores
.yarnrc.yml
to exclude theeslint
package from audits and corrected indentation.