Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reindex_chainstate action #147

Merged
merged 6 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ COPY --from=bitcoin-core /opt /opt
COPY ./manager/target/${ARCH}-unknown-linux-musl/release/bitcoind-manager \
./docker_entrypoint.sh \
./actions/reindex.sh \
./actions/reindex_chainstate.sh \
./check-rpc.sh \
./check-synced.sh \
/usr/local/bin/
Expand Down
20 changes: 20 additions & 0 deletions actions/reindex_chainstate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

set -e

touch /root/.bitcoin/requires.reindex_chainstate
action_result_running=" {
\"version\": \"0\",
\"message\": \"Bitcoin Core restarting in reindex chainstate mode\",
\"value\": null,
\"copyable\": false,
\"qr\": false
}"
action_result_stopped=" {
\"version\": \"0\",
\"message\": \"Bitcoin Core will reindex the chainstate the next time the service is started\",
\"value\": null,
\"copyable\": false,
\"qr\": false
}"
bitcoin-cli -rpcconnect=bitcoind.embassy stop >/dev/null 2>/dev/null && echo $action_result_running || echo $action_result_stopped
7 changes: 5 additions & 2 deletions manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ fn sidecar(config: &Mapping, addr: &str) -> Result<(), Box<dyn Error>> {
Ok(())
}

fn inner_main(reindex: bool) -> Result<(), Box<dyn Error>> {
fn inner_main(reindex: bool, reindex_chainstate: bool) -> Result<(), Box<dyn Error>> {
while !Path::new("/root/.bitcoin/start9/config.yaml").exists() {
std::thread::sleep(std::time::Duration::from_secs(1));
}
Expand Down Expand Up @@ -455,6 +455,8 @@ fn inner_main(reindex: bool) -> Result<(), Box<dyn Error>> {
}
if reindex {
btc_args.push("-reindex".to_owned());
} else if reindex_chainstate {
btc_args.push("-reindex-chainstate".to_owned());
}

std::io::copy(
Expand Down Expand Up @@ -533,6 +535,7 @@ fn inner_main(reindex: bool) -> Result<(), Box<dyn Error>> {
fn main() -> Result<(), Box<dyn Error>> {
env_logger::Builder::from_env(Env::default().default_filter_or("warn")).init();
let reindex = Path::new("/root/.bitcoin/requires.reindex").exists();
let reindex_chainstate = Path::new("/root/.bitcoin/requires.reindex_chainstate").exists();
ctrlc::set_handler(move || {
if let Some(raw_child) = *CHILD_PID.lock().unwrap() {
use nix::{
Expand All @@ -544,7 +547,7 @@ fn main() -> Result<(), Box<dyn Error>> {
std::process::exit(143)
}
})?;
inner_main(reindex)
inner_main(reindex, reindex_chainstate)
}

fn human_readable_timestamp(unix_time: u64) -> String {
Expand Down
18 changes: 17 additions & 1 deletion manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ actions:
reindex:
name: "Reindex Blockchain"
description: "Rebuilds the block and chainstate databases starting from genesis. If blocks already exist on disk, these are used rather than being redownloaded. For pruned nodes, this means downloading the entire blockchain over again."
warning: Blocks not stored on disk will be redownloaded in order to rebuild the database. If your node is pruned, this action is equivalent to syncing the node from scratch, so this process could take a couple of weeks.
warning: Blocks not stored on disk will be redownloaded in order to rebuild the database. If your node is pruned, this action is equivalent to syncing the node from scratch, so this process could take weeks on low-end hardware.
allowed-statuses:
- running
- stopped
Expand All @@ -150,6 +150,22 @@ actions:
mounts:
main: /root/.bitcoin
io-format: json
reindex-chainstate:
name: "Reindex Chainstate"
description: "Rebuilds the chainstate database using existing block index data; as the block index is not rebuilt, 'reindex_chainstate' should be strictly faster than 'reindex'. This action should only be used in the case of chainstate corruption; if the blocks stored on disk are corrupted, the 'reindex' action will need to be run instead."
warning: Blocks not stored on disk will be redownloaded in order to rebuild the database. If your node is pruned, this action is equivalent to syncing the node from scratch, so this process could take weeks on low-end hardware.
allowed-statuses:
- running
- stopped
implementation:
type: docker
image: main
system: false
entrypoint: reindex_chainstate.sh
args: []
mounts:
main: /root/.bitcoin
io-format: json
delete-txindex:
name: "Delete Transaction Index"
description: "Deletes the Transaction Index (txindex) in case it gets corrupted."
Expand Down