Skip to content

feat!: allow nextnet to mine randomxT#7070

Merged
SWvheerden merged 9 commits intotari-project:developmentfrom
SWvheerden:sw_update_consensus_nextnet
May 20, 2025
Merged

feat!: allow nextnet to mine randomxT#7070
SWvheerden merged 9 commits intotari-project:developmentfrom
SWvheerden:sw_update_consensus_nextnet

Conversation

@SWvheerden
Copy link
Copy Markdown
Collaborator

@SWvheerden SWvheerden commented May 20, 2025

Description

enable nextnet to mine randomxT

Summary by CodeRabbit

  • New Features

    • Added new consensus configurations with an additional proof-of-work algorithm and updated parameters effective from block heights 1500 and 15,000.
  • Refactor

    • Improved compatibility by splitting accumulated difficulty into two parts for better data handling, without impacting user experience.
  • Tests

    • Ensured consistent network settings during difficulty calculation tests for reliable results.

@SWvheerden SWvheerden requested a review from a team as a code owner May 20, 2025 12:42
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 20, 2025

Warning

Rate limit exceeded

@SWvheerden has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 13 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f585172 and 14fc0ef.

📒 Files selected for processing (8)
  • base_layer/core/src/base_node/chain_metadata_service/service.rs (3 hunks)
  • base_layer/core/src/base_node/proto/chain_metadata.proto (1 hunks)
  • base_layer/core/src/base_node/proto/chain_metadata.rs (2 hunks)
  • base_layer/core/src/consensus/consensus_constants.rs (2 hunks)
  • base_layer/core/src/proof_of_work/monero_rx/helpers.rs (2 hunks)
  • base_layer/wallet/tests/support/comms_rpc.rs (2 hunks)
  • base_layer/wallet/tests/transaction_service_tests/service.rs (1 hunks)
  • base_layer/wallet/tests/utxo_scanner/mod.rs (8 hunks)

Walkthrough

The changes split the accumulated_difficulty field in the ChainMetadata protobuf into two separate byte arrays for low and high parts, updating both the .proto definition and Rust serialization/deserialization logic to handle this. Test code and mocks were updated accordingly. Additionally, new consensus constant configurations were added for both nextnet() and mainnet(), introducing a third proof-of-work algorithm and updating related parameters. A test was also updated to enforce serial execution and consistent network configuration.

Changes

File(s) Change Summary
base_layer/core/src/base_node/proto/chain_metadata.proto Split accumulated_difficulty field into accumulated_difficulty_low and accumulated_difficulty_high in the ChainMetadata proto.
base_layer/core/src/base_node/proto/chain_metadata.rs Updated conversion logic to handle two 32-byte fields for accumulated difficulty, with validation and serialization adjustments.
base_layer/core/src/consensus/consensus_constants.rs Added third and fourth consensus constant configurations in nextnet() and mainnet(), introducing another PoW algorithm and updating versioning parameters.
base_layer/core/src/base_node/chain_metadata_service/service.rs Updated test sample chain metadata to use split accumulated difficulty fields with a 512-bit value instead of 256-bit.
base_layer/wallet/tests/support/comms_rpc.rs Updated mock state and test code to replace single accumulated difficulty field with low and high parts as empty vectors.
base_layer/wallet/tests/utxo_scanner/mod.rs Updated test code to replace single accumulated difficulty field with separate low and high fields initialized as empty vectors.
base_layer/core/src/proof_of_work/monero_rx/helpers.rs Added #[serial] attribute to a test to enforce serial execution; ensured consistent network configuration during the test.

Sequence Diagram(s)

sequenceDiagram
    participant Node
    participant ProtoChainMetadata
    participant ChainMetadata

    Node->>ProtoChainMetadata: Receive proto with accumulated_difficulty_low & high
    ProtoChainMetadata->>ChainMetadata: Validate & concatenate high + low, convert to U512
    ChainMetadata-->>ProtoChainMetadata: On serialize, split U512 into high & low, assign to proto fields
Loading

Poem

In fields of bytes, we split the load,
Low and high, the chain bestowed.
Consensus grows, a third appears,
With new algorithms, the path now steers.
Rabbits hop where changes flow—
Onward, blockchain, onward we go!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

stringhandler
stringhandler previously approved these changes May 20, 2025
Copy link
Copy Markdown
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 8f38071 and 382dd28.

