Skip to content

Commit 3a58533

Browse files
committed
merge bitcoin#25315: Add warning on first startup if free disk space is less than necessary
1 parent adeebb0 commit 3a58533

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/init.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,24 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
23032303
return false;
23042304
}
23052305

2306+
int chain_active_height = WITH_LOCK(cs_main, return chainman.ActiveChain().Height());
2307+
2308+
// On first startup, warn on low block storage space
2309+
if (!fReindex && !fReindexChainState && chain_active_height <= 1) {
2310+
uint64_t additional_bytes_needed = fPruneMode ? nPruneTarget
2311+
: chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024;
2312+
2313+
if (!CheckDiskSpace(args.GetBlocksDirPath(), additional_bytes_needed)) {
2314+
InitWarning(strprintf(_(
2315+
"Disk space for %s may not accommodate the block files. " \
2316+
"Approximately %u GB of data will be stored in this directory."
2317+
),
2318+
fs::quoted(fs::PathToString(args.GetBlocksDirPath())),
2319+
chainparams.AssumedBlockchainSize()
2320+
));
2321+
}
2322+
}
2323+
23062324
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
23072325
// No locking, as this happens before any background thread is started.
23082326
boost::signals2::connection block_notify_genesis_wait_connection;
@@ -2393,8 +2411,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
23932411

23942412
// ********************************************************* Step 12: start node
23952413

2396-
int chain_active_height;
2397-
23982414
//// debug print
23992415
{
24002416
LOCK(cs_main);

test/functional/p2p_dos_header_tree.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from test_framework.blocktools import filter_tip_keys
88

9+
from test_framework.governance import EXPECTED_STDERR_NO_GOV_PRUNE
910
from test_framework.messages import (
1011
CBlockHeader,
1112
from_hex,
@@ -23,6 +24,7 @@ def set_test_params(self):
2324
self.setup_clean_chain = True
2425
self.chain = 'testnet3' # Use testnet chain because it has an early checkpoint
2526
self.num_nodes = 2
27+
self.extra_args = [['-prune=945']] * self.num_nodes
2628

2729
def add_options(self, parser):
2830
parser.add_argument(
@@ -64,7 +66,7 @@ def run_test(self):
6466

6567
self.log.info("Feed all fork headers (succeeds without checkpoint)")
6668
# On node 0 it succeeds because checkpoints are disabled
67-
self.restart_node(0, extra_args=['-nocheckpoints'])
69+
self.restart_node(0, extra_args=['-nocheckpoints', '-prune=945'], expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE)
6870
peer_no_checkpoint = self.nodes[0].add_p2p_connection(P2PInterface())
6971
peer_no_checkpoint.send_and_ping(msg_headers(self.headers_fork))
7072
assert {
@@ -84,6 +86,8 @@ def run_test(self):
8486
"status": "headers-only",
8587
} in filter_tip_keys(self.nodes[0].getchaintips())
8688

89+
for idx in range(self.num_nodes):
90+
self.nodes[idx].stop_node(expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE)
8791

8892
if __name__ == '__main__':
8993
RejectLowDifficultyHeadersTest().main()

test/functional/wallet_crosschain.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os
77

8+
from test_framework.governance import EXPECTED_STDERR_NO_GOV_PRUNE
89
from test_framework.test_framework import BitcoinTestFramework
910
from test_framework.util import assert_raises_rpc_error
1011

@@ -21,7 +22,7 @@ def setup_network(self):
2122

2223
# Switch node 1 to testnet before starting it.
2324
self.nodes[1].chain = 'testnet3'
24-
self.nodes[1].extra_args = ['-maxconnections=0'] # disable testnet sync
25+
self.nodes[1].extra_args = ['-maxconnections=0', '-prune=945'] # disable testnet sync
2526
with open(self.nodes[1].bitcoinconf, 'r', encoding='utf8') as conf:
2627
conf_data = conf.read()
2728
with open (self.nodes[1].bitcoinconf, 'w', encoding='utf8') as conf:
@@ -58,11 +59,14 @@ def run_test(self):
5859

5960
if not self.options.descriptors:
6061
self.log.info("Override cross-chain wallet load protection")
62+
self.nodes[1].stop_node(expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE)
6163
self.stop_nodes()
62-
self.start_nodes([['-walletcrosschain']] * self.num_nodes)
64+
self.start_nodes([['-walletcrosschain', '-prune=945']] * self.num_nodes)
6365
self.nodes[0].loadwallet(node1_wallet)
6466
self.nodes[1].loadwallet(node0_wallet)
6567

68+
for idx in range(self.num_nodes):
69+
self.nodes[idx].stop_node(expected_stderr=EXPECTED_STDERR_NO_GOV_PRUNE if not self.options.descriptors or (self.options.descriptors and idx == 1) else "")
6670

6771
if __name__ == '__main__':
6872
WalletCrossChain().main()

0 commit comments

Comments
 (0)