From 1af1366ff3b26598c1f2adef97be028cfcb0d2e7 Mon Sep 17 00:00:00 2001 From: deusstultus Date: Fri, 5 Dec 2014 09:00:07 -0600 Subject: [PATCH 01/14] Revert 25a07f10 -- makefile.unix STATIC=1 not cleanly implemented --- src/makefile.unix | 1 - 1 file changed, 1 deletion(-) diff --git a/src/makefile.unix b/src/makefile.unix index 913b1472d7..48fcd31176 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -23,7 +23,6 @@ ifdef UNIT_TEST DEFS+=-DUNIT_TEST=1 endif -STATIC = 1 LMODE = dynamic LMODE2 = dynamic ifdef STATIC From bdbbcaf3d13c5aa5083b2ab6aef267920a7cd746 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sat, 6 Dec 2014 04:48:12 +0300 Subject: [PATCH 02/14] use separate _debug.log with -wallet option --- src/init.cpp | 6 +++++- src/util.cpp | 8 +++++--- src/util.h | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 5b9aa76f56..b19432581d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -683,7 +683,8 @@ bool AppInit2(boost::thread_group& threadGroup) //ignore masternodes below protocol version nMasternodeMinProtocol = GetArg("-masternodeminprotocol", 0); - std::string strWalletFile = GetArg("-wallet", "wallet.dat"); + //define wallet and debug file + strWalletFile = GetArg("-wallet", "wallet.dat"); // ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log @@ -701,6 +702,9 @@ bool AppInit2(boost::thread_group& threadGroup) if (!lock.try_lock()) return InitError(strprintf(_("Cannot obtain a lock on data directory %s. DarkCoin is probably already running."), strDataDir.c_str())); + if(strWalletFile != "wallet.dat") + strDebugFile = boost::filesystem::basename(strWalletFile) + "_debug.log"; + if (GetBoolArg("-shrinkdebugfile", !fDebug)) ShrinkDebugFile(); LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); diff --git a/src/util.cpp b/src/util.cpp index 7c3500b208..36fb5025d0 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -73,6 +73,8 @@ map > mapMultiArgs; bool fMasterNode = false; string strMasterNodePrivKey = ""; string strMasterNodeAddr = ""; +string strWalletFile = "wallet.dat"; +string strDebugFile = "debug.log"; int nInstantXDepth = 1; int nDarksendRounds = 2; int nAnonymizeDarkcoinAmount = 1000; @@ -250,7 +252,7 @@ static void DebugPrintInit() assert(fileout == NULL); assert(mutexDebugLog == NULL); - boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; + boost::filesystem::path pathDebug = GetDataDir() / strDebugFile; fileout = fopen(pathDebug.string().c_str(), "a"); if (fileout) setbuf(fileout, NULL); // unbuffered @@ -287,7 +289,7 @@ int LogPrint(const char* category, const char* pszFormat, ...) // reopen the log file, if requested if (fReopenDebugLog) { fReopenDebugLog = false; - boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; + boost::filesystem::path pathDebug = GetDataDir() / strDebugFile; if (freopen(pathDebug.string().c_str(),"a",fileout) != NULL) setbuf(fileout, NULL); // unbuffered } @@ -1287,7 +1289,7 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) { void ShrinkDebugFile() { // Scroll debug.log if it's getting too big - boost::filesystem::path pathLog = GetDataDir() / "debug.log"; + boost::filesystem::path pathLog = GetDataDir() / strDebugFile; FILE* file = fopen(pathLog.string().c_str(), "r"); if (file && GetFilesize(file) > 10 * 1000000) { diff --git a/src/util.h b/src/util.h index 507ade862d..4b5a4a492c 100644 --- a/src/util.h +++ b/src/util.h @@ -137,6 +137,8 @@ extern int nLiquidityProvider; extern bool fEnableDarksend; extern int64 enforceMasternodePaymentsTime; extern std::string strMasterNodeAddr; +extern std::string strWalletFile; +extern std::string strDebugFile; extern int nMasternodeMinProtocol; extern int keysLoaded; extern bool fSucessfullyLoaded; From c4419878bc5ae099170e953f0fad9eca5b188775 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sat, 6 Dec 2014 04:50:53 +0300 Subject: [PATCH 03/14] use separate _debug.log with -wallet option - fix comments --- src/init.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index b19432581d..21c7ee96a3 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -683,7 +683,7 @@ bool AppInit2(boost::thread_group& threadGroup) //ignore masternodes below protocol version nMasternodeMinProtocol = GetArg("-masternodeminprotocol", 0); - //define wallet and debug file + //define wallet strWalletFile = GetArg("-wallet", "wallet.dat"); // ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log @@ -702,6 +702,7 @@ bool AppInit2(boost::thread_group& threadGroup) if (!lock.try_lock()) return InitError(strprintf(_("Cannot obtain a lock on data directory %s. DarkCoin is probably already running."), strDataDir.c_str())); + //use _debug.log with -wallet option if(strWalletFile != "wallet.dat") strDebugFile = boost::filesystem::basename(strWalletFile) + "_debug.log"; From f0e2db9c244160b26e1833a6b4d8616da305f168 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 8 Dec 2014 23:22:52 +0300 Subject: [PATCH 04/14] fix anonimizeonly parameter work/description for console --- src/bitcoinrpc.cpp | 1 + src/rpcwallet.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index f80c15ab05..3ef1be0bb5 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1180,6 +1180,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 2) ConvertTo(params[2]); if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); + if (strMethod == "walletpassphrase" && n > 2) ConvertTo(params[2]); if (strMethod == "getblocktemplate" && n > 0) ConvertTo(params[0]); if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); if (strMethod == "sendmany" && n > 1) ConvertTo(params[1]); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index a1ebcffa49..f36f62ee38 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -1354,7 +1354,7 @@ Value walletpassphrase(const Array& params, bool fHelp) { if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3)) throw runtime_error( - "walletpassphrase [anonymizenonly]\n" + "walletpassphrase [anonymizenonly=false]\n" "Stores the wallet decryption key in memory for seconds.\n" "if [anonymizeonly] is true sending functions are disabled."); if (fHelp) @@ -1388,7 +1388,7 @@ Value walletpassphrase(const Array& params, bool fHelp) } else throw runtime_error( - "walletpassphrase [anonymizeonly]\n" + "walletpassphrase [anonymizeonly=false]\n" "Stores the wallet decryption key in memory for seconds.\n" "if [anonymizeonly] is true sending functions are disabled."); From e64becee9e8084dd44db8cffbbb570d56b2c84e5 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 12 Dec 2014 07:58:50 +0300 Subject: [PATCH 05/14] fix wallet locking after sending coins --- src/qt/sendcoinsdialog.cpp | 24 ++++++++++++++++++++---- src/qt/sendcoinsdialog.h | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index e2cf9edc5e..8aa5095e0c 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -187,14 +187,30 @@ void SendCoinsDialog::on_sendButton_clicked() return; } - WalletModel::UnlockContext ctx(model->requestUnlock(true)); - if(!ctx.isValid()) + // request unlock only if was locked or unlocked for mixing: + // this way we let users unlock by walletpassphrase or by menu + // and make many transactions while unlocking through this dialog + // will call relock + WalletModel::EncryptionStatus encStatus = model->getEncryptionStatus(); + if(encStatus == model->Locked || + encStatus == model->UnlockedForAnonymizationOnly) { - // Unlock wallet was cancelled - fNewRecipientAllowed = true; + WalletModel::UnlockContext ctx(model->requestUnlock(true)); + if(!ctx.isValid()) + { + // Unlock wallet was cancelled + fNewRecipientAllowed = true; + return; + } + send(recipients); return; } + send(recipients); +} + +void SendCoinsDialog::send(QList recipients) +{ WalletModel::SendCoinsReturn sendstatus; if (!model->getOptionsModel() || !model->getOptionsModel()->getCoinControlFeatures()) sendstatus = model->sendCoins(recipients); diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h index 8d8d71d0d9..f123e398a2 100644 --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -50,6 +50,7 @@ private: bool fNewRecipientAllowed; bool boolCheckedBalance; int cachedNumBlocks; + void send(QList recipients); private slots: void on_sendButton_clicked(); From f70100df260781a4777f4feb9a8c92937f83fed7 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 12 Dec 2014 08:53:09 +0300 Subject: [PATCH 06/14] revert _debug.log --- src/init.cpp | 7 +------ src/util.cpp | 8 +++----- src/util.h | 2 -- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 21c7ee96a3..5b9aa76f56 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -683,8 +683,7 @@ bool AppInit2(boost::thread_group& threadGroup) //ignore masternodes below protocol version nMasternodeMinProtocol = GetArg("-masternodeminprotocol", 0); - //define wallet - strWalletFile = GetArg("-wallet", "wallet.dat"); + std::string strWalletFile = GetArg("-wallet", "wallet.dat"); // ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log @@ -702,10 +701,6 @@ bool AppInit2(boost::thread_group& threadGroup) if (!lock.try_lock()) return InitError(strprintf(_("Cannot obtain a lock on data directory %s. DarkCoin is probably already running."), strDataDir.c_str())); - //use _debug.log with -wallet option - if(strWalletFile != "wallet.dat") - strDebugFile = boost::filesystem::basename(strWalletFile) + "_debug.log"; - if (GetBoolArg("-shrinkdebugfile", !fDebug)) ShrinkDebugFile(); LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); diff --git a/src/util.cpp b/src/util.cpp index 36fb5025d0..7c3500b208 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -73,8 +73,6 @@ map > mapMultiArgs; bool fMasterNode = false; string strMasterNodePrivKey = ""; string strMasterNodeAddr = ""; -string strWalletFile = "wallet.dat"; -string strDebugFile = "debug.log"; int nInstantXDepth = 1; int nDarksendRounds = 2; int nAnonymizeDarkcoinAmount = 1000; @@ -252,7 +250,7 @@ static void DebugPrintInit() assert(fileout == NULL); assert(mutexDebugLog == NULL); - boost::filesystem::path pathDebug = GetDataDir() / strDebugFile; + boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; fileout = fopen(pathDebug.string().c_str(), "a"); if (fileout) setbuf(fileout, NULL); // unbuffered @@ -289,7 +287,7 @@ int LogPrint(const char* category, const char* pszFormat, ...) // reopen the log file, if requested if (fReopenDebugLog) { fReopenDebugLog = false; - boost::filesystem::path pathDebug = GetDataDir() / strDebugFile; + boost::filesystem::path pathDebug = GetDataDir() / "debug.log"; if (freopen(pathDebug.string().c_str(),"a",fileout) != NULL) setbuf(fileout, NULL); // unbuffered } @@ -1289,7 +1287,7 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) { void ShrinkDebugFile() { // Scroll debug.log if it's getting too big - boost::filesystem::path pathLog = GetDataDir() / strDebugFile; + boost::filesystem::path pathLog = GetDataDir() / "debug.log"; FILE* file = fopen(pathLog.string().c_str(), "r"); if (file && GetFilesize(file) > 10 * 1000000) { diff --git a/src/util.h b/src/util.h index 4b5a4a492c..507ade862d 100644 --- a/src/util.h +++ b/src/util.h @@ -137,8 +137,6 @@ extern int nLiquidityProvider; extern bool fEnableDarksend; extern int64 enforceMasternodePaymentsTime; extern std::string strMasterNodeAddr; -extern std::string strWalletFile; -extern std::string strDebugFile; extern int nMasternodeMinProtocol; extern int keysLoaded; extern bool fSucessfullyLoaded; From cc28fefbcab8e20260acfb3a67d37a3f61d5a64c Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 12 Dec 2014 08:54:58 +0300 Subject: [PATCH 07/14] comments --- src/qt/sendcoinsdialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 8aa5095e0c..5c69fe4cd7 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -205,7 +205,7 @@ void SendCoinsDialog::on_sendButton_clicked() send(recipients); return; } - + // already unlocked or not encrypted at all send(recipients); } From ee8174a2c690b995003449a046b036d87ae25b5d Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Sun, 14 Dec 2014 18:04:35 -0700 Subject: [PATCH 08/14] fixed possible masternode payment exploit --- src/main.cpp | 112 +++++++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 49 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3b2283b379..c02d976d89 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -943,7 +943,7 @@ bool CTxMemPool::acceptable(CValidationState &state, CTransaction &tx, bool fChe return false; } } - + // Check for conflicts with in-memory transactions for (unsigned int i = 0; i < tx.vin.size(); i++) { @@ -980,7 +980,7 @@ bool CTxMemPool::acceptable(CValidationState &state, CTransaction &tx, bool fChe // only helps filling in pfMissingInputs (to determine missing vs spent). BOOST_FOREACH(const CTxIn txin, tx.vin) { if (!view.HaveCoins(txin.prevout.hash)) { - if (pfMissingInputs) + if (pfMissingInputs) *pfMissingInputs = true; return false; } @@ -1048,7 +1048,7 @@ bool CTransaction::AcceptToMemoryPool(CValidationState &state, bool fCheckInputs bool CTransaction::IsAcceptable(CValidationState &state, bool fCheckInputs, bool fLimitFree, bool* pfMissingInputs, bool fScriptChecks) { - return mempool.acceptable(state, *this, fCheckInputs, fLimitFree, pfMissingInputs, fScriptChecks); + return mempool.acceptable(state, *this, fCheckInputs, fLimitFree, pfMissingInputs, fScriptChecks); } bool CTransaction::AcceptableInputs(CValidationState &state, bool fLimitFree) @@ -1167,7 +1167,7 @@ int CMerkleTx::IsTransactionLocked() const for (unsigned int b = 0; b < vout.size(); b++) { for(it_ctxl it = mapTxLocks.begin(); it != mapTxLocks.end(); it++) { for (unsigned int a = 0; a < it->second.tx.vout.size(); a++) { - if(vout[b] == it->second.tx.vout[a]) + if(vout[b] == it->second.tx.vout[a]) found++; } if(found > 0) break; @@ -1387,7 +1387,7 @@ int64 static GetBlockValue(int nBits, int nHeight, int64 nFees) /* fixed bug caused diff to not be correctly calculated */ if(nHeight > 4500 || fTestNet) dDiff = ConvertBitsToDouble(nBits); - int64 nSubsidy = 0; + int64 nSubsidy = 0; if(nHeight >= 5465) { if((nHeight >= 17000 && dDiff > 75) || nHeight >= 24000) { // GPU/ASIC difficulty calc // 2222222/(((x+2600)/9)^2) @@ -1412,7 +1412,7 @@ int64 static GetBlockValue(int nBits, int nHeight, int64 nFees) for(int i = 46200; i <= nHeight; i += 210240) nSubsidy -= nSubsidy/14; } else { // yearly decline of production by 7.1% per year, projected 21.3M coins max by year 2050. - for(int i = 210240; i <= nHeight; i += 210240) nSubsidy -= nSubsidy/14; + for(int i = 210240; i <= nHeight; i += 210240) nSubsidy -= nSubsidy/14; } return nSubsidy + nFees; @@ -1424,7 +1424,7 @@ int64 GetMasternodePayment(int nHeight, int64 blockValue) if(fTestNet) { if(nHeight > 46000) ret += blockValue / 20; //25% - 2014-10-07 - if(nHeight > 46000+((576*1)*1)) ret += blockValue / 20; //30% - 2014-10-08 + if(nHeight > 46000+((576*1)*1)) ret += blockValue / 20; //30% - 2014-10-08 if(nHeight > 46000+((576*1)*2)) ret += blockValue / 20; //35% - 2014-10-09 if(nHeight > 46000+((576*1)*3)) ret += blockValue / 20; //40% - 2014-10-10 if(nHeight > 46000+((576*1)*4)) ret += blockValue / 20; //45% - 2014-10-11 @@ -1433,7 +1433,7 @@ int64 GetMasternodePayment(int nHeight, int64 blockValue) if(nHeight > 46000+((576*1)*7)) ret += blockValue / 20; //60% - 2014-10-14 } - if(nHeight > 158000) ret += blockValue / 20; //25.0% - 2014-10-23 + if(nHeight > 158000) ret += blockValue / 20; //25.0% - 2014-10-23 if(nHeight > 158000+((576*30)*1)) ret += blockValue / 20; //30.0% - 2014-11-23 if(nHeight > 158000+((576*30)*2)) ret += blockValue / 20; //35.0% - 2014-12-23 if(nHeight > 158000+((576*30)*3)) ret += blockValue / 40; //37.5% - 2015-01-23 @@ -1562,17 +1562,17 @@ unsigned int static KimotoGravityWell(const CBlockIndex* pindexLast, const CBloc double EventHorizonDeviation; double EventHorizonDeviationFast; double EventHorizonDeviationSlow; - + if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || (uint64)BlockLastSolved->nHeight < PastBlocksMin) { return bnProofOfWorkLimit.GetCompact(); } - + for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) { if (PastBlocksMax > 0 && i > PastBlocksMax) { break; } PastBlocksMass++; - + if (i == 1) { PastDifficultyAverage.SetCompact(BlockReading->nBits); } else { PastDifficultyAverage = ((CBigNum().SetCompact(BlockReading->nBits) - PastDifficultyAveragePrev) / i) + PastDifficultyAveragePrev; } PastDifficultyAveragePrev = PastDifficultyAverage; - + PastRateActualSeconds = BlockLastSolved->GetBlockTime() - BlockReading->GetBlockTime(); PastRateTargetSeconds = TargetBlocksSpacingSeconds * PastBlocksMass; PastRateAdjustmentRatio = double(1); @@ -1583,14 +1583,14 @@ unsigned int static KimotoGravityWell(const CBlockIndex* pindexLast, const CBloc EventHorizonDeviation = 1 + (0.7084 * pow((double(PastBlocksMass)/double(28.2)), -1.228)); EventHorizonDeviationFast = EventHorizonDeviation; EventHorizonDeviationSlow = 1 / EventHorizonDeviation; - + if (PastBlocksMass >= PastBlocksMin) { if ((PastRateAdjustmentRatio <= EventHorizonDeviationSlow) || (PastRateAdjustmentRatio >= EventHorizonDeviationFast)) { assert(BlockReading); break; } } if (BlockReading->pprev == NULL) { assert(BlockReading); break; } BlockReading = BlockReading->pprev; } - + CBigNum bnNew(PastDifficultyAverage); if (PastRateActualSeconds != 0 && PastRateTargetSeconds != 0) { bnNew *= PastRateActualSeconds; @@ -1598,9 +1598,9 @@ unsigned int static KimotoGravityWell(const CBlockIndex* pindexLast, const CBloc } if (bnNew > bnProofOfWorkLimit) { - bnNew = bnProofOfWorkLimit; + bnNew = bnProofOfWorkLimit; } - + return bnNew.GetCompact(); } @@ -1618,10 +1618,10 @@ unsigned int static DarkGravityWave3(const CBlockIndex* pindexLast, const CBlock CBigNum PastDifficultyAverage; CBigNum PastDifficultyAveragePrev; - if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || BlockLastSolved->nHeight < PastBlocksMin) { - return bnProofOfWorkLimit.GetCompact(); + if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || BlockLastSolved->nHeight < PastBlocksMin) { + return bnProofOfWorkLimit.GetCompact(); } - + for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) { if (PastBlocksMax > 0 && i > PastBlocksMax) { break; } CountBlocks++; @@ -1636,12 +1636,12 @@ unsigned int static DarkGravityWave3(const CBlockIndex* pindexLast, const CBlock int64 Diff = (LastBlockTime - BlockReading->GetBlockTime()); nActualTimespan += Diff; } - LastBlockTime = BlockReading->GetBlockTime(); + LastBlockTime = BlockReading->GetBlockTime(); if (BlockReading->pprev == NULL) { assert(BlockReading); break; } BlockReading = BlockReading->pprev; } - + CBigNum bnNew(PastDifficultyAverage); int64 nTargetTimespan = CountBlocks*nTargetSpacing; @@ -1658,7 +1658,7 @@ unsigned int static DarkGravityWave3(const CBlockIndex* pindexLast, const CBlock if (bnNew > bnProofOfWorkLimit){ bnNew = bnProofOfWorkLimit; } - + return bnNew.GetCompact(); } @@ -1670,14 +1670,14 @@ unsigned int static GetNextWorkRequired_V2(const CBlockIndex* pindexLast, const int64 PastSecondsMax = TimeDaySeconds * 7; uint64 PastBlocksMin = PastSecondsMin / BlocksTargetSpacing; uint64 PastBlocksMax = PastSecondsMax / BlocksTargetSpacing; - + return KimotoGravityWell(pindexLast, pblock, BlocksTargetSpacing, PastBlocksMin, PastBlocksMax); } unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock) { int DiffMode = 1; - + if (fTestNet) { if (pindexLast->nHeight+1 >= 256) DiffMode = 3; } @@ -1821,7 +1821,7 @@ void CBlockHeader::UpdateTime(const CBlockIndex* pindexPrev) } uint256 CBlockHeader::GetHash() const -{ +{ return HashX11(BEGIN(nVersion), END(nNonce)); } @@ -2807,12 +2807,13 @@ bool CBlock::CheckBlock(CValidationState &state, bool fCheckPOW, bool fCheckMerk if(pindexBest->GetBlockHash() == hashPrevBlock){ int64 masternodePaymentAmount = GetMasternodePayment(pindexBest->nHeight+1, vtx[0].GetValueOut()); bool fIsInitialDownload = IsInitialBlockDownload(); - + // If we don't already have its previous block, skip masternode payment step if (!fIsInitialDownload && pindexBest != NULL) { bool foundPaymentAmount = false; bool foundPayee = false; + bool foundPaymentAndPayee = false; CScript payee; if(!masternodePayments.GetBlockPayee(pindexBest->nHeight+1, payee) || payee == CScript()){ @@ -2824,15 +2825,28 @@ bool CBlock::CheckBlock(CValidationState &state, bool fCheckPOW, bool fCheckMerk foundPaymentAmount = true; if(vtx[0].vout[i].scriptPubKey == payee ) foundPayee = true; + if(vtx[0].vout[i].nValue == masternodePaymentAmount && vtx[0].vout[i].scriptPubKey == payee) + foundPaymentAndPayee = true; } - if(!foundPaymentAmount || !foundPayee) { - CTxDestination address1; - ExtractDestination(payee, address1); - CBitcoinAddress address2(address1); + if (GetBlockTime() < 1419207339){ + if(!foundPaymentAmount || !foundPayee) { + CTxDestination address1; + ExtractDestination(payee, address1); + CBitcoinAddress address2(address1); - LogPrintf("CheckBlock() : Couldn't find masternode payment(%d|%"PRI64u") or payee(%d|%s) nHeight %d. \n", foundPaymentAmount, masternodePaymentAmount, foundPayee, address2.ToString().c_str(), pindexBest->nHeight+1); - if(EnforceMasternodePayments) return state.DoS(100, error("CheckBlock() : Couldn't find masternode payment or payee")); + LogPrintf("CheckBlock() : Couldn't find masternode payment(%d|%"PRI64u") or payee(%d|%s) nHeight %d. \n", foundPaymentAmount, masternodePaymentAmount, foundPayee, address2.ToString().c_str(), pindexBest->nHeight+1); + if(EnforceMasternodePayments) return state.DoS(100, error("CheckBlock() : Couldn't find masternode payment or payee")); + } + } else { + if(!foundPaymentAndPayee) { + CTxDestination address1; + ExtractDestination(payee, address1); + CBitcoinAddress address2(address1); + + LogPrintf("CheckBlock() : Couldn't find masternode payment(%d|%"PRI64u") or payee(%d|%s) nHeight %d. \n", foundPaymentAmount, masternodePaymentAmount, foundPayee, address2.ToString().c_str(), pindexBest->nHeight+1); + if(EnforceMasternodePayments) return state.DoS(100, error("CheckBlock() : Couldn't find masternode payment or payee")); + } } } } else { @@ -2905,7 +2919,7 @@ bool CBlock::AcceptBlock(CValidationState &state, CDiskBlockPos *dbp) double n1 = ConvertBitsToDouble(nBits); double n2 = ConvertBitsToDouble(nBitsNext); - if (abs(n1-n2) > n1*0.5) + if (abs(n1-n2) > n1*0.5) return state.DoS(100, error("AcceptBlock() : incorrect proof of work (DGW pre-fork) - %f", abs(n1-n2))); } else { if (nBits != GetNextWorkRequired(pindexPrev, this)) @@ -3506,7 +3520,7 @@ bool InitBlockIndex() { if (pindexGenesisBlock != NULL) { // Check whether the master checkpoint key has changed and reset the sync checkpoint if needed. if (!CheckCheckpointPubKey()) - return error("LoadBlockIndex() : failed to reset checkpoint master pubkey"); + return error("LoadBlockIndex() : failed to reset checkpoint master pubkey"); return true; } @@ -3524,7 +3538,7 @@ bool InitBlockIndex() { // CTxOut(nValue=50.00000000, scriptPubKey=040184710fa689ad5023690c80f3a4) // vMerkleTree: 97ddfbbae6 - // Genesis block + // Genesis block const char* pszTimestamp = "Wired 09/Jan/2014 The Grand Experiment Goes Live: Overstock.com Is Now Accepting Bitcoins"; CTransaction txNew; txNew.vin.resize(1); @@ -3926,7 +3940,7 @@ void static ProcessGetData(CNode* pfrom) { // Send stream from relay memory bool pushed = false; - + if(!mapDarksendBroadcastTxes.count(inv.hash)) { LOCK(cs_mapRelay); @@ -3942,10 +3956,10 @@ void static ProcessGetData(CNode* pfrom) if(mapDarksendBroadcastTxes.count(inv.hash)){ CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss.reserve(1000); - ss << - mapDarksendBroadcastTxes[inv.hash].tx << - mapDarksendBroadcastTxes[inv.hash].vin << - mapDarksendBroadcastTxes[inv.hash].vchSig << + ss << + mapDarksendBroadcastTxes[inv.hash].tx << + mapDarksendBroadcastTxes[inv.hash].vin << + mapDarksendBroadcastTxes[inv.hash].vchSig << mapDarksendBroadcastTxes[inv.hash].sigTime; pfrom->PushMessage("dstx", ss); @@ -4073,7 +4087,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // Change version pfrom->PushMessage("verack"); pfrom->ssSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); - + if (!pfrom->fInbound) { // Advertise our address @@ -4381,7 +4395,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) return true; } - std::string strMessage = tx.GetHash().ToString() + boost::lexical_cast(sigTime); + std::string strMessage = tx.GetHash().ToString() + boost::lexical_cast(sigTime); std::string errorMessage = ""; if(!darkSendSigner.VerifyMessage(mn.pubkey2, vchSig, strMessage, errorMessage)){ @@ -4662,7 +4676,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else { - //probably one the extensions + //probably one the extensions ProcessMessageDarksend(pfrom, strCommand, vRecv); ProcessMessageMasternode(pfrom, strCommand, vRecv); ProcessMessageInstantX(pfrom, strCommand, vRecv); @@ -5098,7 +5112,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) int payments = 1; // Create coinbase tx CTransaction txNew; - txNew.vin.resize(1); + txNew.vin.resize(1); txNew.vin[0].prevout.SetNull(); txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; @@ -5116,13 +5130,13 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) bMasterNodePayment = true; } } - + int64 nFees = 0; { LOCK2(cs_main, mempool.cs); CCoinsViewCache view(*pcoinsTip, true); CBlockIndex* pindexPrev = pindexBest; - + if(bMasterNodePayment) { bool hasPayment = true; //spork @@ -5131,7 +5145,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) int winningNode = GetCurrentMasterNode(1); if(winningNode >= 0){ pblock->payee.SetDestination(darkSendMasterNodes[winningNode].pubkey.GetID()); - } else { + } else { LogPrintf("CreateNewBlock: Failed to detect masternode to pay\n"); hasPayment = false; } @@ -5357,7 +5371,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) int64 blockValue = GetBlockValue(pindexPrev->nBits, pindexPrev->nHeight, nFees); int64 masternodePayment = GetMasternodePayment(pindexPrev->nHeight+1, blockValue); - + //create masternode payment if(payments > 1){ pblock->vtx[0].vout[payments-1].nValue = masternodePayment; @@ -5374,7 +5388,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nNonce = 0; pblock->vtx[0].vin[0].scriptSig = CScript() << OP_0 << OP_0; pblocktemplate->vTxSigOps[0] = pblock->vtx[0].GetLegacySigOpCount(); - + CBlockIndex indexDummy(*pblock); indexDummy.pprev = pindexPrev; From adcf6609d8564e09fac4ab5ee45c685ab1868ca0 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Tue, 16 Dec 2014 06:13:11 -0700 Subject: [PATCH 09/14] Better support for non-specific masternode payments --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index c02d976d89..8ad5831abc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2818,6 +2818,8 @@ bool CBlock::CheckBlock(CValidationState &state, bool fCheckPOW, bool fCheckMerk CScript payee; if(!masternodePayments.GetBlockPayee(pindexBest->nHeight+1, payee) || payee == CScript()){ foundPayee = true; //doesn't require a specific payee + foundPaymentAmount = true; + foundPaymentAndPayee = true; } for (unsigned int i = 0; i < vtx[0].vout.size(); i++) { From 4ff18d627767c1ef2f341058f6dc7112711810eb Mon Sep 17 00:00:00 2001 From: Francis Reynders Date: Tue, 16 Dec 2014 19:58:53 +0100 Subject: [PATCH 10/14] Fixed lookup for correct vin in GetMasterNodeVin when txHash is available. --- src/activemasternode.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 98a5e6916b..d6fd44f62e 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -296,10 +296,12 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr if(!strTxHash.empty()) { // Let's find it uint256 txHash(strTxHash); - int outputIndex = boost::lexical_cast(outputIndex); + int outputIndex = 0; + outputIndex = boost::lexical_cast(outputIndex); bool found = false; BOOST_FOREACH(COutput& out, possibleCoins) { - if(true) { + if(out.tx->GetHash() == txHash && out.i == outputIndex) + { selectedOutput = &out; found = true; break; From f89f68f55a4e2a3d3d192d8463bacddc52d23ca3 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Tue, 16 Dec 2014 14:46:36 -0700 Subject: [PATCH 11/14] added masternode outputs command for use with start-many --- src/rpcdarksend.cpp | 47 +++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/rpcdarksend.cpp b/src/rpcdarksend.cpp index 285ebf7b99..162de10792 100644 --- a/src/rpcdarksend.cpp +++ b/src/rpcdarksend.cpp @@ -23,10 +23,10 @@ Value darksend(const Array& params, bool fHelp) "darkcoinaddress, reset, or auto (AutoDenominate)" " is a real and is rounded to the nearest 0.00000001" + HelpRequiringPassphrase()); - + if(fMasterNode) return "DarkSend is not supported from masternodes"; - + if (pwalletMain->IsLocked()) throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); @@ -89,9 +89,9 @@ Value masternode(const Array& params, bool fHelp) if (fHelp || (strCommand != "start" && strCommand != "start-alias" && strCommand != "start-many" && strCommand != "stop" && strCommand != "stop-alias" && strCommand != "stop-many" && strCommand != "list" && strCommand != "list-conf" && strCommand != "count" && strCommand != "enforce" - && strCommand != "debug" && strCommand != "current" && strCommand != "winners" && strCommand != "genkey" && strCommand != "connect")) + && strCommand != "debug" && strCommand != "current" && strCommand != "winners" && strCommand != "genkey" && strCommand != "connect" && strCommand != "outputs")) throw runtime_error( - "masternode passphrase\n"); + "masternode [passphrase]\n"); if (strCommand == "stop") { @@ -107,7 +107,7 @@ Value masternode(const Array& params, bool fHelp) throw runtime_error( "Your wallet is locked, passphrase is required\n"); } - + if(!pwalletMain->Unlock(strWalletPass)){ return "incorrect passphrase"; } @@ -118,10 +118,10 @@ Value masternode(const Array& params, bool fHelp) return "stop failed: " + errorMessage; } pwalletMain->Lock(); - + if(activeMasternode.status == MASTERNODE_STOPPED) return "successfully stopped masternode"; if(activeMasternode.status == MASTERNODE_NOT_CAPABLE) return "not capable masternode"; - + return "unknown"; } @@ -234,7 +234,7 @@ Value masternode(const Array& params, bool fHelp) } if (strCommand == "list") - { + { std::string strCommand = "active"; if (params.size() == 2){ @@ -248,7 +248,7 @@ Value masternode(const Array& params, bool fHelp) Object obj; BOOST_FOREACH(CMasterNode mn, darkSendMasterNodes) { - mn.Check(); + mn.Check(); if(strCommand == "active"){ obj.push_back(Pair(mn.addr.ToString().c_str(), (int)mn.IsEnabled())); @@ -290,7 +290,7 @@ Value masternode(const Array& params, bool fHelp) throw runtime_error( "Your wallet is locked, passphrase is required\n"); } - + if(!pwalletMain->Unlock(strWalletPass)){ return "incorrect passphrase"; } @@ -300,7 +300,7 @@ Value masternode(const Array& params, bool fHelp) std::string errorMessage; activeMasternode.ManageStatus(); pwalletMain->Lock(); - + if(activeMasternode.status == MASTERNODE_REMOTELY_ENABLED) return "masternode started remotely"; if(activeMasternode.status == MASTERNODE_INPUT_TOO_NEW) return "masternode input must have at least 15 confirmations"; if(activeMasternode.status == MASTERNODE_STOPPED) return "masternode is stopped"; @@ -364,9 +364,9 @@ Value masternode(const Array& params, bool fHelp) return statusObj; } - + if (strCommand == "start-many") - { + { if(pwalletMain->IsLocked()) { SecureString strWalletPass; strWalletPass.reserve(100); @@ -442,9 +442,22 @@ Value masternode(const Array& params, bool fHelp) } } + if (strCommand == "outputs"){ + // Find possible candidates + vector possibleCoins = activeMasternode.SelectCoinsMasternode(); + + Object obj; + BOOST_FOREACH(COutput& out, possibleCoins) { + obj.push_back(Pair(out.tx->GetHash().ToString().c_str(), boost::lexical_cast(out.i))); + } + + return obj; + + } + if (strCommand == "create") { - + return "Not implemented yet, please look at the documentation for instructions on masternode creation"; } @@ -459,7 +472,7 @@ Value masternode(const Array& params, bool fHelp) } if (strCommand == "genkey") - { + { CKey secret; secret.MakeNewKey(false); @@ -467,7 +480,7 @@ Value masternode(const Array& params, bool fHelp) } if (strCommand == "winners") - { + { Object obj; for(int nHeight = pindexBest->nHeight-10; nHeight < pindexBest->nHeight+20; nHeight++) @@ -499,7 +512,7 @@ Value masternode(const Array& params, bool fHelp) } else { throw runtime_error( "Masternode address required\n"); - } + } CService addr = CService(strAddress); From 8eed460b31990fe8c3667857816facd183722969 Mon Sep 17 00:00:00 2001 From: crowning- Date: Tue, 30 Dec 2014 10:28:17 +0100 Subject: [PATCH 12/14] Disable RFC1918 local addresses again There are private addresses in the Masternode list which should not happen. --- src/masternode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/masternode.cpp b/src/masternode.cpp index 31080128a5..005c543bb0 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -59,7 +59,7 @@ void ProcessMessageMasternode(CNode* pfrom, std::string& strCommand, CDataStream return; } - bool isLocal = false; // addr.IsRFC1918(); + bool isLocal = addr.IsRFC1918(); std::string vchPubKey(pubkey.begin(), pubkey.end()); std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); From 0f19e8f30569fc74545809e567ee7defe5c4e560 Mon Sep 17 00:00:00 2001 From: crowning- Date: Tue, 30 Dec 2014 12:55:54 +0100 Subject: [PATCH 13/14] Updated some old Bitcoin constants --- doc/coding.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/coding.md b/doc/coding.md index 3581d7deb2..8d74fc4d09 100644 --- a/doc/coding.md +++ b/doc/coding.md @@ -5,8 +5,7 @@ Please be consistent with the existing coding style. Block style: - bool Function(char* psz, int n) - { + bool Function(char* psz, int n) { // Comment summarising what this section of code does for (int i = 0; i < n; i++) { @@ -65,9 +64,11 @@ Threads - StartNode : Starts other threads. +- ThreadCheckDarkSendPool : Builds and update Masternode list, starts auto-denomination + - ThreadGetMyExternalIP : Determines outside-the-firewall IP address, sends addr message to connected peers when it determines it. -- ThreadSocketHandler : Sends/Receives data from peers on port 8333. +- ThreadSocketHandler : Sends/Receives data from peers on port 9999. - ThreadMessageHandler : Higher-level message handling (sending and receiving). @@ -83,9 +84,9 @@ Threads - ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used in 500ms. -- ThreadRPCServer : Remote procedure call handler, listens on port 8332 for connections and services them. +- ThreadRPCServer : Remote procedure call handler, listens on port 9998 for connections and services them. -- ThreadBitcoinMiner : Generates bitcoins +- DarkcoinMiner : Generates darkcoins - ThreadMapPort : Universal plug-and-play startup/shutdown From ccd54725ff96107c60d5997fe837394bd14cce5b Mon Sep 17 00:00:00 2001 From: vertoe Date: Thu, 1 Jan 2015 21:56:18 +0100 Subject: [PATCH 14/14] Update public key versions. --- src/base58.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/base58.h b/src/base58.h index 015e4fd48d..04a94a71c1 100644 --- a/src/base58.h +++ b/src/base58.h @@ -272,10 +272,10 @@ class CBitcoinAddress : public CBase58Data public: enum { - PUBKEY_ADDRESS = 48+28, // DarkCoin addresses start with X - SCRIPT_ADDRESS = 5, - PUBKEY_ADDRESS_TEST = 111, - SCRIPT_ADDRESS_TEST = 196, + PUBKEY_ADDRESS = 76, // Darkcoin addresses start with 'X' + SCRIPT_ADDRESS = 16, // Darkcoin script addresses start with '7' + PUBKEY_ADDRESS_TEST = 139, // Testnet darkcoin addresses start with 'x' or 'y' + SCRIPT_ADDRESS_TEST = 19, // Testnet darkcoin script addresses start with '8' or '9' }; bool Set(const CKeyID &id) { @@ -400,8 +400,8 @@ class CBitcoinSecret : public CBase58Data public: enum { - PRIVKEY_ADDRESS = CBitcoinAddress::PUBKEY_ADDRESS + 128, - PRIVKEY_ADDRESS_TEST = CBitcoinAddress::PUBKEY_ADDRESS_TEST + 128, + PRIVKEY_ADDRESS = 204, // Darkcoin private keys start with '7' or 'X' + PRIVKEY_ADDRESS_TEST = 239, // Testnet private keys start with '9' or 'c' (Bitcoin defaults) }; void SetKey(const CKey& vchSecret)