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

chore: kip9 version remove & test-11 payload active #210

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

witter-deland
Copy link
Contributor

@witter-deland witter-deland commented Dec 12, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new property for payload activation in consensus parameters.
  • Bug Fixes
    • Removed deprecated handling of KIP9 versioning across multiple classes, simplifying mass calculation logic.
  • Chores
    • Removed unused exports and files related to KIP9 versioning, streamlining the codebase.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes in this pull request involve multiple modifications across various files in the coin-kaspa package. Key alterations include updating constants, removing properties and parameters related to Kip9Version, and introducing a new property payloadActivation in the Params class. The kip module has been removed from exports, and several classes have had their methods simplified by eliminating version checks. Overall, these changes focus on streamlining the codebase by removing unnecessary dependencies and enhancing the clarity of mass calculation logic.

Changes

File Change Summary
packages/coin-kaspa/src/lib/consensus/config/constants/perf.ts Updated DEFAULT_REINDEX_SLACK from 1n << 12n to 1n << 14n.
packages/coin-kaspa/src/lib/consensus/config/network-params.ts Removed kip9Version from NetworkParams class; updated constructor and instances for various network parameters.
packages/coin-kaspa/src/lib/consensus/config/params.ts Added payloadActivation property to Params class; updated kip10Activation and payloadActivation in TESTNET11_PARAMS.
packages/coin-kaspa/src/lib/consensus/index.ts Removed export statement for kip module.
packages/coin-kaspa/src/lib/consensus/kip/index.ts Deleted file, removing all exports from kip9.
packages/coin-kaspa/src/lib/consensus/kip/kip9.ts Removed Kip9Version enum.
packages/coin-kaspa/src/lib/tx/generator/genrator.ts Simplified massCalculator initialization; removed Kip9Version import and related logic in calculateMass.
packages/coin-kaspa/src/lib/tx/mass/signed-tx-mass-calc.ts Removed Kip9Version parameter from calcTxStorageMass and calcTxOverallMass methods.
packages/coin-kaspa/src/lib/tx/mass/storage-mass-calc.ts Removed version parameter from calcStorageMass method.
packages/coin-kaspa/src/lib/tx/mass/unsigned-tx-mass-calc.ts Removed networkParams parameter from constructor; simplified version handling in combineMass.

Poem

In the code where rabbits play,
Constants change, and old ways sway.
No more Kip9 to hold us tight,
We hop along, with code in sight.
New paths we carve, with joy we sing,
Simpler ways make our hearts take wing! 🐇✨


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

Copy link

Deploy preview for hibit-id ready!

✅ Preview
https://hibit-p92zvernw-delandlabs-projects.vercel.app

Built with commit 7f7ea8b.
This pull request is being automatically deployed with vercel-action

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 (5)
packages/coin-kaspa/src/lib/tx/mass/storage-mass-calc.ts (1)

Line range hint 31-35: Document the optimization condition rationale

The condition for optimized mass calculation path should be documented to explain why these specific cases (outsLen === 1n || insLen === 1n || (outsLen === 2n && insLen === 2n)) are handled differently.

Consider adding a comment explaining the rationale:

