This picks up #15954
I fixed the code and added at a functional test utilizing the scripts in contrib/linearize as suggested by @MarcoFalke .
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
loadblock, not loadpath
fixed
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
remove "in"
fixed
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
Yes, that's much better, implemented that.
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.
I was weighing different options initially and thought using just one node might be more economical. But I did not think about the logs. I am now using a second node.
Concept ACK
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.
DOCKER_EXEC cp -R ../../contrib/ contrib/
Also, if those files are missing because they are not in the distdir, I'd prefer to add them instead of copying them manually in the ci
Yes, that seems cleaner, doing that instead now
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)
Shouldn't you check the return code?
Also, does the > work on all OS flavors? It seems that appveyor windows is passing, so it seems fine!?
also, please use 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
subprocessinstead ofos.systemto invoke other processes from python
done
Shouldn't you check the return code?
done
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
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()) {
You could remove this check, iterating an empty array is fine.
done
Concept ACK
Concept ACK
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
what does this comment mean? GetArgs takes care of the -noloadblock option
Also, why is this code block changed at all?
True, after implementing the feedback this doesn't do anything different aside from using 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);
why is this removed? I'd rather add a test for importing blk000.dat files.
@MarcoFalke: I suggested removing that above, because it seemed to imply a non-existing naming convention for the file (might as well load from bootstrap.dat or whatever your file is named).
See for example this test:
diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py
index bf2a4ff61f..a532a83946 100755
--- a/test/functional/feature_loadblock.py
+++ b/test/functional/feature_loadblock.py
@@ -25,7 +25,7 @@ from test_framework.util import assert_equal, wait_until
class LoadblockTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
- self.num_nodes = 2
+ self.num_nodes = 3
def run_test(self):
self.nodes[1].setnetworkactive(state=False)
@@ -71,13 +71,16 @@ class LoadblockTest(BitcoinTestFramework):
subprocess.run([sys.executable, linearize_data_file, cfg_file],
check=True)
- self.log.info("Restart second, unsynced node with bootstrap file")
+ self.log.info("Restart unsynced nodes with bootstrap file or raw block file")
self.stop_node(1)
self.start_node(1, ["-loadblock=" + bootstrap_file])
- wait_until(lambda: self.nodes[1].getblockcount() == 100)
+ self.stop_node(2)
+ self.start_node(2, ["-loadblock=" + os.path.join(blocks_dir, 'blk00000.dat')])
+ for i in [1, 2]:
+ wait_until(lambda: self.nodes[i].getblockcount() == 100)
- assert_equal(self.nodes[1].getblockchaininfo()['blocks'], 100)
- assert_equal(self.nodes[0].getbestblockhash(), self.nodes[1].getbestblockhash())
+ assert_equal(self.nodes[i].getblockchaininfo()['blocks'], 100)
+ assert_equal(self.nodes[0].getbestblockhash(), self.nodes[i].getbestblockhash())
if __name__ == '__main__':
Agree with removing this. blkXXXXX.dat are the block files and the way to (re)index them is -reindex, it has nothing to do with -loadblock.
Isn't the point that you can import the block.dat files from another datadir with -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?
Yeah, that was my understanding as well. But I did see it spelled out anywhere explicitly.
Oh, so it is multi-arg to support a split-up bootstrap.dat?
I think so; linearize splits it into 1GB files by default.
some questions
ACK 5453e2ddf5f9c432d59ba64315a239792136526d
nit:
diff --git a/doc/developer-notes.md b/doc/developer-notes.md
index 1a7ce91ca67d47903a3b97d45944fb2df6ea2fa1..08004778e3e13284bf1de95efd24a62202847bfc 100644
--- a/doc/developer-notes.md
+++ b/doc/developer-notes.md
@@ -384,7 +384,7 @@ Threads
- ThreadScriptCheck : Verifies block scripts.
-- ThreadImport : Loads blocks from blk*.dat files or bootstrap.dat.
+- ThreadImport : Loads blocks from `blk*.dat` files or `-loadblock=<file>`.
- StartNode : Starts other threads.
- only load blockfiles when we have paths
- add release notes for modified bootstrap functionality
- amend documentation on ThreadImport
ok, fine LGTM
ACK 104f7de5934f13b837fcf21f6d6b2559799eabe2