aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-05-02 09:51:36 +0100
committerfanquake <fanquake@gmail.com>2023-05-02 10:04:34 +0100
commit8a373a5c7f94dbb5903ae704ae6aab8c28999c08 (patch)
treeb7534ece98817f37f918da9ee09958e0f555815c /test/functional
parentbe0325c6a62505d63bc07320b05e31618ef9bbb1 (diff)
parent8f14fc86225d8fe77353f61ebd6b0bdda8d13aa9 (diff)
downloadbitcoin-8a373a5c7f94dbb5903ae704ae6aab8c28999c08.tar.xz
Merge bitcoin/bitcoin#27191: blockstorage: Adjust fastprune limit if block exceeds blockfile size
8f14fc86225d8fe77353f61ebd6b0bdda8d13aa9 test: cover fastprune with excessive block size (Matthew Zipkin) 271c23e87f61276d7acab74e115b25a35144c8b4 blockstorage: Adjust fastprune limit if block exceeds blockfile size (Martin Zumsande) Pull request description: The debug-only `-fastprune` option used in several tests is not always safe to use: If a `-fastprune` node receives a block larger than the maximum blockfile size of `64kb` bad things happen: The while loop in `BlockManager::FindBlockPos` never terminates, and the node runs oom because memory for `m_blockfile_info` is allocated in each iteration of the loop. The same would happen if a naive user used `-fastprune` on anything other than regtest (so this can be tested by syncing on signet for example, the first block that crashes the node is at height 2232). Change the approach by raising the blockfile size to the size of the block, if that block otherwise wouldn't fit (idea by TheCharlatan). ACKs for top commit: ryanofsky: Code review ACK 8f14fc86225d8fe77353f61ebd6b0bdda8d13aa9. Added new assert, test, and comment since last review TheCharlatan: ACK 8f14fc86225d8fe77353f61ebd6b0bdda8d13aa9 pinheadmz: ACK 8f14fc86225d8fe77353f61ebd6b0bdda8d13aa9 Tree-SHA512: df2fea30613ef9d40ebbc2416eacb574f6d7d96847db5c33dda22a29a2c61a8db831aa9552734ea4477e097f253dbcb6dcb1395d43d2a090cc0588c9ce66eac3
Diffstat (limited to 'test/functional')
-rwxr-xr-xtest/functional/feature_fastprune.py42
-rwxr-xr-xtest/functional/test_runner.py1
2 files changed, 43 insertions, 0 deletions
diff --git a/test/functional/feature_fastprune.py b/test/functional/feature_fastprune.py
new file mode 100755
index 0000000000..825de63e3d
--- /dev/null
+++ b/test/functional/feature_fastprune.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+# Copyright (c) 2023 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 fastprune mode."""
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import (
+ assert_equal
+)
+from test_framework.blocktools import (
+ create_block,
+ create_coinbase,
+ add_witness_commitment
+)
+from test_framework.wallet import MiniWallet
+
+
+class FeatureFastpruneTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.num_nodes = 1
+ self.extra_args = [["-fastprune"]]
+
+ def run_test(self):
+ self.log.info("ensure that large blocks don't crash or freeze in -fastprune")
+ wallet = MiniWallet(self.nodes[0])
+ tx = wallet.create_self_transfer()['tx']
+ annex = [0x50]
+ for _ in range(0x10000):
+ annex.append(0xff)
+ tx.wit.vtxinwit[0].scriptWitness.stack.append(bytes(annex))
+ tip = int(self.nodes[0].getbestblockhash(), 16)
+ time = self.nodes[0].getblock(self.nodes[0].getbestblockhash())['time'] + 1
+ height = self.nodes[0].getblockcount() + 1
+ block = create_block(hashprev=tip, ntime=time, txlist=[tx], coinbase=create_coinbase(height=height))
+ add_witness_commitment(block)
+ block.solve()
+ self.nodes[0].submitblock(block.serialize().hex())
+ assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)
+
+
+if __name__ == '__main__':
+ FeatureFastpruneTest().main()
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index bcedc0c9af..7bae36ab2c 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -320,6 +320,7 @@ BASE_SCRIPTS = [
'feature_includeconf.py',
'feature_addrman.py',
'feature_asmap.py',
+ 'feature_fastprune.py',
'mempool_unbroadcast.py',
'mempool_compatibility.py',
'mempool_accept_wtxid.py',