diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -457,6 +457,7 @@ interfaces/node.cpp merkleblock.cpp miner.cpp + minerfund.cpp net.cpp net_processing.cpp noui.cpp diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -161,6 +161,7 @@ memusage.h \ merkleblock.h \ miner.h \ + minerfund.h \ net.h \ net_processing.h \ netaddress.h \ @@ -277,6 +278,7 @@ dbwrapper.cpp \ merkleblock.cpp \ miner.cpp \ + minerfund.cpp \ net.cpp \ net_processing.cpp \ noui.cpp \ diff --git a/src/chainparams.cpp b/src/chainparams.cpp --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -109,6 +109,46 @@ // December 31, 2008 .nTimeout = 1230767999, }; + consensus.vDeployments[Consensus::DEPLOYEMENT_MINER_FUND] = { + .bit = 0, + // 66% of 2016 + .nActivationThreshold = 1344, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + consensus.vDeployments[Consensus::DEPLOYEMENT_MINER_FUND_ABC] = { + .bit = 1, + // 66% of 2016 + .nActivationThreshold = 1344, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + consensus.vDeployments[Consensus::DEPLOYEMENT_MINER_FUND_BCHD] = { + .bit = 2, + // 66% of 2016 + .nActivationThreshold = 1344, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + consensus + .vDeployments[Consensus::DEPLOYEMENT_MINER_FUND_ELECTRON_CASH] = { + .bit = 3, + // 66% of 2016 + .nActivationThreshold = 1344, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + + // The miner fund is enabled by default on mainnet. + consensus.enableMinerFund = true; // The best chain should have at least this much work. consensus.nMinimumChainWork = @@ -293,6 +333,46 @@ // December 31, 2008 .nTimeout = 1230767999, }; + consensus.vDeployments[Consensus::DEPLOYEMENT_MINER_FUND] = { + .bit = 0, + // 66% of 2016 + .nActivationThreshold = 1344, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + consensus.vDeployments[Consensus::DEPLOYEMENT_MINER_FUND_ABC] = { + .bit = 1, + // 66% of 2016 + .nActivationThreshold = 1344, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + consensus.vDeployments[Consensus::DEPLOYEMENT_MINER_FUND_BCHD] = { + .bit = 2, + // 66% of 2016 + .nActivationThreshold = 1344, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + consensus + .vDeployments[Consensus::DEPLOYEMENT_MINER_FUND_ELECTRON_CASH] = { + .bit = 3, + // 66% of 2016 + .nActivationThreshold = 1344, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + + // The miner fund is disabled by default on testnet. + consensus.enableMinerFund = false; // The best chain should have at least this much work. consensus.nMinimumChainWork = @@ -430,6 +510,46 @@ // 75% of 144 .nActivationThreshold = 108, }; + consensus.vDeployments[Consensus::DEPLOYEMENT_MINER_FUND] = { + .bit = 0, + // 66% of 144 + .nActivationThreshold = 96, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + consensus.vDeployments[Consensus::DEPLOYEMENT_MINER_FUND_ABC] = { + .bit = 1, + // 66% of 144 + .nActivationThreshold = 96, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + consensus.vDeployments[Consensus::DEPLOYEMENT_MINER_FUND_BCHD] = { + .bit = 2, + // 66% of 144 + .nActivationThreshold = 96, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + consensus + .vDeployments[Consensus::DEPLOYEMENT_MINER_FUND_ELECTRON_CASH] = { + .bit = 3, + // 66% of 144 + .nActivationThreshold = 96, + // Nov 15, 2019 12:00:00 UTC + .nStartTime = 1573819200, + // May 15, 2020 12:00:00 UTC + .nTimeout = 1589544000, + }; + + // 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/activation.h b/src/consensus/activation.h --- a/src/consensus/activation.h +++ b/src/consensus/activation.h @@ -8,7 +8,6 @@ #include class CBlockIndex; -class Config; namespace Consensus { struct Params; diff --git a/src/consensus/params.h b/src/consensus/params.h --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -15,8 +15,12 @@ enum DeploymentPos { DEPLOYMENT_TESTDUMMY, + DEPLOYEMENT_MINER_FUND, + DEPLOYEMENT_MINER_FUND_ABC, + DEPLOYEMENT_MINER_FUND_BCHD, + DEPLOYEMENT_MINER_FUND_ELECTRON_CASH, // NOTE: Also add new deployments to VersionBitsDeploymentInfo in - // versionbits.cpp + // versionbitsinfo.cpp MAX_VERSION_BITS_DEPLOYMENTS, }; @@ -89,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 @@ -326,7 +326,7 @@ "-rpcssl", "-benchmark", "-h", "-help", "-socks", "-tor", "-debugnet", "-whitelistalwaysrelay", "-blockminsize", "-dbcrashratio", "-forcecompactdb", "-usehd", "-parkdeepreorg", "-automaticunparking", - "-replayprotectionactivationtime", + "-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 @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -190,6 +191,15 @@ 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 = coinbaseTx.vout[0].nValue / MINER_FUND_RATIO; + 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,24 @@ +// 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