📒 Files selected for processing (3)
  • base_layer/core/src/base_node/proto/chain_metadata.proto (1 hunks)
  • base_layer/core/src/base_node/proto/chain_metadata.rs (2 hunks)
  • base_layer/core/src/consensus/consensus_constants.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
base_layer/core/src/base_node/proto/chain_metadata.rs (2)
base_layer/core/src/proto/block.rs (7)
  • try_from (43-55)
  • try_from (61-66)
  • try_from (74-90)
  • try_from (96-103)
  • try_from (131-196)
  • try_from (204-224)
  • try_from (230-245)
base_layer/common_types/src/chain_metadata.rs (1)
  • accumulated_difficulty (124-126)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: cargo check with stable
  • GitHub Check: ci
🔇 Additional comments (6)
base_layer/core/src/base_node/proto/chain_metadata.proto (1)

15-17: Improved backward compatibility through accumulated difficulty field splitting.

The accumulated difficulty field has been split into low and high parts (each representing a u256) to maintain compatibility with older nodes. This is a good approach as it allows new nodes to work with the full 512-bit difficulty while enabling communication with nodes that might only support part of it.

base_layer/core/src/consensus/consensus_constants.rs (3)

673-694: New consensus constants for RandomXT mining.

The new third consensus configuration introduces RandomXT as an additional proof-of-work algorithm for the NextNet. It's appropriately activated at block height 1500 with a blockchain version bump to 1, which ensures a clean transition to the new mining algorithm.


695-695: Added new consensus configuration to vector.

The consensus constants vector now includes the third configuration with RandomXT.


686-691:

Details

❓ Verification inconclusive

Verify RandomXT mining difficulty is appropriate.

The minimum difficulty for RandomXT is set to 1,200,000 which is identical to RandomXM. Have you confirmed this difficulty setting is appropriate for RandomXT? The chosen value will affect the network's security and block production rate.


🏁 Script executed:

#!/bin/bash
# Check for other RandomXT difficulty references in the codebase
rg "RandomXT.*difficulty" -A 5 -B 5

Length of output: 1109


🏁 Script executed:

#!/bin/bash
rg -n "PowAlgorithm::RandomXM" -A5 -B5 base_layer/core/src/consensus/consensus_constants.rs

Length of output: 5085


Confirm RandomXT difficulty matches RandomXM across consensus versions

I’ve checked the constants and observed that RandomXT’s min_difficulty is identical to RandomXM’s (1,200,000) for chain version 3. Please confirm this is intentional given the difference in algorithm characteristics, or adjust the value if RandomXT requires its own baseline.

Locations:

  • base_layer/core/src/consensus/consensus_constants.rs @ lines 681–685:
    algos.insert(PowAlgorithm::RandomXM, PowAlgorithmConstants { min_difficulty: Difficulty::from_u64(1_200_000)… target_time: 360, });
  • base_layer/core/src/consensus/consensus_constants.rs @ lines 686–690:
    algos.insert(PowAlgorithm::RandomXT, PowAlgorithmConstants { min_difficulty: Difficulty::from_u64(1_200_000)… target_time: 360, });
base_layer/core/src/base_node/proto/chain_metadata.rs (2)

30-31: Added constants for accumulated difficulty byte sizes.

Good practice to define constants for the byte sizes, making the code more maintainable and readable.


36-52: Updated deserialization for split accumulated difficulty.

The deserialization logic now properly validates both the low and high parts of the accumulated difficulty before concatenating them into the full U512 value.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 20, 2025

Test Results (CI)

    3 files     88 suites   41m 35s ⏱️
1 341 tests 1 336 ✅ 0 💤 5 ❌
2 461 runs  2 456 ✅ 0 💤 5 ❌

For more details on these failures, see this check.

Results for commit b576376.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 20, 2025

Test Results (Integration tests)

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 2f26dcd.

♻️ This comment has been updated with latest results.

@SWvheerden SWvheerden force-pushed the sw_update_consensus_nextnet branch from ec552e7 to 46c7792 Compare May 20, 2025 14:23
@SWvheerden SWvheerden force-pushed the sw_update_consensus_nextnet branch from f585172 to 14fc0ef Compare May 20, 2025 15:00
@SWvheerden SWvheerden merged commit 3152af2 into tari-project:development May 20, 2025
9 of 12 checks passed
@SWvheerden SWvheerden deleted the sw_update_consensus_nextnet branch May 20, 2025 15:03
@coderabbitai coderabbitai bot mentioned this pull request Jun 23, 2025
4 tasks
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.

2 participants