#!/bin/sh # checkpoint.sh prints the chain-profile checkpoint for a fork height. # # The checkpoint is the last block the two chains share. Both chain profiles carry the same three # values, because below the fork there is only one chain: the light client starts verifying # above it instead of downloading Bitcoin's history a second time, and the wallet treats every # coin at or below it as Bitcoin on both chains. # # The filter header is the value getblockfilter returns as "header": the running commitment the # client continues from, not the hash of that one block's filter. # # usage: checkpoint.sh # env: BITCOIN_CLI (default: bitcoin-cli), DATADIR, RPCPORT, RPCUSER, RPCPASSWORD # # Example, on the regtest rig: # # DATADIR=$HOME/.blake-swap-test/btc scripts/checkpoint.sh 20000 # {"height":20000,"block_hash":"...","filter_header":"..."} # # Put that object under "checkpoint" in the profile JSON: the bridge and the channel both read # it from there, and -checkpoint-height/-checkpoint-hash/-checkpoint-filter-header override it. set -eu HEIGHT=${1:?usage: checkpoint.sh } CLI=${BITCOIN_CLI:-bitcoin-cli} if [ -z "${DATADIR:-}" ]; then echo "checkpoint: set DATADIR to the node's data directory" >&2 exit 2 fi ARGS="-datadir=$DATADIR" if [ -n "${RPCPORT:-}" ]; then ARGS="$ARGS -rpcport=$RPCPORT"; fi if [ -n "${RPCUSER:-}" ]; then ARGS="$ARGS -rpcuser=$RPCUSER"; fi if [ -n "${RPCPASSWORD:-}" ]; then ARGS="$ARGS -rpcpassword=$RPCPASSWORD"; fi HASH=$($CLI $ARGS getblockhash "$HEIGHT") FILTER=$($CLI $ARGS getblockfilter "$HASH") HEADER=$(printf '%s' "$FILTER" | sed -n 's/.*"header": *"\([0-9a-fA-F]*\)".*/\1/p') if [ -z "$HEADER" ]; then echo "checkpoint: the node returned no filter header for $HASH (is -blockfilterindex=1 set?)" >&2 exit 1 fi printf '{"height":%s,"block_hash":"%s","filter_header":"%s"}\n' "$HEIGHT" "$HASH" "$HEADER"