From 16b0a92cb443e10146fc733ecbbcf2d852f78286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20=C5=BDivkovi=C4=87?= Date: Wed, 27 Nov 2024 21:14:30 +0900 Subject: [PATCH] Add balances restore --- misc/loop/cmd/snapshotter.go | 1 + misc/loop/scripts/pull-gh.sh | 18 ++++++++++++++++++ misc/loop/scripts/start.sh | 3 +++ 3 files changed, 22 insertions(+) diff --git a/misc/loop/cmd/snapshotter.go b/misc/loop/cmd/snapshotter.go index 2dda5d568d9..0173f9aad03 100644 --- a/misc/loop/cmd/snapshotter.go +++ b/misc/loop/cmd/snapshotter.go @@ -150,6 +150,7 @@ func (s snapshotter) startPortalLoopContainer(ctx context.Context) (*types.Conta Env: []string{ "MONIKER=the-portal-loop", "GENESIS_BACKUP_FILE=/backups/backup.jsonl", + "GENESIS_BALANCES_FILE=/backups/balances.jsonl", }, Entrypoint: []string{"/scripts/start.sh"}, ExposedPorts: nat.PortSet{ diff --git a/misc/loop/scripts/pull-gh.sh b/misc/loop/scripts/pull-gh.sh index efbb360d551..55ee0f7762c 100755 --- a/misc/loop/scripts/pull-gh.sh +++ b/misc/loop/scripts/pull-gh.sh @@ -6,6 +6,10 @@ TMP_DIR=temp-tx-exports # that the portal loop use when looping (generating the genesis) MASTER_BACKUP_FILE="backup.jsonl" +# The master balances file will contain the ultimate balances +# backup that the portal loop uses when looping (generating the genesis) +MASTER_BALANCES_FILE="balances.jsonl" + # Clones the portal loop backups subdirectory, located in BACKUPS_REPO (tx-exports) pullGHBackups () { BACKUPS_REPO=https://github.com/gnolang/tx-exports.git @@ -32,8 +36,10 @@ pullGHBackups # Combine the pulled backups into a single backup file TXS_BACKUPS_PREFIX="backup_portal_loop_txs_" +BALANCES_BACKUP_NAME="backup_portal_loop_balances.jsonl" find . -type f -name "${TXS_BACKUPS_PREFIX}*.jsonl" | sort | xargs cat > "temp_$MASTER_BACKUP_FILE" +find . -type f -name "${BALANCES_BACKUP_NAME}" | sort | xargs cat > "temp_$MASTER_BALANCES_FILE" BACKUPS_DIR="../backups" TIMESTAMP=$(date +%s) @@ -47,10 +53,22 @@ if [ -e "$BACKUPS_DIR/$MASTER_BACKUP_FILE" ]; then echo "Renamed $MASTER_BACKUP_FILE to ${MASTER_BACKUP_FILE}-legacy-$TIMESTAMP" fi +# Check if the master balances backup file already exists +if [ -e "$BACKUPS_DIR/$MASTER_BALANCES_FILE" ]; then + # Back up the existing master txs file + echo "Master balances backup file exists, backing up..." + mv "$BACKUPS_DIR/$MASTER_BALANCES_FILE" "$BACKUPS_DIR/${MASTER_BALANCES_FILE}-legacy-$TIMESTAMP" + + echo "Renamed $MASTER_BALANCES_FILE to ${MASTER_BALANCES_FILE}-legacy-$TIMESTAMP" +fi + # Use the GitHub state as the canonical backup mv "temp_$MASTER_BACKUP_FILE" "$BACKUPS_DIR/$MASTER_BACKUP_FILE" echo "Moved temp_$MASTER_BACKUP_FILE to $BACKUPS_DIR/$MASTER_BACKUP_FILE" +mv "temp_$MASTER_BALANCES_FILE" "$BACKUPS_DIR/$MASTER_BALANCES_FILE" +echo "Moved temp_$MASTER_BALANCES_FILE to $BACKUPS_DIR/$MASTER_BALANCES_FILE" + # Clean up the temporary directory cd .. rm -rf $TMP_DIR diff --git a/misc/loop/scripts/start.sh b/misc/loop/scripts/start.sh index 6dd57b2c041..db36de39f2a 100755 --- a/misc/loop/scripts/start.sh +++ b/misc/loop/scripts/start.sh @@ -7,12 +7,15 @@ RPC_LADDR=${RPC_LADDR:-"tcp://0.0.0.0:26657"} CHAIN_ID=${CHAIN_ID:-"portal-loop"} GENESIS_BACKUP_FILE=${GENESIS_BACKUP_FILE:-""} +GENESIS_BALANCES_FILE=${GENESIS_BALANCES_FILE:-""} SEEDS=${SEEDS:-""} PERSISTENT_PEERS=${PERSISTENT_PEERS:-""} echo "" >> /gnoroot/gno.land/genesis/genesis_txs.jsonl +echo "" >> /gnoroot/gno.land/genesis/genesis_balances.jsonl cat "${GENESIS_BACKUP_FILE}" >> /gnoroot/gno.land/genesis/genesis_txs.jsonl +cat "${GENESIS_BALANCES_FILE}" >> /gnoroot/gno.land/genesis/genesis_balances.jsonl # Initialize the secrets gnoland secrets init