From 66f1a0e6d0dc2e317822757fb4b1de4c11168acd Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 24 Dec 2024 01:50:20 +0100 Subject: [PATCH] contrib: add script dump_to_sqlite.sh for direct SQLite3 UTXO dump --- contrib/README.md | 4 ++++ contrib/utxo-tools/dump_to_sqlite.sh | 32 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 contrib/utxo-tools/dump_to_sqlite.sh diff --git a/contrib/README.md b/contrib/README.md index 331d144b8da238..2745c7d79ded96 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -53,3 +53,7 @@ to a SQLite3 database. The coins are stored in a table with the following schema ``` CREATE TABLE utxos(txid TEXT, vout INT, value INT, coinbase INT, height INT, scriptpubkey TEXT) ``` + +### [Dump-to-SQLite](/contrib/utxo-tools/dump_to_sqlite.sh) ### +This script creates an UTXO set dump in SQLite3 format on the fly from a running bitcoind instance, +i.e. with the intermediate step of storing the compact-serialized UTXO set on disk is skipped. diff --git a/contrib/utxo-tools/dump_to_sqlite.sh b/contrib/utxo-tools/dump_to_sqlite.sh new file mode 100755 index 00000000000000..be66c2903244c0 --- /dev/null +++ b/contrib/utxo-tools/dump_to_sqlite.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Copyright (c) 2024 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C +set -e + +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +BITCOIN_CLI=$1 +OUTPUT_FILE=$2 +UTXO_TO_SQLITE=$(dirname "$0")/utxo_to_sqlite.py + +# create named pipe in unique temporary folder +TEMPPATH=$(mktemp -d) +FIFOPATH=$TEMPPATH/utxos.fifo +mkfifo "$FIFOPATH" + +# start dumping UTXO set to the pipe in background +$BITCOIN_CLI dumptxoutset "$FIFOPATH" latest & +BITCOIN_CLI_PID=$! + +# start UTXO to SQLite conversion tool, reading from pipe +$UTXO_TO_SQLITE "$FIFOPATH" "$OUTPUT_FILE" + +# wait and cleanup +wait $BITCOIN_CLI_PID +rm -r "$TEMPPATH"