fix CLN wallet reset (#3296)

* cln: unify and improve the resetWallet function
previously the old config and channel database could have been left
behind when using SEEDRESTORE and FILERESTORE
* prompt to save the wallet password for backup
This commit is contained in:
openoms 2022-08-18 10:44:06 +01:00 committed by openoms
parent 7074455380
commit eaacab9679
No known key found for this signature in database
GPG Key ID: 5BFB77609B081B65

View File

@ -16,7 +16,7 @@ function clRescan() {
dialog --backtitle "Choose the new gap limit" \ dialog --backtitle "Choose the new gap limit" \
--title "Enter the rescan depth or blockheight (-)" \ --title "Enter the rescan depth or blockheight (-)" \
--inputbox " --inputbox "
Enter the number of blocks to rescan from the current tip Enter the number of blocks to rescan from the current tip
or use a negative number for the absolute blockheight to scan from. or use a negative number for the absolute blockheight to scan from.
If left empty will start to rescan from the block 700000 (-700000). If left empty will start to rescan from the block 700000 (-700000).
@ -29,6 +29,13 @@ If left empty will start to rescan from the block 700000 (-700000).
sudo systemctl restart ${netprefix}lightningd sudo systemctl restart ${netprefix}lightningd
} }
function resetWallet() {
echo "# Delete ${CLCONF}"
sudo rm -f ${CLCONF}
echo "# Delete and recreate /home/bitcoin/.lightning/${CLNETWORK}"
sudo rm -rf /home/bitcoin/.lightning/${CLNETWORK}
sudo -u bitcoin mkdir /home/bitcoin/.lightning/${CLNETWORK}
}
# BASIC MENU INFO # BASIC MENU INFO
WIDTH=64 WIDTH=64
@ -76,31 +83,33 @@ case $CHOICE in
/home/admin/config.scripts/cl.hsmtool.sh decrypt $CHAIN /home/admin/config.scripts/cl.hsmtool.sh decrypt $CHAIN
source /mnt/hdd/raspiblitz.conf source /mnt/hdd/raspiblitz.conf
;; ;;
PASSWORD_C) PASSWORD_C)
/home/admin/config.scripts/cl.hsmtool.sh change-password $CHAIN /home/admin/config.scripts/cl.hsmtool.sh change-password $CHAIN
;; ;;
AUTOUNLOCK-ON) AUTOUNLOCK-ON)
/home/admin/config.scripts/cl.hsmtool.sh autounlock-on $CHAIN /home/admin/config.scripts/cl.hsmtool.sh autounlock-on $CHAIN
;; ;;
AUTOUNLOCK-OFF) AUTOUNLOCK-OFF)
/home/admin/config.scripts/cl.hsmtool.sh autounlock-off $CHAIN /home/admin/config.scripts/cl.hsmtool.sh autounlock-off $CHAIN
;; ;;
BACKUP) BACKUP)
if [ "${cl}" == "on" ] || [ "${cl}" == "1" ] && [ "${clEncryptedHSM}" != "on" ]; then if [ "${cl}" == "on" ] || [ "${cl}" == "1" ] && [ "${clEncryptedHSM}" != "on" ]; then
dialog \ dialog \
--title "Encrypt the Core Lightning wallet" \ --title "Encrypt the Core Lightning wallet" \
--msgbox "\nWill proceed to encrypt and lock the Core Lightning wallet to prevent it from starting automatically after the backup" 9 55 --msgbox "
Will proceed to encrypt and lock the Core Lightning wallet to prevent it from starting automatically after the backup.
Save this password as it will be needed to restore the backup (same as the Password C for CLN)." 10 55
sudo /home/admin/config.scripts/cl.hsmtool.sh encrypt mainnet sudo /home/admin/config.scripts/cl.hsmtool.sh encrypt mainnet
fi fi
if [ "${clAutoUnlock}" = "on" ]; then if [ "${clAutoUnlock}" = "on" ]; then
/home/admin/config.scripts/cl.hsmtool.sh autounlock-off mainnet /home/admin/config.scripts/cl.hsmtool.sh autounlock-off mainnet
fi fi
/home/admin/config.scripts/cl.hsmtool.sh lock mainnet /home/admin/config.scripts/cl.hsmtool.sh lock mainnet
## from dialogLightningWallet.sh ## from dialogLightningWallet.sh
_temp="/var/cache/raspiblitz/temp/.temp.tmp" _temp="/var/cache/raspiblitz/temp/.temp.tmp"
clear clear
/home/admin/config.scripts/cl.backup.sh cl-export-gui production $_temp /home/admin/config.scripts/cl.backup.sh cl-export-gui production $_temp
@ -110,10 +119,10 @@ case $CHOICE in
echo "Press ENTER when finished downloading." echo "Press ENTER when finished downloading."
read key read key
;; ;;
RESET) RESET)
# backup # backup
## from dialogLightningWallet.sh ## from dialogLightningWallet.sh
_temp="/var/cache/raspiblitz/temp/.temp.tmp" _temp="/var/cache/raspiblitz/temp/.temp.tmp"
clear clear
/home/admin/config.scripts/cl.backup.sh cl-export-gui production $_temp /home/admin/config.scripts/cl.backup.sh cl-export-gui production $_temp
@ -122,15 +131,12 @@ case $CHOICE in
echo echo
echo "The rescue file is stored on the SDcard named cl-rescue.*.tar.gz just in case." echo "The rescue file is stored on the SDcard named cl-rescue.*.tar.gz just in case."
echo echo
echo "The next step will overwrite the old C-lighthning $CHAIN wallet" echo "The next step will overwrite the old Core Lightning $CHAIN wallet"
echo "Press ENTER to continue or CTRL+C to abort" echo "Press ENTER to continue or CTRL+C to abort"
read key read key
# reset
echo "# Delete ${CLCONF}" resetWallet
sudo rm -f ${CLCONF}
echo "# Delete and recreate /home/bitcoin/.lightning/${CLNETWORK}"
sudo rm -rf /home/bitcoin/.lightning/${CLNETWORK}
sudo -u bitcoin mkdir /home/bitcoin/.lightning/${CLNETWORK}
# make sure the new hsm_secret is treated as unencrypted and clear autounlock # make sure the new hsm_secret is treated as unencrypted and clear autounlock
/home/admin/config.scripts/blitz.conf.sh set ${netprefix}clEncryptedHSM "off" /home/admin/config.scripts/blitz.conf.sh set ${netprefix}clEncryptedHSM "off"
/home/admin/config.scripts/blitz.conf.sh set ${netprefix}clAutoUnlock "off" /home/admin/config.scripts/blitz.conf.sh set ${netprefix}clAutoUnlock "off"
@ -149,10 +155,10 @@ case $CHOICE in
/home/admin/config.scripts/cl.install-service.sh signet /home/admin/config.scripts/cl.install-service.sh signet
fi fi
;; ;;
FILERESTORE) FILERESTORE)
# backup # backup
## from dialogLightningWallet.sh ## from dialogLightningWallet.sh
_temp="/var/cache/raspiblitz/temp/.temp.tmp" _temp="/var/cache/raspiblitz/temp/.temp.tmp"
clear clear
/home/admin/config.scripts/cl.backup.sh cl-export-gui production $_temp /home/admin/config.scripts/cl.backup.sh cl-export-gui production $_temp
@ -161,12 +167,12 @@ case $CHOICE in
echo echo
echo "The rescue file is stored on the SDcard named cl-rescue.*.tar.gz just in case." echo "The rescue file is stored on the SDcard named cl-rescue.*.tar.gz just in case."
echo echo
echo "The next step will overwrite the old C-lighthning $CHAIN wallet" echo "The next step will overwrite the old Core Lightning $CHAIN wallet"
echo "Press ENTER to continue or CTRL+C to abort" echo "Press ENTER to continue or CTRL+C to abort"
read key read key
# reset
sudo rm /home/bitcoin/.lightning/${CLNETWORK}/hsm_secret resetWallet
sudo rm -rf /home/bitcoin/.lightning/${CLNETWORK}/*.*
# import file # import file
_temp="/var/cache/raspiblitz/temp/.temp.tmp" _temp="/var/cache/raspiblitz/temp/.temp.tmp"
clear clear
@ -174,10 +180,10 @@ case $CHOICE in
source $_temp 2>/dev/null source $_temp 2>/dev/null
sudo rm $_temp 2>/dev/null sudo rm $_temp 2>/dev/null
;; ;;
SEEDRESTORE) SEEDRESTORE)
# backup # backup
## from dialogLightningWallet.sh ## from dialogLightningWallet.sh
_temp="/var/cache/raspiblitz/temp/.temp.tmp" _temp="/var/cache/raspiblitz/temp/.temp.tmp"
clear clear
/home/admin/config.scripts/cl.backup.sh cl-export-gui production $_temp /home/admin/config.scripts/cl.backup.sh cl-export-gui production $_temp
@ -186,13 +192,12 @@ case $CHOICE in
echo echo
echo "The rescue file is stored on the SDcard named cl-rescue.*.tar.gz just in case." echo "The rescue file is stored on the SDcard named cl-rescue.*.tar.gz just in case."
echo echo
echo "The next step will overwrite the old C-lighthning $CHAIN wallet" echo "The next step will overwrite the old Core Lightning $CHAIN wallet"
echo "Press ENTER to continue or CTRL+C to abort" echo "Press ENTER to continue or CTRL+C to abort"
read key read key
# reset
sudo rm /home/bitcoin/.lightning/${CLNETWORK}/hsm_secret resetWallet
sudo rm -f /home/bitcoin/.lightning/${CLNETWORK}/config
sudo rm -rf /home/bitcoin/.lightning/${CLNETWORK}/*.*
# import seed # import seed
_temp="/var/cache/raspiblitz/.temp.tmp" _temp="/var/cache/raspiblitz/.temp.tmp"
/home/admin/config.scripts/cl.backup.sh seed-import-gui $_temp /home/admin/config.scripts/cl.backup.sh seed-import-gui $_temp