Skip to content

Commit aeb395d

Browse files
committed
Merge bitcoin/bitcoin#25315: Add warning on first startup if free disk space is less than necessary
6630a1e Add warning on first startup if free disk space is less than necessary (Ben Woosley) Pull request description: This reworks/revives bitcoin/bitcoin#15848 to add a check for low disk space on first startup and issue a warning if disk space is below the expected space required to accommodate the blocks. This PR was fashioned by a team of developers at the [bitcoin++](https://www.btcplusplus.dev/) conference workshop: "[Let's contribute to Bitcoin Core](https://sched.co/12P6Z)" Fixes #15813 ACKs for top commit: achow101: ACK 6630a1e willcl-ark: tACK 6630a1e rebased on master. Warning shows on first start but not on restart after some blocks have been downloaded. aureleoules: ACK 6630a1e pablomartin4btc: re-ACK bitcoin/bitcoin@6630a1e hernanmarino: ReACK bitcoin/bitcoin@6630a1e Tree-SHA512: 0f18acabdf2b514e96e2eea8f304960b952226b83dc91334cf7d1f6355ea2f257aaec0ee38d43ac36435385ecd918333d20657c35a8a7407e7cf2680ccb643bb
2 parents 256120d + 6630a1e commit aeb395d

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/init.cpp

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

1616+
int chain_active_height = WITH_LOCK(cs_main, return chainman.ActiveChain().Height());
1617+
1618+
// On first startup, warn on low block storage space
1619+
if (!fReindex && !fReindexChainState && chain_active_height <= 1) {
1620+
uint64_t additional_bytes_needed = fPruneMode ? nPruneTarget
1621+
: chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024;
1622+
1623+
if (!CheckDiskSpace(args.GetBlocksDirPath(), additional_bytes_needed)) {
1624+
InitWarning(strprintf(_(
1625+
"Disk space for %s may not accommodate the block files. " \
1626+
"Approximately %u GB of data will be stored in this directory."
1627+
),
1628+
fs::quoted(fs::PathToString(args.GetBlocksDirPath())),
1629+
chainparams.AssumedBlockchainSize()
1630+
));
1631+
}
1632+
}
1633+
16161634
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
16171635
// No locking, as this happens before any background thread is started.
16181636
boost::signals2::connection block_notify_genesis_wait_connection;
@@ -1662,8 +1680,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16621680

16631681
// ********************************************************* Step 12: start node
16641682

1665-
int chain_active_height;
1666-
16671683
//// debug print
16681684
{
16691685
LOCK(cs_main);

test/functional/p2p_dos_header_tree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def set_test_params(self):
2222
self.setup_clean_chain = True
2323
self.chain = 'testnet3' # Use testnet chain because it has an early checkpoint
2424
self.num_nodes = 2
25-
self.extra_args = [["-minimumchainwork=0x0"], ["-minimumchainwork=0x0"]]
25+
self.extra_args = [["-minimumchainwork=0x0", '-prune=550']] * self.num_nodes
2626

2727
def add_options(self, parser):
2828
parser.add_argument(
@@ -63,7 +63,7 @@ def run_test(self):
6363

6464
self.log.info("Feed all fork headers (succeeds without checkpoint)")
6565
# On node 0 it succeeds because checkpoints are disabled
66-
self.restart_node(0, extra_args=['-nocheckpoints', "-minimumchainwork=0x0"])
66+
self.restart_node(0, extra_args=['-nocheckpoints', "-minimumchainwork=0x0", '-prune=550'])
6767
peer_no_checkpoint = self.nodes[0].add_p2p_connection(P2PInterface())
6868
peer_no_checkpoint.send_and_ping(msg_headers(self.headers_fork))
6969
assert {

test/functional/wallet_crosschain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setup_network(self):
2121

2222
# Switch node 1 to testnet before starting it.
2323
self.nodes[1].chain = 'testnet3'
24-
self.nodes[1].extra_args = ['-maxconnections=0'] # disable testnet sync
24+
self.nodes[1].extra_args = ['-maxconnections=0', '-prune=550'] # disable testnet sync
2525
with open(self.nodes[1].bitcoinconf, 'r', encoding='utf8') as conf:
2626
conf_data = conf.read()
2727
with open (self.nodes[1].bitcoinconf, 'w', encoding='utf8') as conf:
@@ -51,7 +51,7 @@ def run_test(self):
5151
if not self.options.descriptors:
5252
self.log.info("Override cross-chain wallet load protection")
5353
self.stop_nodes()
54-
self.start_nodes([['-walletcrosschain']] * self.num_nodes)
54+
self.start_nodes([['-walletcrosschain', '-prune=550']] * self.num_nodes)
5555
self.nodes[0].loadwallet(node1_wallet)
5656
self.nodes[1].loadwallet(node0_wallet)
5757

0 commit comments

Comments
 (0)