Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

本指南介绍了使用快照和状态同步快速同步 Stable 节点的各种方法。

同步方法概览

方法同步时间所需存储使用场景
裁剪快照~10 分钟< 5 GiB常规全节点
归档快照~1 小时~500 GB归档节点、区块浏览器

官方快照

Stable 提供每日更新的官方快照(00:00 UTC)。

快照信息

主网

类型压缩格式大小URL更新频率
裁剪LZ4< 5 GiB下载每日
归档ZSTD~300 GB下载每周

测试网

类型压缩格式大小URL更新频率
裁剪LZ4< 5 GiB下载每日
归档ZSTD~800 GB下载每周

使用裁剪快照

裁剪快照包含最近的区块链状态(最后 100-1000 个区块)。

第 1 步:设置环境变量

# Set service name (default: stable)
export SERVICE_NAME=stable

第 2 步:停止节点服务

# Stop the running node
sudo systemctl stop ${SERVICE_NAME}
 
# Verify it's stopped
sudo systemctl status ${SERVICE_NAME}

第 3 步:备份当前数据(可选)

# Create backup directory
mkdir -p ~/stable-backup
 
# Backup current state (optional, requires significant space)
cp -r ~/.stabled/data ~/stable-backup/

第 4 步:下载并解压裁剪快照

Mainnet
# Install dependencies
sudo apt install -y wget zstd pv
 
# Create snapshot directory
mkdir -p ~/snapshot
cd ~/snapshot
 
# Download pruned snapshot with progress
wget -c https://stable-data-dist.s3.us-east-1.amazonaws.com/mainnet/snapshots/snapshot.tar.lz4
 
