Skip to content

Commit

Permalink
Change interval between blocks to 2.5 minutes (#1176)
Browse files Browse the repository at this point in the history
* Set time between block to 2.5 minutes

* Regtest changes for shorter block distance

* Bug fix

* Testnet/Devnet developments and community addresses

* Devnet stage3 start time

* Testnet stage3 start time
  • Loading branch information
psolstice authored May 26, 2022
1 parent 4ac8771 commit 1b4e9e6
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 60 deletions.
40 changes: 36 additions & 4 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ class CMainParams : public CChainParams {
consensus.stage2ZnodeShare = 35;
consensus.stage2DevelopmentFundAddress = "aFrAVZFr8pva5mG8XKaUH8EXcFVVNxLiuB";

consensus.stage3StartTime = 1655380800; // Thursday, 16 June 2022 12:00:00 UTC
consensus.stage3DevelopmentFundShare = 15;
consensus.stage3CommunityFundShare = 10;
consensus.stage3MasternodeShare = 50;
consensus.stage3DevelopmentFundAddress = "aLgRaYSFk6iVw2FqY1oei8Tdn2aTsGPVmP";
consensus.stage3CommunityFundAddress = "aFA2TbqG9cnhhzX5Yny2pBJRK5EaEqLCH7";

consensus.nStartBlacklist = 293990;
consensus.nStartDuplicationCheck = 293526;

Expand Down Expand Up @@ -445,6 +452,7 @@ class CMainParams : public CChainParams {

// ProgPow
consensus.nPPSwitchTime = 1635228000; // Tue Oct 26 2021 06:00:00 GMT+0000
consensus.nPPBlockNumber = 419264;
consensus.nInitialPPDifficulty = 0x1b1774cd; // 40GH/s
}
virtual bool SkipUndoForBlock(int nHeight) const
Expand Down Expand Up @@ -482,13 +490,20 @@ class CTestNetParams : public CChainParams {
consensus.chainType = Consensus::chainTestnet;

consensus.nSubsidyHalvingFirst = 12000;
consensus.nSubsidyHalvingInterval = 100000;
consensus.nSubsidyHalvingInterval = 150000;
consensus.nSubsidyHalvingStopBlock = 1000000;

consensus.stage2DevelopmentFundShare = 15;
consensus.stage2ZnodeShare = 35;
consensus.stage2DevelopmentFundAddress = "TUuKypsbbnHHmZ2auC2BBWfaP1oTEnxjK2";

consensus.stage3StartTime = 1653409800; // May 24th 2022 04:30 UTC
consensus.stage3DevelopmentFundShare = 15;
consensus.stage3CommunityFundShare = 10;
consensus.stage3MasternodeShare = 50;
consensus.stage3DevelopmentFundAddress = "TWDxLLKsFp6qcV1LL4U2uNmW4HwMcapmMU";
consensus.stage3CommunityFundAddress = "TCkC4uoErEyCB4MK3d6ouyJELoXnuyqe9L";

consensus.nStartBlacklist = 0;
consensus.nStartDuplicationCheck = 0;
consensus.nMajorityEnforceBlockUpgrade = 51;
Expand Down Expand Up @@ -720,6 +735,7 @@ class CTestNetParams : public CChainParams {

// ProgPow
consensus.nPPSwitchTime = 1630069200; // August 27 2021, 13:00 UTC
consensus.nPPBlockNumber = 37305;
consensus.nInitialPPDifficulty = 0x1d016e81; // 10MH/s
}
};
Expand All @@ -744,6 +760,13 @@ class CDevNetParams : public CChainParams {
consensus.stage2ZnodeShare = 35;
consensus.stage2DevelopmentFundAddress = "TixHByoJ21dmx5xfMAXTVC4V7k53U7RncU";

consensus.stage3StartTime = 1653382800;
consensus.stage3DevelopmentFundShare = 15;
consensus.stage3CommunityFundShare = 10;
consensus.stage3MasternodeShare = 50;
consensus.stage3DevelopmentFundAddress = "TepVKkmUo1N6sazuM2wWwV7aiG4m1BUShU";
consensus.stage3CommunityFundAddress = "TZpbhfvQE61USHsxd55XdPpWBqu3SXB1EP";

consensus.nStartBlacklist = 0;
consensus.nStartDuplicationCheck = 0;
consensus.nMajorityEnforceBlockUpgrade = 51;
Expand Down Expand Up @@ -937,6 +960,7 @@ class CDevNetParams : public CChainParams {

// ProgPow
consensus.nPPSwitchTime = 1631261566; // immediately after network start
consensus.nPPBlockNumber = 1;
consensus.nInitialPPDifficulty = 0x2000ffff;
}
};
Expand All @@ -954,15 +978,22 @@ class CRegTestParams : public CChainParams {
consensus.chainType = Consensus::chainRegtest;

// To be changed for specific tests
consensus.nSubsidyHalvingFirst = 302438;
consensus.nSubsidyHalvingInterval = 420000;
consensus.nSubsidyHalvingStopBlock = 3646849;
consensus.nSubsidyHalvingFirst = 1500;
consensus.nSubsidyHalvingInterval = 1000;
consensus.nSubsidyHalvingStopBlock = 10000;

consensus.nStartBlacklist = 0;
consensus.nStartDuplicationCheck = 0;
consensus.stage2DevelopmentFundShare = 15;
consensus.stage2ZnodeShare = 35;

consensus.stage3StartTime = INT_MAX; // Thursday, 16 June 2022 12:00:00 UTC
consensus.stage3DevelopmentFundShare = 15;
consensus.stage3CommunityFundShare = 10;
consensus.stage3MasternodeShare = 50;
consensus.stage3DevelopmentFundAddress = "TGEGf26GwyUBE2P2o2beBAfE9Y438dCp5t"; // private key cMrz8Df36VR9TvZjtvSqLPhUQR7pcpkXRXaLNYUxfkKsRuCzHpAN
consensus.stage3CommunityFundAddress = "TJmPzeJF4DECrBwUftc265U7rTPxKmpa4F"; // private key cTyPWqTMM1CgT5qy3K3LSgC1H6Q2RHvnXZHvjWtKB4vq9qXqKmMu

consensus.nMajorityEnforceBlockUpgrade = 750;
consensus.nMajorityRejectBlockOutdated = 950;
consensus.nMajorityWindow = 1000;
Expand Down Expand Up @@ -1155,6 +1186,7 @@ class CRegTestParams : public CChainParams {
// ProgPow
// this can be overridden with either -ppswitchtime or -ppswitchtimefromnow flags
consensus.nPPSwitchTime = INT_MAX;
consensus.nPPBlockNumber = INT_MAX;
consensus.nInitialPPDifficulty = 0x2000ffff;
}

Expand Down
18 changes: 17 additions & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,28 @@ struct Params {
/** Stop subsidy at this block number */
int nSubsidyHalvingStopBlock;

/** parameters for coinbase payment distribution between first and second halvings (aka stage 2) */
/** parameters for coinbase payment distribution between first halving and stage 3 (aka stage 2) */
/** P2PKH or P2SH address for developer funds */
std::string stage2DevelopmentFundAddress;
/** percentage of block subsidy going to developer fund */
int stage2DevelopmentFundShare;
/** percentage of block subsidy going to znode */
int stage2ZnodeShare;

/** parameters for coinbase payment distribution after stage two and before second halving (aka stage 3) */
/** start time of stage 3 */
int stage3StartTime;
/** P2PKH or P2SH address for developer funds */
std::string stage3DevelopmentFundAddress;
/** P2PKH or P2SH address for community funds */
std::string stage3CommunityFundAddress;
/** percentage of block subsidy going to developer fund */
int stage3DevelopmentFundShare;
/** percentage of block subsidy going to community fund */
int stage3CommunityFundShare;
/** percentage of block subsidy going to masternode */
int stage3MasternodeShare;

int nStartDuplicationCheck;
int nStartBlacklist;

Expand Down Expand Up @@ -314,6 +328,8 @@ struct Params {
uint32_t nPPSwitchTime;
/** initial difficulty for ProgPOW */
int nInitialPPDifficulty;
/** block height at the moment of PP transition (0 if unknown) */
int nPPBlockNumber;

/** don't adjust difficulty until some block number */
int nDifficultyAdjustStartBlock;
Expand Down
7 changes: 6 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
nMaxOutboundLimit = GetArg("-maxuploadtarget", DEFAULT_MAX_UPLOAD_TARGET)*1024*1024;
}

// ********************************************************* Prepare ProgPow/MTP tests
// ********************************************************* Prepare ProgPow/MTP/Stage3 tests

Consensus::Params &mutableParams = const_cast<Consensus::Params &>(Params().GetConsensus());
if (Params().GetConsensus().IsRegtest()) {
Expand All @@ -1701,6 +1701,11 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
mutableParams.nMTPSwitchTime = GetArg("-mtpswitchtime", INT_MAX);
else if (IsArgSet("-mtpswitchtimefromnow"))
mutableParams.nMTPSwitchTime = GetArg("-mtpswitchtimefromnow", 0) + (uint32_t)GetTime();

else if (IsArgSet("-stage3switchtime"))
mutableParams.stage3StartTime = GetArg("-stage3switchtime", INT_MAX);
else if (IsArgSet("-stage3switchtimefromnow"))
mutableParams.stage3StartTime = GetArg("-stage3switchtimefromnow", 0) + (uint32_t)GetTime();
}

if (IsArgSet("-mtpstripdatatime"))
Expand Down
20 changes: 10 additions & 10 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool IsBlockValueValid(const CBlock& block, int nBlockHeight, CAmount blockRewar
return isBlockRewardValueMet;
}

bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward)
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, int nTime, CAmount blockReward)
{
if(fLiteMode) {
//there is no budget data to use to check anything, let's just accept the longest chain
Expand All @@ -101,7 +101,7 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount bloc
const Consensus::Params& consensusParams = Params().GetConsensus();

// Check for correct masternode payment
if(mnpayments.IsTransactionValid(txNew, nBlockHeight, blockReward)) {
if(mnpayments.IsTransactionValid(txNew, nBlockHeight, nTime, blockReward)) {
LogPrint("mnpayments", "%s -- Valid znode payment at height %d: %s", __func__, nBlockHeight, txNew.ToString());
return true;
}
Expand All @@ -110,9 +110,9 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount bloc
return false;
}

void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet, std::vector<CTxOut>& /*voutSuperblockPaymentsRet*/)
void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, int nTime, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet, std::vector<CTxOut>& /*voutSuperblockPaymentsRet*/)
{
if (!mnpayments.GetMasternodeTxOuts(nBlockHeight, blockReward, voutMasternodePaymentsRet)) {
if (!mnpayments.GetMasternodeTxOuts(nBlockHeight, nTime, blockReward, voutMasternodePaymentsRet)) {
LogPrint("mnpayments", "%s -- no znode to pay (MN list probably empty)\n", __func__);
}

Expand Down Expand Up @@ -188,12 +188,12 @@ std::map<int, std::string> GetRequiredPaymentsStrings(int nStartHeight, int nEnd
* Get masternode payment tx outputs
*/

bool CMasternodePayments::GetMasternodeTxOuts(int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const
bool CMasternodePayments::GetMasternodeTxOuts(int nBlockHeight, int nTime, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const
{
// make sure it's not filled yet
voutMasternodePaymentsRet.clear();

if(!GetBlockTxOuts(nBlockHeight, blockReward, voutMasternodePaymentsRet)) {
if(!GetBlockTxOuts(nBlockHeight, nTime, blockReward, voutMasternodePaymentsRet)) {
LogPrintf("CMasternodePayments::%s -- no payee (deterministic znode list empty)\n", __func__);
return false;
}
Expand All @@ -209,14 +209,14 @@ bool CMasternodePayments::GetMasternodeTxOuts(int nBlockHeight, CAmount blockRew
return true;
}

bool CMasternodePayments::GetBlockTxOuts(int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const
bool CMasternodePayments::GetBlockTxOuts(int nBlockHeight, int nTime, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const
{
voutMasternodePaymentsRet.clear();
if (nBlockHeight == 0) {
return false;
}

CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockReward);
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, nTime, blockReward);

const CBlockIndex* pindex;
{
Expand Down Expand Up @@ -260,15 +260,15 @@ bool CMasternodePayments::IsScheduled(const CDeterministicMNCPtr& dmnIn, int nNo
return false;
}

bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward) const
bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight, int nTime, CAmount blockReward) const
{
if (!deterministicMNManager->IsDIP3Enforced(nBlockHeight)) {
// can't verify historical blocks here
return true;
}

std::vector<CTxOut> voutMasternodePayments;
if (!GetBlockTxOuts(nBlockHeight, blockReward, voutMasternodePayments)) {
if (!GetBlockTxOuts(nBlockHeight, nTime, blockReward, voutMasternodePayments)) {
LogPrintf("CMasternodePayments::%s -- ERROR failed to get payees for block at height %s\n", __func__, nBlockHeight);
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class CMasternodePayments;

/// TODO: all 4 functions do not belong here really, they should be refactored/moved somewhere (main.cpp ?)
bool IsBlockValueValid(const CBlock& block, int nBlockHeight, CAmount blockReward, std::string& strErrorRet);
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet, std::vector<CTxOut>& voutSuperblockPaymentsRet);
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, int nTime, CAmount blockReward);
void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, int nTime, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet, std::vector<CTxOut>& voutSuperblockPaymentsRet);
std::map<int, std::string> GetRequiredPaymentsStrings(int nStartHeight, int nEndHeight);

extern CMasternodePayments mnpayments;
Expand All @@ -31,11 +31,11 @@ extern CMasternodePayments mnpayments;
class CMasternodePayments
{
public:
bool GetBlockTxOuts(int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const;
bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward) const;
bool GetBlockTxOuts(int nBlockHeight, int nTime, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const;
bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight, int nTime, CAmount blockReward) const;
bool IsScheduled(const CDeterministicMNCPtr& dmn, int nNotBlockHeight) const;

bool GetMasternodeTxOuts(int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const;
bool GetMasternodeTxOuts(int nBlockHeight, int nTime, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const;
};

#endif
34 changes: 26 additions & 8 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc

pblock->nTime = GetAdjustedTime();
bool fMTP = (pblock->nTime >= params.nMTPSwitchTime);
bool fShorterBlockDistance = (pblock->nTime >= params.stage3StartTime);
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();

pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()) | (fMTP ? 0x1000 : 0);
Expand Down Expand Up @@ -248,7 +249,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
coinbaseTx.vout[0].nValue = nFees + nBlockSubsidy;
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;

FillFoundersReward(coinbaseTx, fMTP);
FillFoundersReward(coinbaseTx, fMTP, fShorterBlockDistance);

if (fDIP0003Active_context) {
coinbaseTx.vin[0].scriptSig = CScript() << OP_RETURN;
Expand Down Expand Up @@ -281,7 +282,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
}

std::vector<CTxOut> sbPayments;
FillBlockPayments(coinbaseTx, nHeight, nBlockSubsidy, pblocktemplate->voutMasternodePayments, sbPayments);
FillBlockPayments(coinbaseTx, nHeight, pblock->nTime, nBlockSubsidy, pblocktemplate->voutMasternodePayments, sbPayments);

pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
pblocktemplate->vTxFees[0] = -nFees;
Expand Down Expand Up @@ -800,17 +801,34 @@ void BlockAssembler::addPriorityTxs()
fNeedSizeAccounting = fSizeAccounting;
}

void BlockAssembler::FillFoundersReward(CMutableTransaction &coinbaseTx, bool fMTP) {
void BlockAssembler::FillFoundersReward(CMutableTransaction &coinbaseTx, bool fMTP, bool fShorterBlockDistance) {
const auto &params = chainparams.GetConsensus();
CAmount coin = COIN / (fMTP ? params.nMTPRewardReduction : 1);
if (fShorterBlockDistance)
coin /= 2;

if (nHeight >= params.nSubsidyHalvingFirst && nHeight < params.nSubsidyHalvingFirst + params.nSubsidyHalvingInterval) {
// Stage 2
CScript devPayoutScript = GetScriptForDestination(CBitcoinAddress(params.stage2DevelopmentFundAddress).Get());
CAmount devPayoutValue = (GetBlockSubsidyWithMTPFlag(nHeight, params, fMTP) * params.stage2DevelopmentFundShare) / 100;
if (fShorterBlockDistance) {
// Stage 3
CScript devPayoutScript = GetScriptForDestination(CBitcoinAddress(params.stage3DevelopmentFundAddress).Get());
CAmount devPayoutValue = (GetBlockSubsidyWithMTPFlag(nHeight, params, fMTP, true) * params.stage3DevelopmentFundShare) / 100;
CScript communityPayoutScript = GetScriptForDestination(CBitcoinAddress(params.stage3CommunityFundAddress).Get());
CAmount communityPayoutValue = (GetBlockSubsidyWithMTPFlag(nHeight, params, fMTP, true) * params.stage3CommunityFundShare) / 100;

coinbaseTx.vout[0].nValue -= devPayoutValue;
coinbaseTx.vout.push_back(CTxOut(devPayoutValue, devPayoutScript));

coinbaseTx.vout[0].nValue -= communityPayoutValue;
coinbaseTx.vout.push_back(CTxOut(communityPayoutValue, communityPayoutScript));
}
else {
// Stage 2
CScript devPayoutScript = GetScriptForDestination(CBitcoinAddress(params.stage2DevelopmentFundAddress).Get());
CAmount devPayoutValue = (GetBlockSubsidyWithMTPFlag(nHeight, params, fMTP, false) * params.stage2DevelopmentFundShare) / 100;

coinbaseTx.vout[0].nValue -= devPayoutValue;
coinbaseTx.vout.push_back(CTxOut(devPayoutValue, devPayoutScript));
coinbaseTx.vout[0].nValue -= devPayoutValue;
coinbaseTx.vout.push_back(CTxOut(devPayoutValue, devPayoutScript));
}
}

else if ((nHeight > 0) && (nHeight < params.nSubsidyHalvingFirst)) {
Expand Down
2 changes: 1 addition & 1 deletion src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class BlockAssembler
int UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded, indexed_modified_transaction_set &mapModifiedTx);

/** Firo: fill in founders' reward and znode payout outputs */
void FillFoundersReward(CMutableTransaction &coinbaseTx, bool fMTP);
void FillFoundersReward(CMutableTransaction &coinbaseTx, bool fMTP, bool fShorterBlockDistance);

/** Fill txBlackList set */
void FillBlackListForBlockTemplate();
Expand Down
Loading

0 comments on commit 1b4e9e6

Please sign in to comment.