+  // Optimize mass calculation for common transaction patterns:
+  // - Single input or output transactions
+  // - Two inputs and two outputs (common in standard transactions)
   if (outsLen === 1n || insLen === 1n || (outsLen === 2n && insLen === 2n)) {
packages/coin-kaspa/src/lib/consensus/config/network-params.ts (1)

64-84: Consider extracting network parameters to a configuration file

The network parameters are currently hardcoded in the source code. Consider moving them to a configuration file for better maintainability and easier updates.

Example structure:

// network-config.ts
export const NETWORK_CONFIGS = {
  mainnet: {
    coinbaseTransactionMaturityPeriodDaa: 100n,
    coinbaseTransactionStasisPeriodDaa: 50n,
    userTransactionMaturityPeriodDaa: 10n,
    additionalCompoundTransactionMass: 100n
  },
  testnet11: {
    // ... testnet11 specific values
  },
  // ... other networks
};
packages/coin-kaspa/src/lib/consensus/config/params.ts (1)

430-431: Consider adding timezone information in the comment.

The comment about the activation date could be more specific by including the timezone in a standardized format.

-  // Roughly at Dec 3, 2024 1800 UTC
+  // Activation time: 2024-12-03T18:00:00Z
packages/coin-kaspa/src/lib/tx/generator/genrator.ts (2)

Line range hint 684-692: Add documentation for the storage mass calculation logic

While the code is functionally correct, it would benefit from documentation explaining the business logic behind the condition storageMassWithChange === 0n || storageMassWithChange < computeMassWithChange. This would help future maintainers understand why this specific comparison is important for the mass calculation.

+          // If storage mass is zero or less than compute mass, we don't need to
+          // consider additional fees for storage mass in the transaction
           if (storageMassWithChange === 0n || storageMassWithChange < computeMassWithChange) {
             return 0n;
           } else {

Line range hint 1-800: Consider breaking down the Generator class

The Generator class is quite large and handles multiple responsibilities. Consider splitting it into smaller, more focused classes:

  1. MassCalculator: Extract mass calculation logic
  2. TransactionBuilder: Handle transaction construction
  3. UTXOManager: Handle UTXO selection and management

This would improve maintainability and testability of the codebase.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37ac1c3 and 7f7ea8b.

📒 Files selected for processing (10)
  • packages/coin-kaspa/src/lib/consensus/config/constants/perf.ts (1 hunks)
  • packages/coin-kaspa/src/lib/consensus/config/network-params.ts (1 hunks)
  • packages/coin-kaspa/src/lib/consensus/config/params.ts (2 hunks)
  • packages/coin-kaspa/src/lib/consensus/index.ts (0 hunks)
  • packages/coin-kaspa/src/lib/consensus/kip/index.ts (0 hunks)
  • packages/coin-kaspa/src/lib/consensus/kip/kip9.ts (0 hunks)
  • packages/coin-kaspa/src/lib/tx/generator/genrator.ts (3 hunks)
  • packages/coin-kaspa/src/lib/tx/mass/signed-tx-mass-calc.ts (2 hunks)
  • packages/coin-kaspa/src/lib/tx/mass/storage-mass-calc.ts (1 hunks)
  • packages/coin-kaspa/src/lib/tx/mass/unsigned-tx-mass-calc.ts (3 hunks)
💤 Files with no reviewable changes (3)
  • packages/coin-kaspa/src/lib/consensus/index.ts
  • packages/coin-kaspa/src/lib/consensus/kip/kip9.ts
  • packages/coin-kaspa/src/lib/consensus/kip/index.ts
🔇 Additional comments (8)
packages/coin-kaspa/src/lib/consensus/config/constants/perf.ts (1)

5-5: Verify the 4x increase in reindex slack

The DEFAULT_REINDEX_SLACK has been increased from 1n << 12n to 1n << 14n, which quadruples the slack interval. This could impact the reachability algorithm's performance when handling blocks outside the selected chain.

Please confirm if this significant increase is intentional and required. Consider documenting the rationale for this change.

packages/coin-kaspa/src/lib/consensus/config/network-params.ts (1)

74-74: Verify increased maturity periods for TESTNET11

TESTNET11 has significantly higher maturity periods compared to other networks:

  • Coinbase maturity: 1000n vs 100n (10x increase)
  • Coinbase stasis: 500n vs 50n (10x increase)
  • User transaction maturity: 100n vs 10n (10x increase)

These increases will result in longer confirmation times for transactions on TESTNET11.

Please confirm if these increased periods are intentional and document the rationale for this change.

packages/coin-kaspa/src/lib/tx/mass/signed-tx-mass-calc.ts (2)

82-87: LGTM! Method signature simplified.

The removal of the Kip9Version parameter streamlines the method while maintaining its core functionality.


97-101: LGTM! Mass calculation logic simplified.

The simplified logic maintains the correct behavior of selecting the larger mass between storage and compute mass, while removing unnecessary version-specific branching.

packages/coin-kaspa/src/lib/tx/mass/unsigned-tx-mass-calc.ts (1)

174-174: LGTM! Mass combination logic simplified.

The simplified logic correctly maintains the behavior of selecting the larger mass while removing version-specific handling.

packages/coin-kaspa/src/lib/consensus/config/params.ts (2)

51-52: LGTM! New property well documented.

The payloadActivation property is properly documented with a clear description of its purpose.


429-432: Verify the implications of shared activation timestamp.

Both kip10Activation and payloadActivation are set to activate at the same timestamp (Dec 3, 2024 1800 UTC). Please confirm if this simultaneous activation is intentional and if there are any dependencies between these features that need to be considered.

✅ Verification successful

Let me gather more information about these features to better understand their relationship and implementation.


Let me gather more specific information about these features and their dependencies.


Based on the gathered information, I can now provide a final response:

Simultaneous activation of KIP10 and payload features appears intentional and safe.

The code review reveals that:

  1. Both features are part of the network's consensus parameters and are managed through the ForkActivation mechanism
  2. There are no direct dependencies or conditional relationships between these features in the codebase
  3. The payload feature is related to transaction payload fields, while KIP10 appears to be a separate protocol upgrade
  4. Both are being activated at block height 287238000 (Dec 3, 2024 1800 UTC) in a coordinated network upgrade
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any dependencies between kip10 and payload features
rg -l "kip10.*payload|payload.*kip10" --type ts

# Search for any existing payload-related code that might be affected
rg "payload.*activation" --type ts

Length of output: 210


Script:

#!/bin/bash
# Search for kip10 related code and its usage
rg "kip10" --type ts -A 3

# Search for payload related implementations
rg "payload" --type ts -A 3

# Look for any configuration or documentation about these features
fd "README|CHANGELOG" -e md -X cat

Length of output: 56058


Script:

#!/bin/bash
# Search for any code that checks or uses these activation flags
ast-grep --pattern 'if ($$$kip10Activation$$$) { $$$ }'
ast-grep --pattern 'if ($$$payloadActivation$$$) { $$$ }'

# Look for any tests or documentation related to these features
rg -A 3 "kip10.*activation|payload.*activation" --type ts --type md

Length of output: 1041

packages/coin-kaspa/src/lib/tx/generator/genrator.ts (1)

123-123: LGTM: Simplified massCalculator initialization

The initialization has been improved by deriving params directly from networkId, making the code more maintainable.

@witter-deland witter-deland merged commit 4a575de into main Dec 12, 2024
1 check passed
@witter-deland witter-deland deleted the remove-kip9-params branch December 12, 2024 09:35
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.

1 participant