From 1bd1a233594e597898c62c162c73ce8617405d57 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 13 Dec 2018 14:58:57 +0100 Subject: [PATCH 1/3] Merge #14805: tests: Support calling add_nodes more than once 98a1846b00d9c3076d6dcd96244fae6f923e26a0 tests: Support calling add_nodes more than once (Steven Roose) Pull request description: Ran into this while writing [a multi-chain test for Elements](https://github.com/ElementsProject/elements/pull/458) where I call this method more than once. Tree-SHA512: f2d698fcb560552aa5d81a4c3fbf40b7269b228b34d85a118291649ef83f8c0a30cd82a28d418237b55893bcecd538046b704e64a4d8a41f2c0aef8033dc83e5 --- test/functional/test_framework/test_framework.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 6184a33ecb..7e0f73e9fb 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -319,9 +319,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): assert_equal(len(extra_confs), num_nodes) assert_equal(len(extra_args), num_nodes) assert_equal(len(binary), num_nodes) - old_num_nodes = len(self.nodes) for i in range(num_nodes): - self.nodes.append(TestNode(old_num_nodes + i, get_datadir_path(self.options.tmpdir, old_num_nodes + i), self.extra_args_from_options, chain=self.chain, rpchost=rpchost, timewait=self.rpc_timewait, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli)) + numnode = len(self.nodes) + self.nodes.append(TestNode(numnode, get_datadir_path(self.options.tmpdir, numnode), self.extra_args_from_options, chain=self.chain, rpchost=rpchost, timewait=self.rpc_timewait, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli)) def start_node(self, i, *args, **kwargs): """Start a dashd""" From 5faf6003992eec70834409489ca1ce730c517558 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 13 Dec 2018 16:44:26 -0500 Subject: [PATCH 2/3] Merge #14953: test: Make g_insecure_rand_ctx thread_local faead93c6c test: Make g_insecure_rand_ctx thread_local (MarcoFalke) Pull request description: Some tests might spin up several threads and `FastRandomContext` is not thread safe. Fix that by giving each thread their own randomness context (as opposed to e.g. making `FastRandomContext` thread safe or add locks elsewhere). Also, add the `g_` prefix to it (according to developer notes), since I am touching it anyway. Tree-SHA512: c6b61375636dfbb2f8311efe8b47e9fe7c4f8bee9804871243f877545f3117cb6aa8556a2d9b1d1673e46e2e585b695a8ddd235b746b583c3eab962435efe2d1 --- src/test/denialofservice_tests.cpp | 2 +- src/test/test_dash.cpp | 40 ++++++++++++++---------------- src/test/test_dash.h | 16 ++++++------ 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index 789e158a12..bfb62fbc2d 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction) static void AddRandomOutboundPeer(std::vector &vNodes, PeerLogicValidation &peerLogic, CConnmanTest* connman) { - CAddress addr(ip(insecure_rand_ctx.randbits(32)), NODE_NONE); + CAddress addr(ip(g_insecure_rand_ctx.randbits(32)), NODE_NONE); vNodes.emplace_back(new CNode(id++, ServiceFlags(NODE_NETWORK), 0, INVALID_SOCKET, addr, 0, 0, CAddress(), "", /*fInboundIn=*/ false)); CNode &node = *vNodes.back(); node.SetSendVersion(PROTOCOL_VERSION); diff --git a/src/test/test_dash.cpp b/src/test/test_dash.cpp index 4b8c568a7f..bacd35b8c7 100644 --- a/src/test/test_dash.cpp +++ b/src/test/test_dash.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -30,10 +31,7 @@ const std::function G_TRANSLATION_FUN = nullptr; -FastRandomContext insecure_rand_ctx; - -extern bool fPrintToConsole; -extern void noui_connect(); +thread_local FastRandomContext g_insecure_rand_ctx; std::ostream& operator<<(std::ostream& os, const uint256& num) { @@ -116,23 +114,23 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha TestingSetup::~TestingSetup() { - llmq::InterruptLLMQSystem(); - llmq::StopLLMQSystem(); - g_txindex->Interrupt(); - g_txindex->Stop(); - g_txindex.reset(); - threadGroup.interrupt_all(); - threadGroup.join_all(); - StopScriptCheckWorkerThreads(); - GetMainSignals().FlushBackgroundCallbacks(); - GetMainSignals().UnregisterBackgroundSignalScheduler(); - g_connman.reset(); - g_banman.reset(); - UnloadBlockIndex(); - pcoinsTip.reset(); - llmq::DestroyLLMQSystem(); - pcoinsdbview.reset(); - pblocktree.reset(); + llmq::InterruptLLMQSystem(); + llmq::StopLLMQSystem(); + g_txindex->Interrupt(); + g_txindex->Stop(); + g_txindex.reset(); + threadGroup.interrupt_all(); + threadGroup.join_all(); + StopScriptCheckWorkerThreads(); + GetMainSignals().FlushBackgroundCallbacks(); + GetMainSignals().UnregisterBackgroundSignalScheduler(); + g_connman.reset(); + g_banman.reset(); + UnloadBlockIndex(); + pcoinsTip.reset(); + llmq::DestroyLLMQSystem(); + pcoinsdbview.reset(); + pblocktree.reset(); } TestChainSetup::TestChainSetup(int blockCount) : TestingSetup(CBaseChainParams::REGTEST) diff --git a/src/test/test_dash.h b/src/test/test_dash.h index 41f25abf6f..2e9f0c7251 100644 --- a/src/test/test_dash.h +++ b/src/test/test_dash.h @@ -19,7 +19,7 @@ #include -extern FastRandomContext insecure_rand_ctx; +thread_local extern FastRandomContext g_insecure_rand_ctx; /** * Flag to make GetRand in random.h return the same number @@ -28,14 +28,14 @@ extern bool g_mock_deterministic_tests; static inline void SeedInsecureRand(bool deterministic = false) { - insecure_rand_ctx = FastRandomContext(deterministic); + g_insecure_rand_ctx = FastRandomContext(deterministic); } -static inline uint32_t InsecureRand32() { return insecure_rand_ctx.rand32(); } -static inline uint256 InsecureRand256() { return insecure_rand_ctx.rand256(); } -static inline uint64_t InsecureRandBits(int bits) { return insecure_rand_ctx.randbits(bits); } -static inline uint64_t InsecureRandRange(uint64_t range) { return insecure_rand_ctx.randrange(range); } -static inline bool InsecureRandBool() { return insecure_rand_ctx.randbool(); } +static inline uint32_t InsecureRand32() { return g_insecure_rand_ctx.rand32(); } +static inline uint256 InsecureRand256() { return g_insecure_rand_ctx.rand256(); } +static inline uint64_t InsecureRandBits(int bits) { return g_insecure_rand_ctx.randbits(bits); } +static inline uint64_t InsecureRandRange(uint64_t range) { return g_insecure_rand_ctx.randrange(range); } +static inline bool InsecureRandBool() { return g_insecure_rand_ctx.randbool(); } static constexpr CAmount CENT{1000000}; @@ -61,7 +61,7 @@ class CConnman; class CNode; class PeerLogicValidation; -struct TestingSetup: public BasicTestingSetup { +struct TestingSetup : public BasicTestingSetup { boost::thread_group threadGroup; CScheduler scheduler; From a309982e8269592b6bbc0058981d0f5c2a84855a Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 13 Dec 2018 12:35:00 -0500 Subject: [PATCH 3/3] Merge #14947: scripts: Remove Python 2 import workarounds 4de11a3682 Remove Python 2 import workarounds (practicalswift) Pull request description: Remove Python 2 import workarounds. As noted by @jnewbery in https://github.com/bitcoin/bitcoin/pull/14903#discussion_r241396925: > This exception handling is a vestige from when github-merge.py supported Python 2 and Python 3. We only support Python 3 now so we should be able to remove it entirely and just import from urllib.request. Tree-SHA512: e0d21e6299dd62fb669ad95cbd3d19f7c803195fd336621aac72fd10ddc7431d90443831072a2e1eb2fc880d1d88eb7c3e2ead3da59f545f6db07d349af98fb3 --- contrib/devtools/github-merge.py | 6 +----- contrib/linearize/linearize-data.py | 1 - contrib/linearize/linearize-hashes.py | 8 ++------ test/util/bitcoin-util-test.py | 7 +------ 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/contrib/devtools/github-merge.py b/contrib/devtools/github-merge.py index 98c7e803af..93309d4c2b 100755 --- a/contrib/devtools/github-merge.py +++ b/contrib/devtools/github-merge.py @@ -14,7 +14,6 @@ # In case of a clean merge that is accepted by the user, the local branch with # name $BRANCH is overwritten with the merged result, and optionally pushed. -from __future__ import division,print_function,unicode_literals import os from sys import stdin,stdout,stderr import argparse @@ -23,10 +22,7 @@ import subprocess import sys import json import codecs -try: - from urllib.request import Request,urlopen -except: - from urllib2 import Request,urlopen +from urllib.request import Request, urlopen # External tools (can be overridden using environment) GIT = os.getenv('GIT','git') diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py index 108058ac83..55c807432b 100755 --- a/contrib/linearize/linearize-data.py +++ b/contrib/linearize/linearize-data.py @@ -7,7 +7,6 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. # -from __future__ import print_function, division import struct import re import os diff --git a/contrib/linearize/linearize-hashes.py b/contrib/linearize/linearize-hashes.py index 9eefeb6dd8..ba33cb3f83 100755 --- a/contrib/linearize/linearize-hashes.py +++ b/contrib/linearize/linearize-hashes.py @@ -7,11 +7,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. # -from __future__ import print_function -try: # Python 3 - import http.client as httplib -except ImportError: # Python 2 - import httplib +from http.client import HttpConnection import json import re import base64 @@ -31,7 +27,7 @@ class BitcoinRPC: authpair = "%s:%s" % (username, password) authpair = authpair.encode('utf-8') self.authhdr = b"Basic " + base64.b64encode(authpair) - self.conn = httplib.HTTPConnection(host, port=port, timeout=30) + self.conn = HttpConnection(host, port=port, timeout=30) def execute(self, obj): try: diff --git a/test/util/bitcoin-util-test.py b/test/util/bitcoin-util-test.py index 268d1d7a41..4d89233291 100755 --- a/test/util/bitcoin-util-test.py +++ b/test/util/bitcoin-util-test.py @@ -9,14 +9,9 @@ Runs automatically during `make check`. Can also be run manually.""" -from __future__ import division,print_function,unicode_literals - import argparse import binascii -try: - import configparser -except ImportError: - import ConfigParser as configparser +import configparser import difflib import json import logging