Skip to content
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

Merged
merged 11 commits into from
Oct 5, 2024

Conversation

shumkov
Copy link
Member

@shumkov shumkov commented Oct 3, 2024

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?

  • Choose latest desired version on init chain if protocol version (...genesis.consensus_params.version.app_version) is not set (protocol version 0)
  • Removed default protocol version for local network
  • Added update protocol version in consensus params when it changed.
  • Removed non consensus initial protocol version config option.

How Has This Been Tested?

  • Running local network to make sure that latest desired version is chosen
  • Sync a testnet node to make sure genesis app version is working

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Enhanced withdrawal functionality with new methods for managing withdrawal transactions.
    • Updated consensus parameters handling with new versioning.
    • Introduced new methods for fetching withdrawal documents and managing transaction indices.
    • Added a method to retrieve the desired platform version directly.
  • Bug Fixes

    • Improved handling of protocol versions during chain initialization and execution.
  • Documentation

    • Updated comments to reflect changes in method behavior and versioning.
  • Chores

    • Updated .yarnrc.yml to exclude the eslint package from audits and corrected indentation.

@shumkov shumkov added this to the v1.4.0 milestone Oct 3, 2024
Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

Walkthrough

The changes in this pull request involve significant updates to the getConfigFileMigrationsFactory function and various version structures across multiple files. Key modifications include the introduction of new structures for consensusParams and genesis within migration functions for specific versions, enhancing configuration management for different network types. Additionally, the consensus_params_update method version has been incremented from 0 to 1 in several files, reflecting improvements in the consensus mechanism and withdrawal functionalities.

Changes

File Change Summary
packages/dashmate/configs/getConfigFileMigrationsFactory.js Introduced new structures for consensusParams and genesis within migration functions for versions 1.0.0-dev.2 and 1.1.0-dev.1, enhancing configuration management.
packages/rs-platform-version/src/version/mocks/v3_test.rs Updated consensus_params_update method version from 0 to 1.
packages/rs-platform-version/src/version/v3.rs Updated consensus_params_update method version from 0 to 1.
packages/rs-platform-version/src/version/v4.rs - Incremented consensus_params_update method version from 0 to 1.
- Added multiple withdrawal-related methods, enhancing withdrawal functionalities.
.yarnrc.yml - Added eslint to npmAuditExcludePackages.
- Corrected indentation for @humanwhocodes/config-array.

Possibly related PRs

  • feat(platform)!: withdrawal automatic retries after core rejection #2185: This PR updates the DriveIdentityWithdrawalTransactionQueueMethodVersions structure, which includes modifications to consensus parameters, aligning with the main PR's focus on enhancing the organization of configuration parameters related to consensus and genesis structures.
  • feat(sdk): enable withdrawals v1 in JS SDK #2201: This PR introduces the IdentityCreditWithdrawalTransitionV1, which is relevant to the main PR's updates on consensus parameters and configurations, as both involve handling withdrawal processes and their associated parameters.

Suggested labels

enhancement, js-sdk

Suggested reviewers

  • QuantumExplorer
  • lklimek
  • pshenmic

Poem

In the land of code where rabbits play,
Changes hop in, brightening the day.
With versions updated and tests so grand,
We leap through logic, a joyful band.
Withdrawal paths now clearer than before,
Let's celebrate with a happy encore! 🐇✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@shumkov shumkov linked an issue Oct 3, 2024 that may be closed by this pull request
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 the platform_version and app_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 to u64 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 specific app_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:

  1. How does this change interact with the removal of the default protocol version for local networks mentioned in the PR objectives?
  2. Is there additional logic elsewhere in the codebase that uses this app_version to determine the latest version?
  3. 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:

  1. Detects when the genesis version is not set (protocol version 0).
  2. Dynamically determines the latest desired version.
  3. 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 set
packages/rs-drive-abci/tests/strategy_tests/execution.rs (1)

