Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add balances restore to the portal loop #3220

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions misc/loop/cmd/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
18 changes: 18 additions & 0 deletions misc/loop/scripts/pull-gh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
3 changes: 3 additions & 0 deletions misc/loop/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading