Last active
June 12, 2021 16:44
-
-
Save mutatrum/264cfa84af5fc3dc0b107bcb3ba10893 to your computer and use it in GitHub Desktop.
Print a taproot signalling block diagram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BLOCKCHAININFO=$(bitcoin-cli getblockchaininfo) | |
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks) | |
TAPROOT=$(echo "$BLOCKCHAININFO" | jq .softforks.taproot.bip9) | |
SINCE=$(echo "$TAPROOT" | jq .since) | |
PERIOD=$(echo "$TAPROOT" | jq .statistics.period) | |
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks) | |
PERIOD_COUNT=$(((BLOCKS - SINCE) / PERIOD)) | |
SINCE=$((SINCE + (PERIOD * PERIOD_COUNT))) | |
ELAPSED=$(echo "$TAPROOT" | jq .statistics.elapsed) | |
for BLOCK in $(seq "$SINCE" $((SINCE + ELAPSED - 1))); do | |
HASH=$(bitcoin-cli getblockhash "$BLOCK") | |
HEADER=$(bitcoin-cli getblockheader "$HASH") | |
VERSION=$(echo "$HEADER" | jq .version) | |
SIGNAL=$(((VERSION & 3758096388) == 536870916)) | |
case $SIGNAL in | |
(1) echo -n "π©";; | |
(0) echo -n "π₯";; | |
esac | |
if ((($BLOCK + 1) % 48 == 0)); then echo; fi | |
done | |
echo | |
PERCENTAGE=`echo $BLOCKCHAININFO | jq '.softforks.taproot.bip9.statistics | .count / .elapsed * 100'` | |
echo $PERCENTAGE |
$SINCE
refers to the first period, so you need something slightly more complicated to deal with subsequent periods.
bitcoin/bitcoin#22016 to the rescue:
#!/bin/bash
BLOCKCHAININFO=$(bitcoin-cli getblockchaininfo)
TAPROOT=$(echo "$BLOCKCHAININFO" | jq .softforks.taproot.bip9)
PERIOD_START=$(echo "$TAPROOT" | jq .statistics.period_start)
ELAPSED=$(echo "$TAPROOT" | jq .statistics.elapsed)
for BLOCK in $(seq "$PERIOD_START" $((PERIOD_START + ELAPSED - 1))); do
HASH=$(bitcoin-cli getblockhash "$BLOCK")
HEADER=$(bitcoin-cli getblockheader "$HASH")
VERSION=$(echo "$HEADER" | jq .version)
SIGNAL=$(((VERSION & 3758096388) == 536870916))
case $SIGNAL in
(1) echo -n "π©";;
(0) echo -n "π₯";;
esac
done
The version at the top was updated with the slightly more complicated stuff. But having that field in the API is really nice, it surprised my a bit after the first difficulty period.
Also for testnet you need something like seq -f "%.10g"
to prevent it from messing up the block numbers.
This version uses the new (proposed) period_start
fields and adds testnet support (./taproot.sh -testnet
)
#!/bin/bash
NETWORK=$1
BLOCKCHAININFO=$(bitcoin-cli $NETWORK getblockchaininfo)
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks)
TAPROOT=$(echo "$BLOCKCHAININFO" | jq .softforks.taproot.bip9)
PERIOD=$(echo "$TAPROOT" | jq .statistics.period)
PERIOD_START=$(echo "$TAPROOT" | jq .statistics.period_start)
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks)
ELAPSED=$(echo "$TAPROOT" | jq .statistics.elapsed)
for BLOCK in $(seq -f "%.10g" "$PERIOD_START" $((PERIOD_START + ELAPSED - 1))); do
HASH=$(bitcoin-cli $NETWORK getblockhash "$BLOCK")
HEADER=$(bitcoin-cli $NETWORK getblockheader "$HASH")
VERSION=$(echo "$HEADER" | jq .version)
SIGNAL=$(((VERSION & 3758096388) == 536870916))
case $SIGNAL in
(1) echo -n "π©";;
(0) echo -n "π₯";;
esac
if ((($BLOCK + 1) % 48 == 0)); then echo; fi
done
echo
PERCENTAGE=`echo $BLOCKCHAININFO | jq '.softforks.taproot.bip9.statistics | .count / .elapsed * 100'`
echo $PERCENTAGE
Infinite version
#!/bin/bash
BLOCKCHAININFO=$(bitcoin-cli getblockchaininfo)
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks)
TAPROOT=$(echo "$BLOCKCHAININFO" | jq .softforks.taproot.bip9)
SINCE=$(echo "$TAPROOT" | jq .since)
PERIOD=$(echo "$TAPROOT" | jq .statistics.period)
BLOCKS=$(echo "$BLOCKCHAININFO" | jq .blocks)
PERIOD_COUNT=$(((BLOCKS - SINCE) / PERIOD))
START=$((SINCE + (PERIOD * PERIOD_COUNT)))
ELAPSED=$(echo "$TAPROOT" | jq .statistics.elapsed)
COUNT=0
for BLOCK in $(seq "$SINCE" $((START + ELAPSED - 1))); do
HASH=$(bitcoin-cli getblockhash "$BLOCK")
HEADER=$(bitcoin-cli getblockheader "$HASH")
VERSION=$(echo "$HEADER" | jq .version)
SIGNAL=$(((VERSION & 3758096388) == 536870916))
case $SIGNAL in
(1) echo -n "π§"
((COUNT++))
;;
(0) echo -n "π¦"
;;
esac
if (( ($BLOCK + 1) % 56 == 0 )); then echo " "; COUNT=0; fi
done
echo " $COUNT"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice going! I ran the script through https://www.shellcheck.net/ - it's a linter that finds potentially problematic code.
It didn't find anything aweful, just:
...
. - https://github.com/koalaman/shellcheck/wiki/SC2006Here's the linted version: