Skip to content

Commit

Permalink
chore: add balances restore to the portal loop (gnolang#3220)
Browse files Browse the repository at this point in the history
## Description

This PR allows for a balances restore for the portal loop.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
</details>
  • Loading branch information
zivkovicmilos authored and r3v4s committed Dec 10, 2024
1 parent 83b28d4 commit aaf6858
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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

0 comments on commit aaf6858

Please sign in to comment.