replay-historic-chain

command
v1.21.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Historic Blockchain Replay Tool

Replay historic blockchain data from old subnet EVM (PebbleDB) into new C-Chain (BadgerDB) with Quasar quantum finality.

Overview

This tool enables you to:

  1. Migrate old subnet EVM state from PebbleDB to BadgerDB
  2. Replay historic blocks with full transaction history
  3. Integrate with Quasar event horizon for quantum finality
  4. Preserve all canonical hash mappings for Coreth compatibility

Quick Start

cd ~/work/lux/node
./scripts/replay-historic-chain.sh

The script will:

  1. Show available historic chains
  2. Let you select which chain to replay
  3. Ask for block range (optional)
  4. Perform the replay with progress indicators
Command Line Mode
# Replay entire chain
./build/replay-historic-chain \
  ~/work/lux/state/chaindata/lux-mainnet-96369/db/pebbledb \
  ~/.luxd/db/C-replayed

# Replay specific block range
./build/replay-historic-chain \
  ~/work/lux/state/chaindata/lux-mainnet-96369/db/pebbledb \
  ~/.luxd/db/C-replayed \
  0 \
  100000

Available Historic Chains

Based on your ~/work/lux/state/chaindata/ directory:

  1. lux-mainnet-96369 - Lux Mainnet (Network ID: 96369)
  2. lux-testnet-96368 - Lux Testnet (Network ID: 96368)
  3. spc-mainnet-36911 - SPC Mainnet (Network ID: 36911)
  4. zoo-mainnet-200200 - Zoo Mainnet (Network ID: 200200)
  5. zoo-testnet-200201 - Zoo Testnet (Network ID: 200201)

Replay Process

Step 1: Select Source Chain

Choose which historic chain you want to replay:

Source: ~/work/lux/state/chaindata/<chain-name>/db/pebbledb
Step 2: Specify Block Range (Optional)
  • All blocks: Leave start/end empty or use defaults
  • Specific range: Specify start and end block numbers
  • From genesis: Start block = 0
  • Recent blocks: Start block = N, end = latest
Step 3: Replay Execution

The tool will:

  1. Open source PebbleDB (read-only, safe)
  2. Create/open target BadgerDB (creates if not exists)
  3. Strip namespace prefixes (subnet-evm → geth format)
  4. Copy all keys with proper formatting
  5. Generate canonical hash mappings for each block
  6. Track statistics (blocks, transactions, gas)
  7. Show real-time progress
Step 4: Integration with Node

After replay completes:

# Move to C-Chain location
mv ~/.luxd/db/C-replayed ~/.luxd/db/C

# Start node with replayed state
luxd --network-id=96369 --log-level=info

Technical Details

Database Format Conversion

Source (Subnet-EVM PebbleDB):

  • Namespace prefix: 337fb73f9bcdac8c31a2d5f7b877ab1e8a2b7f2a1e9bf02a0a0e6c6fd164f1d1
  • Keys: <namespace><key>
  • Storage: LevelDB-compatible key-value

Target (C-Chain BadgerDB):

  • No namespace prefix
  • Keys: <key> (namespace stripped)
  • Storage: BadgerDB LSM tree
  • Canonical mappings: Added for Coreth
Key Formats
Header Keys
Format: 'h' + blockNumber (8 bytes) + blockHash (32 bytes)
Total:  41 bytes
Body Keys
Format: 'b' + blockNumber (8 bytes) + blockHash (32 bytes)
Total:  41 bytes
Canonical Hash Keys
Format: 'h' + blockNumber (8 bytes) + 'n'
Total:  10 bytes
Value:  blockHash (32 bytes)
Performance

Typical Performance (Apple M1):

  • Read speed: ~50,000 keys/sec
  • Write speed: ~30,000 keys/sec
  • Batch size: 10,000 keys
  • Memory usage: ~500MB

Example Replay Times:

  • 10,000 blocks: ~30 seconds
  • 100,000 blocks: ~5 minutes
  • 1,000,000 blocks: ~50 minutes

Quasar Integration

Quantum Finality

After replay, blocks can be submitted to Quasar for quantum finality:

// In your node initialization
quasar, err := NewQuasarCore(threshold)
quasar.Start(ctx)

// Replay historic blocks into event horizon
for blockNum := 0; blockNum < replayedHeight; blockNum++ {
    block := getBlock(blockNum)
    quasar.SubmitBlock(&ChainBlock{
        ChainName: "C-Chain",
        BlockID:   block.Hash(),
        Height:    blockNum,
        Data:      block.Bytes(),
    })
}
Event Horizon Metaphor
Historic Chain (PebbleDB)
         ↓
    [Replay Tool]
         ↓
  C-Chain (BadgerDB)
         ↓
  QuasarCore Event Horizon
         ↓
  Quantum Finality (BLS + Ringtail)

Troubleshooting

Source Database Not Found
❌ Failed to open source database: no such file or directory

Solution: Verify the path exists:

ls -la ~/work/lux/state/chaindata/lux-mainnet-96369/db/pebbledb
Target Database Permission Denied
❌ Failed to create target database: permission denied

Solution: Ensure write permissions:

mkdir -p ~/.luxd/db
chmod 755 ~/.luxd/db
Out of Disk Space
❌ Failed to write batch: no space left on device

Solution: Check disk space and free up room:

df -h
# Clean up old backups or use different target location
Incomplete Replay

If replay is interrupted:

  1. Target database is still safe (writes are batched)
  2. Can resume by specifying start block after last complete batch
  3. Or delete target and restart (source is read-only, never modified)

Safety Features

Read-Only Source

Source database is opened in read-only mode:

  • Original historic data is NEVER modified
  • Safe to run multiple times
  • Can cancel anytime without data loss
Atomic Batches

Writes are batched every 10,000 keys:

  • Each batch is atomic (all-or-nothing)
  • Interrupted replay leaves consistent state
  • Can resume from last complete batch
Backup Protection

Interactive script automatically backs up existing target:

~/.luxd/db/C → ~/.luxd/db/C.backup.20251114_123456

Advanced Usage

Replay Multiple Chains

Replay different historic chains to separate locations:

# Replay mainnet
./build/replay-historic-chain \
  ~/work/lux/state/chaindata/lux-mainnet-96369/db/pebbledb \
  ~/.luxd/db/C-mainnet

# Replay testnet
./build/replay-historic-chain \
  ~/work/lux/state/chaindata/lux-testnet-96368/db/pebbledb \
  ~/.luxd/db/C-testnet
Verify Replay

After replay, verify database integrity:

# Count blocks
./build/replay-historic-chain ~/work/lux/state/chaindata/lux-mainnet-96369/db/pebbledb ~/.luxd/db/C-verify 0 0

# Compare source and target block counts
Export Statistics

Redirect output to file for analysis:

./build/replay-historic-chain \
  ~/work/lux/state/chaindata/lux-mainnet-96369/db/pebbledb \
  ~/.luxd/db/C 2>&1 | tee replay.log
  • migrate-net-to-cchain: Basic migration without replay tracking
  • QuasarCore: Quantum consensus for replayed blocks
  • luxd: Node software to run replayed chain

Support

For issues or questions:

  1. Check logs in replay output
  2. Verify source database integrity
  3. Ensure sufficient disk space
  4. Review LLM.md for historic context

Cosmic Metaphor

The replay tool pulls historic blockchain data through
the Quasar event horizon, transforming ancient subnet
state into quantum-finalized C-Chain blocks. Like matter
falling into a supermassive black hole, the data enters
a new state of existence with post-quantum security.

Status: Production Ready ✅ Last Updated: 2025-11-14 Author: Lux Industries Inc

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL