diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -503,6 +503,7 @@ interfaces/chain.cpp interfaces/node.cpp miner.cpp + minerfund.cpp net.cpp net_processing.cpp node/coin.cpp diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -181,6 +181,7 @@ memusage.h \ merkleblock.h \ miner.h \ + minerfund.h \ net.h \ net_permissions.h \ net_processing.h \ @@ -328,6 +329,7 @@ interfaces/node.cpp \ dbwrapper.cpp \ miner.cpp \ + minerfund.cpp \ net.cpp \ net_processing.cpp \ node/coin.cpp \ diff --git a/src/chainparams.cpp b/src/chainparams.cpp --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -112,6 +112,9 @@ .nTimeout = 1230767999, }; + // The miner fund is enabled by default on mainnet. + consensus.enableMinerFund = true; + // The best chain should have at least this much work. consensus.nMinimumChainWork = ChainParamsConstants::MAINNET_MINIMUM_CHAIN_WORK; @@ -313,6 +316,9 @@ .nTimeout = 1230767999, }; + // The miner fund is disabled by default on testnet. + consensus.enableMinerFund = false; + // The best chain should have at least this much work. consensus.nMinimumChainWork = ChainParamsConstants::TESTNET_MINIMUM_CHAIN_WORK; @@ -465,6 +471,9 @@ .nActivationThreshold = 108, }; + // The miner fund is disabled by default on regnet. + consensus.enableMinerFund = false; + // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x00"); diff --git a/src/consensus/params.h b/src/consensus/params.h --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -93,6 +93,9 @@ uint32_t nMinerConfirmationWindow; BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]; + /** Enable or disable te miner fund by default */ + bool enableMinerFund; + /** Proof of work parameters */ uint256 powLimit; bool fPowAllowMinDifficultyBlocks; diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -357,6 +357,7 @@ std::vector hidden_args = { "-h", "-help", "-dbcrashratio", "-forcecompactdb", "-parkdeepreorg", "-automaticunparking", "-replayprotectionactivationtime", + "-enableminerfund", // GUI args. These will be overwritten by SetupUIArgs for the GUI "-allowselfsignedrootcertificates", "-choosedatadir", "-lang=", "-min", "-resetguisettings", "-rootcertificates=", "-splash", diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -190,6 +191,16 @@ nFees + GetBlockSubsidy(nHeight, consensusParams); coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; + const std::vector whitelisted = + GetMinerFundWhitelist(consensusParams, pindexPrev); + if (!whitelisted.empty()) { + const Amount fund = + (MINER_FUND_RATIO * coinbaseTx.vout[0].nValue) / 100; + coinbaseTx.vout[0].nValue -= fund; + coinbaseTx.vout.emplace_back(fund, + GetScriptForDestination(whitelisted[0])); + } + // Make sure the coinbase is big enough. uint64_t coinbaseSize = ::GetSerializeSize(coinbaseTx, PROTOCOL_VERSION); if (coinbaseSize < MIN_TX_SIZE) { diff --git a/src/minerfund.h b/src/minerfund.h new file mode 100644 --- /dev/null +++ b/src/minerfund.h @@ -0,0 +1,27 @@ +// Copyright (c) 2020 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_MINERFUND_H +#define BITCOIN_MINERFUND_H + +#include