Skip to content

Instantly share code, notes, and snippets.

@exd02
Last active March 10, 2026 17:55
Show Gist options
  • Select an option

  • Save exd02/06b3f9455f9b4c66ab228a9550ecba29 to your computer and use it in GitHub Desktop.

Select an option

Save exd02/06b3f9455f9b4c66ab228a9550ecba29 to your computer and use it in GitHub Desktop.
This script is intended to run periodically via a systemd timer (e.g., once per week) to generate updated Bitcoin UTXO hints.
#!/usr/bin/env bash
set -euo pipefail
umask 022
BITCOINCLI="$HOME/dev/bitcoin/build/bin/bitcoin-cli"
HINT_DIR="$HOME/hints"
NEW_HINT_DIR="$HOME/hints_new"
echo "=== $(date) starting generatetxohints ==="
# 1) Check RPC and extract blockchain info
BLOCKCHAININFO_OUTPUT=$("$BITCOINCLI" getblockchaininfo 2>&1) || {
echo "ERROR: bitcoind not reachable via RPC" >&2
exit 1
}
CHAIN_NAME=$(echo "$BLOCKCHAININFO_OUTPUT" | grep '"chain"' | sed 's/.*"chain": *"\([^"]*\)".*/\1/')
BLOCK_HEIGHT=$(echo "$BLOCKCHAININFO_OUTPUT" | grep '"blocks"' | sed 's/.*"blocks": *\([0-9]*\).*/\1/')
BEST_BLOCK_HASH=$(echo "$BLOCKCHAININFO_OUTPUT" | grep '"bestblockhash"' | sed 's/.*"bestblockhash": *"\([^"]*\)".*/\1/')
HASH_SUFFIX="${BEST_BLOCK_HASH: -8}"
FINAL_HINT="$NEW_HINT_DIR/${CHAIN_NAME}_${BLOCK_HEIGHT}_${HASH_SUFFIX}.hints"
VERSIONED_HINT_GZ="$HINT_DIR/${CHAIN_NAME}_${BLOCK_HEIGHT}_${HASH_SUFFIX}.hints.gz"
LATEST_HINT_GZ="$HINT_DIR/${CHAIN_NAME}.hints.gz"
echo "Chain: $CHAIN_NAME | Block: $BLOCK_HEIGHT | Hash suffix: $HASH_SUFFIX"
# 2) Ensure new hints directory exists
rm -rf "$NEW_HINT_DIR"
mkdir -p "$NEW_HINT_DIR"
chmod 755 "$NEW_HINT_DIR"
echo "Cleaned up $NEW_HINT_DIR"
# 3) Generate hints in hints_new directory
if "$BITCOINCLI" --rpcclienttimeout=0 generatetxohints "$FINAL_HINT"; then
echo "Generation finished successfully"
# 4) Ensure hints directory exists
mkdir -p "$HINT_DIR"
chmod 755 "$HINT_DIR"
# 5) Create versioned copy
gzip -c "$FINAL_HINT" > "$VERSIONED_HINT_GZ"
chmod 644 "$VERSIONED_HINT_GZ"
echo "Created versioned hints: $VERSIONED_HINT_GZ"
# 6) Replace latest copy
rm -f "$LATEST_HINT_GZ"
cp "$VERSIONED_HINT_GZ" "$LATEST_HINT_GZ"
chmod 644 "$LATEST_HINT_GZ"
echo "Updated latest hints: $LATEST_HINT_GZ"
else
echo "ERROR: Hints generation failed" >&2
exit 1
fi
echo "=== $(date) finished ==="
@exd02
Copy link
Author

exd02 commented Mar 9, 2026

To create the services:
bitcoin-hints.service:

[Unit]
Description=Generate Bitcoin Hintsfile
After=bitcoind.service

[Service]
Type=oneshot
User=bitcoin
ExecStart=/home/bitcoin/scripts/generate_hints.sh
TimeoutStartSec=800min

StandardOutput=journal
StandardError=journal

bitcoin-hints.timer:

[Unit]
Description=Bitcoin Hintsfile Generator Timer
[Timer]
OnCalendar=Sat 20:00
Persistent=true
[Install]
WantedBy=timers.target

For the web server, you can use miniserve, rob hints-server or directly run it in nginx.

@Davidson-Souza
Copy link

Just sanity-checking my assumptions: I need to run an unpruned fork of bitcoin core (link plz?) to get those, right?

@exd02
Copy link
Author

exd02 commented Mar 9, 2026

Just sanity-checking my assumptions: I need to run an unpruned fork of bitcoin core (link plz?) to get those, right?

Yes. Currently you need a fullnode to generate the hintsfile.
You need to build the core from here. (updated to most recent hintsfile generation)

@rustaceanrob
Copy link

This is my most recent fork for hintsfile generation. Is this what you meant to link?

@exd02
Copy link
Author

exd02 commented Mar 9, 2026

This is my most recent fork for hintsfile generation. Is this what you meant to link?

@rustaceanrob Currently I'm generating the hintsfile from the SwiftSync PR. I assumed Floresta was still using that hintsfile format for experiments, so I linked that one.

Do you think I should generate the hintsfile using the newer version you linked instead?

@rustaceanrob
Copy link

Oh I see, certainly do what is best for Floresta, I was just making sure you had the most up to date branch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment