From 8a47abd98b3dd2b39fe1815dd3c6f5b776424950 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 14 Aug 2018 10:57:11 +0200 Subject: [PATCH 1/6] Merge #13948: trivial: Removes unsed `CBloomFilter` constructor. 265bd50884ac1984c08f0e5916256d5f12e655f5 Removes unsed `CBloomFilter` constructor. (251) Pull request description: This pull request removes the `CBloomFilter::CBloomFilter(const unsigned int, const double, const unsigned int)` constructor, which became obsolete with 086ee67. Tree-SHA512: 46742f178e219661e82609a9bf6b644ebc58ab3efc2d1865c5562980e84f16a5fa286be9813738196ad7a27e639dee926062538eb44cadd67ab87ad5e9a266ba # Conflicts: # src/bloom.h --- src/bloom.cpp | 11 ----------- src/bloom.h | 4 ---- 2 files changed, 15 deletions(-) diff --git a/src/bloom.cpp b/src/bloom.cpp index fbf03133885f..2723c32e9a47 100644 --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -42,17 +42,6 @@ CBloomFilter::CBloomFilter(const unsigned int nElements, const double nFPRate, c { } -// Private constructor used by CRollingBloomFilter -CBloomFilter::CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweakIn) : - vData((unsigned int)(-1 / LN2SQUARED * nElements * log(nFPRate)) / 8), - isFull(false), - isEmpty(true), - nHashFuncs((unsigned int)(vData.size() * 8 / nElements * LN2)), - nTweak(nTweakIn), - nFlags(BLOOM_UPDATE_NONE) -{ -} - inline unsigned int CBloomFilter::Hash(unsigned int nHashNum, const std::vector& vDataToHash) const { // 0xFBA4C795 chosen as it guarantees a reasonable bit difference between nHashNum values. diff --git a/src/bloom.h b/src/bloom.h index ecb3c75599ca..e808a265fe7f 100644 --- a/src/bloom.h +++ b/src/bloom.h @@ -55,10 +55,6 @@ class CBloomFilter unsigned int Hash(unsigned int nHashNum, const std::vector& vDataToHash) const; - // Private constructor for CRollingBloomFilter, no restrictions on size - CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweak); - friend class CRollingBloomFilter; - // Check matches for arbitrary script data elements bool CheckScript(const CScript& script) const; // Check additional matches for special transactions From b40823154be50f307179ff19a095411de4b864f1 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 15 Aug 2018 11:07:34 -0400 Subject: [PATCH 2/6] Merge #13982: refactor: use fs:: over boost::filesystem:: 4b3b85c597 refactor: use fs:: over boost::filesystem:: (fanquake) Pull request description: Noticed while investigating #13973. Tree-SHA512: 20a764d2ff460883fa0fd543c0a51031a9a202b40cfda9943f9995d3108c0a8296a3982b63bbd069167f73a1855003304a83df466763032ce7339b08b3a97d4b # Conflicts: # src/qt/guiutil.cpp --- src/logging.cpp | 2 +- src/wallet/rpcdump.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/logging.cpp b/src/logging.cpp index db0a4c043bbc..7bb1807ac01d 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -303,7 +303,7 @@ void BCLog::Logger::ShrinkDebugFile() size_t log_size = 0; try { log_size = fs::file_size(m_file_path); - } catch (boost::filesystem::filesystem_error &) {} + } catch (const fs::filesystem_error&) {} // If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE // trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 7f9d4ee7f065..3d8f7d54f1a6 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -874,15 +874,15 @@ UniValue dumpwallet(const JSONRPCRequest& request) EnsureWalletIsUnlocked(pwallet); - boost::filesystem::path filepath = request.params[0].get_str(); - filepath = boost::filesystem::absolute(filepath); + fs::path filepath = request.params[0].get_str(); + filepath = fs::absolute(filepath); /* Prevent arbitrary files from being overwritten. There have been reports * that users have overwritten wallet files this way: * https://github.com/bitcoin/bitcoin/issues/9934 * It may also avoid other security issues. */ - if (boost::filesystem::exists(filepath)) { + if (fs::exists(filepath)) { throw JSONRPCError(RPC_INVALID_PARAMETER, filepath.string() + " already exists. If you are sure this is what you want, move it out of the way first"); } From 6af03a3125ebc6f913596f52d990f85325808cdd Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 15 Aug 2018 17:10:19 +0200 Subject: [PATCH 3/6] Merge #13891: [RPC] Remove getinfo deprecation warning b2f23c41538eaadd71c373ada75dd3a982eeb8bf [RPC] Remove getinfo deprecation warning (John Newbery) Pull request description: `getinfo` was removed in V0.16. A removal warning message was left in place to tell users that the method had been removed. We can remove that entirely in V0.18. Tree-SHA512: bf93fbcf57a9be480438dcbdcab2dfd69ce277218b10628776975b093b3ffd2caa1751e0fb4cb0245443c81465693e2b8750e96d3e38632a78bae5ffa04f9212 # Conflicts: # src/rpc/misc.cpp --- src/rpc/misc.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 9db82bc8ea59..48a757f541a7 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1137,18 +1137,6 @@ static UniValue echo(const JSONRPCRequest& request) return request.params; } -static UniValue getinfo_deprecated(const JSONRPCRequest& request) -{ - throw JSONRPCError(RPC_METHOD_NOT_FOUND, - "getinfo\n" - "\nThis call was removed in version 0.16.0. Use the appropriate fields from:\n" - "- getblockchaininfo: blocks, difficulty, chain\n" - "- getnetworkinfo: version, protocolversion, timeoffset, connections, proxy, relayfee, warnings\n" - "- getwalletinfo: balance, coinjoin_balance, keypoololdest, keypoolsize, paytxfee, unlocked_until, walletversion\n" - "\ndash-cli has the option -getinfo to collect and format these in the old format." - ); -} - static const CRPCCommand commands[] = { // category name actor (function) argNames // --------------------- ------------------------ ----------------------- ---------- @@ -1176,7 +1164,6 @@ static const CRPCCommand commands[] = { "hidden", "setmocktime", &setmocktime, {"timestamp"}}, { "hidden", "echo", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, { "hidden", "echojson", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, - { "hidden", "getinfo", &getinfo_deprecated, {}}, { "hidden", "mnauth", &mnauth, {"nodeId", "proTxHash", "publicKey"}}, }; From 805cda6f5fbcd56630bea2a65d002ee6ff4f842d Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 16 Aug 2018 06:49:25 -0400 Subject: [PATCH 4/6] Merge #13985: [trivial] Fix slightly confusing mispelling in feature_blocksdir.py log message 241f8b5de4 Fix typo in feature_blocksdir.py log message (Alexander Leishman) Pull request description: Typo I came across while writing some new tests. Tree-SHA512: cc494553125a1e84f9238a14761e3fb76623e98d951811dd3bfb13595a03a1888d73859487a2cbb76c7ae85897bc64016a220a92c2636b35ea6356a5b5340d66 # Conflicts: # test/functional/feature_blocksdir.py --- test/functional/feature_blocksdir.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/feature_blocksdir.py b/test/functional/feature_blocksdir.py index bb67c6ae2221..408b676e2e4a 100755 --- a/test/functional/feature_blocksdir.py +++ b/test/functional/feature_blocksdir.py @@ -22,12 +22,12 @@ def run_test(self): assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "blocks")) shutil.rmtree(self.nodes[0].datadir) initialize_datadir(self.options.tmpdir, 0, self.chain) - self.log.info("Starting with non exiting blocksdir ...") + self.log.info("Starting with nonexistent blocksdir ...") blocksdir_path = os.path.join(self.options.tmpdir, 'blocksdir') self.nodes[0].assert_start_raises_init_error(["-blocksdir=" + blocksdir_path], 'Error: Specified blocks directory "' + blocksdir_path + '" does not exist.') os.mkdir(blocksdir_path) - self.log.info("Starting with exiting blocksdir ...") + self.log.info("Starting with existing blocksdir ...") self.start_node(0, ["-blocksdir=" + blocksdir_path]) self.log.info("mining blocks..") self.nodes[0].generate(10) From 243ee3137a4cb7fb3811e8bb18daefb770fca834 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 22 Aug 2018 09:59:42 +0200 Subject: [PATCH 5/6] Merge #13967: [walletdb] don't report minversion wallet entry as unknown 321159e53e800c1df2d8dfd6ac03374f1829c327 don't report minversion wallet entry as unknown (Gregory Sanders) Pull request description: It is known in WalletBatch::LoadWallet Tree-SHA512: 82f7e12f48ae7d17317074ce5b5e27c70ba8334b04adbf7cc863f8169cc1aa460b9454571e2698aa00059c8c8f669fe19c0d40c4910dcded260ddca6ce78be9d # Conflicts: # src/wallet/walletdb.cpp --- src/wallet/walletdb.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index d57cae8e3190..d2c9826f8ae7 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -580,7 +580,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, return false; } } - else if (strType != "bestblock" && strType != "bestblock_nomerkle"){ + else if (strType != "bestblock" && strType != "bestblock_nomerkle" && + strType != "minversion"){ wss.m_unknown_records++; } } catch (...) From 19b9e74026afff6ade142d0d37aea4e1bb88d1a0 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sat, 25 Aug 2018 16:52:25 +0200 Subject: [PATCH 6/6] Merge #13631: Add CMerkleTx::IsImmatureCoinBase method 23f434378153cf764230066662f3ec3ad614ff30 Add CMerkleTx::IsImmatureCoinBase method (Ben Woosley) Pull request description: All but one call to `GetBlocksToMaturity` is testing it relative to 0 for the purposes of determining whether the coinbase tx is immature. In such case, the value greater than 0 implies that the tx is coinbase, so there is no need to separately test that status. This names the concept for easy singular use. Tree-SHA512: 4470d07404a0707144f9827b9a94c5c4905f23ee6f9248edc5df599a59d28e21ea0201d8abe5d5d73b39cb05b60c861ea8e04767eef04433e2ee95dcfed653ee # Conflicts: # src/wallet/wallet.h --- src/wallet/rpcwallet.cpp | 4 ++-- src/wallet/wallet.cpp | 21 ++++++++++++--------- src/wallet/wallet.h | 7 +++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f44f20f36a90..6e4e0cf83805 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1785,7 +1785,7 @@ static void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, cons { if (wtx.GetDepthInMainChain() < 1) entry.pushKV("category", "orphan"); - else if (wtx.GetBlocksToMaturity() > 0) + else if (wtx.IsImmatureCoinBase()) entry.pushKV("category", "immature"); else entry.pushKV("category", "generate"); @@ -2098,7 +2098,7 @@ static UniValue listaccounts(const JSONRPCRequest& request) std::list listReceived; std::list listSent; int nDepth = wtx.GetDepthInMainChain(); - if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0) + if (wtx.IsImmatureCoinBase() || nDepth < 0) continue; wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly); mapAccountBalances[strSentAccount] -= nFee; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 6da5cadea928..8601fb1c8ac5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2347,7 +2347,7 @@ CAmount CWalletTx::GetDebit(const isminefilter& filter) const CAmount CWalletTx::GetCredit(const isminefilter& filter) const { // Must wait until coinbase is safely deep enough in the chain before valuing it - if (IsCoinBase() && GetBlocksToMaturity() > 0) + if (IsImmatureCoinBase()) return 0; CAmount credit = 0; @@ -2379,8 +2379,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const { - if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) - { + if (IsImmatureCoinBase() && IsInMainChain()) { if (fUseCache && fImmatureCreditCached) return nImmatureCreditCached; nImmatureCreditCached = pwallet->GetCredit(*tx, ISMINE_SPENDABLE); @@ -2397,7 +2396,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter return 0; // Must wait until coinbase is safely deep enough in the chain before valuing it - if (IsCoinBase() && GetBlocksToMaturity() > 0) + if (IsImmatureCoinBase()) return 0; CAmount* cache = nullptr; @@ -2438,8 +2437,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool fUseCache) const { - if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) - { + if (IsImmatureCoinBase() && IsInMainChain()) { if (fUseCache && fImmatureWatchCreditCached) return nImmatureWatchCreditCached; nImmatureWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY); @@ -2848,7 +2846,7 @@ CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, cons for (const auto& entry : mapWallet) { const CWalletTx& wtx = entry.second; const int depth = wtx.GetDepthInMainChain(); - if (depth < 0 || !CheckFinalTx(*wtx.tx) || wtx.GetBlocksToMaturity() > 0) { + if (depth < 0 || !CheckFinalTx(*wtx.tx) || wtx.IsImmatureCoinBase()) { continue; } @@ -2908,7 +2906,7 @@ void CWallet::AvailableCoins(std::vector &vCoins, bool fOnlySafe, const if (!CheckFinalTx(*pcoin->tx)) continue; - if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) + if (pcoin->IsImmatureCoinBase()) continue; int nDepth = pcoin->GetDepthInMainChain(); @@ -4455,7 +4453,7 @@ std::map CWallet::GetAddressBalances() if (!pcoin->IsTrusted()) continue; - if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) + if (pcoin->IsImmatureCoinBase()) continue; int nDepth = pcoin->GetDepthInMainChain(); @@ -5549,6 +5547,11 @@ int CMerkleTx::GetBlocksToMaturity() const return std::max(0, (COINBASE_MATURITY+1) - chain_depth); } +bool CMerkleTx::IsImmatureCoinBase() const +{ + // note GetBlocksToMaturity is 0 for non-coinbase tx + return GetBlocksToMaturity() > 0; +} bool CWalletTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index d85743f80c73..fafadc3a0e76 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -256,6 +256,12 @@ class CMerkleTx bool IsInMainChain() const { return GetDepthInMainChain() > 0; } bool IsLockedByInstantSend() const; bool IsChainLocked() const; + + /** + * @return number of blocks to maturity for this transaction: + * 0 : is not a coinbase transaction, or is a mature coinbase transaction + * >0 : is a coinbase transaction which matures in this many blocks + */ int GetBlocksToMaturity() const; bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); } bool isAbandoned() const { return (hashBlock == ABANDON_HASH); } @@ -263,6 +269,7 @@ class CMerkleTx const uint256& GetHash() const { return tx->GetHash(); } bool IsCoinBase() const { return tx->IsCoinBase(); } + bool IsImmatureCoinBase() const; }; //Get the marginal bytes of spending the specified output