From 2ec84c30dba861655adc7c94ddbfede16e2e4f11 Mon Sep 17 00:00:00 2001 From: /rootzoll Date: Sun, 15 Jan 2023 21:51:08 +0100 Subject: [PATCH] #3605 refactor reindex script and add to repair menu (#3609) --- CHANGES.md | 3 +- home.admin/00raspiblitz.sh | 7 -- home.admin/98repairBlockchain.sh | 4 - home.admin/98repairMenu.sh | 17 ++- home.admin/config.scripts/network.reindex.sh | 116 ++++++------------- 5 files changed, 55 insertions(+), 92 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 438d3dc6..2d075c4c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ - New: LightningTipBot v0.5 [details](https://github.com/LightningTipBot/LightningTipBot) - New on WebUI: Jam (JoinMarket Web UI) v0.1.4 [details](https://github.com/joinmarket-webui/joinmarket-webui/releases/tag/v0.1.4) - Update: Bitcoin Core v24.0.1 [details](https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-24.0.1.md) -- Update: LND v0.15.5 [details](https://github.com/lightningnetwork/lnd/releases/tag/v0.15.5-beta +- Update: LND v0.15.5 [details](https://github.com/lightningnetwork/lnd/releases/tag/v0.15.5-beta) - Update: Core Lightning v22.11.1 [details](https://github.com/ElementsProject/lightning/releases/tag/v22.11.1) - Update: Electrum Server in Rust (electrs) v0.9.10 [details](https://github.com/romanz/electrs/blob/master/RELEASE-NOTES.md#0910-nov-3-2022) - Update: Lightning Terminal v0.8.4-alpha [details](https://github.com/lightninglabs/lightning-terminal/releases/tag/v0.8.4-alpha) @@ -29,6 +29,7 @@ - Info: Run RaspiBlitz on Proxmox [details](https://github.com/rootzoll/raspiblitz/tree/dev/alternative.platforms/Proxmox) - Info: IP2Tor unavailable & deactivated in SSH menus [details](https://github.com/rootzoll/raspiblitz/issues/3417#issuecomment-1310303480) - Info: 32GB sdcard is now enforced (after being recommended since v1.5) +- Info: 'Reindex Blockchain' is not part of 'repair' menu ## What's new in Version 1.8.0c of RaspiBlitz? diff --git a/home.admin/00raspiblitz.sh b/home.admin/00raspiblitz.sh index 93017c66..ef28bd46 100755 --- a/home.admin/00raspiblitz.sh +++ b/home.admin/00raspiblitz.sh @@ -48,13 +48,6 @@ if [ "${copyInProgress}" = "1" ]; then exit fi -# special state: reindex was triggered -if [ "${state}" = "reindex" ]; then - echo "Re-Index in progress ... start monitoring:" - /home/admin/config.scripts/network.reindex.sh - exit -fi - # special state: copystation if [ "${state}" = "copystation" ]; then echo "Copy Station is Running ..." diff --git a/home.admin/98repairBlockchain.sh b/home.admin/98repairBlockchain.sh index f02e9cb8..414695b1 100755 --- a/home.admin/98repairBlockchain.sh +++ b/home.admin/98repairBlockchain.sh @@ -29,10 +29,6 @@ elif [ "${CHOICE}" = "RESYNC" ]; then echo "rebooting .. (please wait)" sudo /home/admin/config.scripts/blitz.shutdown.sh reboot -elif [ "${CHOICE}" = "REINDEX" ]; then - echo "Starting REINDEX ..." - sudo /home/admin/config.scripts/network.reindex.sh - elif [ "${CHOICE}" = "BACKUP" ]; then /home/admin/config.scripts/lnd.compact.sh interactive sudo /home/admin/config.scripts/lnd.backup.sh lnd-export-gui diff --git a/home.admin/98repairMenu.sh b/home.admin/98repairMenu.sh index 1a8c78bc..af202a29 100755 --- a/home.admin/98repairMenu.sh +++ b/home.admin/98repairMenu.sh @@ -76,11 +76,12 @@ if [ "${lightning}" == "cl" ] || [ "${cl}" == "on" ]; then fi OPTIONS+=(MIGRATION "Migrate Blitz Data to new Hardware") OPTIONS+=(COPY-SOURCE "Copy Blockchain Source Modus") +OPTIONS+=(REINDEX "Redindex Bitcoin Blockchain") +OPTIONS+=(DELETE-INDEX "Delete Bitcoin Transaction-Index") OPTIONS+=(RESET-CHAIN "Delete Blockchain & Re-Download") OPTIONS+=(RESET-HDD "Delete HDD Data but keep Blockchain") OPTIONS+=(RESET-ALL "Delete HDD completely to start fresh") OPTIONS+=(DELETE-ELEC "Delete Electrum Index") -OPTIONS+=(DELETE-INDEX "Delete Bitcoin Transaction-Index") CHOICE=$(whiptail --clear --title "Repair Options" --menu "" 19 62 12 "${OPTIONS[@]}" 2>&1 >/dev/tty) @@ -89,7 +90,15 @@ case $CHOICE in # HARDWARE) # ;; SOFTWARE) - sudo /home/admin/config.scripts/blitz.debug.sh + echo "Generating debug logs. Be patient, this should take maximum 2 minutes .." + sudo rm /var/cache/raspiblitz/debug.log 2>/dev/null + /home/admin/config.scripts/blitz.debug.sh > /var/cache/raspiblitz/debug.log + echo "Redacting .." + /home/admin/config.scripts/blitz.debug.sh redact /var/cache/raspiblitz/debug.log + sudo chmod 640 /var/cache/raspiblitz/debug.log + sudo chown root:sudo /var/cache/raspiblitz/debug.log + cat /var/cache/raspiblitz/debug.log + echo echo "Press ENTER to return to main menu." read key ;; @@ -148,6 +157,10 @@ case $CHOICE in /home/admin/config.scripts/network.txindex.sh delete exit 0; ;; + REINDEX) + /home/admin/config.scripts/network.reindex.sh reindex main + exit 0; + ;; COPY-SOURCE) /home/admin/config.scripts/blitz.copychain.sh source /home/admin/config.scripts/lnd.unlock.sh diff --git a/home.admin/config.scripts/network.reindex.sh b/home.admin/config.scripts/network.reindex.sh index 0919ba63..b67b5126 100755 --- a/home.admin/config.scripts/network.reindex.sh +++ b/home.admin/config.scripts/network.reindex.sh @@ -1,93 +1,53 @@ #!/bin/bash # command info -if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then - echo "script to run re-index if the blockchain (in case of repair)" - echo "run to start or monitor re-index progress" +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "script to run re-index if the blockchain - blocks will not be deleted but re-indexed" + echo "will trigger reboot after started and progress can be monitored thru normal sync status" + echo "network.reindex.sh reindex [mainnet|testnet|signet] --> use to start re-index chain" exit 1 fi -# check and load raspiblitz config -# to know which network is running -source /home/admin/raspiblitz.info source /mnt/hdd/raspiblitz.conf -# if re-index is not running, start ... -source <(/home/admin/_cache.sh get state) -if [ "${state}" != "reindex" ]; then +################### +# START +################### +if [ "$1" = "reindex" ]; then - # stop services - echo "making sure services are not running .." - sudo systemctl stop lnd 2>/dev/null - sudo systemctl stop ${network}d 2>/dev/null + # network prefixes + if [ "$2" = "mainnet" ]; then + echo "# network.reindex.sh reindex --> mainnet" + prefix="" + netparam="" + elif [ "$2" = "testnet" ]; then + echo "# network.reindex.sh reindex --> testnet" + prefix="t" + netparam="-testnet " + elif [ "$2" = "signet" ]; then + echo "# network.reindex.sh reindex --> signet" + prefix="s" + netparam="-signet " + else + echo "error='unknown/missing secondary parameter'" + exit 1 + fi + + # stop bitcoin service + echo "# stopping ${network} service (please wait - can take time) .." + sudo systemctl stop ${prefix}${network}d # starting reindex - echo "starting re-index ..." - sudo -u bitcoin /usr/local/bin/${network}d -daemon -reindex -conf=/home/bitcoin/.${network}/${network}.conf -datadir=/home/bitcoin/.${network} - - # set reindex flag in raspiblitz.info (gets deleted after (final) reboot) - sudo sed -i "s/^state=.*/state=reindex/g" /home/admin/raspiblitz.info + echo "# starting ${network} service with -reindex flag" + sudo -u bitcoin /usr/local/bin/${network}d ${netparam}-daemon -reindex -conf=/mnt/hdd/${network}/${network}.conf -datadir=/mnt/hdd/${network} 1>&2 + echo "# waiting 10 secs" + sleep 10 + echo "# going into reboot - reindex process can be monitored like normal blockchain sync status" + sudo /home/admin/config.scripts/blitz.shutdown.sh reboot + exit 0 fi -# while loop to wait to finish -finished=0 -progress=0 -while [ ${finished} -eq 0 ] - do - clear - echo "*************************" - echo "REINDEXING BLOCKCHAIN" - echo "*************************" - date - echo "THIS CAN TAKE SOME VERY LONG TIME" - echo "See Raspiblitz FAQ: https://github.com/rootzoll/raspiblitz" - echo "On question: My blockchain data is corrupted - what can I do?" - echo "If you dont see any progress after 24h keep X pressed to stop." +echo "error='unknown main parameter'" +exit 1 - # get blockchain sync progress - blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo) - progress=$(echo "${blockchaininfo}" | jq -r '.verificationprogress') - #progress=$(echo "${progress}*100" | bc) - progress=$(echo $progress | awk '{printf( "%.2f%%", 100 * $1)}') - inprogress="$(echo "${blockchaininfo}" | jq -r '.initialblockdownload')" - if [ "${inprogress}" = "false" ]; then - finished=1 - fi - - echo "" - echo "RUNNING: ${inprogress}" - echo "PROGRESS: ${progress}" - echo "" - - echo "You can close terminal while reindex is running.." - echo "But you have to login again to check if ready." - - # wait 2 seconds for key input - read -n 1 -t 2 keyPressed - - # check if user wants to abort monitor - if [ "${keyPressed}" = "x" ]; then - echo "stopped by user ..." - break - fi - -done - - -# trigger reboot when finished -echo "*************************" -if [ ${finished} -eq 0 ]; then - echo "Re-Index CANCELED" -else - echo "Re-Index finished" -fi -echo "Starting reboot ..." -echo "*************************" -# stop bitcoind -sudo -u bitcoin ${network}-cli stop -sleep 4 -# clean logs (to prevent a false reindex detection) -sudo rm /mnt/hdd/${network}/debug.log 2>/dev/null -# reboot -sudo /home/admin/config.scripts/blitz.shutdown.sh reboot \ No newline at end of file