Skip to content

Commit 6630a1e

Browse files
EmpactdarosiorbenthecarmanlitchLiranCohen
committed
Add warning on first startup if free disk space is less than necessary
To accommodate the expected blocks data. Co-authored-by: Antoine Poinsot <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: Justin Litchfield <[email protected]> Co-authored-by: Liran Cohen <[email protected]> Co-authored-by: Ryan Loomba <[email protected]> Co-authored-by: Buck Perley <[email protected]> Co-authored-by: bajjer <[email protected]> Co-authored-by: Suhail Saqan <[email protected]> Co-authored-by: Christopher Sweeney <[email protected]> Co-authored-by: Alyssa <[email protected]> Co-authored-by: Ben Schroth <[email protected]> Co-authored-by: Jason Hester <[email protected]> Co-authored-by: Matt Clough <[email protected]> Co-authored-by: Elise Schedler <[email protected]> Co-authored-by: ghander <[email protected]> Co-authored-by: PopeLaz <[email protected]> Co-authored-by: Aurèle Oulès <[email protected]>
1 parent 57c1927 commit 6630a1e

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
@@ -1569,6 +1569,24 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15691569
return false;
15701570
}
15711571

1572+
int chain_active_height = WITH_LOCK(cs_main, return chainman.ActiveChain().Height());
1573+
1574+
// On first startup, warn on low block storage space
1575+
if (!fReindex && !fReindexChainState && chain_active_height <= 1) {
1576+
uint64_t additional_bytes_needed = fPruneMode ? nPruneTarget
1577+
: chainparams.AssumedBlockchainSize() * 1024 * 1024 * 1024;
1578+
1579+
if (!CheckDiskSpace(args.GetBlocksDirPath(), additional_bytes_needed)) {
1580+
InitWarning(strprintf(_(
1581+
"Disk space for %s may not accommodate the block files. " \
1582+
"Approximately %u GB of data will be stored in this directory."
1583+
),
1584+
fs::quoted(fs::PathToString(args.GetBlocksDirPath())),
1585+
chainparams.AssumedBlockchainSize()
1586+
));
1587+
}
1588+
}
1589+
15721590
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
15731591
// No locking, as this happens before any background thread is started.
15741592
boost::signals2::connection block_notify_genesis_wait_connection;
@@ -1618,8 +1636,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16181636

16191637
// ********************************************************* Step 12: start node
16201638

1621-
int chain_active_height;
1622-
16231639
//// debug print
16241640
{
16251641
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)