Skip to content

Commit 6df8c0b

Browse files
authored
chore: example for a snapshot node (#89)
* chore: example for a snapshot node * chore: add README, update cli * chore: put latest version * chore: update docs
1 parent 4367a68 commit 6df8c0b

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-0
lines changed

snapshots-node/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
env
2+
gnoland-data/*

snapshots-node/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Snapshots node
2+
3+
## How it's works
4+
5+
1. Setup the environment variables and setup the variables for the [minio-client](https://min.io) with your S3 credentials
6+
7+
``` sh
8+
cp env.example env
9+
```
10+
11+
2. Start the node
12+
13+
By default, a snapshots will occur every 4 hours, and will upload it to S3
14+
15+
``` sh
16+
docker compose up -d
17+
```
18+
19+
## How to force a snapshot now
20+
21+
``` sh
22+
docker compose exec snapshotter sh /scripts/snapshots.sh
23+
```
24+
25+
## TO-DOs
26+
27+
[ ] Prune the node before uploading the snapshots

snapshots-node/docker-compose.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "gnoland-snapshot-node"
2+
3+
services:
4+
gnoland:
5+
image: "ghcr.io/gnolang/gno/gnoland:chain-test4.3"
6+
entrypoint: ["/scripts/entrypoint.gnoland.sh"]
7+
ports:
8+
- 127.0.0.1:26657:26657
9+
volumes:
10+
- ./scripts:/scripts
11+
- ./gnoland-data:/gnoroot/gnoland-data
12+
13+
snapshotter:
14+
image: "docker:27.2.0-cli-alpine3.20"
15+
entrypoint: ["sh", "/scripts/entrypoint.snapshotter.sh"]
16+
env_file: "env"
17+
environment:
18+
CHAIN_ID: "test4"
19+
volumes:
20+
- "/var/run/docker.sock:/var/run/docker.sock:ro"
21+
- "./scripts:/scripts"
22+
- "./docker-compose.yml:/docker-compose.yml"
23+
- "./env:/env"
24+
- "./gnoland-data:/gnoroot/gnoland-data:ro"

snapshots-node/env.example

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
MC_ENDPOINT=""
3+
MC_ACCESS_KEY=""
4+
MC_SECRET_KEY=""
5+
MC_BUCKET=""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env sh
2+
3+
LOG_LEVEL=${LOG_LEVEL:-"info"}
4+
5+
MONIKER=${MONIKER:-"gnode"}
6+
P2P_LADDR=${P2P_LADDR:-"tcp://0.0.0.0:26656"}
7+
RPC_LADDR=${RPC_LADDR:-"tcp://0.0.0.0:26657"}
8+
9+
CHAIN_ID=${CHAIN_ID:-"dev"}
10+
11+
gnoland config init
12+
13+
gnoland config set rpc.laddr "${RPC_LADDR}"
14+
gnoland config set p2p.laddr "${P2P_LADDR}"
15+
16+
exec gnoland start --lazy --genesis="./gnoland-data/genesis.json" --log-level=${LOG_LEVEL}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env sh
2+
3+
apk add --no-cache curl jq lz4 minio-client
4+
5+
export DAEMON_HOME="/gnoroot/gnoland-data"
6+
7+
[ -z "$MC_ENDPOINT" ] && echo "MC_ENDPOINT is not set, skip snapshot" && exit 1
8+
[ -z "$MC_ACCESS_KEY" ] && echo "MC_ACCESS_KEY is not set, skip snapshot" && exit 1
9+
[ -z "$MC_SECRET_KEY" ] && echo "MC_SECRET_KEY is not set, skip snapshot" && exit 1
10+
11+
mcli alias set s3 ${MC_ENDPOINT} ${MC_ACCESS_KEY} ${MC_SECRET_KEY}
12+
13+
# exec snapshots script every 4 hours
14+
echo "0 */4 * * * sh /scripts/snapshots.sh" > /etc/crontabs/root
15+
crontab /etc/crontabs/root
16+
17+
exec crond -f

snapshots-node/scripts/snapshots.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env sh
2+
3+
DAEMON_HOME="/gnoroot/gnoland-data"
4+
5+
HEIGHT=$(curl -s gnoland:26657/status | jq -r '.result.sync_info.latest_block_height')
6+
echo "[INFO] Snapshotting at height: ${HEIGHT}"
7+
8+
echo "[INFO] Stopping gnoland..."
9+
docker compose stop gnoland
10+
11+
FILE="gnoland-${HEIGHT}-${CHAIN_ID}.tar.lz4"
12+
13+
tar cvf - -C ${DAEMON_HOME} wal db | lz4 > $FILE
14+
15+
mcli cp --attr x-amz-acl=public-read --tags="type=snapshot" ${FILE} "s3/${MC_BUCKET}/${CHAIN_ID}/${FILE}"; echo
16+
17+
rm -vf ${FILE}
18+
19+
echo "[INFO] Starting gnoland ..."
20+
docker compose start gnoland

0 commit comments

Comments
 (0)