# Remove old data
rm -rf ~/.stabled/data/*
 
# Extract snapshot with progress indicator
pv stable_pruned.tar.zst | zstd -d -c | tar -xf - -C ~/.stabled/
 
# Alternative extraction without pv
zstd -d stable_pruned.tar.zst -c | tar -xvf - -C ~/.stabled/
 
# Clean up
rm stable_pruned.tar.zst

第 5 步:重启节点

# Start the node
sudo systemctl start ${SERVICE_NAME}
 
# Check status
sudo systemctl status ${SERVICE_NAME}
 
# Monitor logs
sudo journalctl -u stabled -f

使用归档快照

归档快照包含完整的区块链历史。

第 1 步:准备系统

# Stop node
sudo systemctl stop ${SERVICE_NAME}
 
# Install dependencies
sudo apt install -y wget zstd pv
 
# Check available disk space (need 2x snapshot size)
df -h ~/.stabled

第 2 步:下载并解压归档快照

Mainnet
# Create working directory
mkdir -p ~/snapshot
cd ~/snapshot
 
# Download archive snapshot
wget -c https://stable-data-dist.s3.us-east-1.amazonaws.com/mainnet/snapshots/stable_archive.tar.zst
 
# Clear old data
rm -rf ~/.stabled/data/*
 
# Extract with high memory for better performance
pv stable_archive.tar.zst | zstd -d --long=31 --memory=2048MB -c - | tar -xf - -C ~/.stabled/
 
# Alternative: Standard extraction
zstd -d --long=31 stable_archive.tar.zst -c | tar -xvf - -C ~/.stabled/
 
# Clean up
rm stable_archive.tar.zst

第 3 步:启动节点

# Start service
sudo systemctl start ${SERVICE_NAME}
 
# Verify sync status
curl -s localhost:26657/status | jq '.result.sync_info'

创建你自己的快照

手动创建快照

# Stop node
sudo systemctl stop ${SERVICE_NAME}
 
# Create snapshot archive
cd ~/.stabled
tar -cf - data/ | lz4 -9 > ~/stable-snapshot-$(date +%Y%m%d).tar.lz4
 
# Create checksum
sha256sum ~/stable-snapshot-*.tar.lz4 > checksums.txt
 
# Restart node
sudo systemctl start ${SERVICE_NAME}

自动化快照脚本

#!/bin/bash
# snapshot.sh - Automated snapshot creation
 
# Configuration
SNAPSHOT_DIR="/var/snapshots"
STABLED_HOME="$HOME/.stabled"
KEEP_DAYS=7
 
# Create snapshot directory
mkdir -p $SNAPSHOT_DIR
 
# Stop node
sudo systemctl stop ${SERVICE_NAME}
 
# Create snapshot
SNAPSHOT_NAME="stable-snapshot-$(date +%Y%m%d-%H%M%S).tar.lz4"
tar -cf - -C $STABLED_HOME data/ | lz4 -9 > $SNAPSHOT_DIR/$SNAPSHOT_NAME
 
# Generate metadata
cat > $SNAPSHOT_DIR/latest.json <<EOF
{
  "filename": "$SNAPSHOT_NAME",
  "height": "$(cat $STABLED_HOME/data/cs.wal/wal | grep height | tail -1 | awk '{print $2}' | tr -d ',')",
  "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
  "size": "$(du -h $SNAPSHOT_DIR/$SNAPSHOT_NAME | awk '{print $1}')",
  "checksum": "$(sha256sum $SNAPSHOT_DIR/$SNAPSHOT_NAME | awk '{print $1}')"
}
EOF
 
# Clean old snapshots
find $SNAPSHOT_DIR -name "stable-snapshot-*.tar.lz4" -mtime +$KEEP_DAYS -delete
 
# Restart node
sudo systemctl start ${SERVICE_NAME}
 
echo "Snapshot created: $SNAPSHOT_DIR/$SNAPSHOT_NAME"

调度自动化快照

# Add to crontab (weekly on Sunday at 2 AM)
(crontab -l ; echo "0 2 * * 0 /usr/local/bin/snapshot.sh") | crontab -

验证与故障排查

验证快照完整性

# Check snapshot checksum
sha256sum -c checksums.txt
 
# Verify extraction
tar -I lz4 -tvf snapshot.tar.lz4 | head -20
 
# Test snapshot size
tar -I lz4 -tvf snapshot.tar.lz4 | wc -l

常见问题

问题:快照解压失败

# Check disk space
df -h
 
# Verify file integrity
lz4 -t snapshot.tar.lz4
 
# Try alternative extraction
lz4 -d snapshot.tar.lz4 snapshot.tar
tar -xvf snapshot.tar -C ~/.stabled/

问题:快照后节点无法启动

# Check permissions
ls -la ~/.stabled/data/
 
# Fix permissions
sudo chown -R $USER:$USER ~/.stabled/
 
# Verify genesis file
sha256sum ~/.stabled/config/genesis.json
 
# Reset and try again
stabled comet unsafe-reset-all
# Then restore snapshot

问题:状态同步失败

# Try different RPC servers
# Update config.toml with alternative RPCs
 
# Increase chunk fetchers
sed -i 's/chunk_fetchers = .*/chunk_fetchers = 8/' ~/.stabled/config/config.toml
 
# Clear and retry
stabled comet unsafe-reset-all --keep-addr-book

性能优化

下载优化

# Use aria2 for parallel downloads
aria2c -x 16 -s 16 https://stable-data-dist.s3.us-east-1.amazonaws.com/testnet/snapshots/snapshot.tar.lz4
 
# Use wget with compression
wget --header="Accept-Encoding: gzip" -c URL
 
# Resume interrupted downloads
curl -C - -o snapshot.tar.lz4 URL

解压优化

# Use parallel extraction
pigz -d -c snapshot.tar.gz | tar -xf - -C ~/.stabled/
 
# Monitor extraction progress
pv snapshot.tar.lz4 | tar -I lz4 -xf - -C ~/.stabled/
 
# Use more memory for zstd
zstd -d --long=31 --memory=4096MB archive.tar.zst

最佳实践

  1. 在替换数据之前始终备份验证者密钥
  2. 在解压快照之前验证校验和
  3. 在解压期间监控磁盘空间(需要 2 倍快照大小)
  4. 尽可能使用官方快照
  5. 先在非生产环境中测试快照
  6. 为你的归档节点调度定期快照
  7. 记录快照来源以便审计追踪

后续步骤