Skip to content

Commit

Permalink
add reindex_chainstate action
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominion5254 committed May 17, 2024
1 parent 1e1a5e9 commit a43da52
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
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
16 changes: 16 additions & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ actions:
mounts:
main: /root/.bitcoin
io-format: json
reindex_chainstate:
name: "Reindex Chainstaate"
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 a couple of weeks.
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

0 comments on commit a43da52

Please sign in to comment.