837-837: Unnecessary use of drop(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 and config 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 to Silent. 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-matches

Length 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.rs

Length of output: 170

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6230b53 and 5c99b08.

⛔ 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 the static_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 the static_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 the protocol_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:

  1. New v1 module added for the updated logic.
  2. consensus_params_update function updated to handle the new version.
  3. 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 specific app_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:

  1. 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?

  2. 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 both getMainnetConfigFactory.js and getTestnetConfigFactory.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:

  1. Consider adding assertions to verify the initial protocol version immediately after platform creation.
  2. 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 parameters

The code correctly checks for the presence of consensus_params in the request and returns a BadRequest error with a clear message if it is missing.


34-43: Proper extraction and validation of protocol version

The code appropriately extracts protocol_version from the consensus_params.version and handles the case where version is missing by returning a BadRequest error with a clear message.


44-51: Correct initialization of platform version

The logic for determining the platform_version is correctly implemented. It uses the desired platform version when the protocol_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 logic

The 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 of consensus_params_update is appropriate

The added import statement correctly brings consensus_params_update into scope, ensuring that the function can be used later in the code.


12-13: Imports for EpochInfoV0 and EpochInfo are necessary

The new imports of EpochInfoV0 and EpochInfo are required for calculating the epoch information during chain initialization.


135-138: Usage of PlatformVersion::first() aligns with Tenderdash requirements

Assigning first_platform_version using PlatformVersion::first() ensures compatibility with Tenderdash's expectation of starting genesis with the first protocol versions by default.


139-145: Epoch information calculated correctly

The epoch information is properly calculated using EpochInfoV0::calculate, which will accurately set up epoch-related parameters for the initialization process.


147-152: Verify parameters in consensus_params_update function call

In the consensus_params_update function call, both first_platform_version and platform_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 versions

The default_with_protocol_versions function is called with platform_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 identical protocol_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 5

Length of output: 5237

packages/rs-drive-abci/tests/strategy_tests/execution.rs (2)

832-836: Retrieving protocol_version from platform_state

The code correctly retrieves protocol_version from platform_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: Updating static_init_chain_request with protocol_version

Passing protocol_version to static_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 for consensus_params_update is appropriate

The method version for consensus_params_update has been incremented from 0 to 1, 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 issue

Remove 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 removing initial_protocol_version from PlatformConfig.


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 calls

The .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.

QuantumExplorer
QuantumExplorer previously approved these changes Oct 4, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 networks

The 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

📥 Commits

Files that changed from the base of the PR and between 3ab1f02 and 6d939cc.

📒 Files selected for processing (1)
  • packages/dashmate/configs/getConfigFileMigrationsFactory.js (4 hunks)
🔇 Additional comments (1)
packages/dashmate/configs/getConfigFileMigrationsFactory.js (1)

1184-1196: LGTM

The changes correctly remove the version parameter from consensus_params for the base and local configurations and set it for testnet, aligning with the PR objectives to ensure the latest version is used when the genesis version is not set.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 updates

The 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:

  1. For 'base' and 'local' configurations, the version field is removed from consensus_params.
  2. For the testnet network, a specific version with app_version: '1' is set.
  3. 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 types

This change introduces a standardized consensusParams object and applies it to different network types (base, local, testnet, mainnet) through the genesis 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:

  1. Add comments explaining the purpose and impact of each consensus parameter for better maintainability.
  2. Consider extracting the consensusParams and genesis 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 application

This change updates the consensus parameters and applies them more selectively. The new approach only applies the consensusParams to configurations that exist in defaultConfigs. 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:

  1. 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.

  2. 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 changes

The 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:

  1. Standardized consensus parameters across network types.
  2. More nuanced application of consensus parameters based on configuration type.
  3. 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:

  1. Reduce duplication by extracting repeated objects (like consensusParams) into reusable constants or configuration files.
  2. Enhance maintainability by adding comments explaining the rationale behind version-specific changes and the purpose of consensus parameters.
  3. 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:

  1. Creating a configuration schema to validate configuration objects.
  2. Implementing a plugin system for network-specific configurations.
  3. 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

📥 Commits

Files that changed from the base of the PR and between 19ab56f and ec32ee5.

📒 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 approved

The indentation for the '@humanwhocodes/config-array' entry has been corrected, improving the file's readability and consistency.


18-18: ⚠️ Potential issue

Temporary 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 on

Length of output: 1030

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 maintainability

The 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:

  1. Extract common operations into helper functions to reduce duplication across migration functions.
  2. Use a more declarative approach for defining migrations, possibly using a configuration object that describes the changes for each version.
  3. 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

📥 Commits

Files that changed from the base of the PR and between ec32ee5 and 6c06c16.

📒 Files selected for processing (1)
  • packages/dashmate/configs/getConfigFileMigrationsFactory.js (4 hunks)
🔇 Additional comments (1)
packages/dashmate/configs/getConfigFileMigrationsFactory.js (1)

1001-1013: ⚠️ Potential issue

Consider 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.

@shumkov shumkov merged commit 00fb663 into v1.4-dev Oct 5, 2024
77 checks passed
@shumkov shumkov deleted the feat/start-network-with-latest-protocol-version branch October 5, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Start new networks with latest protocol version
2 participants