# Fast Sync Optimization for BTCPay Server
**Date**: September 16, 2025

## Optimizations Applied

### Bitcoin Core Fast Sync
- **dbcache**: Increased from 1000MB to 2000MB for faster processing
- **assumevalid**: Added recent block hash to skip signature verification for known-good blocks
  - Hash: `00000000000000000002a23d6df20eecec15b21d32c75833cce28f113de888b7`
  - This significantly speeds up initial sync by skipping cryptographic verification

### Monero Fast Sync
- **fast-block-sync**: Enabled for faster block processing
- **block-sync-size**: Set to 20 blocks per batch
- **max-concurrency**: Increased from 2 to 4 threads
- **db-sync-mode**: Changed from `safe:sync` to `fast:async:250000000bytes`
  - `safe:sync` - Slowest but safest (original setting)
  - `fast:async` - Much faster, slight risk if power loss during sync
  - `fastest:async` - Maximum speed but highest risk (not recommended)

## Configuration File
Location: `/opt/btcpayserver-docker/docker-compose.override.yml`
```yaml
version: "3.6"

services:
  bitcoind:
    environment:
      BITCOIN_EXTRA_ARGS: |
        prune=10000
        maxmempool=300
        dbcache=2000
        maxconnections=40
        rpcthreads=6
        assumevalid=00000000000000000002a23d6df20eecec15b21d32c75833cce28f113de888b7

  monerod:
    environment:
      MONERO_EXTRA_ARGS: |
        --prune-blockchain
        --sync-pruned-blocks
        --fast-block-sync=1
        --block-sync-size=20
        --max-concurrency=4
        --db-sync-mode=fast:async:250000000bytes
```

## Expected Sync Times (With Optimizations)

### Before Optimizations
- Bitcoin: 24-36 hours
- Monero: 48-72 hours

### After Optimizations
- **Bitcoin**: 8-12 hours (from current 43% progress)
- **Monero**: 18-24 hours (from current 0.2% progress)

## Alternative Fast Sync Options

### 1. Bootstrap Files (Not Used)
- Download pre-synced blockchain data
- Pros: Very fast (2-4 hours)
- Cons: Trust required, large download (50GB+)

### 2. Remote Node (Not Used)
- Connect to existing synced node
- Pros: Instant availability
- Cons: Less privacy, dependency on external service

### 3. Checkpoint Sync (Partially Used)
- Bitcoin: `assumevalid` implemented
- Monero: Built-in checkpoints used automatically

## Monitoring Commands

### Check Sync Progress
```bash
# Bitcoin
sudo docker exec btcpayserver_bitcoind bitcoin-cli getblockchaininfo | grep -E "blocks|progress"

# Monero
sudo docker exec btcpayserver_monerod monerod status
```

### View Sync Speed
```bash
# Bitcoin (blocks per minute)
sudo docker logs btcpayserver_bitcoind --tail 100 | grep UpdateTip

# Monero (blocks per second)
sudo docker logs btcpayserver_monerod --tail 100 | grep Synced
```

## Safety Notes
- `fast:async` mode trades some safety for speed
- After sync completes, mode automatically becomes safer
- Power loss during sync may require resync of recent blocks
- Pruning remains active to limit disk usage

## Rollback if Needed
Backup saved at: `/opt/btcpayserver-docker/docker-compose.override.yml.backup-*`
```bash
sudo cp /opt/btcpayserver-docker/docker-compose.override.yml.backup-* /opt/btcpayserver-docker/docker-compose.override.yml
cd /opt/btcpayserver-docker
sudo docker-compose restart bitcoind monerod
```