From 3834c100989bc179dc0573737e6e52af612c8d3e Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 19 Feb 2019 10:12:07 -0500 Subject: [PATCH 1/6] Merge #15415: [test] functional: allow custom cwd, use tmpdir as default e3e1a5631e [test] functional: set cwd of nodes to tmpdir (Sjors Provoost) Pull request description: Any process launched by bitcoind will have `self.datadir` as its `cwd`. Tree-SHA512: 0b311643bb96c7dc2f693774620173243b3add40bf373284695af2f0071823b23485289fd2ffe152b7f63e0bfe989b16720077cfc2ce33905f9b8e7f2630f3c0 --- test/functional/test_framework/test_framework.py | 2 ++ test/functional/test_framework/test_node.py | 10 +++++++--- test/functional/wallet_dump.py | 7 ------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 4066740b024c..36b9b0afda81 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -400,6 +400,7 @@ def add_nodes(self, num_nodes, extra_args=None, *, rpchost=None, binary=None): bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, + cwd=self.options.tmpdir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli, @@ -581,6 +582,7 @@ def _initialize_chain(self, extra_args=None): bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=None, + cwd=self.options.tmpdir, )) self.nodes[i].args = args self.start_node(i) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 77772f84d1b5..098b055f5af3 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -60,7 +60,7 @@ class TestNode(): To make things easier for the test writer, any unrecognised messages will be dispatched to the RPC connection.""" - def __init__(self, i, datadir, extra_args_from_options, *, chain, rpchost, timewait, bitcoind, bitcoin_cli, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False, start_perf=False): + def __init__(self, i, datadir, extra_args_from_options, *, chain, rpchost, timewait, bitcoind, bitcoin_cli, mocktime, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False): """ Kwargs: start_perf (bool): If True, begin profiling the node with `perf` as soon as @@ -78,6 +78,7 @@ def __init__(self, i, datadir, extra_args_from_options, *, chain, rpchost, timew self.rpc_timeout *= Options.timeout_scale self.binary = bitcoind self.coverage_dir = coverage_dir + self.cwd = cwd self.mocktime = mocktime if extra_conf is not None: append_config(datadir, extra_conf) @@ -185,7 +186,7 @@ def __getattr__(self, name): assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection") return getattr(self.rpc, name) - def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs): + def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, **kwargs): """Start the node.""" if extra_args is None: extra_args = self.extra_args @@ -198,6 +199,9 @@ def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs): self.stderr = stderr self.stdout = stdout + if cwd is None: + cwd = self.cwd + all_args = self.args + self.extra_args_from_options + extra_args if self.mocktime != 0: all_args = all_args + ["-mocktime=%d" % self.mocktime] @@ -210,7 +214,7 @@ def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs): # add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are written to stderr and not the terminal subp_env = dict(os.environ, LIBC_FATAL_STDERR_="1") - self.process = subprocess.Popen(all_args, env=subp_env, stdout=stdout, stderr=stderr, **kwargs) + self.process = subprocess.Popen(all_args, env=subp_env, stdout=stdout, stderr=stderr, cwd=cwd, **kwargs) self.running = True self.log.debug("dashd started, waiting for RPC to come up") diff --git a/test/functional/wallet_dump.py b/test/functional/wallet_dump.py index 05c9de670259..e2dda3e03979 100755 --- a/test/functional/wallet_dump.py +++ b/test/functional/wallet_dump.py @@ -78,7 +78,6 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old): class WalletDumpTest(BitcoinTestFramework): def set_test_params(self): - self.setup_clean_chain = True self.num_nodes = 1 self.extra_args = [["-keypool=90", "-usehd=1"]] self.rpc_timeout = 120 @@ -87,12 +86,6 @@ def skip_test_if_missing_module(self): self.skip_if_no_wallet() def setup_network(self): - # TODO remove this when usehd=1 becomes the default - # use our own cache and -usehd=1 as extra arg as the default cache is run with -usehd=0 - self.options.tmpdir = os.path.join(self.options.tmpdir, 'hd') - self.options.cachedir = os.path.join(self.options.cachedir, 'hd') - self._initialize_chain(extra_args=self.extra_args[0]) - self.set_cache_mocktime() self.add_nodes(self.num_nodes, extra_args=self.extra_args) self.start_nodes() From 525c12e60f502d6cdc4efd50a965ae8369868da1 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 15 Feb 2019 08:56:43 -0500 Subject: [PATCH 2/6] Merge #15383: [rpc] mining: Omit uninitialized currentblockweight, currentblocktx fa178a6385 [rpc] mining: Omit uninitialized currentblockweight, currentblocktx (MarcoFalke) Pull request description: Previously we'd report "0", which could be mistaken for a valid number. E.g. the number of transactions is 0 or the block weight is 0, whatever that means. Tree-SHA512: ee94ab203a329e272211b726f4c23edec4b09c650ec363b77fd59ad9264165d73064f78ebb9e11b5c2c543b73c157752410a307655560531c7d5444d203aa0ea --- src/miner.cpp | 19 +++++-------- src/miner.h | 9 ++++-- src/rpc/mining.cpp | 28 +++++++++---------- src/validation.h | 4 +-- test/functional/feature_csv_activation.py | 10 +++---- test/functional/mining_basic.py | 27 ++++++++++++++---- test/functional/test_framework/blocktools.py | 5 +++- .../test_framework/test_framework.py | 10 +++---- 8 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 09a3a8b7293d..04b97b942b57 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -10,16 +10,16 @@ #include #include #include -#include #include +#include #include #include #include #include #include #include -#include #include +#include #include #include @@ -33,14 +33,6 @@ #include #include -// Unconfirmed transactions in the memory pool often depend on other -// transactions in the memory pool. When we select transactions from the -// pool, we select by highest fee rate of a transaction combined with all -// its ancestors. - -uint64_t nLastBlockTx = 0; -uint64_t nLastBlockSize = 0; - int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { int64_t nOldTime = pblock->nTime; @@ -100,6 +92,9 @@ void BlockAssembler::resetBlock() nFees = 0; } +Optional BlockAssembler::m_last_block_num_txs{nullopt}; +Optional BlockAssembler::m_last_block_size{nullopt}; + std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn) { int64_t nTimeStart = GetTimeMicros(); @@ -160,8 +155,8 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc int64_t nTime1 = GetTimeMicros(); - nLastBlockTx = nBlockTx; - nLastBlockSize = nBlockSize; + m_last_block_num_txs = nBlockTx; + m_last_block_size = nBlockSize; LogPrintf("CreateNewBlock(): total size %u txs: %u fees: %ld sigops %d\n", nBlockSize, nBlockTx, nFees, nBlockSigOps); // Create coinbase transaction. diff --git a/src/miner.h b/src/miner.h index 942063f66d80..7d6a67444340 100644 --- a/src/miner.h +++ b/src/miner.h @@ -1,17 +1,19 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2015 The Bitcoin Core developers +// Copyright (c) 2009-2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_MINER_H #define BITCOIN_MINER_H +#include #include #include #include -#include #include +#include + #include #include @@ -159,6 +161,9 @@ class BlockAssembler /** Construct a new block template with coinbase to scriptPubKeyIn */ std::unique_ptr CreateNewBlock(const CScript& scriptPubKeyIn); + static Optional m_last_block_num_txs; + static Optional m_last_block_size; + private: // utility functions /** Clear the block's state and prepare for assembling a new block */ diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 03f52c7ea5d5..0918a53db425 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -199,36 +199,36 @@ static UniValue generatetoaddress(const JSONRPCRequest& request) static UniValue getmininginfo(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 0) + if (request.fHelp || request.params.size() != 0) { throw std::runtime_error( RPCHelpMan{"getmininginfo", "\nReturns a json object containing mining-related information.", {}, RPCResult{ - "{\n" - " \"blocks\": nnn, (numeric) The current block\n" - " \"currentblocksize\": nnn, (numeric) The last block size\n" - " \"currentblocktx\": nnn, (numeric) The last block transaction\n" - " \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n" - " \"networkhashps\": nnn, (numeric) The network hashes per second\n" - " \"pooledtx\": n (numeric) The size of the mempool\n" - " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" - " \"warnings\": \"...\" (string) any network and blockchain warnings\n" - "}\n" + "{\n" + " \"blocks\": nnn, (numeric) The current block\n" + " \"currentblocksize\": nnn, (numeric, optional) The block size of the last assembled block (only present if a block was ever assembled)\n" + " \"currentblocktx\": nnn, (numeric, optional) The number of block transactions of the last assembled block (only present if a block was ever assembled)\n" + " \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n" + " \"networkhashps\": nnn, (numeric) The network hashes per second\n" + " \"pooledtx\": n (numeric) The size of the mempool\n" + " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" + " \"warnings\": \"...\" (string) any network and blockchain warnings\n" + "}\n" }, RPCExamples{ HelpExampleCli("getmininginfo", "") + HelpExampleRpc("getmininginfo", "") }, }.ToString()); - + } LOCK(cs_main); UniValue obj(UniValue::VOBJ); obj.pushKV("blocks", (int)::ChainActive().Height()); - obj.pushKV("currentblocksize", (uint64_t)nLastBlockSize); - obj.pushKV("currentblocktx", (uint64_t)nLastBlockTx); + if (BlockAssembler::m_last_block_size) obj.pushKV("currentblocksize", *BlockAssembler::m_last_block_size); + if (BlockAssembler::m_last_block_num_txs) obj.pushKV("currentblocktx", *BlockAssembler::m_last_block_num_txs); obj.pushKV("difficulty", (double)GetDifficulty(::ChainActive().Tip())); obj.pushKV("networkhashps", getnetworkhashps(request)); obj.pushKV("pooledtx", (uint64_t)mempool.size()); diff --git a/src/validation.h b/src/validation.h index f9ff6bcbffc5..87dd9ab0cbf4 100644 --- a/src/validation.h +++ b/src/validation.h @@ -15,8 +15,8 @@ #include #include // for ReadLE64 #include -#include // For CMessageHeader::MessageStartChars #include +#include // For CMessageHeader::MessageStartChars #include