mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-23 13:29:43 +02:00
Merge #16899: UTXO snapshot creation (dumptxoutset)
92b2f5306btest: add dumptxoutset RPC test (James O'Beirne)c1ccbc3ddedevtools: add utxo_snapshot.sh (James O'Beirne)57cf74c991rpc: add dumptxoutset (James O'Beirne)92fafb3a7dcoinstats: add coins_count (James O'Beirne)707fde7b9badd unused SnapshotMetadata class (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11): Parent PR: #15606 Issue: #15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal --- This changeset defines the serialization format for UTXO snapshots and adds an RPC command for creating them, `dumptxoutset`. It also adds a convenience script for generating and verifying snapshots at a certain height, since that requires doing a hacky rewind of the chain via `invalidateblock`. All of this is unused at the moment. ACKs for top commit: laanwj: ACK92b2f5306bTree-SHA512: 200dff87767f157d627e99506ec543465d9329860a6cd49363081619c437163a640a46d008faa92b1f44fd403bfc7a7c9e851c658b5a4849efa9a34ca976bf31
This commit is contained in:
51
test/functional/rpc_dumptxoutset.py
Executable file
51
test/functional/rpc_dumptxoutset.py
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2019 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test the generation of UTXO snapshots using `dumptxoutset`.
|
||||
"""
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal, assert_raises_rpc_error
|
||||
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class DumptxoutsetTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
def run_test(self):
|
||||
"""Test a trivial usage of the dumptxoutset RPC command."""
|
||||
node = self.nodes[0]
|
||||
mocktime = node.getblockheader(node.getblockhash(0))['time'] + 1
|
||||
node.setmocktime(mocktime)
|
||||
node.generate(100)
|
||||
|
||||
FILENAME = 'txoutset.dat'
|
||||
out = node.dumptxoutset(FILENAME)
|
||||
expected_path = Path(node.datadir) / 'regtest' / FILENAME
|
||||
|
||||
assert expected_path.is_file()
|
||||
|
||||
assert_equal(out['coins_written'], 100)
|
||||
assert_equal(out['base_height'], 100)
|
||||
assert_equal(out['path'], str(expected_path))
|
||||
# Blockhash should be deterministic based on mocked time.
|
||||
assert_equal(
|
||||
out['base_hash'],
|
||||
'6fd417acba2a8738b06fee43330c50d58e6a725046c3d843c8dd7e51d46d1ed6')
|
||||
|
||||
with open(str(expected_path), 'rb') as f:
|
||||
digest = hashlib.sha256(f.read()).hexdigest()
|
||||
# UTXO snapshot hash should be deterministic based on mocked time.
|
||||
assert_equal(
|
||||
digest, 'be032e5f248264ba08e11099ac09dbd001f6f87ffc68bf0f87043d8146d50664')
|
||||
|
||||
# Specifying a path to an existing file will fail.
|
||||
assert_raises_rpc_error(
|
||||
-8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME)
|
||||
|
||||
if __name__ == '__main__':
|
||||
DumptxoutsetTest().main()
|
||||
@@ -191,6 +191,7 @@ BASE_SCRIPTS = [
|
||||
'rpc_uptime.py',
|
||||
'wallet_resendwallettransactions.py',
|
||||
'wallet_fallbackfee.py',
|
||||
'rpc_dumptxoutset.py',
|
||||
'feature_minchainwork.py',
|
||||
'rpc_getblockstats.py',
|
||||
'wallet_create_tx.py',
|
||||
|
||||
Reference in New Issue
Block a user