Add regtest support to bitcoin-chainstate tool
What changed, and why it matters
This commit adds a command-line flag to an experimental developer/testing tool so it can use Bitcoin's local-only 'regtest' network instead of the real main network. It is a straightforward feature addition with no security relevance.
No security action needed. Treat as a normal feature/test-tool improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change modifies src/bitcoin-chainstate.cpp to accept an optional ‘-regtest’ argument before the DATADIR path. It adjusts argument validation and selects ChainType::REGTEST when the flag is present, otherwise defaulting to ChainType::MAINNET. The tool remains explicitly experimental and intended for testing only.
Changed components
src/bitcoin-chainstate.cppInspect captured patch +6 / −4
diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp
index 91c5639e..71d0f3e9 100644
--- a/src/bitcoin-chainstate.cpp
+++ b/src/bitcoin-chainstate.cpp
@@ -144,16 +144,18 @@ public:
int main(int argc, char* argv[])
{
// SETUP: Argument parsing and handling
- if (argc != 2) {
+ const bool has_regtest_flag{argc == 3 && std::string(argv[1]) == "-regtest"};
+ if (argc < 2 || argc > 3 || (argc == 3 && !has_regtest_flag)) {
std::cerr
- << "Usage: " << argv[0] << " DATADIR" << std::endl
+ << "Usage: " << argv[0] << " [-regtest] DATADIR" << std::endl
<< "Display DATADIR information, and process hex-encoded blocks on standard input." << std::endl
+ << "Uses mainnet parameters by default, regtest with -regtest flag" << std::endl
<< std::endl
<< "IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING ONLY, AND EXPECTED TO" << std::endl
<< " BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR ACTUAL DATADIR." << std::endl;
return 1;
}
- std::filesystem::path abs_datadir{std::filesystem::absolute(argv[1])};
+ std::filesystem::path abs_datadir{std::filesystem::absolute(argv[argc-1])};
std::filesystem::create_directories(abs_datadir);
btck_LoggingOptions logging_options = {
@@ -169,7 +171,7 @@ int main(int argc, char* argv[])
Logger logger{std::make_unique<KernelLog>()};
ContextOptions options{};
- ChainParams params{ChainType::MAINNET};
+ ChainParams params{has_regtest_flag ? ChainType::REGTEST : ChainType::MAINNET};
options.SetChainParams(params);
options.SetNotifications(std::make_shared<TestKernelNotifications>());
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.