diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 33fc90dd78..8be2147d10 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1258,16 +1258,22 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) obj.pushKV("blocks", (int)chainActive.Height()); obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1); obj.pushKV("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()); - obj.pushKV("difficulty", (double)GetDifficulty(chainActive.Tip())); + if (!g_signed_blocks) { + obj.pushKV("difficulty", (double)GetDifficulty(chainActive.Tip())); + } obj.pushKV("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast()); obj.pushKV("verificationprogress", GuessVerificationProgress(chainparams.TxData(), chainActive.Tip())); obj.pushKV("initialblockdownload", IsInitialBlockDownload()); - obj.pushKV("chainwork", chainActive.Tip()->nChainWork.GetHex()); + if (!g_signed_blocks) { + obj.pushKV("chainwork", chainActive.Tip()->nChainWork.GetHex()); + } obj.pushKV("size_on_disk", CalculateCurrentUsage()); obj.pushKV("pruned", fPruneMode); - CScript sign_block_script = chainparams.GetConsensus().signblockscript; - obj.pushKV("signblock_asm", ScriptToAsmStr(sign_block_script)); - obj.pushKV("signblock_hex", HexStr(sign_block_script)); + if (g_signed_blocks) { + CScript sign_block_script = chainparams.GetConsensus().signblockscript; + obj.pushKV("signblock_asm", ScriptToAsmStr(sign_block_script)); + obj.pushKV("signblock_hex", HexStr(sign_block_script)); + } if (fPruneMode) { CBlockIndex* block = chainActive.Tip(); diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index d681cdc8ab..cfb067bc15 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -7,17 +7,14 @@ Test the following RPCs: - getblockchaininfo - gettxoutsetinfo - - getdifficulty - getbestblockhash - getblockhash - getblockheader - getchaintxstats - - getnetworkhashps - verifychain Tests correspond to code in rpc/blockchain.cpp. """ - from decimal import Decimal import http.client import subprocess @@ -54,8 +51,6 @@ class BlockchainTest(BitcoinTestFramework): self._test_getchaintxstats() self._test_gettxoutsetinfo() self._test_getblockheader() - self._test_getdifficulty() - self._test_getnetworkhashps() self._test_stopatheight() self._test_waitforblockheight() assert self.nodes[0].verifychain(4, 0) @@ -68,17 +63,18 @@ class BlockchainTest(BitcoinTestFramework): 'bip9_softforks', 'blocks', 'chain', - 'chainwork', - 'difficulty', 'headers', 'initialblockdownload', 'mediantime', 'pruned', + 'signblock_asm', + 'signblock_hex', 'size_on_disk', 'softforks', 'verificationprogress', 'warnings', ] + res = self.nodes[0].getblockchaininfo() # result should have these additional pruning keys if manual pruning is enabled @@ -212,29 +208,14 @@ class BlockchainTest(BitcoinTestFramework): assert_equal(header['height'], 200) assert_equal(header['confirmations'], 1) assert_equal(header['previousblockhash'], secondbesthash) - assert_is_hex_string(header['chainwork']) assert_equal(header['nTx'], 1) assert_is_hash_string(header['hash']) assert_is_hash_string(header['previousblockhash']) assert_is_hash_string(header['merkleroot']) - assert_is_hash_string(header['bits'], length=None) assert isinstance(header['time'], int) assert isinstance(header['mediantime'], int) - assert isinstance(header['nonce'], int) assert isinstance(header['version'], int) assert isinstance(int(header['versionHex'], 16), int) - assert isinstance(header['difficulty'], Decimal) - - def _test_getdifficulty(self): - difficulty = self.nodes[0].getdifficulty() - # 1 hash in 2 should be valid, so difficulty should be 1/2**31 - # binary => decimal => binary math is why we do this check - assert abs(difficulty * 2**31 - 1) < 0.0001 - - def _test_getnetworkhashps(self): - hashes_per_second = self.nodes[0].getnetworkhashps() - # This should be 2 hashes every 10 minutes or 1/300 - assert abs(hashes_per_second * 300 - 1) < 0.0001 def _test_stopatheight(self): assert_equal(self.nodes[0].getblockcount(), 200) diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py index 987ade4044..88490d51c1 100644 --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -27,6 +27,7 @@ from .messages import ( ser_uint256, sha256, uint256_from_str, + CProof, ) from .script import ( CScript, @@ -55,6 +56,7 @@ def create_block(hashprev, coinbase, ntime=None): block.hashPrevBlock = hashprev block.nBits = 0x207fffff # difficulty retargeting is disabled in REGTEST chainparams block.vtx.append(coinbase) + block.proof = CProof(bytearray.fromhex('51'), bytearray.fromhex('')) block.hashMerkleRoot = block.calc_merkle_root() block.calc_sha256() return block