Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2020-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Test UTXO set hash value calculation in gettxoutsetinfo."""7from test_framework.messages import (8CBlock,9COutPoint,10from_hex,11)12from test_framework.crypto.muhash import MuHash307213from test_framework.test_framework import BitcoinTestFramework14from test_framework.util import assert_equal15from test_framework.wallet import MiniWallet17class UTXOSetHashTest(BitcoinTestFramework):18def set_test_params(self):19self.num_nodes = 120self.setup_clean_chain = True22def test_muhash_implementation(self):23self.log.info("Test MuHash implementation consistency")25node = self.nodes[0]26wallet = MiniWallet(node)27mocktime = node.getblockheader(node.getblockhash(0))['time'] + 128node.setmocktime(mocktime)30# Generate 100 blocks and remove the first since we plan to spend its31# coinbase32block_hashes = self.generate(wallet, 1) + self.generate(node, 99)33blocks = list(map(lambda block: from_hex(CBlock(), node.getblock(block, False)), block_hashes))34blocks.pop(0)36# Create a spending transaction and mine a block which includes it37txid = wallet.send_self_transfer(from_node=node)['txid']38tx_block = self.generateblock(node, output=wallet.get_address(), transactions=[txid])39blocks.append(from_hex(CBlock(), node.getblock(tx_block['hash'], False)))41# Serialize the outputs that should be in the UTXO set and add them to42# a MuHash object43muhash = MuHash3072()45for height, block in enumerate(blocks):46# The Genesis block coinbase is not part of the UTXO set and we47# spent the first mined block48height += 250for tx in block.vtx:51for n, tx_out in enumerate(tx.vout):52coinbase = 1 if not tx.vin[0].prevout.hash else 054# Skip witness commitment55if (coinbase and n > 0):56continue58data = COutPoint(tx.txid_int, n).serialize()59data += (height * 2 + coinbase).to_bytes(4, "little")60data += tx_out.serialize()62muhash.insert(data)64finalized = muhash.digest()65node_muhash = node.gettxoutsetinfo("muhash")['muhash']67assert_equal(finalized[::-1].hex(), node_muhash)69self.log.info("Test deterministic UTXO set hash results")70assert_equal(node.gettxoutsetinfo()['hash_serialized_3'], "396058cfd7f3b4c05dcdfaf360be9986d859d2c8315082d3aadda6d2d16add25")71assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "97f341d4226cb4451dd9da2856759fb97659cfc238a0b8d5452e64af6032bd3d")73def run_test(self):74self.test_muhash_implementation()77if __name__ == '__main__':78UTXOSetHashTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.