From 0516aa5971733be3674dcb3f9f04c27953f40a6a Mon Sep 17 00:00:00 2001 From: /rootzoll Date: Sun, 9 Jun 2024 22:24:02 +0200 Subject: [PATCH] #2552 adding electrum sync progress to infoscreen (#4603) * #2552 getting the synced blockheight with nc * feat: Add blockheight information to electrs status command * add info in CHANGES --- CHANGES.md | 1 + home.admin/00infoBlitz.sh | 6 ++- home.admin/config.scripts/bonus.electrs.sh | 43 +++++++++++++--------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ffb37f74a..1c3bedcd3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ - Update: Specter Desktop 2.0.4 with reactivated UPDATE option [details](https://github.com/cryptoadvance/specter-desktop/releases/tag/v2.0.4) - Update: BTCPayServer 1.13.0 [details](https://github.com/btcpayserver/btcpayserver/releases/tag/v1.13.0) - Update: acme.sh 3.0.7 (repair duckdns.org dyndns) +- Update: show progress of electrs building index on LCD - Update: lndmanage 0.16.0 [details](https://github.com/bitromortac/lndmanage) - Experimental: charge-lnd install script [details](https://github.com/raspiblitz/raspiblitz/discussions/3955) - Experimental: config.scripts/lnd.signaddress.sh to easy sign messages on addresses on LND [details](https://github.com/raspiblitz/raspiblitz/issues/4540) diff --git a/home.admin/00infoBlitz.sh b/home.admin/00infoBlitz.sh index d7cd1e1c7..c12e5e18f 100755 --- a/home.admin/00infoBlitz.sh +++ b/home.admin/00infoBlitz.sh @@ -355,7 +355,8 @@ else appInfoLine="" # Electrum Server - electrs - if [ "${ElectRS}" == "on" ]; then + fileFlagExists=$(sudo ls /mnt/hdd/app-storage/electrs/initial-sync.done 2>/dev/null | grep -c 'initial-sync.done') + if [ "${ElectRS}" == "on" ] && [ $fileFlagExists -eq 0 ]; then error="" source <(sudo /home/admin/config.scripts/bonus.electrs.sh status-sync 2>/dev/null) if [ ${#infoSync} -gt 0 ]; then @@ -364,7 +365,8 @@ else fi # Electrum Server - fulcrum - if [ "${fulcrum}" == "on" ]; then + fileFlagExists=$(sudo ls /mnt/hdd/app-storage/fulcrum/initial-sync.done 2>/dev/null | grep -c 'initial-sync.done') + if [ "${fulcrum}" == "on" ] && [ $fileFlagExists -eq 0 ]; then error="" source <(sudo /home/admin/config.scripts/bonus.fulcrum.sh status-sync 2>/dev/null) if [ ${#infoSync} -gt 0 ]; then diff --git a/home.admin/config.scripts/bonus.electrs.sh b/home.admin/config.scripts/bonus.electrs.sh index 1bca344fc..2fb54ae83 100755 --- a/home.admin/config.scripts/bonus.electrs.sh +++ b/home.admin/config.scripts/bonus.electrs.sh @@ -105,22 +105,6 @@ if [ "$1" = "status-sync" ]; then echo "serviceRunning=${serviceRunning}" if [ ${serviceRunning} -eq 1 ]; then - # Experimental try to get sync Info (electrs debug info would need more details) - #source <(/home/admin/_cache.sh get btc_mainnet_blocks_headers) - #blockchainHeight="${btc_mainnet_blocks_headers}" - #lastBlockchainHeight=$(($blockchainHeight -1)) - #syncedToBlock=$(sudo journalctl -u electrs --no-pager -n2000 | grep "height=" | tail -n1| cut -d= -f3) - #syncProgress=0 - #if [ "${syncedToBlock}" != "" ] && [ "${blockchainHeight}" != "" ] && [ "${blockchainHeight}" != "0" ]; then - # syncProgress="$(echo "$syncedToBlock" "$blockchainHeight" | awk '{printf "%.2f", $1 / $2 * 100}')" - #fi - #echo "syncProgress=${syncProgress}%" - #if [ "${syncedToBlock}" = "${blockchainHeight}" ] || [ "${syncedToBlock}" = "${lastBlockchainHeight}" ]; then - # echo "tipSynced=1" - #else - # echo "tipSynced=0" - #fi - # check if initial sync was done, by setting a file as once electrs is the first time responding on port 50001 electrumResponding=$(echo '{"jsonrpc":"2.0","method":"server.ping","params":[],"id":"electrs-check"}' | netcat -w 2 127.0.0.1 50001 | grep -c "result") if [ ${electrumResponding} -gt 1 ]; then @@ -128,6 +112,27 @@ if [ "$1" = "status-sync" ]; then fi echo "electrumResponding=${electrumResponding}" + blockheight=0 + blockheightPercent=0 + if [ ${electrumResponding} -eq 0 ]; then + + # get the synced blockheight + syncedBlock=$(echo '{"id": 1, "method": "blockchain.headers.subscribe", "params": []}' | nc -w 20 -q 1 localhost 50001 | jq '.result.height') + if [ "$syncedBlock" -eq "$syncedBlock" ] 2>/dev/null; then + blockheight=${syncedBlock} + + # calculate the progress + source <(/home/admin/_cache.sh get btc_mainnet_blocks_verified) + if [ "$btc_mainnet_blocks_verified" -eq "$btc_mainnet_blocks_verified" ] 2>/dev/null; then + blockheightPercent=$(echo "scale=2; $syncedBlock / $btc_mainnet_blocks_verified * 100" | bc) + blockheightPercent=$(printf "%.0f\n" $blockheightPercent) + fi + + fi + fi + echo "blockheight='${blockheight}'" + echo "blockheightPercent='${blockheightPercent}'" + fileFlagExists=$(sudo ls /mnt/hdd/app-storage/electrs/initial-sync.done 2>/dev/null | grep -c 'initial-sync.done') if [ ${fileFlagExists} -eq 0 ] && [ ${electrumResponding} -gt 0 ]; then # set file flag for the future @@ -137,7 +142,11 @@ if [ "$1" = "status-sync" ]; then fi if [ ${fileFlagExists} -eq 0 ]; then echo "initialSynced=0" - echo "infoSync='Building Index (please wait)'" + if [ "${blockheightPercent}" != "0" ]; then + echo "infoSync='Building Index ${blockheightPercent}% (please wait)'" + else + echo "infoSync='Building Index (please wait)'" + fi else echo "initialSynced=1" fi