From 7344993b22e6a8deff4d2eafaeda42582772a40b Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 5 Feb 2023 22:33:53 +0100 Subject: [PATCH] btc: add bitcoin core setup using the latest v24.0.1 the scripts are nearly identical to lnd/env. current nakamochi nodes are running bitcoind v23. so, this also upgrades to the latest. release notes are here: https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-24.0.1.md a notable change in v24 is the "full rbf". --- apply.sh | 5 ++++- btc/env | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 btc/env diff --git a/apply.sh b/apply.sh index 96c520d..2c3e4d3 100755 --- a/apply.sh +++ b/apply.sh @@ -7,11 +7,14 @@ exit_code=0 # base os ./base/voidlinux.sh || exit 1 +# bitcoin core +. ./btc/env +bitcoin_apply || exit_code=$? + # lnd lightning . ./lnd/env lnd_apply || exit_code=$? -# TODO: bitcoind # TODO: electrs # TODO: nd and ngui diff --git a/btc/env b/btc/env new file mode 100644 index 0000000..83fb6ba --- /dev/null +++ b/btc/env @@ -0,0 +1,59 @@ +BITCOIN_CORE_VERSION_DIR_AARCH64=bitcoin-24.0.1 +BITCOIN_CORE_URL_AARCH64=https://bitcoincore.org/bin/bitcoin-core-24.0.1/bitcoin-24.0.1-aarch64-linux-gnu.tar.gz +BITCOIN_CORE_SHA256_AARCH64=0b48b9e69b30037b41a1e6b78fb7cbcc48c7ad627908c99686e81f3802454609 + +BITCOIN_HOME=/home/bitcoind + +bitcoin_core_bin_install() { + cd $BITCOIN_HOME + local targz=$BITCOIN_CORE_VERSION_DIR_AARCH64.tar.gz + test -f $BITCOIN_CORE_VERSION_DIR_AARCH64/bin/bitcoind && return 0; + curl -sSL -o $targz "$BITCOIN_CORE_URL_AARCH64" + if [ $? -ne 0 ]; then + printf "ERROR: unable to download $BITCOIN_CORE_URL_AARCH64\n" 1>&2 + return 1 + fi + printf "$BITCOIN_CORE_SHA256_AARCH64 $targz" | sha256sum --check + [ $? -ne 0 ] && return 1 + tar -C $BITCOIN_HOME --no-same-owner -xf $targz + rm -f $targz + return $? +} + +bitcoind_svc_install() { + local svdir=/etc/sv/bitcoind + mkdir -p $svdir + cat < $svdir/run.new +#!/bin/sh +exec chpst -u bitcoind $BITCOIN_HOME/$BITCOIN_CORE_VERSION_DIR_AARCH64/bin/bitcoind -conf=$BITCOIN_HOME/mainnet.conf 2>&1 +EOF + chmod +x $svdir/run.new + test -f $svdir/run && diff $svdir/run $svdir/run.new + if [ $? -ne 0 ]; then + mv $svdir/run.new $svdir/run + # don't touch the actual service if on manual control - the down file + test -f $svdir/down && return 0 + sv -w 600 stop bitcoind || printf "ERROR: sv stop bitcoind failed\n" 1>&2 + sv start bitcoind || printf "ERROR: sv start bitcoind failed\n" 1>&2 + fi + rm -f $svdir/run.new +} + +bitcoin_cli_install() { + mkdir -p /opt/bin + cat < /opt/bin/bitcoin-cli.sh +#!/bin/sh +set -eu +CLI=$BITCOIN_HOME/$BITCOIN_CORE_VERSION_DIR_AARCH64/bin/bitcoin-cli +DATA=/ssd/bitcoind/mainnet +CHAIN=main +exec doas -u bitcoind \$CLI -datadir=\$DATA -chain=\$CHAIN "\$@" +EOF + chmod +x /opt/bin/bitcoin-cli.sh +} + +bitcoin_apply() { + bitcoin_core_bin_install || return 1 + bitcoind_svc_install || return 1 + bitcoin_cli_install || return 1 +}