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

[For Discuss] Implement concept of DFIPS 1 Hard Fork #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ class CMainParams : public CChainParams {
consensus.foundationShare = 10;
consensus.foundationMembers.clear();

consensus.DFIP1Height = 300000;
consensus.foundationSharePercentageDFIP1 = 9.95; // Change from 10% to 9.95%
consensus.anchorRewardPertentage = 0.05; // 0.05%, If block reward is 200, anchor reward 0.1

// owner base58, operator base58
vMasternodes.push_back({"8PuErAcazqccCVzRcc8vJ3wFaZGm4vFbLe", "8J846CKFF83Jcj5m4EReJmxiaJ6Jy1Y6Ea"});
vMasternodes.push_back({"8RPZm7SVUNhGN1RgGY3R92rvRkZBwETrCX", "8bzHwhaF2MaVs4owRvpWtZQVug3mKuJji2"});
Expand Down Expand Up @@ -329,6 +333,10 @@ class CTestNetParams : public CChainParams {
consensus.foundationShare = 10;
consensus.foundationMembers.clear();

consensus.DFIP1Height = 300000;
consensus.foundationSharePercentageDFIP1 = 9.95; // Change from 10% to 9.95%
consensus.anchorRewardPertentage = 0.05; // 0.05%, If block reward is 200, anchor reward 0.1

// owner base58, operator base58
vMasternodes.push_back({"7LMorkhKTDjbES6DfRxX2RiNMbeemUkxmp", "7KEu9JMKCx6aJ9wyg138W3p42rjg19DR5D"});
vMasternodes.push_back({"7E8Cjn9cqEwnrc3E4zN6c5xKxDSGAyiVUM", "78MWNEcAAJxihddCw1UnZD8T7fMWmUuBro"});
Expand Down Expand Up @@ -450,6 +458,10 @@ class CDevNetParams : public CChainParams {
consensus.foundationShareScript = GetScriptForDestination(DecodeDestination("7Q2nZCcKnxiRiHSNQtLB27RA5efxm2cE7w", *this));
consensus.foundationShare = 10;

consensus.DFIP1Height = 300000;
consensus.foundationSharePercentageDFIP1 = 9.95; // Change from 10% to 9.95%
consensus.anchorRewardPertentage = 0.05; // 0.05%, If block reward is 200, anchor reward 0.1

// now it is for devnet and regtest only, 2 first of genesis MNs acts as foundation members
consensus.foundationMembers.emplace(GetScriptForDestination(DecodeDestination("7M3g9CSERjLdXisE5pv2qryDbURUj9Vpi1", *this)));
consensus.foundationMembers.emplace(GetScriptForDestination(DecodeDestination("7L29itepC13pgho1X2y7mcuf4WjkBi7x2w", *this)));
Expand Down Expand Up @@ -579,6 +591,10 @@ class CRegTestParams : public CChainParams {
consensus.foundationShareScript.clear();
consensus.foundationShare = 0;

consensus.DFIP1Height = 300000;
consensus.foundationSharePercentageDFIP1 = 9.95; // Change from 10% to 9.95%
consensus.anchorRewardPertentage = 0.05; // 0.05%, If block reward is 200, anchor reward 0.1

// now it is for devnet and regtest only, 2 first and 2 last of genesis MNs acts as foundation members
consensus.foundationMembers.emplace(GetScriptForDestination(DecodeDestination("mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU", *this)));
consensus.foundationMembers.emplace(GetScriptForDestination(DecodeDestination("msER9bmJjyEemRpQoS8YYVL21VyZZrSgQ7", *this)));
Expand Down
13 changes: 13 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ struct Params {
* BIP 16 exception blocks. */
int SegwitHeight;

/** Block height at which DFIP1 becomes active */
int DFIP1Height;

/** The address for anchor reward */
CScript anchorRewardScript;

/** The community foundation reward percentage in DFIP1 */
float foundationSharePercentageDFIP1;

/** Percentage of shares go to anchor reward, the DFI is
* baseBlockSubsidy * anchorRewardPertentage / 100 */
float anchorRewardPertentage;

/** Proof of stake parameters */
struct PoS {
uint256 diffLimit;
Expand Down
49 changes: 38 additions & 11 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,46 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
coinbaseTx.vout.resize(1);
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
// Pinch off foundation share
CAmount foundationsReward = coinbaseTx.vout[0].nValue * chainparams.GetConsensus().foundationShare / 100;
if (!chainparams.GetConsensus().foundationShareScript.empty() && chainparams.GetConsensus().foundationShare != 0) {
if (pcustomcsview->GetFoundationsDebt() < foundationsReward) {
coinbaseTx.vout.resize(2);
coinbaseTx.vout[1].scriptPubKey = chainparams.GetConsensus().foundationShareScript;
coinbaseTx.vout[1].nValue = foundationsReward - pcustomcsview->GetFoundationsDebt();
coinbaseTx.vout[0].nValue -= coinbaseTx.vout[1].nValue;
} else {
pcustomcsview->SetFoundationsDebt(pcustomcsview->GetFoundationsDebt() - foundationsReward);
const auto nTotalRewards = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
coinbaseTx.vout[0].nValue = nTotalRewards;

if (nHeight >= chainparams.GetConsensus().DFIP1Height)
{
// Implement DFIPS1 here, using foundationSharePercentageDFIP1 instead of
CAmount foundationsReward = nTotalRewards * chainparams.GetConsensus().foundationSharePercentageDFIP1 / 100;
if (!chainparams.GetConsensus().foundationShareScript.empty() && foundationsReward != 0) {
if (pcustomcsview->GetFoundationsDebt() < foundationsReward) {
coinbaseTx.vout.resize(2);
coinbaseTx.vout[1].scriptPubKey = chainparams.GetConsensus().foundationShareScript;
coinbaseTx.vout[1].nValue = foundationsReward - pcustomcsview->GetFoundationsDebt();
coinbaseTx.vout[0].nValue -= coinbaseTx.vout[1].nValue;
} else {
pcustomcsview->SetFoundationsDebt(pcustomcsview->GetFoundationsDebt() - foundationsReward);
}
}

const CAmount anchorReward = nTotalRewards * chainparams.GetConsensus().anchorRewardPertentage / 100;
if (!chainparams.GetConsensus().anchorRewardScript.empty() && anchorReward != 0) {
coinbaseTx.vout.resize(coinbaseTx.vout.size() + 1);
coinbaseTx.vout.back().scriptPubKey = chainparams.GetConsensus().anchorRewardScript;
coinbaseTx.vout.back().nValue = anchorReward;
coinbaseTx.vout[0].nValue -= coinbaseTx.vout.back().nValue;
}
}
else
{
// Pinch off foundation share
CAmount foundationsReward = coinbaseTx.vout[0].nValue * chainparams.GetConsensus().foundationShare / 100;
if (!chainparams.GetConsensus().foundationShareScript.empty() && chainparams.GetConsensus().foundationShare != 0) {
if (pcustomcsview->GetFoundationsDebt() < foundationsReward) {
coinbaseTx.vout.resize(2);
coinbaseTx.vout[1].scriptPubKey = chainparams.GetConsensus().foundationShareScript;
coinbaseTx.vout[1].nValue = foundationsReward - pcustomcsview->GetFoundationsDebt();
coinbaseTx.vout[0].nValue -= coinbaseTx.vout[1].nValue;
} else {
pcustomcsview->SetFoundationsDebt(pcustomcsview->GetFoundationsDebt() - foundationsReward);
}
}
}

pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
Expand Down