Merge bitcoin/bitcoin#32033: test: Check datadir cleanup after assumeutxo was successful

52482cb24400f8c44ba9628aaaecb7c04b11beb2 test: Check datadir cleanup after assumeutxo was successful (Fabian Jahr)

Pull request description:

  I noticed that the proper datadir cleanup after a successful restart of an assumutxo node does not seem to be covered in our tests. This is added here.

ACKs for top commit:
  l0rinc:
    utACK 52482cb24400f8c44ba9628aaaecb7c04b11beb2
  mabu44:
    Re-ACK 52482cb24400f8c44ba9628aaaecb7c04b11beb2
  Prabhat1308:
    re-ACK [`52482cb`](52482cb244)
  TheCharlatan:
    Re-ACK 52482cb24400f8c44ba9628aaaecb7c04b11beb2

Tree-SHA512: cc941afeba250050eaccf5112255d961253fec9b2683545454a0d2fbe4d542178394b301d169a9dd79edbf6b5d478d95282727dbb0aca96ee79d4cd1ff80f19b
This commit is contained in:
Hennadii Stepanov 2025-03-17 13:42:45 +00:00
commit 257fd27e4b
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

View File

@ -9,6 +9,7 @@ to a hash that has been compiled into bitcoind.
The assumeutxo value generated and used here is committed to in
`CRegTestParams::m_assumeutxo_data` in `src/kernel/chainparams.cpp`.
"""
import contextlib
from shutil import rmtree
from dataclasses import dataclass
@ -349,6 +350,22 @@ class AssumeutxoTest(BitcoinTestFramework):
assert 'NETWORK' not in node_services
assert 'NETWORK_LIMITED' in node_services
@contextlib.contextmanager
def assert_disk_cleanup(self, node, assumeutxo_used):
"""
Ensure an assumeutxo node is cleaning up the background chainstate
"""
msg = []
if assumeutxo_used:
# Check that the snapshot actually existed before restart
assert (node.datadir_path / node.chain / "chainstate_snapshot").exists()
msg = ["cleaning up unneeded background chainstate"]
with node.assert_debug_log(msg):
yield
assert not (node.datadir_path / node.chain / "chainstate_snapshot").exists()
def run_test(self):
"""
Bring up two (disconnected) nodes, mine some new blocks on the first,
@ -656,7 +673,8 @@ class AssumeutxoTest(BitcoinTestFramework):
for i in (0, 1):
n = self.nodes[i]
self.log.info(f"Restarting node {i} to ensure (Check|Load)BlockIndex passes")
self.restart_node(i, extra_args=self.extra_args[i])
with self.assert_disk_cleanup(n, i == 1):
self.restart_node(i, extra_args=self.extra_args[i])
assert_equal(n.getblockchaininfo()["blocks"], FINAL_HEIGHT)
@ -733,7 +751,8 @@ class AssumeutxoTest(BitcoinTestFramework):
for i in (0, 2):
n = self.nodes[i]
self.log.info(f"Restarting node {i} to ensure (Check|Load)BlockIndex passes")
self.restart_node(i, extra_args=self.extra_args[i])
with self.assert_disk_cleanup(n, i == 2):
self.restart_node(i, extra_args=self.extra_args[i])
assert_equal(n.getblockchaininfo()["blocks"], FINAL_HEIGHT)