From 451741962885eaa4b55033d53af731e0ba22650f Mon Sep 17 00:00:00 2001 From: dergoegge Date: Thu, 9 Mar 2023 18:17:06 +0100 Subject: [PATCH 1/2] [util] Avoid integer overflow in CheckDiskSpace --- src/init.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 281e0d4966..0eb33ec132 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1631,10 +1631,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) // On first startup, warn on low block storage space if (!fReindex && !fReindexChainState && chain_active_height <= 1) { + uint64_t assumed_chain_bytes{chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024}; uint64_t additional_bytes_needed{ chainman.m_blockman.IsPruneMode() ? - chainman.m_blockman.GetPruneTarget() : - chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024}; + std::min(chainman.m_blockman.GetPruneTarget(), assumed_chain_bytes) : + assumed_chain_bytes}; if (!CheckDiskSpace(args.GetBlocksDirPath(), additional_bytes_needed)) { InitWarning(strprintf(_( From 05eeba2c5fb312e0e6a730b01eb7d1b422d75dbb Mon Sep 17 00:00:00 2001 From: dergoegge Date: Mon, 13 Mar 2023 12:55:03 +0100 Subject: [PATCH 2/2] [test] Add manual prune startup test case --- test/functional/rpc_blockchain.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 7a0cedb1f5..6022042c11 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -69,6 +69,7 @@ def set_test_params(self): def run_test(self): self.wallet = MiniWallet(self.nodes[0]) + self._test_prune_disk_space() self.mine_chain() self._test_max_future_block_time() self.restart_node( @@ -100,6 +101,13 @@ def mine_chain(self): self.generate(self.wallet, 1) assert_equal(self.nodes[0].getblockchaininfo()['blocks'], HEIGHT) + def _test_prune_disk_space(self): + self.log.info("Test that a manually pruned node does not run into " + "integer overflow on first start up") + self.restart_node(0, extra_args=["-prune=1"]) + self.log.info("Avoid warning when assumed chain size is enough") + self.restart_node(0, extra_args=["-prune=123456789"]) + def _test_max_future_block_time(self): self.stop_node(0) self.log.info("A block tip of more than MAX_FUTURE_BLOCK_TIME in the future raises an error")