From c119ba3c9b321a7f4418860741b3f69173e9c891 Mon Sep 17 00:00:00 2001 From: Michael Polzer Date: Wed, 20 Feb 2019 21:00:04 +0100 Subject: [PATCH 0001/2453] [doc] clarify getdata limit after #14897 GETDATA is limited to blocks and transactions now and can't be used for other non-block data --- src/net_processing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 18dd2f010cd..1574a985d10 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3877,7 +3877,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto) } // - // Message: getdata (non-blocks) + // Message: getdata (transactions) // auto& tx_process_time = state.m_tx_download.m_tx_process_time; while (!tx_process_time.empty() && tx_process_time.begin()->first <= nNow && state.m_tx_download.m_tx_in_flight.size() < MAX_PEER_TX_IN_FLIGHT) { From 32def8d1c29e0855fe5429687acabd2f29119316 Mon Sep 17 00:00:00 2001 From: Peter Bushnell Date: Sun, 31 Mar 2019 14:47:54 +0100 Subject: [PATCH 0002/2453] Catch ios_base::failure specifically --- src/wallet/walletdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index a1928f45c45..6a470f38b84 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -277,7 +277,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, { ssValue >> hash; } - catch (...) {} + catch (const std::ios_base::failure&) {} bool fSkipCheck = false; From 7486e2771e7b5d6fa84df6e954be76350c84e220 Mon Sep 17 00:00:00 2001 From: Bushstar Date: Tue, 10 Mar 2020 07:42:31 +0000 Subject: [PATCH 0003/2453] Tests: Unit test related to WalletDB ReadKeyValue --- src/Makefile.test.include | 1 + src/wallet/test/walletdb_tests.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/wallet/test/walletdb_tests.cpp diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 669ebcbc485..80fbedbdebb 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -217,6 +217,7 @@ BITCOIN_TESTS += \ wallet/test/db_tests.cpp \ wallet/test/psbt_wallet_tests.cpp \ wallet/test/wallet_tests.cpp \ + wallet/test/walletdb_tests.cpp \ wallet/test/wallet_crypto_tests.cpp \ wallet/test/coinselector_tests.cpp \ wallet/test/init_tests.cpp \ diff --git a/src/wallet/test/walletdb_tests.cpp b/src/wallet/test/walletdb_tests.cpp new file mode 100644 index 00000000000..a3859e2e4b7 --- /dev/null +++ b/src/wallet/test/walletdb_tests.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2012-2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include + +#include + +BOOST_FIXTURE_TEST_SUITE(walletdb_tests, BasicTestingSetup) + +BOOST_AUTO_TEST_CASE(walletdb_readkeyvalue) +{ + /** + * When ReadKeyValue() reads from either a "key" or "wkey" it first reads the CDataStream steam into a + * CPrivKey or CWalletKey respectively and then reads a hash of the pubkey and privkey into a uint256. + * Wallets from 0.8 or before do not store the pubkey/privkey hash, trying to read the hash from old + * wallets throws an exception, for backwards compatibility this read is wrapped in a try block to + * silently fail. The test here makes sure the type of exception thrown from CDataStream::read() + * matches the type we expect, otherwise we need to update the "key"/"wkey" exception type caught. + */ + CDataStream ssValue(SER_DISK, CLIENT_VERSION); + uint256 dummy; + BOOST_CHECK_THROW(ssValue >> dummy, std::ios_base::failure); +} + +BOOST_AUTO_TEST_SUITE_END() From 05f9770c1fa64bd9730cd6e18ec333e0801c00d6 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Wed, 8 Apr 2020 15:08:35 -0400 Subject: [PATCH 0004/2453] doc: Clarify developer notes about constant naming I'm pretty sure developer notes were intended to say constants should be upper case and variables should be lower case, but right now they are ambiguous about whether to write: ```c++ // foo.h extern const int SYMBOL; // foo.cpp const int SYMBOL = 1; ``` or: ```c++ // foo.h extern const int g_symbol; // foo.cpp const int g_symbol = 1; ``` First convention above is better than the second convention because it tells you without having to look anything up that the value of `SYMBOL` will never change at runtime. Also I've never seen any c++ project anywhere using the second convention --- doc/developer-notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index da07080724b..97659cf76af 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -83,7 +83,7 @@ code. separate words (snake_case). - Class member variables have a `m_` prefix. - Global variables have a `g_` prefix. - - Compile-time constant names are all uppercase, and use `_` to separate words. + - Constant names are all uppercase, and use `_` to separate words. - Class names, function names, and method names are UpperCamelCase (PascalCase). Do not prefix class names with `C`. - Test suite naming convention: The Boost test suite in file From 83a425d25af033086744c1c8c892015014ed46bd Mon Sep 17 00:00:00 2001 From: William Casarin Date: Fri, 1 May 2020 17:31:38 -0700 Subject: [PATCH 0005/2453] compressor: use a prevector in compressed script serialization Use a prevector for stack allocation instead of heap allocation during script compression and decompression. These functions were doing millions of unnecessary heap allocations during IBD. We introduce a CompressedScript type alias for this prevector. It is size 33 as that is the maximum size of a compressed script. Fix the DecompressScript header to match the variable name from compressor.cpp Signed-off-by: William Casarin --- src/compressor.cpp | 4 ++-- src/compressor.h | 20 ++++++++++++++++---- src/test/compress_tests.cpp | 8 ++++---- src/test/fuzz/script.cpp | 8 +++++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/compressor.cpp b/src/compressor.cpp index a70306d320e..ef3135e7a5d 100644 --- a/src/compressor.cpp +++ b/src/compressor.cpp @@ -52,7 +52,7 @@ static bool IsToPubKey(const CScript& script, CPubKey &pubkey) return false; } -bool CompressScript(const CScript& script, std::vector &out) +bool CompressScript(const CScript& script, CompressedScript& out) { CKeyID keyID; if (IsToKeyID(script, keyID)) { @@ -92,7 +92,7 @@ unsigned int GetSpecialScriptSize(unsigned int nSize) return 0; } -bool DecompressScript(CScript& script, unsigned int nSize, const std::vector &in) +bool DecompressScript(CScript& script, unsigned int nSize, const CompressedScript& in) { switch(nSize) { case 0x00: diff --git a/src/compressor.h b/src/compressor.h index 478bfff0b69..40b2496f06e 100644 --- a/src/compressor.h +++ b/src/compressor.h @@ -6,14 +6,26 @@ #ifndef BITCOIN_COMPRESSOR_H #define BITCOIN_COMPRESSOR_H +#include #include #include