Skip to content

Commit

Permalink
🌱 Add snapshot support
Browse files Browse the repository at this point in the history
  • Loading branch information
sameersubudhi committed Jul 19, 2024
1 parent 820f90c commit 254046e
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ GENESIS_FILE_PATH=mainnet/genesis.json
SEQUENCER_HTTP=https://rpc.api.lisk.com
RETH_CHAIN=lisk

APPLY_SNAPSHOT=false
SNAPSHOT_URL=http://snapshots.lisk.com/mainnet/geth-snapshot

# [optional] used to enable geth stats:
# OP_GETH_ETH_STATS=nodename:secret@host:port

Expand Down
3 changes: 3 additions & 0 deletions .env.sepolia
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ SEQUENCER_HTTP=https://rpc.sepolia-api.lisk.com
OP_NODE_OVERRIDE_CANYON=0
RETH_CHAIN=lisk-sepolia

APPLY_SNAPSHOT=false
SNAPSHOT_URL=http://snapshots.lisk.com/sepolia/geth-snapshot

# [optional] used to enable geth stats:
# OP_GETH_ETH_STATS=nodename:secret@host:port

Expand Down
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ For more information refer to the OP [documentation](https://docs.optimism.io/bu

#### Initialize op-geth

> **Important**: If you already had your node running prior to the Fjord upgrade (Mainnet: July 10, 2024 & Sepolia: May 29, 2024), please make sure to re-initialize your data directory with the updated genesis block. This is automatically taken care of for the Docker users.

Navigate to your `op-geth` directory and initialize the service by running the command:

```sh
Expand Down Expand Up @@ -268,9 +270,34 @@ Refer to the `op-node` configuration [documentation](https://docs.optimism.io/bu

## Snapshots

TBA
> **Note**: Currently, snapshots are only available for the `op-geth` client and are **NOT** regularly updated. We are currently working on improving this.

### Docker

To enable auto-snapshot download and application, please set the `APPLY_SNAPSHOT` environment variable to `true` when starting the node.
```sh
APPLY_SNAPSHOT=true docker compose up --build --detach
```

### Source

Please follow the steps below:

- Download the snapshot and the corresponding checksum from. The latest snapshot is always named `geth-snapshot`:
- Mainnet: https://snapshots.lisk.com/mainnet
- Sepolia: https://snapshots.lisk.com/sepolia

- Verify the integrity of the downloaded snapshot with:
```sh
sha256sum -c <checksum-file-name>
```

- Import the snapshot
```sh
./build/bin/geth import --datadir=$GETH_DATA_DIR <path-to-snapshot>
```

### Syncing
## Syncing

Sync speed depends on your L1 node, as the majority of the chain is derived from data submitted to the L1. You can check your syncing status using the `optimism_syncStatus` RPC on the `op-node` container. Example:

Expand Down
1 change: 1 addition & 0 deletions geth/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ COPY --from=op /app/op-node/bin/op-node ./
COPY --from=geth /app/build/bin/geth ./
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY geth/geth-entrypoint ./execution-entrypoint
COPY geth/download-apply-snapshot.sh .
COPY op-node-entrypoint .
COPY sepolia ./sepolia
COPY mainnet ./mainnet
Expand Down
63 changes: 63 additions & 0 deletions geth/download-apply-snapshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
set -eu

# Set alias for echoBanner if unavailable - for local testing
[[ $(type -t echoBanner) == function ]] || alias echoBanner=echo

# Translate APPLY_SNAPSHOT to uppercase; default to FALSE
APPLY_SNAPSHOT=$(echo "${APPLY_SNAPSHOT-false}" | tr "[:lower:]" "[:upper:]")

if [[ "$APPLY_SNAPSHOT" == "FALSE" ]]; then
echo "Automatic snapshot application disabled; to enable, set 'APPLY_SNAPSHOT=true' and restart"
exit 0
fi

if [[ "${SNAPSHOT_URL-x}" == x || -z $SNAPSHOT_URL ]]; then
echo "APPLY_SNAPSHOT enabled but SNAPSHOT_URL is undefined"
exit 1
fi

if [[ "${GETH_DATA_DIR-x}" == x ]]; then
echo "GETH_DATA_DIR is undefined"
exit 2
fi

SNAPSHOT_DIR=./snapshot
SNAPSHOT_FILENAME=$(basename ${SNAPSHOT_URL})
SNAPSHOT_SHA256_URL="${SNAPSHOT_URL}.SHA256"
SNAPSHOT_SHA256_FILENAME="${SNAPSHOT_FILENAME}.SHA256"

# Clear any existing snapshots
rm -rf $SNAPSHOT_DIR

# Download the snapshot & the checksum file
echoBanner "Downloading snapshot to '${SNAPSHOT_DIR}/$SNAPSHOT_FILENAME' from '${SNAPSHOT_URL}'..."
curl --create-dirs --output $SNAPSHOT_DIR/$SNAPSHOT_FILENAME --location $SNAPSHOT_URL
curl --create-dirs --output $SNAPSHOT_DIR/$SNAPSHOT_SHA256_FILENAME --location $SNAPSHOT_SHA256_URL

echoBanner "Verifying integrity of the downloaded snapshot..."
if command -v sha256sum &>/dev/null; then
(cd $SNAPSHOT_DIR && sha256sum --check $SNAPSHOT_SHA256_FILENAME &>/dev/null)
elif command -v shasum &>/dev/null; then
(cd $SNAPSHOT_DIR && shasum --algorithm 256 --check $SNAPSHOT_SHA256_FILENAME &>/dev/null)
else
echo "Neither sha256sum nor shasum available. Skipping..."
exit 9
fi

if [[ "$?" == "0" ]]; then
echo "Snapshot successfully downloaded and verified"
else
echo "Snapshot is corrupted. Skipping snapshot application..."
exit 10
fi

# Import snapshot
echoBanner "Importing snapshot..."
./geth import --datadir=$GETH_DATA_DIR $SNAPSHOT_DIR/$SNAPSHOT_FILENAME
if [[ "$?" == "0" ]]; then
echo "Snapshot successfully imported"
else
echo "Snapshot import failed. Skipping snapshot application..."
exit 11
fi
18 changes: 15 additions & 3 deletions geth/geth-entrypoint
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/bash
set -eu

echoBanner() {
echo -e "\n------------------------------------------------------------------------------------------------------------"
echo -e "$@"
echo -e "------------------------------------------------------------------------------------------------------------\n"
}

VERBOSITY=${GETH_VERBOSITY:-3}
GETH_DATA_DIR=/data
RPC_PORT="${RPC_PORT:-8545}"
Expand All @@ -21,6 +27,14 @@ OP_GETH_SYNCMODE="${OP_GETH_SYNCMODE:-full}"

mkdir -p $GETH_DATA_DIR

# Init genesis
echoBanner "Initializing data directory under '${GETH_DATA_DIR}'"
./geth init --datadir=$GETH_DATA_DIR "$GENESIS_FILE_PATH"

# Download and apply snapshot, when configured
(. download-apply-snapshot.sh)

# Set the start flags
echo "$OP_NODE_L2_ENGINE_AUTH_RAW" > "$OP_NODE_L2_ENGINE_AUTH"

if [ "${OP_GETH_ETH_STATS+x}" = x ]; then
Expand All @@ -47,10 +61,8 @@ if [ "${OP_NODE_OVERRIDE_CANYON+x}" = x ]; then
ADDITIONAL_ARGS="$ADDITIONAL_ARGS --override.canyon=$OP_NODE_OVERRIDE_CANYON"
fi

# Init genesis
./geth init --datadir=$GETH_DATA_DIR "$GENESIS_FILE_PATH"

# Start service
echoBanner "Starting node..."
./geth \
--datadir="$GETH_DATA_DIR" \
--verbosity="$VERBOSITY" \
Expand Down

0 comments on commit 254046e

Please sign in to comment.