From d3794546b148370b6680e16d0789cc9c65518c65 Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 16:43:25 +1030 Subject: [PATCH 01/11] add 'setdebug' rpc command for run-time changes to debug output add debugFS type for future restriction of FS debugging --- src/bitcoinrpc.cpp | 1 + src/bitcoinrpc.h | 1 + src/fortunastake.cpp | 2 +- src/init.cpp | 6 ++++-- src/rpcnet.cpp | 28 +++++++++++++++++++++++++++- src/util.cpp | 1 + src/util.h | 1 + 7 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index fddcae9c..e280d310 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -336,6 +336,7 @@ static const CRPCCommand vRPCCommands[] = { "repairwallet", &repairwallet, false, true}, { "resendtx", &resendtx, false, true}, { "makekeypair", &makekeypair, false, true}, + { "setdebug", &setdebug, true, false }, { "sendalert", &sendalert, false, false}, { "gettxout", &gettxout, true, false }, { "importaddress", &importaddress, false, false }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index a07a4646..d469bda3 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -157,6 +157,7 @@ extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fH extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value setdebug(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getsubsidy(const json_spirit::Array& params, bool fHelp); diff --git a/src/fortunastake.cpp b/src/fortunastake.cpp index c4b4d434..857433f2 100644 --- a/src/fortunastake.cpp +++ b/src/fortunastake.cpp @@ -795,7 +795,7 @@ int CFortunaStake::UpdateLastPaidAmounts(const CBlockIndex *pindex, int nMaxBloc // set the node's current 'reward rate' - pay value divided by rounds (3) payRate = (payValue / scanBack)*100; - if (fDebug) printf("CFortunaStake::UpdateLastPaidAmounts -- MN %s in last %d blocks was paid %d times for %s D, rate:%s count:%d val:%s\n", address2.ToString().c_str(), scanBack, rewardCount, FormatMoney(rewardValue).c_str(), FormatMoney(payRate).c_str(), payCount, FormatMoney(payValue).c_str()); + if (fDebugFS) printf("CFortunaStake::UpdateLastPaidAmounts -- MN %s in last %d blocks was paid %d times for %s D, rate:%s count:%d val:%s\n", address2.ToString().c_str(), scanBack, rewardCount, FormatMoney(rewardValue).c_str(), FormatMoney(payRate).c_str(), payCount, FormatMoney(payValue).c_str()); return rewardCount; } else { diff --git a/src/init.cpp b/src/init.cpp index 224fa750..514a4705 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -568,10 +568,11 @@ bool AppInit2() fDebug = GetBoolArg("-debug"); - // - debug implies fDebug*, unless otherwise specified + // - debug implies fDebug*, unless otherwise specified, except debugnet/debugfs since it's -really- noisy. if (fDebug) { - SoftSetBoolArg("-debugnet", true); + SoftSetBoolArg("-debugnet", false); + SoftSetBoolArg("-debugfs", false); SoftSetBoolArg("-debugsmsg", true); SoftSetBoolArg("-debugchain", true); SoftSetBoolArg("-debugringsig", true); @@ -580,6 +581,7 @@ bool AppInit2() fDebugNet = GetBoolArg("-debugnet"); fDebugSmsg = GetBoolArg("-debugsmsg"); fDebugChain = GetBoolArg("-debugchain"); + fDebugFS = GetBoolArg("-debugfs"); fDebugRingSig = GetBoolArg("-debugringsig"); fNoSmsg = GetBoolArg("-nosmsg"); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 79044a36..072b1479 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -109,7 +109,33 @@ Value addnode(const Array& params, bool fHelp) return Value::null; } - + +Value setdebug(const Array& params, bool fHelp) +{ + string strType; + string strOn; + if (params.size() == 2) + { + strType = params[0].get_str(); + strOn = params[1].get_str(); + } + if (fHelp || params.size() != 2 || + (strOn != "on" && strOn != "off" && (strType != "all" && strType != "fs" && strType != "net" && strType != "chain" && strType != "ringsig" && strType != "smsg") )) + throw runtime_error( + "setdebug \n" + "Sets the debug mode on the wallet. type 'all' includes 'fs', 'net', 'chain', 'ringsig', 'smsg'"); + + + fDebug = strType == "all" && strOn == "on"; + fDebugFS = (strType == "all" || strType == "fs") && strOn == "on"; + fDebugChain = (strType == "all" || strType == "chain") && strOn == "on"; + fDebugNet = (strType == "all" || strType == "net") && strOn == "on"; + fDebugRingSig = (strType == "all" || strType == "ringsig") && strOn == "on"; + fDebugSmsg = (strType == "all" || strType == "smsg") && strOn == "on"; + + return Value::null; +} + // ppcoin: send alert. // There is a known deadlock situation with ThreadMessageHandler // ThreadMessageHandler: holds cs_vSend and acquiring cs_main in SendMessages() diff --git a/src/util.cpp b/src/util.cpp index 00c0d2dc..6c777ce7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -77,6 +77,7 @@ map > mapMultiArgs; bool fDebug = false; bool fDebugNet = false; bool fDebugSmsg = false; +bool fDebugFS = false; bool fDebugChain = false; bool fDebugRingSig = false; bool fNoSmsg = false; diff --git a/src/util.h b/src/util.h index 75e670a2..0999c807 100644 --- a/src/util.h +++ b/src/util.h @@ -146,6 +146,7 @@ extern std::map > mapMultiArgs; extern bool fDebug; extern bool fDebugNet; extern bool fDebugSmsg; +extern bool fDebugFS; extern bool fDebugChain; extern bool fDebugRingSig; extern bool fNoSmsg; From 5724540830249bdacd83988c91673eb5181b9568 Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 16:45:18 +1030 Subject: [PATCH 02/11] caching of pay data --- src/fortunastake.cpp | 2 ++ src/main.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/fortunastake.cpp b/src/fortunastake.cpp index 857433f2..506df787 100644 --- a/src/fortunastake.cpp +++ b/src/fortunastake.cpp @@ -732,6 +732,8 @@ int CFortunaStake::UpdateLastPaidAmounts(const CBlockIndex *pindex, int nMaxBloc if (!pindex || IsInitialBlockDownload()) return 0; if(!pindex) return 0; + if (payData.size()) return; // let's only do the payData once, it is cleared if the chain is reorged + const CBlockIndex *BlockReading = pindex; int scanBack = max(FORTUNASTAKE_FAIR_PAYMENT_MINIMUM, (int)mnCount) * FORTUNASTAKE_FAIR_PAYMENT_ROUNDS; diff --git a/src/main.cpp b/src/main.cpp index 319a53f6..3bc337c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2874,6 +2874,13 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) vResurrect.push_front(tx); } + // Clear pay data from Fortunastakes. Will be recalculated in ConnectBlock. + // TODO: Cache this payData somewhere under the current BlockHash, so we don't have to run the block loop again if the chain reorgs to the same block again + BOOST_FOREACH(CFortunaStake& mn, vecFortunastakes) + { + mn.payData.clear(); + } + // Connect longer branch vector vDelete; for (unsigned int i = 0; i < vConnect.size(); i++) From 32f370beb9c2d9363dea8bb996372fdea717a838 Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 16:46:39 +1030 Subject: [PATCH 03/11] restrict rank calcs properly --- src/fortunastake.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fortunastake.cpp b/src/fortunastake.cpp index 506df787..74c7affe 100644 --- a/src/fortunastake.cpp +++ b/src/fortunastake.cpp @@ -518,6 +518,8 @@ bool GetFortunastakeRanks(CBlockIndex* pindex) vecFortunastakeScores.clear(); int i; if (vecFortunastakeScoresListHash == pindex->GetBlockHash()) { + // if ScoresList was calculated for the current pindex hash, then just use that list + // TODO: make a vector of these somehow BOOST_FOREACH(CFortunaStake& mn, vecFortunastakeScoresList) { i++; @@ -685,8 +687,10 @@ int CFortunaStake::GetPaymentAmount(const CBlockIndex *pindex, int nMaxBlocksToS int matches = 0; BOOST_FOREACH(PAIRTYPE(int, int64_t) &item, payData) { - amount += item.second; - matches++; + if (item.first > pindex->nHeight - nMaxBlocksToScanBack) { // find payments in last scanrange + amount += item.second; + matches++; + } } //printf("done checking for matches: %d found with %s value\n", matches, FormatMoney(amount).c_str()); if (matches > 0) { From e6446c8e4a50bffda88b304652e6e380d80ed3dd Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 16:47:17 +1030 Subject: [PATCH 04/11] use the right block index to calculate ranks --- src/main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3bc337c6..ed8f73d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2482,9 +2482,8 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) { LOCK2(cs_main, mempool.cs); - CBlockIndex *pindex = pindexBest; - if(IsProofOfStake() && pindex != NULL){ - if(pindex->GetBlockHash() == hashPrevBlock){ + if(IsProofOfStake() && pindexBest != NULL){ + if(pindexBest->GetBlockHash() == hashPrevBlock){ // Calculate Coin Age for Fortunastake Reward Calculation uint64_t nCoinAge; @@ -2612,8 +2611,8 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) } else { if(fDebug) { printf("CheckBlock-POS() : Skipping fortunastake payment check - nHeight %ld Hash %s\n", pindexBest->nHeight+1, GetHash().ToString().c_str()); } } - }else if(IsProofOfWork() && pindex != NULL){ - if(pindex->GetBlockHash() == hashPrevBlock){ + }else if(IsProofOfWork() && pindexBest != NULL){ + if(pindexBest->GetBlockHash() == hashPrevBlock){ int64_t fortunastakePaymentAmount = GetFortunastakePayment(pindex->nHeight+1, vtx[0].GetValueOut()); // If we don't already have its previous block, skip fortunastake payment step From fd528c3d7f37aa9c1c4df3a8571b357fda2ab221 Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 16:47:59 +1030 Subject: [PATCH 05/11] add space and remove clutter --- src/fortunastake.cpp | 1 - src/main.cpp | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fortunastake.cpp b/src/fortunastake.cpp index 74c7affe..c5e8bc5e 100644 --- a/src/fortunastake.cpp +++ b/src/fortunastake.cpp @@ -753,7 +753,6 @@ int CFortunaStake::UpdateLastPaidAmounts(const CBlockIndex *pindex, int nMaxBloc // reset counts payCount = 0; payValue = 0; - payData.clear(); LOCK(cs_fortunastakes); for (int i = 0; i < scanBack; i++) { diff --git a/src/main.cpp b/src/main.cpp index ed8f73d6..0cd60158 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2855,6 +2855,8 @@ bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) printf("REORGANIZE: Disconnect %"PRIszu" blocks; %s..%s\n", vDisconnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexBest->GetBlockHash().ToString().substr(0,20).c_str()); printf("REORGANIZE: Connect %"PRIszu" blocks; %s..%s\n", vConnect.size(), pfork->GetBlockHash().ToString().substr(0,20).c_str(), pindexNew->GetBlockHash().ToString().substr(0,20).c_str()); + + // Disconnect shorter branch list vResurrect; BOOST_FOREACH(CBlockIndex* pindex, vDisconnect) From b65b54c5b77da3b421e5f041e823ecebeaed9f0c Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 17:04:52 +1030 Subject: [PATCH 06/11] allow burn addresses in payment checker --- src/main.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0cd60158..38842d2c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2482,6 +2482,11 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) { LOCK2(cs_main, mempool.cs); + CScript burnPayee; + CBitcoinAddress burnDestination; + burnDestination.SetString("DNRXXXXXXXXXXXXXXXXXXXXXXXXXZeeDTw"); + burnPayee = GetScriptForDestination(burnDestination.Get()); + if(IsProofOfStake() && pindexBest != NULL){ if(pindexBest->GetBlockHash() == hashPrevBlock){ @@ -2502,13 +2507,14 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) bool paymentOK = false; CScript payee; - // Non specific payee if(!fortunastakePayments.GetBlockPayee(pindexBest->nHeight+1, payee) || payee == CScript()){ foundPayee = true; //doesn't require a specific payee if(fDebug) { printf("CheckBlock-POS() : Using non-specific fortunastake payments %ld\n", pindexBest->nHeight+1); } } + + // Check transaction for payee and if contains fortunastake reward payment if(fDebug) { printf("CheckBlock-POS(): Transaction 1 Size : %i\n", vtx[1].vout.size()); } if(fDebug) { printf("CheckBlock-POS() : Expected Fortunastake reward of: %ld\n", fortunastakePaymentAmount); } @@ -2522,6 +2528,9 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) if (pubScript == vtx[1].vout[i].scriptPubKey) { printf("CheckBlock-POS() : Found fortunastake payment: %s D to anonymous payee.\n", FormatMoney(vtx[1].vout[i].nValue).c_str()); foundPayee = true; + } else if (pubScript == burnPayee) { + printf("CheckBlock-POS() : Found fortunastake payment: %s D to burn address.\n", FormatMoney(vtx[1].vout[i].nValue).c_str()); + foundPayee = true; } else { CTxDestination mnDest; ExtractDestination(vtx[1].vout[i].scriptPubKey, mnDest); @@ -2581,6 +2590,8 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) } } + + if (!foundPayee) { if (pindexBest->nHeight >= MN_ENFORCEMENT_ACTIVE_HEIGHT) { return error("CheckBlock-POS() : Did not find this payee in the fortunastake list, rejecting block."); @@ -2695,6 +2706,9 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) foundPayee = true; paymentOK = true; break; + } else if (pubScript == burnPayee) { + printf("CheckBlock-POW() : Found fortunastake payment: %s D to burn address.\n", FormatMoney(vtx[1].vout[i].nValue).c_str()); + foundPayee = true; } } } From 6ac6a88bbb8ed25431256b06d7ccbb3867b5c45a Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 21:31:12 +1030 Subject: [PATCH 07/11] gigantic squash commit --- denarius-qt.pro | 11 ++++-- src/activefortunastake.cpp | 4 +- src/fortunastake.cpp | 49 +++++++++++++++--------- src/fortunastake.h | 14 ++++--- src/init.cpp | 4 +- src/main.cpp | 69 ++++++++++++++++------------------ src/main.h | 2 +- src/net.cpp | 4 +- src/net.h | 6 +-- src/netbase.cpp | 4 +- src/qt/bitcoingui.cpp | 2 +- src/qt/fortunastakemanager.cpp | 4 +- src/rpcfortuna.cpp | 8 ++-- 13 files changed, 99 insertions(+), 82 deletions(-) diff --git a/denarius-qt.pro b/denarius-qt.pro index 98c5b898..569f09b4 100644 --- a/denarius-qt.pro +++ b/denarius-qt.pro @@ -24,8 +24,8 @@ BOOST_INCLUDE_PATH=C:/deps/boost_1_57_0 BOOST_LIB_PATH=C:/deps/boost_1_57_0/stage/lib BDB_INCLUDE_PATH=C:/deps/db-4.8.30.NC/build_unix BDB_LIB_PATH=C:/deps/db-4.8.30.NC/build_unix -OPENSSL_INCLUDE_PATH=C:/deps/openssl-1.0.1j/include -OPENSSL_LIB_PATH=C:/deps/openssl-1.0.1j +OPENSSL_INCLUDE_PATH=C:/deps/openssl-1.0.1l/include +OPENSSL_LIB_PATH=C:/deps/openssl-1.0.1l MINIUPNPC_INCLUDE_PATH=C:/deps/ MINIUPNPC_LIB_PATH=C:/deps/miniupnpc LIBPNG_INCLUDE_PATH=C:/deps/libpng-1.6.16 @@ -87,6 +87,11 @@ contains(USE_PROFILER, 1) { QMAKE_CXXFLAGS += -pg } +contains(USE_DEBUG_FLAGS, 1) { + QMAKE_LFLAGS += -Og + QMAKE_CXXFLAGS += -Og +} + # use: qmake "USE_UPNP=1" ( enabled by default; default) # or: qmake "USE_UPNP=0" (disabled by default) # or: qmake "USE_UPNP=-" (not supported) @@ -207,7 +212,7 @@ contains(USE_O3, 1) { QMAKE_CFLAGS += -msse2 } -QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector +QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wno-ignored-qualifiers -Wno-format -Wno-unused-parameter -Wstack-protector # Input diff --git a/src/activefortunastake.cpp b/src/activefortunastake.cpp index e4361e4a..de2941cb 100644 --- a/src/activefortunastake.cpp +++ b/src/activefortunastake.cpp @@ -69,8 +69,8 @@ void CActiveFortunastake::ManageStatus() if(GetFortunaStakeVin(vin, pubKeyCollateralAddress, keyCollateralAddress)) { - if(GetInputAge(vin) < (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)){ - printf("CActiveFortunastake::ManageStatus() - Input must have least %d confirmations - %d confirmations\n", (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS), GetInputAge(vin)); + if(GetInputAge(vin, pindexBest) < (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)){ + printf("CActiveFortunastake::ManageStatus() - Input must have least %d confirmations - %d confirmations\n", (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS), GetInputAge(vin, pindexBest)); status = FORTUNASTAKE_INPUT_TOO_NEW; return; } diff --git a/src/fortunastake.cpp b/src/fortunastake.cpp index c5e8bc5e..3129c9f4 100644 --- a/src/fortunastake.cpp +++ b/src/fortunastake.cpp @@ -169,7 +169,7 @@ void ProcessMessageFortunastake(CNode* pfrom, std::string& strCommand, CDataStre return; } - if(fDebug) printf("dsee - Got NEW fortunastake entry %s\n", addr.ToString().c_str()); + if(fDebugFS) printf("dsee - Got NEW fortunastake entry %s\n", addr.ToString().c_str()); // make sure it's still unspent // - this is checked later by .check() in many places and by ThreadCheckForTunaPool() @@ -177,7 +177,7 @@ void ProcessMessageFortunastake(CNode* pfrom, std::string& strCommand, CDataStre if(CheckFortunastakeVin(vin,vinError)){ if (fDebugNet) printf("dsee - Accepted input for fortunastake entry %i %i\n", count, current); - if(GetInputAge(vin) < (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)){ + if(GetInputAge(vin, pindexBest) < (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)){ if (fDebugNet) printf("dsee - Input must have least %d confirmations\n", (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)); Misbehaving(pfrom->GetId(), 20); return; @@ -199,12 +199,11 @@ void ProcessMessageFortunastake(CNode* pfrom, std::string& strCommand, CDataStre if(count == -1 && !isLocal) RelayForTunaElectionEntry(vin, addr, vchSig, sigTime, pubkey, pubkey2, count, current, lastUpdated, protocolVersion); - // mn.UpdateLastPaidBlock(pindex, 1000); // do a search back 1000 blocks when receiving a new fortunastake to find their last payment - int value; - int payments = mn.UpdateLastPaidAmounts(pindex, 1000, value); // do a search back 1000 blocks when receiving a new fortunastake to find their last payment, payments = number of payments received, value = amount - if (payments > 0) { - printf("Registered new fortunastake %s(%i/%i) - paid %d times for %f D\n", addr.ToString().c_str(), count, current, payments, value); - } + // no need to look up the payment amounts right now, they aren't eligible for payment now anyway + //int payments = mn.UpdateLastPaidAmounts(pindex, 1000, value); // do a search back 1000 blocks when receiving a new fortunastake to find their last payment, payments = number of payments received, value = amount + + if (fDebugFS) printf("Registered new fortunastake %s (%i/%i)\n", addr.ToString().c_str(), count, current); + vecFortunastakes.push_back(mn); } else { @@ -327,11 +326,11 @@ void ProcessMessageFortunastake(CNode* pfrom, std::string& strCommand, CDataStre if(vin == CTxIn()){ mn.Check(true); if(mn.IsEnabled()) { - if(fDebug) printf("dseg - Sending fortunastake entry - %s \n", mn.addr.ToString().c_str()); + if(fDebugFS && fDebugNet) printf("dseg - Sending fortunastake entry - %s \n", mn.addr.ToString().c_str()); pfrom->PushMessage("dsee", mn.vin, mn.addr, mn.sig, mn.now, mn.pubkey, mn.pubkey2, count, i, mn.lastTimeSeen, mn.protocolVersion); } } else if (vin == mn.vin) { - if(fDebug) printf("dseg - Sending fortunastake entry - %s \n", mn.addr.ToString().c_str()); + if(fDebugFS && fDebugNet) printf("dseg - Sending fortunastake entry - %s \n", mn.addr.ToString().c_str()); pfrom->PushMessage("dsee", mn.vin, mn.addr, mn.sig, mn.now, mn.pubkey, mn.pubkey2, count, i, mn.lastTimeSeen, mn.protocolVersion); printf("dseg - Sent 1 fortunastake entries to %s\n", pfrom->addr.ToString().c_str()); return; @@ -432,11 +431,23 @@ struct CompareLastPay bool operator()(const pair& t1, const pair& t2) const { + if (t2.second->nTimeRegistered > pindex->GetBlockHash()) return true; return (t1.second->payValue == t2.second->payValue ? t1.second->CalculateScore(1, pindex->nHeight) > t2.second->CalculateScore(1, pindex->nHeight) : t1.second->payValue > t2.second->payValue); } CBlockIndex* pindex; }; +struct CompareSigTimeTo +{ + CompareSigTimeTo(CBlockIndex* pindex) { this->pindex = pindex; } + bool operator()(const pair& t1, + const pair& t2) const + { + return (t2.second->nTimeRegistered > pindex->GetBlockTime() && t1.second->nTimeRegistered == t2.second->nTimeRegistered ? t1.second->CalculateScore(1, pindex->nHeight) > t2.second->CalculateScore(1, pindex->nHeight) : t2.second->nTimeRegistered > pindex->GetBlockTime()); + } + CBlockIndex* pindex; +}; + struct CompareLastPayValue { bool operator()(const pair& t1, @@ -516,7 +527,7 @@ bool GetFortunastakeRanks(CBlockIndex* pindex) if (!pindex || IsInitialBlockDownload() || pindex->GetBlockTime() < GetTime() - 30*nCoinbaseMaturity) return true; vecFortunastakeScores.clear(); - int i; + int i = 0; if (vecFortunastakeScoresListHash == pindex->GetBlockHash()) { // if ScoresList was calculated for the current pindex hash, then just use that list // TODO: make a vector of these somehow @@ -533,6 +544,10 @@ bool GetFortunastakeRanks(CBlockIndex* pindex) mn.Check(); if(mn.protocolVersion < MIN_MN_PROTO_VERSION) continue; + // check the block time against the entry and don't use it if it's newer than the current block time + 600 secs + // stops new stakes from being calculated in rank lists until the time of their first seen broadcast + // if (mn.now > pindex->GetBlockTime()) continue; + int value = -1; // CBlockIndex* pindex = pindexBest; // don't use the best chain, use the chain we're asking about! int payments = mn.UpdateLastPaidAmounts(pindex, max(FORTUNASTAKE_FAIR_PAYMENT_MINIMUM, (int)mnCount) * FORTUNASTAKE_FAIR_PAYMENT_ROUNDS, value); // do a search back 1000 blocks when receiving a new fortunastake to find their last payment, payments = number of payments received, value = amount @@ -547,17 +562,17 @@ bool GetFortunastakeRanks(CBlockIndex* pindex) // NO MORE TODO: Store the Scores vector in a caching hash map, maybe need hashPrev as well to make sure it re calculates any different chains with the same end block? //vecFortunastakeScoresCache.insert(make_pair(pindex->GetBlockHash(), vecFortunastakeScoresList)); - sort(vecFortunastakeScores.rbegin(), vecFortunastakeScores.rend(), CompareLastPay(pindex)); // sort requires current pindex as pindexBest is different between clients - + sort(vecFortunastakeScores.rbegin(), vecFortunastakeScores.rend(), CompareLastPay(pindex)); // sort requires current pindex for modulus as pindexBest is different between clients + //sort(vecFortunastakeScores.rbegin(), vecFortunastakeScores.rend(), CompareSigTimeTo(pindex)); // put mn's that are new to last rank return true; } -int GetFortunastakeRank(CFortunaStake &tmn, int64_t nBlockHeight, int minProtocol) +int GetFortunastakeRank(CFortunaStake &tmn, CBlockIndex* pindex, int minProtocol) { if (IsInitialBlockDownload()) return 0; LOCK(cs_fortunastakes); - GetFortunastakeRanks(pindexBest); + GetFortunastakeRanks(pindex); unsigned int i = 0; BOOST_FOREACH(PAIRTYPE(int, CFortunaStake*)& s, vecFortunastakeScores) @@ -734,9 +749,9 @@ int CFortunaStake::GetPaymentAmount(const CBlockIndex *pindex, int nMaxBlocksToS int CFortunaStake::UpdateLastPaidAmounts(const CBlockIndex *pindex, int nMaxBlocksToScanBack, int &value) { if (!pindex || IsInitialBlockDownload()) return 0; - if(!pindex) return 0; + if (now > pindex->GetBlockTime()) return 0; // don't update paid amounts for nodes before the block they broadcasted on - if (payData.size()) return; // let's only do the payData once, it is cleared if the chain is reorged + if (payData.size()) return 0; // let's only do the payData once, it is cleared if the chain is reorged const CBlockIndex *BlockReading = pindex; int scanBack = max(FORTUNASTAKE_FAIR_PAYMENT_MINIMUM, (int)mnCount) * FORTUNASTAKE_FAIR_PAYMENT_ROUNDS; diff --git a/src/fortunastake.h b/src/fortunastake.h index ebbec2b9..288ce013 100644 --- a/src/fortunastake.h +++ b/src/fortunastake.h @@ -96,6 +96,7 @@ class CFortunaStake int nBlockLastPaid; int64_t nTimeLastChecked; int64_t nTimeLastPaid; + int64_t nTimeRegistered; //the dsq count from the last dsq broadcast of this node @@ -121,6 +122,7 @@ class CFortunaStake nBlockLastPaid = 0; nTimeLastChecked = 0; nTimeLastPaid = 0; + nTimeRegistered = newNow; } uint256 CalculateScore(int mod=1, int64_t nBlockHeight=0); @@ -167,16 +169,16 @@ class CFortunaStake return enabled == 1; } - int GetFortunastakeInputAge() + int GetFortunastakeInputAge(CBlockIndex* pindex=pindexBest) { - if(pindexBest == NULL) return 0; + if(pindex == NULL) return 0; if(cacheInputAge == 0){ - cacheInputAge = GetInputAge(vin); - cacheInputAgeBlock = pindexBest->nHeight; + cacheInputAge = GetInputAge(vin, pindex); + cacheInputAgeBlock = pindex->nHeight; } - return cacheInputAge+(pindexBest->nHeight-cacheInputAgeBlock); + return cacheInputAge+(pindex->nHeight-cacheInputAgeBlock); } }; @@ -186,7 +188,7 @@ class CFortunaStake int GetCurrentFortunaStake(int mod=1, int64_t nBlockHeight=0, int minProtocol=CFortunaStake::minProtoVersion); int GetFortunastakeByVin(CTxIn& vin); -int GetFortunastakeRank(CFortunaStake& tmn, int64_t nBlockHeight=0, int minProtocol=CFortunaStake::minProtoVersion); +int GetFortunastakeRank(CFortunaStake& tmn, CBlockIndex* pindex, int minProtocol=CFortunaStake::minProtoVersion); int GetFortunastakeByRank(int findRank, int64_t nBlockHeight=0, int minProtocol=CFortunaStake::minProtoVersion); bool GetFortunastakeRanks(CBlockIndex* pindex=pindexBest); diff --git a/src/init.cpp b/src/init.cpp index 514a4705..60156f5f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -568,12 +568,12 @@ bool AppInit2() fDebug = GetBoolArg("-debug"); - // - debug implies fDebug*, unless otherwise specified, except debugnet/debugfs since it's -really- noisy. + // - debug implies fDebug*, unless otherwise specified, except net/fs/smsg since they are -really- noisy. if (fDebug) { SoftSetBoolArg("-debugnet", false); SoftSetBoolArg("-debugfs", false); - SoftSetBoolArg("-debugsmsg", true); + SoftSetBoolArg("-debugsmsg", false); SoftSetBoolArg("-debugchain", true); SoftSetBoolArg("-debugringsig", true); }; diff --git a/src/main.cpp b/src/main.cpp index 38842d2c..483db484 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1180,7 +1180,7 @@ bool AcceptableInputs(CTxMemPool& pool, const CTransaction &txo, bool fLimitFree return true; } -int GetInputAge(CTxIn& vin) +int GetInputAge(CTxIn& vin, CBlockIndex* pindex) { const uint256& prevHash = vin.prevout.hash; CTransaction tx; @@ -1190,7 +1190,7 @@ int GetInputAge(CTxIn& vin) { if(mapBlockIndex.find(hashBlock) != mapBlockIndex.end()) { - return pindexBest->nHeight - mapBlockIndex[hashBlock]->nHeight; + return pindex->nHeight - mapBlockIndex[hashBlock]->nHeight; } else return 0; @@ -2497,7 +2497,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) int64_t nCalculatedStakeReward = GetProofOfStakeReward(nCoinAge, nFees); // Calculate expected fortunastakePaymentAmmount - int64_t fortunastakePaymentAmount = GetFortunastakePayment(pindex->nHeight+1, nCalculatedStakeReward); + int64_t fortunastakePaymentAmount = GetFortunastakePayment(pindex->nHeight, nCalculatedStakeReward); // If we don't already have its previous block, skip fortunastake payment step if (pindex != NULL) @@ -2507,13 +2507,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) bool paymentOK = false; CScript payee; - // Non specific payee - if(!fortunastakePayments.GetBlockPayee(pindexBest->nHeight+1, payee) || payee == CScript()){ - foundPayee = true; //doesn't require a specific payee - if(fDebug) { printf("CheckBlock-POS() : Using non-specific fortunastake payments %ld\n", pindexBest->nHeight+1); } - } - - + if(fDebug) { printf("CheckBlock-POS() : Using fortunastake payments for block %ld\n", pindex->nHeight); } // Check transaction for payee and if contains fortunastake reward payment if(fDebug) { printf("CheckBlock-POS(): Transaction 1 Size : %i\n", vtx[1].vout.size()); } @@ -2523,12 +2517,13 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) if(vtx[1].vout[i].nValue == fortunastakePaymentAmount ) { foundPaymentAmount = true; + payee = vtx[1].vout[i].scriptPubKey; CScript pubScript; - if (pubScript == vtx[1].vout[i].scriptPubKey) { + if (pubScript == payee) { printf("CheckBlock-POS() : Found fortunastake payment: %s D to anonymous payee.\n", FormatMoney(vtx[1].vout[i].nValue).c_str()); foundPayee = true; - } else if (pubScript == burnPayee) { + } else if (payee == burnPayee) { printf("CheckBlock-POS() : Found fortunastake payment: %s D to burn address.\n", FormatMoney(vtx[1].vout[i].nValue).c_str()); foundPayee = true; } else { @@ -2547,10 +2542,10 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) { int64_t value = vtx[1].vout[i].nValue; int lastPaid = mn.nBlockLastPaid; - int vinAge = GetInputAge(mn.vin); - int rank = (GetFortunastakeRank(mn, pindexBest->nHeight+1)); - int maxrank = mnCount/2; - if (fDebug) printf("CheckBlock-POS() : Fortunastake PoS payee found at block %d: %s who got paid %s D rate:%d age: %d, rank %d\n", pindex->nHeight+1, address2.ToString().c_str(), FormatMoney(value).c_str(), mn.payRate, vinAge, rank); + int vinAge = mn.GetFortunastakeInputAge(pindex); + int rank = (GetFortunastakeRank(mn, pindex)); + int maxrank = mnCount-(mnCount/10); + if (fDebug) printf("CheckBlock-POS() : Fortunastake PoS payee found at block %d: %s who got paid %s D rate:%d age: %d, rank %d\n", pindex->nHeight, address2.ToString().c_str(), FormatMoney(value).c_str(), mn.payRate, vinAge, rank); if(vinAge < (nBestHeight > BLOCK_START_FORTUNASTAKE_DELAYPAY ? FORTUNASTAKE_MIN_CONFIRMATIONS_NOPAY : FORTUNASTAKE_MIN_CONFIRMATIONS)) // if MN is too new { @@ -2578,9 +2573,9 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) if (fDebug) printf("CheckBlock-POS() : Wallet currently in startup mode, ignoring rate requirements."); } // add mn payment data - mn.nBlockLastPaid = pindex->nHeight+1; - mn.payData.push_back(make_pair(pindex->nHeight+1, value)); - mn.SetPayRate(pindex->nHeight+1); + mn.nBlockLastPaid = pindex->nHeight; + mn.payData.push_back(make_pair(pindex->nHeight, value)); + mn.SetPayRate(pindex->nHeight); foundPayee = true; paymentOK = true; break; @@ -2620,11 +2615,11 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) if(fDebug) { printf("CheckBlock-POS() : Is initial download, skipping fortunastake payment check %ld\n", pindexBest->nHeight+1); } } } else { - if(fDebug) { printf("CheckBlock-POS() : Skipping fortunastake payment check - nHeight %ld Hash %s\n", pindexBest->nHeight+1, GetHash().ToString().c_str()); } + if(fDebug) { printf("CheckBlock-POS() : Skipping fortunastake payment check - nHeight %ld Hash %s\n", pindex->nHeight, GetHash().ToString().c_str()); } } }else if(IsProofOfWork() && pindexBest != NULL){ if(pindexBest->GetBlockHash() == hashPrevBlock){ - int64_t fortunastakePaymentAmount = GetFortunastakePayment(pindex->nHeight+1, vtx[0].GetValueOut()); + int64_t fortunastakePaymentAmount = GetFortunastakePayment(pindex->nHeight, vtx[0].GetValueOut()); // If we don't already have its previous block, skip fortunastake payment step if (pindex != NULL) @@ -2632,17 +2627,13 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) bool foundPaymentAmount = false; bool foundPayee = false; bool paymentOK = true; - CScript payee; - if(!fortunastakePayments.GetBlockPayee(pindexBest->nHeight+1, payee) || payee == CScript()){ - // foundPayee = true; //doesn't require a specific payee - if(fDebug) { printf("CheckBlock-POW() : Using non-specific fortunastake payments %ld\n", pindexBest->nHeight+1); } - } + if(fDebug) { printf("CheckBlock-POW() : Using non-specific fortunastake payments %ld\n", pindex->nHeight); } // Check transaction for payee and if contains fortunastake reward payment - if(fDebug) { printf("CheckBlock-POW(): Transaction 0 Size : %i\n", vtx[0].vout.size()); } - if(fDebug) { printf("CheckBlock-POW() : Expected Fortunastake reward of: %ld\n", fortunastakePaymentAmount); } + if (fDebug) { printf("CheckBlock-POW(): Transaction 0 Size : %i\n", vtx[0].vout.size()); } + if (fDebug) { printf("CheckBlock-POW() : Expected Fortunastake reward of: %ld\n", fortunastakePaymentAmount); } for (unsigned int i = 0; i < vtx[0].vout.size(); i++) { if(fDebug) { printf("CheckBlock-POW() : Payment vout number: %i , Amount: %lld\n",i, vtx[0].vout[i].nValue); } if(vtx[0].vout[i].nValue == fortunastakePaymentAmount ) @@ -2664,12 +2655,12 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) ExtractDestination(pubScript, address1); CBitcoinAddress address2(address1); - if (vtx[0].vout[i].scriptPubKey == pubScript) + if (payee == pubScript) { int lastPaid = mn.nBlockLastPaid; - int vinAge = GetInputAge(mn.vin); - int rank = (GetFortunastakeRank(mn, pindexBest->nHeight+1)); - int maxrank = mnCount/2; + int vinAge = mn.GetFortunastakeInputAge(pindex); + int rank = (GetFortunastakeRank(mn, pindex)); + int maxrank = mnCount - (mnCount/10); if (fDebug) printf("CheckBlock-POW() : Fortunastake PoW payee found at block %d: %s who got paid %s D rate:%d age: %d, rank %d\n", pindex->nHeight+1, address2.ToString().c_str(), FormatMoney(vtx[0].vout[i].nValue).c_str(), FormatMoney(mn.payRate).c_str(), vinAge, rank); @@ -2700,13 +2691,13 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) if (fDebug) printf("CheckBlock-POW() : Wallet currently in startup mode, ignoring rate requirements."); } - mn.nBlockLastPaid = pindex->nHeight+1; - mn.payData.push_back(make_pair(pindex->nHeight+1, vtx[0].vout[i].nValue)); - mn.SetPayRate(pindex->nHeight+1); + mn.nBlockLastPaid = pindex->nHeight; + mn.payData.push_back(make_pair(pindex->nHeight, vtx[0].vout[i].nValue)); + mn.SetPayRate(pindex->nHeight); foundPayee = true; paymentOK = true; break; - } else if (pubScript == burnPayee) { + } else if (payee == burnPayee) { printf("CheckBlock-POW() : Found fortunastake payment: %s D to burn address.\n", FormatMoney(vtx[1].vout[i].nValue).c_str()); foundPayee = true; } @@ -2731,6 +2722,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) if(fDebug) {printf("CheckBlock-POW(): foundPaymentAmount= %i ; foundPayee = %i\n", foundPaymentAmount, foundPayee); } if(!(foundPaymentAmount && foundPayee)) { + CScript payee; CTxDestination address1; ExtractDestination(payee, address1); CBitcoinAddress address2(address1); @@ -3021,6 +3013,9 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) return error("SetBestChain() : Reorganize failed"); } + // Force MN rank calculation here, as ranks are cleared during reorganization + GetFortunastakeRanks(pindexBest); + // Connect further blocks BOOST_REVERSE_FOREACH(CBlockIndex *pindex, vpindexSecondary) { @@ -4209,7 +4204,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { static map mapReuseKey; RandAddSeedPerfmon(); - if (fDebug) + if (fDebugNet) printf("received: %s (%"PRIszu" bytes)\n", strCommand.c_str(), vRecv.size()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { diff --git a/src/main.h b/src/main.h index 48020703..87875582 100644 --- a/src/main.h +++ b/src/main.h @@ -193,7 +193,7 @@ bool Finalise(); bool FindTransactionsByDestination(const CTxDestination &dest, std::vector &vtxhash); -int GetInputAge(CTxIn& vin); +int GetInputAge(CTxIn& vin, CBlockIndex* pindex); int GetInputAgeIX(uint256 nTXHash, CTxIn& vin); int GetIXConfirmations(uint256 nTXHash); /** Abort with a message */ diff --git a/src/net.cpp b/src/net.cpp index 0ed3f417..015a5c47 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -509,7 +509,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool forTunaMaster /// debug print - printf("net: trying connection %s lastseen=%.1fhrs\n", + if (fDebugNet) printf("net: trying connection %s lastseen=%.1fhrs\n", pszDest ? pszDest : addrConnect.ToString().c_str(), pszDest ? 0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0); @@ -521,7 +521,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool forTunaMaster { addrman.Attempt(addrConnect); - printf("net: connected %s\n", pszDest ? pszDest : addrConnect.ToString().c_str()); + if (fDebugNet) printf("net: connected %s\n", pszDest ? pszDest : addrConnect.ToString().c_str()); // Set to non-blocking #ifdef WIN32 diff --git a/src/net.h b/src/net.h index 953bfd89..ed98641f 100644 --- a/src/net.h +++ b/src/net.h @@ -506,7 +506,7 @@ class CNode ENTER_CRITICAL_SECTION(cs_vSend); assert(ssSend.size() == 0); ssSend << CMessageHeader(pszCommand, 0); - if (fDebug) + if (fDebugNet) printf("net: to %s: %s ", this->addr.ToString().c_str(), pszCommand); } @@ -516,7 +516,7 @@ class CNode LEAVE_CRITICAL_SECTION(cs_vSend); - if (fDebug) + if (fDebugNet) printf("(aborted)\n"); } @@ -543,7 +543,7 @@ class CNode assert(ssSend.size () >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum)); memcpy((char*)&ssSend[CMessageHeader::CHECKSUM_OFFSET], &nChecksum, sizeof(nChecksum)); - if (fDebug) { + if (fDebugNet) { printf("(%d bytes)\n", nSize); } diff --git a/src/netbase.cpp b/src/netbase.cpp index da10416f..048c9c3c 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -351,13 +351,13 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe int nRet = select(hSocket + 1, NULL, &fdset, NULL, &timeout); if (nRet == 0) { - printf("connection timeout\n"); + if (fDebugNet) printf("connection timeout\n"); closesocket(hSocket); return false; } if (nRet == SOCKET_ERROR) { - printf("select() for connection failed: %i\n",WSAGetLastError()); + if (fDebugNet) printf("select() for connection failed: %i\n",WSAGetLastError()); closesocket(hSocket); return false; } diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 9fc65847..f527e869 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -854,7 +854,7 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks) if (nBlocksPerSec>0) progressBar->setFormat(tr("~%1 block(s) remaining (est: %2 at %3 blocks/sec)").arg(nRemainingBlocks).arg(nRemainingTime).arg(nBlocksPerSec)); else - progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks)); + progressBar->setFormat(tr("~%1 block(s) remaining", "", nRemainingBlocks)); progressBar->setMaximum(nTotalBlocks); progressBar->setValue(count); progressBar->setVisible(true); diff --git a/src/qt/fortunastakemanager.cpp b/src/qt/fortunastakemanager.cpp index 64676a5d..6836ecc8 100644 --- a/src/qt/fortunastakemanager.cpp +++ b/src/qt/fortunastakemanager.cpp @@ -178,7 +178,7 @@ void FortunastakeManager::updateAdrenalineNode(QString alias, QString addr, QStr BOOST_FOREACH(CFortunaStake& mn, vecFortunastakes) { if (mn.addr.ToString().c_str() == addr){ - rank = GetFortunastakeRank(mn, pindexBest->nHeight); + rank = GetFortunastakeRank(mn, pindexBest); status = QString::fromStdString("Online"); collateral = QString::fromStdString(address2.ToString().c_str()); //int64_t value; @@ -262,7 +262,7 @@ void FortunastakeManager::updateNodeList() { int mnRow = 0; ui->tableWidget->insertRow(0); - int mnRank = GetFortunastakeRank(mn, pindexBest->nHeight); + int mnRank = GetFortunastakeRank(mn, pindexBest); int64_t value; double rate; mn.GetPaymentInfo(pindexBest, value, rate); diff --git a/src/rpcfortuna.cpp b/src/rpcfortuna.cpp index 32e28561..ff4637db 100644 --- a/src/rpcfortuna.cpp +++ b/src/rpcfortuna.cpp @@ -249,7 +249,7 @@ Value fortunastake(const Array& params, bool fHelp) } else if (strCommand == "activeseconds") { obj.push_back(Pair(mn.addr.ToString().c_str(), (int64_t)(mn.lastTimeSeen - mn.now))); } else if (strCommand == "rank") { - obj.push_back(Pair(mn.addr.ToString().c_str(), (int)(GetFortunastakeRank(mn, pindexBest->nHeight)))); + obj.push_back(Pair(mn.addr.ToString().c_str(), (int)(GetFortunastakeRank(mn, pindexBest)))); } else if (strCommand == "full") { Object list; @@ -267,7 +267,7 @@ Value fortunastake(const Array& params, bool fHelp) list.push_back(Pair("protocolversion", (int64_t)mn.protocolVersion)); list.push_back(Pair("lastseen", (int64_t)mn.lastTimeSeen)); list.push_back(Pair("activeseconds", (int64_t)(mn.lastTimeSeen - mn.now))); - list.push_back(Pair("rank", (int)(GetFortunastakeRank(mn, pindexBest->nHeight)))); + list.push_back(Pair("rank", (int)(GetFortunastakeRank(mn, pindexBest)))); list.push_back(Pair("lastpaid", mn.nBlockLastPaid)); obj.push_back(Pair(mn.addr.ToString().c_str(), list)); } @@ -853,7 +853,7 @@ Value masternode(const Array& params, bool fHelp) } else if (strCommand == "activeseconds") { obj.push_back(Pair(mn.addr.ToString().c_str(), (int64_t)(mn.lastTimeSeen - mn.now))); } else if (strCommand == "rank") { - obj.push_back(Pair(mn.addr.ToString().c_str(), (int)(GetFortunastakeRank(mn, pindexBest->nHeight)))); + obj.push_back(Pair(mn.addr.ToString().c_str(), (int)(GetFortunastakeRank(mn, pindexBest)))); } else if (strCommand == "full") { Object list; @@ -871,7 +871,7 @@ Value masternode(const Array& params, bool fHelp) list.push_back(Pair("protocolversion", (int64_t)mn.protocolVersion)); list.push_back(Pair("lastseen", (int64_t)mn.lastTimeSeen)); list.push_back(Pair("activeseconds", (int64_t)(mn.lastTimeSeen - mn.now))); - list.push_back(Pair("rank", (int)(GetFortunastakeRank(mn, pindexBest->nHeight)))); + list.push_back(Pair("rank", (int)(GetFortunastakeRank(mn, pindexBest)))); list.push_back(Pair("lastpaid", mn.nBlockLastPaid)); obj.push_back(Pair(mn.addr.ToString().c_str(), list)); } From c00858e9d892c3bd6d6ca11776ec14f510c03622 Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 22:04:13 +1030 Subject: [PATCH 08/11] move new fortuna stakes to last rank until the right block --- src/fortunastake.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fortunastake.cpp b/src/fortunastake.cpp index 3129c9f4..a52888ae 100644 --- a/src/fortunastake.cpp +++ b/src/fortunastake.cpp @@ -563,7 +563,16 @@ bool GetFortunastakeRanks(CBlockIndex* pindex) //vecFortunastakeScoresCache.insert(make_pair(pindex->GetBlockHash(), vecFortunastakeScoresList)); sort(vecFortunastakeScores.rbegin(), vecFortunastakeScores.rend(), CompareLastPay(pindex)); // sort requires current pindex for modulus as pindexBest is different between clients - //sort(vecFortunastakeScores.rbegin(), vecFortunastakeScores.rend(), CompareSigTimeTo(pindex)); // put mn's that are new to last rank + // put mn's that are new to last rank + i = 0; + BOOST_FOREACH(CFortunaStake& mn, vecFortunastakeScoresList) + { + i++; + if (mn.nTimeRegistered > pindex->GetBlockTime()) { + vecFortunastakeScores.push_back(vecFortunastakeScores[i]); + vecFortunastakeScores.erase(vecFortunastakeScores.begin() + i); + } + } return true; } From 251ea62862d57c6344674eeeb249657d3d5ea8b9 Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 22:35:17 +1030 Subject: [PATCH 09/11] don't do payment checks early on in long chains as the mn list is stale payment for blocks in the past is confirmed by network anyway --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 483db484..48d87c86 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2478,7 +2478,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) } } - if(pindex->GetBlockTime() > GetTime() - 30*nCoinbaseMaturity && !IsInitialBlockDownload() && FortunastakePayments == true) + if(pindex->GetBlockTime() > GetTime() - 30*nCoinbaseMaturity && (pindex->nHeight < pindexBest->nHeight+20) && !IsInitialBlockDownload() && FortunastakePayments == true) { LOCK2(cs_main, mempool.cs); From 41fd78f3c2d5fc76f09e1409566b52eaa25291f1 Mon Sep 17 00:00:00 2001 From: enkayz Date: Thu, 6 Dec 2018 22:42:23 +1030 Subject: [PATCH 10/11] version update --- denarius-qt.pro | 2 +- src/clientversion.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/denarius-qt.pro b/denarius-qt.pro index 569f09b4..694f7bae 100644 --- a/denarius-qt.pro +++ b/denarius-qt.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = Denarius -VERSION = 3.2.0.0 +VERSION = 3.2.5.0 INCLUDEPATH += src src/json src/qt src/tor src/qt/plugins/mrichtexteditor DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE CONFIG += no_include_pwd diff --git a/src/clientversion.h b/src/clientversion.h index 7150e35d..477c7aa2 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -8,7 +8,7 @@ // These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it #define CLIENT_VERSION_MAJOR 3 #define CLIENT_VERSION_MINOR 2 -#define CLIENT_VERSION_REVISION 0 +#define CLIENT_VERSION_REVISION 5 #define CLIENT_VERSION_BUILD 0 // Converts the parameter X to a string after macro replacement on X has been performed. From f6a333d7d71ffac0aa5f8e601bc07aff394b9b63 Mon Sep 17 00:00:00 2001 From: enkayz Date: Fri, 7 Dec 2018 00:39:21 +1030 Subject: [PATCH 11/11] go back to the future --- denarius-qt.pro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/denarius-qt.pro b/denarius-qt.pro index 694f7bae..d3b05351 100644 --- a/denarius-qt.pro +++ b/denarius-qt.pro @@ -24,8 +24,8 @@ BOOST_INCLUDE_PATH=C:/deps/boost_1_57_0 BOOST_LIB_PATH=C:/deps/boost_1_57_0/stage/lib BDB_INCLUDE_PATH=C:/deps/db-4.8.30.NC/build_unix BDB_LIB_PATH=C:/deps/db-4.8.30.NC/build_unix -OPENSSL_INCLUDE_PATH=C:/deps/openssl-1.0.1l/include -OPENSSL_LIB_PATH=C:/deps/openssl-1.0.1l +OPENSSL_INCLUDE_PATH=C:/deps/openssl-1.0.1j/include +OPENSSL_LIB_PATH=C:/deps/openssl-1.0.1j MINIUPNPC_INCLUDE_PATH=C:/deps/ MINIUPNPC_LIB_PATH=C:/deps/miniupnpc LIBPNG_INCLUDE_PATH=C:/deps/libpng-1.6.16