Skip to content

Commit 9b48b3a

Browse files
author
MarcoFalke
committed
Merge #21390: test: Test improvements for UTXO set hash tests
4f2653a test: Use deterministic chain in utxo set hash test (Fabian Jahr) 4973c51 test: Remove wallet dependency of utxo set hash test (Fabian Jahr) 1a27af1 rpc: Improve gettxoutsetinfo help (Fabian Jahr) Pull request description: Follow-ups to #19145: - Small improvement on the help text of RPC gettxoutsetinfo - Using deterministic blockchain in the test `functional/feature_utxo_set_hash.py` - Removing wallet dependency in the test `functional/feature_utxo_set_hash.py` Split out of #19521. ACKs for top commit: MarcoFalke: review ACK 4f2653a 👲 Tree-SHA512: 92927b3aa22b6324eb4fc9d346755313dec44d973aa69a0ebf80a8569b5f3a7cf3539721ebdba183737534b9e29b3e33f412515890f0d0b819878032a3bba8f9
2 parents 9217f9f + 4f2653a commit 9b48b3a

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

src/node/coinstats.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <map>
1717

18+
// Database-independent metric indicating the UTXO set size
1819
static uint64_t GetBogoSize(const CScript& scriptPubKey)
1920
{
2021
return 32 /* txid */ +

src/rpc/blockchain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,15 +1050,15 @@ static RPCHelpMan gettxoutsetinfo()
10501050
RPCResult{
10511051
RPCResult::Type::OBJ, "", "",
10521052
{
1053-
{RPCResult::Type::NUM, "height", "The current block height (index)"},
1054-
{RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at the tip of the chain"},
1053+
{RPCResult::Type::NUM, "height", "The block height (index) of the returned statistics"},
1054+
{RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at which these statistics are calculated"},
10551055
{RPCResult::Type::NUM, "transactions", "The number of transactions with unspent outputs"},
10561056
{RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs"},
10571057
{RPCResult::Type::NUM, "bogosize", "A meaningless metric for UTXO set size"},
10581058
{RPCResult::Type::STR_HEX, "hash_serialized_2", /* optional */ true, "The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)"},
10591059
{RPCResult::Type::STR_HEX, "muhash", /* optional */ true, "The serialized hash (only present if 'muhash' hash_type is chosen)"},
10601060
{RPCResult::Type::NUM, "disk_size", "The estimated size of the chainstate on disk"},
1061-
{RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount"},
1061+
{RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount of coins in the UTXO set"},
10621062
}},
10631063
RPCExamples{
10641064
HelpExampleCli("gettxoutsetinfo", "")

test/functional/feature_utxo_set_hash.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import struct
88

9-
from test_framework.blocktools import create_transaction
109
from test_framework.messages import (
1110
CBlock,
1211
COutPoint,
@@ -15,38 +14,30 @@
1514
from test_framework.muhash import MuHash3072
1615
from test_framework.test_framework import BitcoinTestFramework
1716
from test_framework.util import assert_equal
17+
from test_framework.wallet import MiniWallet
1818

1919
class UTXOSetHashTest(BitcoinTestFramework):
2020
def set_test_params(self):
2121
self.num_nodes = 1
2222
self.setup_clean_chain = True
2323

24-
def skip_test_if_missing_module(self):
25-
self.skip_if_no_wallet()
26-
27-
def test_deterministic_hash_results(self):
28-
self.log.info("Test deterministic UTXO set hash results")
29-
30-
# These depend on the setup_clean_chain option, the chain loaded from the cache
31-
assert_equal(self.nodes[0].gettxoutsetinfo()['hash_serialized_2'], "b32ec1dda5a53cd025b95387aad344a801825fe46a60ff952ce26528f01d3be8")
32-
assert_equal(self.nodes[0].gettxoutsetinfo("muhash")['muhash'], "dd5ad2a105c2d29495f577245c357409002329b9f4d6182c0af3dc2f462555c8")
33-
3424
def test_muhash_implementation(self):
3525
self.log.info("Test MuHash implementation consistency")
3626

3727
node = self.nodes[0]
28+
wallet = MiniWallet(node)
29+
mocktime = node.getblockheader(node.getblockhash(0))['time'] + 1
30+
node.setmocktime(mocktime)
3831

3932
# Generate 100 blocks and remove the first since we plan to spend its
4033
# coinbase
41-
block_hashes = node.generate(100)
34+
block_hashes = wallet.generate(1) + node.generate(99)
4235
blocks = list(map(lambda block: FromHex(CBlock(), node.getblock(block, False)), block_hashes))
43-
spending = blocks.pop(0)
36+
blocks.pop(0)
4437

4538
# Create a spending transaction and mine a block which includes it
46-
tx = create_transaction(node, spending.vtx[0].rehash(), node.getnewaddress(), amount=49)
47-
txid = node.sendrawtransaction(hexstring=tx.serialize_with_witness().hex(), maxfeerate=0)
48-
49-
tx_block = node.generateblock(output=node.getnewaddress(), transactions=[txid])
39+
txid = wallet.send_self_transfer(from_node=node)['txid']
40+
tx_block = node.generateblock(output=wallet.get_address(), transactions=[txid])
5041
blocks.append(FromHex(CBlock(), node.getblock(tx_block['hash'], False)))
5142

5243
# Serialize the outputs that should be in the UTXO set and add them to
@@ -77,8 +68,11 @@ def test_muhash_implementation(self):
7768

7869
assert_equal(finalized[::-1].hex(), node_muhash)
7970

71+
self.log.info("Test deterministic UTXO set hash results")
72+
assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "5b1b44097406226c0eb8e1362cd17a1f346522cf9390a8175a57a5262cb1963f")
73+
assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "4b8803075d7151d06fad3e88b68ba726886794873fbfa841d12aefb2cc2b881b")
74+
8075
def run_test(self):
81-
self.test_deterministic_hash_results()
8276
self.test_muhash_implementation()
8377

8478

test/functional/test_framework/wallet.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def generate(self, num_blocks):
4949
self._utxos.append({'txid': cb_tx['txid'], 'vout': 0, 'value': cb_tx['vout'][0]['value']})
5050
return blocks
5151

52+
def get_address(self):
53+
return self._address
54+
5255
def get_utxo(self, *, txid=''):
5356
"""
5457
Returns a utxo and marks it as spent (pops it from the internal list)

0 commit comments

Comments
 (0)