Repository navigation
fix(storage): detect signet_<hash> directories and respect network arg - #23
Merged
secsovereign merged 7 commits intoOct 15, 2026
Merged
Conversation
Follow-up to PR #22 (testnet4 support): 1. detect_network: Add testnet4 detection. Custom signet directories (signet_<hash>) now return None instead of silently falling back to mainnet. The caller must decide how to handle unknown networks. 2. detect_network_strict: New method that returns an explicit error for custom signet directories, with a clear message instructing the user to specify --network signet. 3. is_bitcoin_core_dir: Now respects the network argument. Mainnet data is expected at the root of base_dir, while other networks use their standard subdirectories (testnet3/, testnet4/, signet/, regtest/). 4. Tests: Added comprehensive unit tests and integration-style tests for testnet4 datadir detection, custom signet handling, and network-specific directory layout validation. Co-authored-by: Secure Sovereign <secsovereign@users.noreply.github.com>
The production caller in open_core_block_reader_for_store was still using .unwrap_or(CoreDataNetwork::Mainnet) after detect_network returned None for custom signet directories. This silently opened a Mainnet reader for signet_<hash> directories. Changes: - Replace detect_network + unwrap_or(Mainnet) with detect_network_strict - Log a clear warning and return None when network cannot be determined - Make open_core_block_reader_for_store pub(crate) for testing Tests: - test_custom_signet_core_dir_does_not_produce_mainnet_reader: verifies that signet_<hash> directories with reuse enabled return None, not a Mainnet reader - test_standard_signet_core_dir_detection_works: verifies standard signet directories are still detected correctly Co-authored-by: Secure Sovereign <secsovereign@users.noreply.github.com>
cursor
Bot
force-pushed
the
cursor/fix-bitcoin-core-datadir-detection-efcf
branch
from
October 7, 2026 21:38
98cb229 to
2bdd1d1
Compare
secsovereign
marked this pull request as ready for review
October 7, 2026 22:06
…re-datadir-detection-efcf
…er and node Core block-file reuse now resolves the network with BitcoinCoreDetection::resolve_reuse_network: migration marker, then the Core folder name, then the node's configured network. Every known source must agree; custom signet (signet_<hash>) folders are always refused. - B2: non-standard mainnet datadirs (Bitcoin, bitcoin, /srv/btc-data) keep reuse when the node runs mainnet; nothing defaults to mainnet. - S3: the marker's network is validated instead of trusted. - B1: the reader-level tests move into the crate (src/storage/core_reuse_tests.rs, cfg(all(test, feature="rocksdb"))) since open_core_block_reader_for_store is pub(crate). - The custom signet error names storage.reuse_core_block_files instead of a --network flag that never reached this code.
The rocksdb-gated Core import and block-reuse code was never compiled into a CI test run.
…re-datadir-detection-efcf
…re-datadir-detection-efcf
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to PR #22 (testnet4 support, merged as badc23e). Fixes how BLVM decides which network's Bitcoin Core block files to read when it reuses a Core datadir in place (
storage.reuse_core_block_files, on by default).On
main, a Core datadir whose network could not be detected silently became mainnet, so a custom signet (signet_<hash>) or an unrecognised folder could get a reader with the wrong network magic. This PR stops that without dropping reuse for real mainnet datadirs with non-standard names.Network rule for Core block reuse
BitcoinCoreDetection::resolve_reuse_network(core_dir, marker_network, node_network)decides the network from three sources, in this order:networkin the BLVM migration marker (blvm_meta/migration.json); empty counts as absent.bitcoin/bitcoind→ mainnet,testnet3,testnet4,signet,regtest)open_for_nodepasses it; library callers passconsensus_network)Every source that is known must agree, and the first known one wins. Reuse is skipped with a warning, and no reader is opened, when:
signet_<hash>), whatever the marker or node say, because its block magic is not the standard signet magic.bitcoin/signet, or a mainnet node on.bitcoin/testnet3)So
~/Library/Application Support/Bitcoin,%APPDATA%\Bitcoin,bitcoinor/srv/btc-dataopened by a mainnet node keep block reuse, and nothing falls back to mainnet by default.Changes
src/storage/bitcoin_detection.rsdetect_network: custom signet (signet_<hash>) and unknown folders returnNoneinstead of mainnet.detect_network_strict(new): an error for custom signets and unknown folders. The custom signet message names the setting that actually applies (storage.reuse_core_block_files = false), not a--networkflag.resolve_reuse_network(new): the rule above.is_bitcoin_core_dir: now public, and checks the network's subfolder (testnet3/,testnet4/,signet/,regtest/; mainnet at the root).src/storage/mod.rsopen_core_block_reader_for_storetakes the node network and usesresolve_reuse_network. The marker's network is no longer trusted unchecked.open_blockstoreand both storage constructors pass the caller'sconsensus_networkthrough.with_backend_pruning_and_indexingno longer swaps an unknown network forSome(Mainnet)before Core reuse.Small accessors
BitcoinCoreBlockReader::network()andBlockStore::bitcoin_core_reader_network()(rocksdb), used by the tests.CI
Run tests (rocksdb feature)step:cargo test --features rocksdb. The rocksdb-gated Core import and reuse code was never compiled into a test run before. That's how the E0624 in the previous head went unnoticed.Tests
src/storage/core_reuse_tests.rs(new,#[cfg(all(test, feature = "rocksdb"))]): callsopen_core_block_reader_for_storefrom inside the crate. It replaces the integration test that called thispub(crate)fn and failed to compile with E0624. It covers:bitcoin,Bitcoin,srv/btc-data) with a mainnet node → mainnet reader.bitcoin/signet→ no readersignet_<hash>→ no reader (with and without a signet node)Storage::with_backend_pruning_and_indexingbitcoin_detectionunit tests forresolve_reuse_network: priority, every disagreement pair, custom signet with every marker/node combination, an unknown marker network, and the wording of the custom signet message. These run with default features too.Results:
Run locally at b79ba28 (crates.io deps as in CI:
[patch.crates-io]stripped, blvm-protocol 0.1.30, blvm-consensus 0.1.54;-j 2):--features rocksdb--lib--test bitcoin_core_tests--test storage_tests--test core_drop_in_integrationcargo clippy -- -D warnings--lib --bins --examplesclean--libcleancargo fmt --checkis clean. One default-features--librun failednode::parallel_ibd::tip_stage::tests::tip_crawl_supply_healthy_requires_past_body_and_fast_gd_or_stream, which is timing-sensitive and not touched here. It passed 3/3 in isolation and in the full rerun. The other ~195 integration test binaries were not run locally because of disk on the shared box. CI'sRun testsand the newRun tests (rocksdb feature)step cover them.Revert checks (each fix reverted alone,
cargo test --features rocksdb):nonstandard_mainnet_names_reuse_with_node_network_mainnet,nonstandard_name_follows_node_network,open_for_node_passes_the_node_network_to_core_reuse,folder_and_node_disagreement_is_refused,marker_and_node_disagreement_is_refused)mainnet_marker_on_standard_signet_folder_is_refused,marker_and_folder_disagreement_is_refused,marker_and_node_disagreement_is_refused,resolve_marker_folder_disagreement_refuses,resolve_node_disagreement_refuses)custom_signet_core_dir_does_not_produce_a_reader,signet_marker_on_custom_signet_folder_is_refused,resolve_custom_signet_refuses_whatever_the_other_sources_say,custom_signet_error_names_the_real_setting)--networkwording:custom_signet_error_names_the_real_settingfails--test bitcoin_core_testsfails to compile (E0624, private fn)Out of scope
consensus_network.unwrap_or(Mainnet)defaults still used for pruning inwith_backend_pruning_and_indexing/with_backend_pruning_indexing_and_compressionare unchanged. Core block reuse no longer depends on them.