From 9ee8ffcca7b1be1d7836c09c5763334dc4e0481c Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 12 May 2013 12:03:32 +0200 Subject: [PATCH] Check for correct genesis At startup, check that the expected genesis is loaded. This should prevent cases where accidentally a datadir from the wrong network is loaded (testnet vs mainnet, e.g.). --- src/init.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 767d7525a66..eb148745de9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -864,6 +864,11 @@ bool AppInit2(boost::thread_group& threadGroup) break; } + // If the loaded chain has a wrong genesis, bail out immediately + // (we're likely using a testnet datadir, or the other way around). + if (!mapBlockIndex.empty() && pindexGenesisBlock == NULL) + return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?")); + // Initialize the block index (no-op if non-empty database was already loaded) if (!InitBlockIndex()) { strLoadError = _("Error initializing block database");