From 4e6762780e2d57646b75022dee13cfeb739ac975 Mon Sep 17 00:00:00 2001 From: Andrew K Date: Wed, 11 Jul 2018 14:26:47 +0000 Subject: [PATCH 1/9] increase hashrate units to GH/s --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 99884f132b..5aaee100da 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -132,7 +132,7 @@ double GetPeakHashrate (const CBlockIndex* blockindex, int algo) { return std::numeric_limits::max(); } //LogPrintf("hashes = %f, time = %f\n",(double)hashes_bn.getulong(),(double)time_f); - double hashes = ((hashes_bn/time_f)/1000000).getulong(); + double hashes = (((hashes_bn/time_f)/1000000)/1000).getulong(); //LogPrintf("hashes per sec = %f\n",hashes); if (hashes>hashes_peak) hashes_peak = hashes; } @@ -196,7 +196,7 @@ double GetCurrentHashrate (const CBlockIndex* blockindex, int algo) { //as used return std::numeric_limits::max(); } //LogPrintf("return %lu / %f\n",(double)hashes_bn.getulong(),(double)time_f); - return ((hashes_bn/time_f)/1000000).getulong(); + return (((hashes_bn/time_f)/1000000)/1000).getulong(); } blockindex = get_pprev_algo(blockindex,-1); } while (blockindex); From f2a8fa918b116be854c7388f3a31750170e95ac4 Mon Sep 17 00:00:00 2001 From: Andrew K Date: Wed, 11 Jul 2018 14:28:44 +0000 Subject: [PATCH 2/9] gigawork --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b50979dd41..c6c636a65e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5026,7 +5026,7 @@ unsigned long get_ssf_work (const CBlockIndex * pindex) { CBigNum hashes_bn = pprev_algo->GetBlockWork(); for (int i=0; inVersion)) { - return (hashes_bn/1000000).getulong(); + return ((hashes_bn/1000000)/1000).getulong(); } pprev_algo = get_pprev_algo(pprev_algo,-1); if (!pprev_algo) return 0; From 5f638d2dcc0f836e7ab7bccaad7b99399952eea0 Mon Sep 17 00:00:00 2001 From: akrmn Date: Fri, 20 Jul 2018 21:05:23 +0200 Subject: [PATCH 3/9] fix fork warning conditions --- src/core.h | 11 +++++++++++ src/main.cpp | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core.h b/src/core.h index 5269b8caa0..a3dc9dc962 100644 --- a/src/core.h +++ b/src/core.h @@ -978,6 +978,17 @@ class CBlockIndex return (CBigNum(1)<<256) / (bnTarget/weight+1); } + CBigNum GetBlockWorkAv() const + { + CBigNum work = 0; + const CBlockIndex * pindex = this; + for (int i=0; i<50; i++) { + work += pindex->GetBlockWork(); + pindex = pindex->pprev; + } + return work/50; + } + bool CheckIndex() const { return true; diff --git a/src/main.cpp b/src/main.cpp index c6c636a65e..512dd3f460 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1724,7 +1724,7 @@ void CheckForkWarningConditions() if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 180) pindexBestForkTip = NULL; - if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (chainActive.Tip()->GetBlockWork() * 6).getuint256())) + if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (chainActive.Tip()->GetBlockWorkAv() * 30).getuint256())) { if (!fLargeWorkForkFound) { @@ -1775,7 +1775,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip) // We define it this way because it allows us to only store the highest fork tip (+ base) which meets // the 7-block condition and from this always have the most-likely-to-cause-warning fork if (pfork && (!pindexBestForkTip || (pindexBestForkTip && pindexNewForkTip->nHeight > pindexBestForkTip->nHeight)) && - pindexNewForkTip->nChainWork - pfork->nChainWork > (pfork->GetBlockWork() * 7).getuint256() && + pindexNewForkTip->nChainWork - pfork->nChainWork > (pfork->GetBlockWorkAv() * 31).getuint256() && chainActive.Height() - pindexNewForkTip->nHeight < 180) { pindexBestForkTip = pindexNewForkTip; From 3c65aabd325ac8a3de2857627273971fd997a092 Mon Sep 17 00:00:00 2001 From: akrmn Date: Sat, 21 Jul 2018 15:10:09 +0200 Subject: [PATCH 4/9] safeguard against low height case --- src/core.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core.h b/src/core.h index a3dc9dc962..a245f16bc5 100644 --- a/src/core.h +++ b/src/core.h @@ -982,11 +982,14 @@ class CBlockIndex { CBigNum work = 0; const CBlockIndex * pindex = this; + int n = 0; for (int i=0; i<50; i++) { work += pindex->GetBlockWork(); + n++; pindex = pindex->pprev; + if (!pindex) break; } - return work/50; + return work/n; } bool CheckIndex() const From f9edb92810c6fcea0a85cd5e4fae20af1e0df603 Mon Sep 17 00:00:00 2001 From: Andrew K Date: Thu, 26 Jul 2018 20:36:57 +0000 Subject: [PATCH 5/9] add version command to daemon --- src/bitmarkd.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/bitmarkd.cpp b/src/bitmarkd.cpp index 95450b31dc..b361165b58 100644 --- a/src/bitmarkd.cpp +++ b/src/bitmarkd.cpp @@ -103,6 +103,15 @@ bool AppInit(int argc, char* argv[]) return false; } + if (mapArgs.count("-v") || mapArgs.count("--version")) + { + // First part of help message is specific to bitmarkd / RPC client + std::string strUsage = _("Bitmark Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n"; + fprintf(stdout, "%s", strUsage.c_str()); + return false; + } + + // Command-line RPC bool fCommandLine = false; for (int i = 1; i < argc; i++) From c4319dd4f5af29e193a4550a9d93d9794a5a9e75 Mon Sep 17 00:00:00 2001 From: akrmn Date: Wed, 15 Aug 2018 17:34:03 +0200 Subject: [PATCH 6/9] fork2: bug fixes --- src/core.h | 5 +++++ src/main.cpp | 32 +++++++++++++++++++++++--------- src/main.h | 2 +- src/pureheader.h | 2 +- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/core.h b/src/core.h index a245f16bc5..8de791bbc4 100644 --- a/src/core.h +++ b/src/core.h @@ -924,6 +924,11 @@ class CBlockIndex return false; } + bool onFork2() const { + if (this->nHeight >= nForkHeight && IsSuperMajority(5,this->pprev,75,100)) return true; + return false; + } + CBlockHeader GetBlockHeader() const { CBlockHeader block; diff --git a/src/main.cpp b/src/main.cpp index 512dd3f460..22bc5c2730 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1202,6 +1202,10 @@ 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 @@ -1236,10 +1240,10 @@ int64_t GetBlockValue(CBlockIndex* pindex, int64_t nFees, bool noScale) emitted = NUM_ALGOS * get_mpow_ms_correction(pindex); } - unsigned int scalingFactor = 0; + CBigNum scalingFactor = CBigNum(0); if (onFork(pindex) && !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 +1553,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; } @@ -2107,8 +2111,13 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C return false; // Force min version after fork - if (onFork(pindex) && block.nVersion 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) { @@ -4955,8 +4964,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); @@ -5003,7 +5012,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; From ffb4773ee089acd8c56c113078baecdc10241892 Mon Sep 17 00:00:00 2001 From: akrmn Date: Wed, 15 Aug 2018 18:07:58 +0200 Subject: [PATCH 7/9] fix type declaration --- src/core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.h b/src/core.h index 8de791bbc4..2fda82c749 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; From 0c07f93aa8950a313d0d94a8a50e3198f0095c40 Mon Sep 17 00:00:00 2001 From: akrmn Date: Wed, 15 Aug 2018 18:14:54 +0200 Subject: [PATCH 8/9] optimizations --- src/bitmarkd.cpp | 2 -- src/main.cpp | 17 ++++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/bitmarkd.cpp b/src/bitmarkd.cpp index b361165b58..e3bff45675 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; @@ -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/main.cpp b/src/main.cpp index 22bc5c2730..e90f4c599a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1210,8 +1210,9 @@ 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(); @@ -1241,7 +1242,7 @@ int64_t GetBlockValue(CBlockIndex* pindex, int64_t nFees, bool noScale) } CBigNum scalingFactor = CBigNum(0); - if (onFork(pindex) && !noScale) { + if (onForkNow && !noScale) { scalingFactor = pindex->subsidyScalingFactor; if (!scalingFactor.getuint()) { // find the key block and recalculate CBlockIndex * pprev_algo = pindex; @@ -2109,9 +2110,11 @@ 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.nVersion<4) { + if (onForkNow && block.nVersion<4) { LogPrintf("version<4 and after fork\n"); return false; } @@ -2122,7 +2125,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C } // Check SSF - if (onFork(pindex)) { //new multi algo blocks are identified like this + if (onForkNow) { //new multi algo blocks are identified like this CBlockIndex * pprev_algo = pindex; if (update_ssf(pindex->nVersion)) { for (int i=0; inVersion)) { pindex->subsidyScalingFactor = get_ssf(pindex); } @@ -2290,7 +2293,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; } From 5c0887b9bcec2386e711e650072c3a29c8611deb Mon Sep 17 00:00:00 2001 From: akrmn Date: Sun, 19 Aug 2018 18:14:48 +0200 Subject: [PATCH 9/9] 950/1000 required for fork2 --- src/core.h | 2 +- src/rpcblockchain.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core.h b/src/core.h index 2fda82c749..bf3464c500 100644 --- a/src/core.h +++ b/src/core.h @@ -925,7 +925,7 @@ class CBlockIndex } bool onFork2() const { - if (this->nHeight >= nForkHeight && IsSuperMajority(5,this->pprev,75,100)) return true; + if (this->nHeight >= nForkHeight && IsSuperMajority(5,this->pprev,950,1000)) return true; return false; } 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();