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 节点的各种方法。

同步方法概述

方法同步时间所需存储空间用例
修剪快照 (Pruned Snapshot)约10分钟< 5 GiB常规全节点
归档快照 (Archive Snapshot)约3小时约700 GB归档节点、区块浏览器

官方快照

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

快照信息

主网

类型压缩方式大小URL更新频率
修剪快照LZ4< 5 GiB下载每日
归档快照ZSTD约700 GB下载每周

测试网

类型压缩方式大小URL更新频率
修剪快照LZ4< 5 GiB下载每日
归档快照ZSTD约1.2 TB下载每周

使用修剪快照

修剪快照包含最近的区块链状态(最近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. 记录快照来源以便进行审计追踪

后续步骤