firoorg / firo

The privacy-focused cryptocurrency
https://firo.org
MIT License
720 stars 354 forks source link

Spark coinbase #1494

Open levonpetrosyan93 opened 2 weeks ago

levonpetrosyan93 commented 2 weeks ago

Spark coinbase implementation After HF block there is allowed to create coinbase transactions with spark outputs. It supports also masternode owners to put spark address as payout address. for this we need to make k value public inside spark coin to allow verify that the con is generated to the right address, for other spark coinsk is not supposed to be public, otherwise it will break privacy, We also implemented immature period for spark coinbase outputs, it is the same as regular coinbase outputs, 100 blocks,

coderabbitai[bot] commented 2 weeks ago

Walkthrough

The changes in this pull request introduce significant updates to the blockchain's handling of Spark transactions, including modifications to data structures, serialization logic, and transaction validation. Key updates include the introduction of new consensus parameters for Spark, enhancements to the CBlockIndex class to manage minted coins with boolean flags, and the integration of Spark address handling throughout various components, including wallets and RPC functions. Additionally, the wallet's transaction management has been refined to accommodate Spark and Lelantus features, ensuring robust validation and error handling.

Changes

File Change Summary
src/chain.h Updated sparkMintedCoins from std::map<int, std::vector<spark::Coin>> to std::map<int, std::vector<std::pair<spark::Coin, bool>>>. Added conditional serialization logic based on block height.
src/chainparams.cpp Added consensus.nSparkStartBlock and consensus.nSparkCoinbase to CMainParams, CTestNetParams, CDevNetParams, and CRegTestParams. Added Lelantus and Sigma parameters.
src/consensus/params.h Introduced int nSparkCoinbase to Params struct.
src/evo/deterministicmns.cpp Enhanced ToString and ToJson methods in CDeterministicMNState to handle payout addresses using spark::ToStringSparkAddress.
src/evo/providertx.cpp Updated CheckProRegTx, CheckProUpServTx, and CheckProUpRegTx functions to validate payout scripts as Spark addresses. Modified ToString and ToJson methods for Spark address representation.
src/libspark/coin.cpp Updated Coin constructor to accept COIN_TYPE_COINBASE. Added isValidMNPayment method. Enhanced handling for coin types.
src/libspark/coin.h Added const char COIN_TYPE_COINBASE = 2; and updated serialization logic to include this new type.
src/libspark/keys.cpp Added toByteVector and fromByteVector methods to Address class for address conversion.
src/libspark/keys.h Added declarations for toByteVector and fromByteVector methods in Address class.
src/libspark/mint_transaction.cpp Updated MintTransaction constructor to accept output.type for flexible coin types.
src/libspark/mint_transaction.h Added char type to MintedCoinData struct.
src/masternode-payments.cpp Commented out IsOldBudgetBlockValueValid. Simplified IsBlockValueValid. Enhanced GetRequiredPaymentsString and logging in GetMasternodeTxOuts. Expanded IsTransactionValid to include mint outputs.
src/miner.cpp Enhanced CreateNewBlock to process Spark-related outputs and create Spark mint recipients.
src/qt/masternodelist.cpp Added support for Spark addresses in masternode handling. Introduced variables for parameters and network type.
src/qt/walletmodel.cpp Added validateSparkAddress method. Introduced methods for minting and spending Spark coins. Enhanced error handling in transaction preparation methods.
src/rpc/mining.cpp Enhanced handling of masternode payments and integrated Spark address support in mining RPC functions.
src/rpc/rpcevo.cpp Introduced parseSparkAddress function for Spark address validation. Updated protx_register, protx_update_service, and protx_revoke functions to handle Spark addresses.
src/spark/sparkwallet.cpp Updated CSparkWallet constructor to accept height. Modified balance calculation methods to consider coin maturity.
src/spark/sparkwallet.h Updated constructor to require uint32_t height. Changed RemoveSparkMints method to accept pairs of coins and boolean flags.
src/spark/state.cpp Updated CheckSparkMintTransaction to include isCoinbase parameter. Added functions for Spark address validation and conversion. Enhanced CheckSparkSpendTransaction.
src/spark/state.h Updated CSparkTxInfo to store mints as pairs with boolean flags. Added functions for Spark address handling.
src/test/spark_state_test.cpp Updated PopulateSparkTxInfo method to accept pairs of coins and boolean flags. Adjusted test cases accordingly.
src/test/spark_tests.cpp Enhanced tests for Spark transactions, improved error handling, and refined state management in tests.
src/test/test_bitcoin.cpp Updated CSparkWallet instantiation in TestingSetup to include height parameter.
src/validation.cpp Enhanced CheckTransaction and AcceptToMemoryPool to include checks for Spark transactions.
src/wallet/wallet.cpp Updated transaction handling to accommodate Spark and Lelantus features. Added methods for listing and creating Spark transactions.
src/wallet/wallet.h Added static const bool DEFAULT_SPARK_REWARD.

Possibly related PRs

Suggested reviewers

Poem

In the burrows of code, where the changes take flight,
Spark coins now shimmer, a beautiful sight.
With mints and new types, our blockchain's aglow,
Hopping through logic, where bright ideas flow.
So here’s to our updates, both clever and bright,
A leap for the future, in the soft moonlight! 🐇✨


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.