diff --git a/src/bitmarkd.cpp b/src/bitmarkd.cpp index 1168606541..956a902dd6 100644 --- a/src/bitmarkd.cpp +++ b/src/bitmarkd.cpp @@ -55,7 +55,6 @@ void DetectShutdownThread(boost::thread_group* threadGroup) // bool AppInit(int argc, char* argv[]) { - printf("appinit\n"); boost::thread_group threadGroup; boost::thread* detectShutdownThread = NULL; @@ -110,7 +109,7 @@ bool AppInit(int argc, char* argv[]) std::string strUsage = _("Bitmark Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n"; fprintf(stdout, "%s", strUsage.c_str()); return false; - } + } // Command-line RPC bool fCommandLine = false; @@ -183,7 +182,6 @@ bool AppInit(int argc, char* argv[]) int main(int argc, char* argv[]) { - printf("main"); SetupEnvironment(); bool fRet = false; diff --git a/src/core.h b/src/core.h index 5c37ee89f1..efbeb7d4e3 100644 --- a/src/core.h +++ b/src/core.h @@ -820,7 +820,7 @@ class CBlockIndex int64_t nMoneySupply; // the scaling factor for the block - unsigned int subsidyScalingFactor; + CBigNum subsidyScalingFactor; // Which # file this block is stored in (blk?????.dat) int nFile; @@ -924,6 +924,11 @@ class CBlockIndex return false; } + bool onFork2() const { + if (this->nHeight >= nForkHeight && IsSuperMajority(5,this->pprev,950,1000)) return true; + return false; + } + CBlockHeader GetBlockHeader() const { CBlockHeader block; @@ -977,7 +982,7 @@ class CBlockIndex //LogPrintf("algo is %d and weight is %lu\n",nVersion & BLOCK_VERSION_ALGO,weight.getulong()); return (CBigNum(1)<<256) / (bnTarget/weight+1); } - + // Get Average Work of latest 50 Blocks CBigNum GetBlockWorkAv() const { @@ -988,7 +993,7 @@ class CBlockIndex work += pindex->GetBlockWork(); n++; pindex = pindex->pprev; - if (!pindex) break; + if (!pindex) break; } return work/n; } diff --git a/src/main.cpp b/src/main.cpp index 8be80cd864..8c6812ebf2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1202,12 +1202,17 @@ bool onFork (const CBlockIndex * pindex) { return pindex->onFork(); } +bool onFork2(const CBlockIndex * pindex) { + return pindex->onFork2(); +} + int64_t GetBlockValue(CBlockIndex* pindex, int64_t nFees, bool noScale) { // for testnet int nHeight = pindex->nHeight; + bool onForkNow = onFork(pindex); - if (!onFork(pindex)) { + if (!onForkNow) { int64_t nHalfReward = 10 * COIN; int64_t nSubsidy = 0; int halvings = nHeight / Params().SubsidyHalvingInterval(); @@ -1236,10 +1241,10 @@ int64_t GetBlockValue(CBlockIndex* pindex, int64_t nFees, bool noScale) emitted = NUM_ALGOS * get_mpow_ms_correction(pindex); } - unsigned int scalingFactor = 0; - if (onFork(pindex) && !noScale) { + CBigNum scalingFactor = CBigNum(0); + if (onForkNow && !noScale) { scalingFactor = pindex->subsidyScalingFactor; - if (!scalingFactor) { // find the key block and recalculate + if (!scalingFactor.getuint()) { // find the key block and recalculate CBlockIndex * pprev_algo = pindex; do { if (update_ssf(pprev_algo->nVersion)) { @@ -1549,7 +1554,7 @@ unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, int algo) { if (lastInRow>=9 && !lastInRowMod) { bnNew /= 3; } - else if (!justHadSurge) { + else if (!justHadSurge || smultiply && CBlockIndex::IsSuperMajority(5,pindexLast,75,100)) { bnNew *= nActualTimespan; bnNew /= _nTargetTimespan; } @@ -2106,15 +2111,22 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C // Check it again in case a previous version let a bad block in if (!CheckBlock(block, state, !fJustCheck, !fJustCheck)) return false; + + bool onForkNow = onFork(pindex); // Force min version after fork - if (onFork(pindex) && block.nVersionnVersion)) { for (int i=0; inVersion)) { pindex->subsidyScalingFactor = get_ssf(pindex); } @@ -2264,7 +2276,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C if (block.vtx[0].GetValueOut() > block_value_needed) return state.DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%d vs limit=%d)", - block.vtx[0].GetValueOut(), GetBlockValue(pindex, nFees, false)), + block.vtx[0].GetValueOut(), block_value_needed), REJECT_INVALID, "bad-cb-amount"); if (block.vtx[0].GetValueOut() < block_value_needed) { @@ -2282,7 +2294,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C // Increment the nMoneySupply to include this blocks subsidy - if (onFork(pindex)) { + if (onForkNow) { if (pprev_algo) { pindex->nMoneySupply = pprev_algo->nMoneySupply + block.vtx[0].GetValueOut() - nFees; } @@ -4956,8 +4968,8 @@ bool update_ssf (int nVersion) { return nVersion & BLOCK_VERSION_UPDATE_SSF; } -unsigned int get_ssf (CBlockIndex * pindex) { - unsigned int scalingFactor = 0; // ensures that it has no effect +CBigNum get_ssf (CBlockIndex * pindex) { + CBigNum scalingFactor = CBigNum(0); // ensures that it has no effect CBlockIndex * pprev_algo = pindex; CBigNum hashes_peak = CBigNum(0); CBigNum hashes_cur = CBigNum(0); @@ -5004,7 +5016,12 @@ unsigned int get_ssf (CBlockIndex * pindex) { if (i==0) hashes_cur = hashes; } if (hashes_peak > CBigNum(0) && hashes_cur != hashes_peak) { - scalingFactor = ((100000000*hashes_peak)/(hashes_peak-hashes_cur)).getuint(); // a 9-10 digit integer + if (onFork2(pindex)) { + scalingFactor = (100000000*hashes_peak)/(hashes_peak-hashes_cur); + } + else { + scalingFactor = CBigNum(((100000000*hashes_peak)/(hashes_peak-hashes_cur)).getuint()); + } } //LogPrintf("return scaling factor %lu\n",scalingFactor); return scalingFactor; diff --git a/src/main.h b/src/main.h index 758e0ec51d..d24b711456 100644 --- a/src/main.h +++ b/src/main.h @@ -684,7 +684,7 @@ int64_t get_mpow_ms_correction (CBlockIndex * p); bool update_ssf (int nVersion); /* Calculate the subsidy scaling factor for the CBlockIndex pointer */ -unsigned int get_ssf (CBlockIndex * pindex); +CBigNum get_ssf (CBlockIndex * pindex); /* Get the number of blocks since the last update of the subsidy scaling factor */ int get_ssf_height (const CBlockIndex * pindex); diff --git a/src/pureheader.h b/src/pureheader.h index f1cbadb547..1631f77830 100644 --- a/src/pureheader.h +++ b/src/pureheader.h @@ -40,7 +40,7 @@ enum class CPureBlockHeader { // Needed to resolve circular dependecies with CAuxPow in CBlockHeader public: - static const int CURRENT_VERSION=4; + static const int CURRENT_VERSION=5; int nVersion; uint256 hashPrevBlock; uint256 hashMerkleRoot; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5aaee100da..c00ba44fb8 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -341,6 +341,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex) result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); + result.push_back(Pair("coreversion",GetBlockVersion(block.nVersion))); int algo = GetAlgo(block.nVersion); result.push_back(Pair("algo",GetAlgoName(algo))); bool auxpow = block.IsAuxpow();