From e9999203b1ad5a8ad0822f947da5f83ca3741829 Mon Sep 17 00:00:00 2001 From: nzsquirrell Date: Wed, 2 Mar 2016 13:54:25 +1300 Subject: [PATCH] clean up some debug code and comments --- src/chainparams.cpp | 111 -------------------------------------------- src/main.cpp | 20 +------- src/pow.cpp | 109 ------------------------------------------- src/pow.h | 1 - 4 files changed, 1 insertion(+), 240 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 0edb4bcb..1e9b7e4d 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -5,7 +5,6 @@ #include "arith_uint256.h" #include "tinyformat.h" #include "chainparams.h" -#include #include "util.h" #include "utilstrencodings.h" @@ -112,42 +111,6 @@ public: consensus.hashGenesisBlock = genesis.GetHash(); - // If genesis block hash does not match, then generate new genesis hash. - - uint256 tmphashGenesisBlock = uint256S("0x00000ffde4c020b5938441a0ea3d314bf619eff0b38f32f78f7583cffa1ea485"); - if (true && genesis.GetHash() != tmphashGenesisBlock) - { - printf("Searching for genesis block...\n"); - bool fNegative; - bool fOverflow; - arith_uint256 bnTarget; - bnTarget.SetCompact(genesis.nBits, &fNegative, &fOverflow); - int algo = genesis.GetAlgo(); - uint256 thash = genesis.GetPoWHash(algo); - - while (UintToArith256(thash) > bnTarget) - { - thash = genesis.GetPoWHash(algo); - if (UintToArith256(thash) <= bnTarget) - break; - if ((genesis.nNonce & 0xFFFFF) == 0) - { - printf("nonce %08X: PoWhash = %s (target = %s)\n", genesis.nNonce, thash.ToString().c_str(), bnTarget.ToString().c_str()); - } - ++genesis.nNonce; - if (genesis.nNonce == 0) - { - printf("NONCE WRAPPED, incrementing time\n"); - ++genesis.nTime; - } - } - printf("genesis.nTime = %u \n", genesis.nTime); - printf("genesis.nNonce = %u \n", genesis.nNonce); - printf("genesis.GetHash = %s\n", genesis.GetHash().ToString().c_str()); - printf("genesis.GetPoWHash = %s\n", genesis.GetPoWHash(algo).ToString().c_str()); - printf("genesis.hashMerkleRoot = %s\n", genesis.BuildMerkleTree().ToString().c_str()); - } - assert(consensus.hashGenesisBlock == uint256S("0x00000ffde4c020b5938441a0ea3d314bf619eff0b38f32f78f7583cffa1ea485")); assert(genesis.hashMerkleRoot == uint256S("0x3f75db3c18e92f46c21530dc1222e1fddf4ccebbf88e289a6c9dc787fd6469da")); @@ -232,43 +195,6 @@ public: genesis.nNonce = 416875379; consensus.hashGenesisBlock = genesis.GetHash(); - // If genesis block hash does not match, then generate new genesis hash. - - uint256 tmphashGenesisBlock = uint256S("0x0000017ce2a79c8bddafbbe47c004aa92b20678c354b34085f62b762084b9788"); - if (true && genesis.GetHash() != tmphashGenesisBlock) - { - printf("Searching for Testnet genesis block...\n"); - bool fNegative; - bool fOverflow; - arith_uint256 bnTarget; - bnTarget.SetCompact(genesis.nBits, &fNegative, &fOverflow); - - int algo = genesis.GetAlgo(); - uint256 thash = genesis.GetPoWHash(algo); - - while (UintToArith256(thash) > bnTarget) - { - thash = genesis.GetPoWHash(algo); - if (UintToArith256(thash) <= bnTarget) - break; - if ((genesis.nNonce & 0xFFFFF) == 0) - { - printf("nonce %08X: PoWhash = %s (target = %s)\n", genesis.nNonce, thash.ToString().c_str(), bnTarget.ToString().c_str()); - } - ++genesis.nNonce; - if (genesis.nNonce == 0) - { - printf("NONCE WRAPPED, incrementing time\n"); - ++genesis.nTime; - } - } - printf("genesis.nTime = %u \n", genesis.nTime); - printf("genesis.nNonce = %u \n", genesis.nNonce); - printf("genesis.GetHash = %s\n", genesis.GetHash().ToString().c_str()); - printf("genesis.GetPoWHash = %s\n", genesis.GetPoWHash(algo).ToString().c_str()); - printf("genesis.hashMerkleRoot = %s\n", genesis.BuildMerkleTree().ToString().c_str()); - } - assert(consensus.hashGenesisBlock == uint256S("0x0000017ce2a79c8bddafbbe47c004aa92b20678c354b34085f62b762084b9788")); vFixedSeeds.clear(); @@ -326,43 +252,6 @@ public: consensus.hashGenesisBlock = genesis.GetHash(); nDefaultPort = 18444; - // If genesis block hash does not match, then generate new genesis hash. - - uint256 tmphashGenesisBlock = uint256S("0x63b92987ddc93808aa33dddc80b3e52948bdfffaf2420bf4cd9c5137b54ea37c"); - if (true && genesis.GetHash() != tmphashGenesisBlock) - { - printf("Searching for Regtest genesis block...\n"); - bool fNegative; - bool fOverflow; - arith_uint256 bnTarget; - bnTarget.SetCompact(genesis.nBits, &fNegative, &fOverflow); - - int algo = genesis.GetAlgo(); - uint256 thash = genesis.GetPoWHash(algo); - - while (UintToArith256(thash) > bnTarget) - { - thash = genesis.GetPoWHash(algo); - if (UintToArith256(thash) <= bnTarget) - break; - if ((genesis.nNonce & 0xFFFFF) == 0) - { - printf("nonce %08X: PoWhash = %s (target = %s)\n", genesis.nNonce, thash.ToString().c_str(), bnTarget.ToString().c_str()); - } - ++genesis.nNonce; - if (genesis.nNonce == 0) - { - printf("NONCE WRAPPED, incrementing time\n"); - ++genesis.nTime; - } - } - printf("genesis.nTime = %u \n", genesis.nTime); - printf("genesis.nNonce = %u \n", genesis.nNonce); - printf("genesis.GetHash = %s\n", genesis.GetHash().ToString().c_str()); - printf("genesis.GetPoWHash = %s\n", genesis.GetPoWHash(algo).ToString().c_str()); - printf("genesis.hashMerkleRoot = %s\n", genesis.BuildMerkleTree().ToString().c_str()); - } - assert(consensus.hashGenesisBlock == uint256S("0x63b92987ddc93808aa33dddc80b3e52948bdfffaf2420bf4cd9c5137b54ea37c")); nPruneAfterHeight = 1000; diff --git a/src/main.cpp b/src/main.cpp index 060ea420..c488cdf3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1268,7 +1268,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) // return 0; CAmount nSubsidy = 1000 * COIN; - // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years. + // Subsidy is cut in half every 967680 blocks. nSubsidy >>= halvings; if(nSubsidy < 1 * COIN) nSubsidy = 1 * COIN; @@ -2919,10 +2919,6 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) { const CChainParams& chainparams = Params(); - // const int64_t nBlockSequentialAlgoRuleStart = 740000; // block where sequential algo rule starts - // const int64_t nBlockSequentialAlgoRuleStart2 = 766000; // block where sequential algo rule starts - // const int nBlockSequentialAlgoMaxCount = 6; // maximum sequential blocks of same algo - // const int nBlockSequentialAlgoMaxCount2 = 3; // maximum sequential blocks of same algo AssertLockHeld(cs_main); // Check for duplicate @@ -3068,20 +3064,6 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) { -/* if(fDebug) - { - uint256 hash = pblock->GetHash(); - uint256 hashPoW = pblock->GetPoWHash(); - bool fNegative; - bool fOverflow; - arith_uint256 bnTarget; - bnTarget.SetCompact(pblock->nBits, &fNegative, &fOverflow); - - LogPrintf("DEBUG: proof-of-work submitted \n block-PoWhash: %s\nblock-hash: %s\n ntarget: %s\n", - hashPoW.ToString().c_str(), - hash.ToString().c_str(), - bnTarget.ToString().c_str()); - }*/ // Preliminary checks bool checked = CheckBlock(*pblock, state); diff --git a/src/pow.cpp b/src/pow.cpp index 9ccd8f4a..47c34414 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -16,10 +16,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params, int algo) { const arith_uint256 nProofOfWorkLimit = UintToArith256(params.powLimit); - // const int64_t nBlockTimeWarpPreventStart = 740500; // block where time warp 1 prevention starts - // const int64_t nBlockTimeWarpPreventStart2 = 766000; // block where time warp 2 prevention starts - // const int64_t nBlockTimeWarpPreventStart3 = 1048320; // block where time warp 3 prevention starts - // const int64_t Phase2Timespan_Start = 1401000; // Genesis block if (pindexLast == NULL) @@ -160,15 +156,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead unsigned int CalculateNextWorkRequiredV1(const CBlockIndex* pindexPrev, const CBlockIndex* pindexFirst, const Consensus::Params& params, int algo, int64_t nActualTimespan, int nHeight) { - //const int64_t nBlockDiffAdjustV2 = 766000; // block where difficulty adjust V2 starts const arith_uint256 nProofOfWorkLimit = UintToArith256(params.powLimit); int64_t nTargetSpacingPerAlgo = params.nPowTargetSpacingV1 * NUM_ALGOS; // 30 * 5 = 150s per algo int64_t nAveragingTargetTimespan = params.nAveragingInterval * nTargetSpacingPerAlgo; // 10 * 150 = 1500s, 25 minutes - // int64_t nMaxAdjustDown = 4; // 4% adjustment down - // int64_t nMaxAdjustUpV1 = 2; // 2% adjustment up - // int64_t nMaxAdjustUpV2 = 4; // 4% adjustment up - int64_t nMinActualTimespanV1 = nAveragingTargetTimespan * (100 - params.nMaxAdjustUpV1) / 100; int64_t nMinActualTimespanV2 = nAveragingTargetTimespan * (100 - params.nMaxAdjustUpV2) / 100; int64_t nMaxActualTimespan = nAveragingTargetTimespan * (100 + params.nMaxAdjustDown) / 100; @@ -222,9 +213,6 @@ unsigned int CalculateNextWorkRequiredV2(const CBlockIndex* pindexPrev, const CB int64_t nTargetSpacingPerAlgo = params.nPowTargetSpacingV2 * NUM_ALGOS; // 60 * 5 = 300s per algo int64_t nAveragingTargetTimespan = params.nAveragingInterval * nTargetSpacingPerAlgo; // 10 * 300 = 3000s, 50 minutes - // int64_t nMaxAdjustDown = 4; // 4% adjustment down - // int64_t nMaxAdjustUp = 4; // 4% adjustment up - int64_t nMinActualTimespan = nAveragingTargetTimespan * (100 - params.nMaxAdjustUpV2) / 100; int64_t nMaxActualTimespan = nAveragingTargetTimespan * (100 + params.nMaxAdjustDown) / 100; @@ -419,9 +407,7 @@ arith_uint256 GetGeometricMeanPrevWork(const CBlockIndex& block) bnBlockWork *= bnBlockWorkAlt; } } - //bnRes = nBlockWork; // Compute the geometric mean - //bnRes = nthRoot(bnRes, NUM_ALGOS); CBigNum bnRes = bnBlockWork.nthRoot(NUM_ALGOS); // Scale to roughly match the old work calculation @@ -433,12 +419,6 @@ arith_uint256 GetGeometricMeanPrevWork(const CBlockIndex& block) arith_uint256 GetBlockProof(const CBlockIndex& block) { - // const int64_t nBlockAlgoWorkWeightStart = 142000; // block where algo work weighting starts - // const int64_t nBlockAlgoNormalisedWorkStart = 740000; // block where algo combined weight starts - // const int64_t nBlockAlgoNormalisedWorkDecayStart = 866000; // block where weight decay starts - // const int64_t nBlockAlgoNormalisedWorkDecayStart2 = 932000; // block where weight decay starts - // const int64_t nGeoAvgWork_Start = 1400000; - const CChainParams& chainparams = Params(); arith_uint256 bnTarget; @@ -583,93 +563,4 @@ const CBlockIndex* GetLastBlockIndexForAlgo(const CBlockIndex* pindex, int algo) } } -int BN_cmp(arith_uint256 a, arith_uint256 b) -{ - if(a < b) - return -1; - if(a > b) - return 1; - return 0; -} -arith_uint256 BN_set_negative(arith_uint256 value, int sign) -{ - if(value<0 && sign) - { - return value; - } - else - { - return -1 * value; - } -} - -arith_uint256 nthRoot(const arith_uint256& value, int n) -{ - assert(n > 1); - if (value==0) - return 0; - assert(value>0); - - // starting approximation - int nRootBits = (value.bits() + n - 1) / n; - int nStartingBits = std::min(8, nRootBits); - arith_uint256 bnUpper = value; - bnUpper >>= (nRootBits - nStartingBits)*n; - arith_uint256 bnCur = 0; - for (int i = nStartingBits - 1; i >= 0; i--) - { - arith_uint256 bnNext = bnCur; - bnNext += 1 << i; - arith_uint256 bnPower(1); - for (int j = 0; j < n; j++) - bnPower *= bnNext; - if (BN_cmp(bnPower, bnUpper) <= 0) - bnCur = bnNext; - } - if (nRootBits == nStartingBits) - return bnCur; - bnCur <<= nRootBits - nStartingBits; - - // iterate: cur = cur + (*this / cur^^(n-1) - cur)/n - arith_uint256 bnDelta; - arith_uint256 bnRoot(n); - int nTerminate = 0; - // this should always converge in fewer steps, but limit just in case - for (int it = 0; it < 20; it++) - { - arith_uint256 bnDenominator = 1; - for (int i = 0; i < n - 1; i++) - bnDenominator *= bnCur; - bnDelta = value / bnDenominator - bnCur; - if (bnDelta.EqualTo(0)) - return bnCur; - if (bnDelta<0) - { - if (nTerminate == 1) - return bnCur - 1; - bnDelta = BN_set_negative(bnDelta, 0); - if (BN_cmp(bnDelta, bnRoot) <= 0) - { - bnCur -= 1; - nTerminate = -1; - continue; - } - bnDelta = BN_set_negative(bnDelta, 1); - } - else - { - if (nTerminate == -1) - return bnCur; - if (BN_cmp(bnDelta, bnRoot) <= 0) - { - bnCur += 1; - nTerminate = 1; - continue; - } - } - bnCur += bnDelta / n; - nTerminate = 0; - } - return bnCur; -} diff --git a/src/pow.h b/src/pow.h index 31a1b79b..074ace4b 100644 --- a/src/pow.h +++ b/src/pow.h @@ -37,6 +37,5 @@ int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& fr const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, int algo); const CBlockIndex* GetLastBlockIndexForAlgo(const CBlockIndex* pindex, int algo); -arith_uint256 nthRoot(const arith_uint256& value, int n); #endif // BITCOIN_POW_H