This picks up #15954
I fixed the code and added at a functional test utilizing the scripts in contrib/linearize
as suggested by @MarcoFalke .
bootstrap.dat
and associated code
#17044
This picks up #15954
I fixed the code and added at a functional test utilizing the scripts in contrib/linearize
as suggested by @MarcoFalke .
0@@ -0,0 +1,87 @@
1+#!/usr/bin/env python3
2+# Copyright (c) 2017-2019 The Bitcoin Core developers
3+# Distributed under the MIT software license, see the accompanying
4+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+"""Test loadblock option
6+
7+Test the option to start a node with the option loadpath which
0@@ -0,0 +1,87 @@
1+#!/usr/bin/env python3
2+# Copyright (c) 2017-2019 The Bitcoin Core developers
3+# Distributed under the MIT software license, see the accompanying
4+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+"""Test loadblock option
6+
7+Test the option to start a node with the option loadpath which
8+loads a serialized blockchain from a file (usually called bootstrap.dat).
9+To generate that file this test uses the helper scripts in available
The CIs don’t like the new test yet, probably because the relative paths require one to be in the bitcoin root dir for the scripts to be found.
Also, the help text for loadblock
, “Imports blocks from external blk000??.dat file on startup” could be updated to remove the file name.
57+ port=node_url.port,
58+ host=node_url.hostname,
59+ hashlist=hashlist_path,
60+ block_dir=block_dir,
61+ genesis=genesis_block))
62+ cfg.close()
Can use https://docs.python.org/3/reference/compound_stmts.html#with instead?
And the writing it like this, should make the test shorter in line count. https://github.com/bitcoin/bitcoin/blob/7b701fef58f627956d597817a1f9422edd890cdc/test/functional/test_framework/util.py#L306
67+
68+ # use a new empty blocks dir to make sure blocks are loaded from bootstrap file
69+ shutil.rmtree(self.nodes[0].datadir)
70+ initialize_datadir(self.options.tmpdir, 0, self.chain)
71+ blocksdir_path = os.path.join(self.options.tmpdir, 'blocksdir')
72+ os.mkdir(blocksdir_path)
What is the point of blocksdir_path
(new empty blocks dir), when the whole datadir is cleaned?
I’d even go further and not remove the whole datadir tree. Since that also deletes the debug log for debugging purposes.
You could spin up two nodes, and call setnetworkactive(False)
on the second one. Then reboot the second one with the -loadblock
arg here.
7@@ -8,6 +8,9 @@ export LC_ALL=C.UTF-8
8
9 cd "build/bitcoin-$HOST" || (echo "could not enter distdir build/bitcoin-$HOST"; exit 1)
10
11+mkdir -p contrib
12+cp -R ../../contrib/ contrib/
I think you can’t run these with the travis
user, only with the docker root
user.
I.e.
0DOCKER_EXEC cp -R ../../contrib/ contrib/
54+ base_dir = self.config["environment"]["SRCDIR"]
55+ linearize_dir = os.path.join(base_dir, "contrib", "linearize")
56+
57+ self.log.info("Run linearization of block hashes")
58+ linearize_hashes_path = os.path.join(linearize_dir, "linearize-hashes.py")
59+ os.system(linearize_hashes_path + " " + cfg_path + " > " + hashlist_path)
>
work on all OS flavors? It seems that appveyor windows is passing, so it seems fine!?
subprocess
instead of os.system
to invoke other processes from python
Also, does the
>
work on all OS flavors? It seems that appveyor windows is passing, so it seems fine!?
I did a brief check and did not find any issues concerning windows. I am on macOS and it’s fine.
also, please use
subprocess
instead ofos.system
to invoke other processes from python
done
Shouldn’t you check the return code?
done
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
1704+
1705+ if (gArgs.IsArgSet("-loadblock")) {
1706+ const std::vector<std::string> vLoadBlockArgs = gArgs.GetArgs("-loadblock");
1707+
1708+ // Regard the '-noloadblock' argument
1709+ if (!vLoadBlockArgs.empty()) {
1703- vImportFiles.push_back(strFile);
1704+
1705+ if (gArgs.IsArgSet("-loadblock")) {
1706+ const std::vector<std::string> vLoadBlockArgs = gArgs.GetArgs("-loadblock");
1707+
1708+ // Regard the '-noloadblock' argument
GetArgs
takes care of the -noloadblock
option
AbsPathForConfigVal()
which does not seem to be critical here.
373@@ -374,7 +374,7 @@ void SetupServerArgs()
374 gArgs.AddArg("-debuglogfile=<file>", strprintf("Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s)", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
375 gArgs.AddArg("-feefilter", strprintf("Tell other nodes to filter invs to us by our mempool min fee (default: %u)", DEFAULT_FEEFILTER), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
376 gArgs.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
377- gArgs.AddArg("-loadblock=<file>", "Imports blocks from external blk000??.dat file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
378+ gArgs.AddArg("-loadblock=<file>", "Imports blocks from external file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
blk000.dat
files.
bootstrap.dat
or whatever your file is named).
See for example this test:
0diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py
1index bf2a4ff61f..a532a83946 100755
2--- a/test/functional/feature_loadblock.py
3+++ b/test/functional/feature_loadblock.py
4@@ -25,7 +25,7 @@ from test_framework.util import assert_equal, wait_until
5 class LoadblockTest(BitcoinTestFramework):
6 def set_test_params(self):
7 self.setup_clean_chain = True
8- self.num_nodes = 2
9+ self.num_nodes = 3
10
11 def run_test(self):
12 self.nodes[1].setnetworkactive(state=False)
13@@ -71,13 +71,16 @@ class LoadblockTest(BitcoinTestFramework):
14 subprocess.run([sys.executable, linearize_data_file, cfg_file],
15 check=True)
16
17- self.log.info("Restart second, unsynced node with bootstrap file")
18+ self.log.info("Restart unsynced nodes with bootstrap file or raw block file")
19 self.stop_node(1)
20 self.start_node(1, ["-loadblock=" + bootstrap_file])
21- wait_until(lambda: self.nodes[1].getblockcount() == 100)
22+ self.stop_node(2)
23+ self.start_node(2, ["-loadblock=" + os.path.join(blocks_dir, 'blk00000.dat')])
24+ for i in [1, 2]:
25+ wait_until(lambda: self.nodes[i].getblockcount() == 100)
26
27- assert_equal(self.nodes[1].getblockchaininfo()['blocks'], 100)
28- assert_equal(self.nodes[0].getbestblockhash(), self.nodes[1].getbestblockhash())
29+ assert_equal(self.nodes[i].getblockchaininfo()['blocks'], 100)
30+ assert_equal(self.nodes[0].getbestblockhash(), self.nodes[i].getbestblockhash())
31
32
33 if __name__ == '__main__':
blkXXXXX.dat
are the block files and the way to (re)index them is -reindex
, it has nothing to do with -loadblock
.
-loadblock=blk001.dat -loadblock=blk002.dat -loadblock=...
I don’t think that’s the point. In that case it’s less hassle to copy over all the blk files and do a reindex
.
I think the idea behind -loadblock
is to import the output from linearize; huge consecutive ‘block archives’ (there used to be torrents for this). But I might be wrong. I’m not sure what it’s used for nowadays.
Oh, so it is multi-arg to support a split-up bootstrap.dat?
I think so; linearize splits it into 1GB files by default.
nit:
0diff --git a/doc/developer-notes.md b/doc/developer-notes.md
1index 1a7ce91ca67d47903a3b97d45944fb2df6ea2fa1..08004778e3e13284bf1de95efd24a62202847bfc 100644
2--- a/doc/developer-notes.md
3+++ b/doc/developer-notes.md
4@@ -384,7 +384,7 @@ Threads
5
6 - ThreadScriptCheck : Verifies block scripts.
7
8-- ThreadImport : Loads blocks from blk*.dat files or bootstrap.dat.
9+- ThreadImport : Loads blocks from `blk*.dat` files or `-loadblock=<file>`.
10
11 - StartNode : Starts other threads.
12
- only load blockfiles when we have paths
- add release notes for modified bootstrap functionality
- amend documentation on ThreadImport