From c1997837aff540e10c0f05d9861415ac1144ebc6 Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Sat, 18 Mar 2023 11:02:03 -0400 Subject: [PATCH] Initial support for seeding zfs blocks/chainstate. --- create_lxc_base.sh | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/create_lxc_base.sh b/create_lxc_base.sh index 570b8e6..f482879 100755 --- a/create_lxc_base.sh +++ b/create_lxc_base.sh @@ -27,11 +27,11 @@ else # TODO move this sovereign-stack-base construction VM to separate dedicated IP lxc config set "$BASE_IMAGE_VM_NAME" - # for CHAIN in mainnet testnet; do - # for DATA in blocks chainstate; do - # lxc storage volume attach ss-base "$CHAIN-$DATA" "$BASE_IMAGE_VM_NAME" "/home/ubuntu/$CHAIN/$DATA" - # done - # done + for CHAIN in mainnet testnet; do + for DATA in blocks chainstate; do + lxc storage volume attach ss-base "$CHAIN-$DATA" "$BASE_IMAGE_VM_NAME" "/home/ubuntu/.ss/cache/bitcoin/$CHAIN/$DATA" + done + done lxc start "$BASE_IMAGE_VM_NAME" @@ -43,14 +43,23 @@ else # ensure the ssh service is listening at localhost lxc exec "$BASE_IMAGE_VM_NAME" -- wait-for-it -t 100 127.0.0.1:22 - sleep 3 - - - # for CHAIN in testnet mainnet; do - # for DATA in blocks chainstate; do - # lxc file push --recursive --project=default "/home/ubuntu/.ss/cache/bitcoin/$CHAIN/$DATA/" "$BASE_IMAGE_VM_NAME/home/ubuntu/$CHAIN/$DATA/" - # done - # done + # If we have any chaninstate or blocks in our SSME, let's push them to the + # remote host as a zfs volume that way deployments can share a common history + # of chainstate/blocks. + for CHAIN in testnet mainnet; do + for DATA in blocks chainstate; do + DATA_PATH="/home/ubuntu/.ss/cache/bitcoin/$CHAIN/$DATA" + if [ -d "$DATA_PATH" ]; then + COMPLETE_FILE_PATH="$DATA_PATH/complete" + if lxc exec "$BASE_IMAGE_VM_NAME" -- [ ! -f "$COMPLETE_FILE_PATH" ]; then + lxc file push --recursive --project=default "$DATA_PATH/" "$BASE_IMAGE_VM_NAME/home/ubuntu/.ss/cache/bitcoin/$CHAIN/$DATA/" + lxc exec "$BASE_IMAGE_VM_NAME" -- su ubuntu - bash -c "echo $(date) > $COMPLETE_FILE_PATH" + else + echo "INFO: it appears as though $CHAIN/$DATA has already been initialized. Continuing." + fi + fi + done + done # stop the VM and get a snapshot. lxc stop "$BASE_IMAGE_VM_NAME" @@ -63,3 +72,10 @@ lxc publish --public "$BASE_IMAGE_VM_NAME/$UBUNTU_BASE_IMAGE_NAME" --project=def echo "INFO: Success! We can now delete the base image." lxc delete -f "$BASE_IMAGE_VM_NAME" + +# now let's get a snapshot of each of the blocks/chainstate directories. +for CHAIN in testnet mainnet; do + for DATA in blocks chainstate; do + lxc storage volume snapshot ss-base --project=default "$CHAIN-$DATA" + done +done