From 509274af4de6e0ff7d1652de3b41a98c8ecec908 Mon Sep 17 00:00:00 2001 From: Dominion5254 Date: Wed, 29 May 2024 14:33:09 -0600 Subject: [PATCH] add reindex_chainstate action (#147) * add reindex_chainstate action * fix typo * fix action id build error * Copy reindex_chainstate.sh into container * Commas, phrasing * typo correction --------- Co-authored-by: gStart9 --- Dockerfile | 1 + actions/reindex_chainstate.sh | 20 ++++++++++++++++++++ manager/src/main.rs | 7 +++++-- manifest.yaml | 18 +++++++++++++++++- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 actions/reindex_chainstate.sh diff --git a/Dockerfile b/Dockerfile index 594695f..df7e513 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ diff --git a/actions/reindex_chainstate.sh b/actions/reindex_chainstate.sh new file mode 100644 index 0000000..8b7e25e --- /dev/null +++ b/actions/reindex_chainstate.sh @@ -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 \ No newline at end of file diff --git a/manager/src/main.rs b/manager/src/main.rs index dc1323a..4996a65 100644 --- a/manager/src/main.rs +++ b/manager/src/main.rs @@ -418,7 +418,7 @@ fn sidecar(config: &Mapping, addr: &str) -> Result<(), Box> { Ok(()) } -fn inner_main(reindex: bool) -> Result<(), Box> { +fn inner_main(reindex: bool, reindex_chainstate: bool) -> Result<(), Box> { while !Path::new("/root/.bitcoin/start9/config.yaml").exists() { std::thread::sleep(std::time::Duration::from_secs(1)); } @@ -455,6 +455,8 @@ fn inner_main(reindex: bool) -> Result<(), Box> { } if reindex { btc_args.push("-reindex".to_owned()); + } else if reindex_chainstate { + btc_args.push("-reindex-chainstate".to_owned()); } std::io::copy( @@ -533,6 +535,7 @@ fn inner_main(reindex: bool) -> Result<(), Box> { fn main() -> Result<(), Box> { 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::{ @@ -544,7 +547,7 @@ fn main() -> Result<(), Box> { std::process::exit(143) } })?; - inner_main(reindex) + inner_main(reindex, reindex_chainstate) } fn human_readable_timestamp(unix_time: u64) -> String { diff --git a/manifest.yaml b/manifest.yaml index 2c4e037..64f7079 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -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 @@ -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."