From 0084cc8ee2646740ed57adb62cb6629158fe336c Mon Sep 17 00:00:00 2001 From: Mrs-X Date: Tue, 20 Dec 2016 22:30:14 +0100 Subject: [PATCH 1/2] Testnet integration into master-branch + probable superblock-issue-fix --- src/main.cpp | 89 +++++++++---------------------------- src/main.h | 4 +- src/masternode-budget.cpp | 31 +++++++++---- src/masternode-payments.cpp | 4 +- src/miner.cpp | 36 ++++++++------- src/pow.cpp | 4 +- 6 files changed, 71 insertions(+), 97 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 239929a8fd47..6b7288cc3544 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1636,6 +1636,17 @@ double ConvertBitsToDouble(unsigned int nBits) int64_t GetBlockValue(int nHeight) { int64_t nSubsidy = 0; + + if(Params().NetworkID() == CBaseChainParams::TESTNET) + { + if(nHeight < 200 && nHeight > 0) + return 250000 * COIN; + + // Add TESTNET_OFFSET to nheight because that is the current height at time of writing this code + // This will allow the testnet simulation to catch up to current main net conditions + nHeight += TESTNET_OFFSET; + } + if(nHeight == 0) { nSubsidy = 60001 * COIN; } @@ -1681,14 +1692,6 @@ int64_t GetBlockValue(int nHeight) else { nSubsidy = 0 * COIN; } - if(Params().NetworkID() == CBaseChainParams::TESTNET){ - if(nHeight < 200 && nHeight > 0) { - nSubsidy = 25000 * COIN; - } - else { - nSubsidy = 50 * COIN; - } - } return nSubsidy; } @@ -1696,6 +1699,16 @@ int64_t GetMasternodePayment(int nHeight, int64_t blockValue) { int64_t ret = 0; + if(Params().NetworkID() == CBaseChainParams::TESTNET) + { + if(nHeight < 200) + return 0; + + // Add TESTNET_OFFSET to nheight because that is the current height at time of writing this code + // This will allow the testnet simulation to catch up to current main net conditions + nHeight += TESTNET_OFFSET; + } + if(nHeight <= 43200) { ret = blockValue/5; } @@ -2031,66 +2044,6 @@ int64_t GetMasternodePayment(int nHeight, int64_t blockValue) } } } - if(Params().NetworkID() == CBaseChainParams::TESTNET){ - int64_t nMoneySupply = chainActive.Tip()->nMoneySupply; - int64_t mNodeCoins = mnodeman.size() * 10000 * COIN; - - if(fDebug) - LogPrintf("GetMasternodePayment(): moneysupply=%s, nodecoins=%s \n", FormatMoney(nMoneySupply).c_str(), - FormatMoney(mNodeCoins).c_str()); - - if (mNodeCoins == 0) { - ret = 0; - } - else if (mNodeCoins <= (nMoneySupply * .05) && mNodeCoins > 0) { - ret = blockValue * .85; - } - else if (mNodeCoins <= (nMoneySupply * .1) && mNodeCoins > (nMoneySupply * .05)) { - ret = blockValue * .8; - } - else if (mNodeCoins <= (nMoneySupply * .15) && mNodeCoins > (nMoneySupply * .1)) { - ret = blockValue * .75; - } - else if (mNodeCoins <= (nMoneySupply * .2) && mNodeCoins > (nMoneySupply * .15)) { - ret = blockValue * .7; - } - else if (mNodeCoins <= (nMoneySupply * .25) && mNodeCoins > (nMoneySupply * .2)) { - ret = blockValue * .65; - } - else if (mNodeCoins <= (nMoneySupply * .3) && mNodeCoins > (nMoneySupply * .25)) { - ret = blockValue * .6; - } - else if (mNodeCoins <= (nMoneySupply * .35) && mNodeCoins > (nMoneySupply * .3)) { - ret = blockValue * .55; - } - else if (mNodeCoins <= (nMoneySupply * .4) && mNodeCoins > (nMoneySupply * .35)) { - ret = blockValue * .5; - } - else if (mNodeCoins <= (nMoneySupply * .45) && mNodeCoins > (nMoneySupply * .4)) { - ret = blockValue * .45; - } - else if (mNodeCoins <= (nMoneySupply * .5) && mNodeCoins > (nMoneySupply * .45)) { - ret = blockValue * .4; - } - else if (mNodeCoins <= (nMoneySupply * .55) && mNodeCoins > (nMoneySupply * .5)) { - ret = blockValue * .35; - } - else if (mNodeCoins <= (nMoneySupply * .6) && mNodeCoins > (nMoneySupply * .55)) { - ret = blockValue * .3; - } - else if (mNodeCoins <= (nMoneySupply * .65) && mNodeCoins > (nMoneySupply * .6)) { - ret = blockValue * .25; - } - else if (mNodeCoins <= (nMoneySupply * .7) && mNodeCoins > (nMoneySupply * .65)) { - ret = blockValue * .2; - } - else if (mNodeCoins <= (nMoneySupply * .75) && mNodeCoins > (nMoneySupply * .7)) { - ret = blockValue * .15; - } - else{ - ret = blockValue * .1; - } - } return ret; } diff --git a/src/main.h b/src/main.h index 7432696cc63d..afa06a903e2a 100644 --- a/src/main.h +++ b/src/main.h @@ -50,7 +50,9 @@ class CValidationState; struct CBlockTemplate; struct CNodeStateStats; - + +/** Allow testnet to catch up to mainnet */ +static const int TESTNET_OFFSET = 436126; /** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/ static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 750000; static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0; diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 9bc9b7264cdf..8ca6646c38dd 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -451,14 +451,29 @@ void CBudgetManager::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, b if(fProofOfStake) { if(nHighestCount > 0) { - unsigned int i = txNew.vout.size(); - txNew.vout.resize(i + 1); - txNew.vout[i].scriptPubKey = payee; - txNew.vout[i].nValue = nAmount; - - //stakers get the full amount on these blocks - txNew.vout[i - 1].nValue = blockValue; - + if (Params().NetworkID() == CBaseChainParams::TESTNET) + { + // Test for superblock-issue. + txNew.vout[0].nValue = blockValue; + + txNew.vout.resize(2); + + // these are super blocks, so their value can be much larger than normal + txNew.vout[1].scriptPubKey = payee; + txNew.vout[1].nValue = nAmount; + } + else + { + // Current mainnet logic. Can be changed when testnet runs okay + unsigned int i = txNew.vout.size(); + txNew.vout.resize(i + 1); + txNew.vout[i].scriptPubKey = payee; + txNew.vout[i].nValue = nAmount; + + //stakers get the full amount on these blocks + txNew.vout[i - 1].nValue = blockValue; + } + CTxDestination address1; ExtractDestination(payee, address1); CBitcoinAddress address2(address1); diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 8d6c508ebc2f..c88ec82cef43 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -314,7 +314,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe CAmount blockValue = GetBlockValue(pindexPrev->nHeight); CAmount masternodePayment = GetMasternodePayment(pindexPrev->nHeight, blockValue); - + txNew.vout[0].nValue = blockValue; if(hasPayment) { @@ -331,7 +331,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe txNew.vout.resize(2); txNew.vout[1].scriptPubKey = payee; txNew.vout[1].nValue = masternodePayment; - txNew.vout[0].nValue = blockValue - masternodePayment; + txNew.vout[0].nValue -= masternodePayment; } CTxDestination address1; diff --git a/src/miner.cpp b/src/miner.cpp index d49c934e1513..a82ff7bf4f81 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -388,7 +388,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, CValidationState state; if (!TestBlockValidity(state, *pblock, pindexPrev, false, false)) { - LogPrintf("CreateNewBlock() : TestBlockValidity failed"); + LogPrintf("CreateNewBlock() : TestBlockValidity failed\n"); return NULL; } } @@ -465,6 +465,7 @@ bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) bool fGenerateBitcoins = false; // ***TODO*** that part changed in bitcoin, we are using a mix with old one here for now + void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) { LogPrintf("DarkNetMiner started\n"); @@ -487,26 +488,29 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) while (fGenerateBitcoins || fProofOfStake) { - if(chainActive.Tip()->nHeight < Params().LAST_POW_BLOCK()) - { - MilliSleep(5000); - continue; - } - - while (chainActive.Tip()->nTime < 1471482000 || vNodes.empty() || pwallet->IsLocked() || !fMintableCoins || nReserveBalance >= pwallet->GetBalance() || !masternodeSync.IsSynced()) + if(fProofOfStake) { - nLastCoinStakeSearchInterval = 0; - MilliSleep(5000); - if (!fGenerateBitcoins && !fProofOfStake) + if(chainActive.Tip()->nHeight < Params().LAST_POW_BLOCK()) + { + MilliSleep(5000); continue; - } + } - if(mapHashedBlocks.count(chainActive.Tip()->nHeight)) //search our map of hashed blocks, see if bestblock has been hashed yet - { - if(GetTime() - mapHashedBlocks[chainActive.Tip()->nHeight] < max(pwallet->nHashInterval, (unsigned int)1)) // wait half of the nHashDrift with max wait of 3 minutes + while (chainActive.Tip()->nTime < 1471482000 /*|| vNodes.empty()*/ || pwallet->IsLocked() || !fMintableCoins || nReserveBalance >= pwallet->GetBalance() /*|| !masternodeSync.IsSynced()*/) { + nLastCoinStakeSearchInterval = 0; MilliSleep(5000); - continue; + if (!fGenerateBitcoins && !fProofOfStake) + continue; + } + + if(mapHashedBlocks.count(chainActive.Tip()->nHeight)) //search our map of hashed blocks, see if bestblock has been hashed yet + { + if(GetTime() - mapHashedBlocks[chainActive.Tip()->nHeight] < max(pwallet->nHashInterval, (unsigned int)1)) // wait half of the nHashDrift with max wait of 3 minutes + { + MilliSleep(5000); + continue; + } } } diff --git a/src/pow.cpp b/src/pow.cpp index 6731f014c8f1..908498a7a549 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -110,7 +110,7 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits) bool fOverflow; uint256 bnTarget; - if (Params().SkipProofOfWorkCheck()) + if (Params().SkipProofOfWorkCheck() || Params().NetworkID() == CBaseChainParams::TESTNET) return true; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); @@ -120,7 +120,7 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits) return error("CheckProofOfWork() : nBits below minimum work"); // Check proof of work matches claimed amount - if (hash > bnTarget) + if (hash > bnTarget && Params().NetworkID() != CBaseChainParams::TESTNET) return error("CheckProofOfWork() : hash doesn't match nBits"); return true; From e093b9b1be8835bf72ca1dbc4d52b9fa5aded20b Mon Sep 17 00:00:00 2001 From: Mrs-X Date: Tue, 20 Dec 2016 22:37:26 +0100 Subject: [PATCH 2/2] Testnet integration into master-branch + probable superblock-issue-fix (LogPrintf message added) --- src/masternode-budget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 8ca6646c38dd..284d92ed66aa 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -454,8 +454,10 @@ void CBudgetManager::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, b if (Params().NetworkID() == CBaseChainParams::TESTNET) { // Test for superblock-issue. + LogPrintf("CBudgetManager::FillBlockPayee - txNew.vout.size() = %d\n", txNew.vout.size()); + txNew.vout[0].nValue = blockValue; - + txNew.vout.resize(2); // these are super blocks, so their value can be much larger than normal