# Files Copy Checklist

Complete checklist of all files that need to be copied during deployment.

## Source Project Location
**Default**: `/home/intlc/projects/smom-dbis-138`

---

## Required Files for Besu Deployment

### 1. Genesis File (ALL Besu Nodes)
- **Source**: `config/genesis.json`
- **Destination**: `/etc/besu/genesis.json`
- **Copied to**: All Besu nodes (validators, sentries, RPC)
- **Status**: ⚠️ **REQUIRED** - Deployment will fail if missing

### 2. Permissions Files (ALL Besu Nodes)

#### permissions-nodes.toml
- **Source**: `config/permissions-nodes.toml`
- **Destination**: `/etc/besu/permissions-nodes.toml`
- **Copied to**: All Besu nodes
- **Status**: ⚠️ **REQUIRED** - Required for node allowlisting

#### permissions-accounts.toml
- **Source**: `config/permissions-accounts.toml`
- **Destination**: `/etc/besu/permissions-accounts.toml`
- **Copied to**: All Besu nodes (if exists)
- **Status**: ⚠️ **OPTIONAL** - Required if account permissioning is enabled

### 3. Static Nodes File (ALL Besu Nodes)
- **Source**: `config/static-nodes.json` (generated during bootstrap)
- **Destination**: `/etc/besu/static-nodes.json`
- **Copied to**: All Besu nodes
- **Status**: ⚠️ **GENERATED** - Created/updated by bootstrap script

---

## Node-Specific Configuration Files

### Validators (VMID 1000-1004)

**File Detection Order**:
1. `config/nodes/validator-1/config.toml` (if `config/nodes/` structure exists)
2. `config/nodes/validator-1/config-validator.toml` (if `config/nodes/` structure exists)
3. `config/config-validator.toml` (flat structure fallback)

**Destination**: `/etc/besu/config-validator.toml`

**Node Mapping**:
- VMID 1000 → validator-1
- VMID 1001 → validator-2
- VMID 1002 → validator-3
- VMID 1003 → validator-4
- VMID 1004 → validator-5

### Sentries (VMID 1500-1503)

**File Detection Order**:
1. `config/nodes/sentry-1/config.toml` (if `config/nodes/` structure exists)
2. `config/nodes/sentry-1/config-sentry.toml` (if `config/nodes/` structure exists)
3. `config/config-sentry.toml` (flat structure fallback)
4. `config/config-member.toml` (backwards compatibility)

**Destination**: `/etc/besu/config-sentry.toml`

**Node Mapping**:
- VMID 1500 → sentry-1
- VMID 1501 → sentry-2
- VMID 1502 → sentry-3
- VMID 1503 → sentry-4

### RPC Nodes (VMID 2500-2502) - Type-Specific

**Each RPC node uses a different config file type:**

#### VMID 2500: Core RPC
**File Detection Order**:
1. `config/nodes/rpc-1/config.toml` (if `config/nodes/` structure exists)
2. `config/nodes/rpc-1/config-rpc-core.toml` (if `config/nodes/` structure exists)
3. `config/config-rpc-core.toml` (flat structure fallback)

**Destination**: `/etc/besu/config-rpc-core.toml`

#### VMID 2501: Permissioned RPC
**File Detection Order**:
1. `config/nodes/rpc-2/config.toml` (if `config/nodes/` structure exists)
2. `config/nodes/rpc-2/config-rpc-perm.toml` (if `config/nodes/` structure exists)
3. `config/config-rpc-perm.toml` (flat structure fallback)

**Destination**: `/etc/besu/config-rpc-perm.toml`

#### VMID 2502: Public RPC
**File Detection Order**:
1. `config/nodes/rpc-3/config.toml` (if `config/nodes/` structure exists)
2. `config/nodes/rpc-3/config-rpc-public.toml` (if `config/nodes/` structure exists)
3. `config/config-rpc-public.toml` (flat structure fallback)

**Destination**: `/etc/besu/config-rpc-public.toml`

**Node Mapping**:
- VMID 2500 → rpc-1 (Core RPC)
- VMID 2501 → rpc-2 (Permissioned RPC)
- VMID 2502 → rpc-3 (Public RPC)

---

## Node Keys (if using config/nodes/ structure)

### Node Keys
- **Source**: `config/nodes/<node-name>/nodekey`
- **Destination**: `/data/besu/nodekey`
- **Copied to**: Node-specific (each node gets its own)
- **Status**: ⚠️ **OPTIONAL** - Only if using node-specific directories

**Example**:
- `config/nodes/validator-1/nodekey` → VMID 1000: `/data/besu/nodekey`
- `config/nodes/sentry-1/nodekey` → VMID 1500: `/data/besu/nodekey`

---

## Validator Keys (VALIDATORS ONLY - VMID 1000-1004)

### Validator Key Directories
- **Source**: `keys/validators/validator-*/`
- **Destination**: `/keys/validators/validator-*/`
- **Copied to**: Validator nodes only
- **Status**: ⚠️ **REQUIRED** - Validators will not function without keys

### Required Files Per Validator
Each `keys/validators/validator-N/` directory must contain:
- `key` - Private key (CRITICAL - keep secure!)
- `key.pub` - Public key
- `address` - Account address

### Validator Key Mapping
- `keys/validators/validator-1/` → VMID 1000
- `keys/validators/validator-2/` → VMID 1001
- `keys/validators/validator-3/` → VMID 1002
- `keys/validators/validator-4/` → VMID 1003
- `keys/validators/validator-5/` → VMID 1004

---

## Complete File Structure Reference

```
../smom-dbis-138/
├── config/
│   ├── genesis.json                    ⚠️ REQUIRED - All nodes
│   ├── permissions-nodes.toml          ⚠️ REQUIRED - All nodes
│   ├── permissions-accounts.toml       ⚠️ OPTIONAL - All nodes (if account permissioning)
│   ├── static-nodes.json               ⚠️ GENERATED - Created by bootstrap script
│   │
│   ├── config-validator.toml           ⚠️ FALLBACK - Validators (if no nodes/ structure)
│   ├── config-sentry.toml              ⚠️ FALLBACK - Sentries (if no nodes/ structure)
│   ├── config-rpc-public.toml          ⚠️ FALLBACK - RPC (if no nodes/ structure)
│   │
│   └── nodes/                          ⚠️ OPTIONAL - Node-specific configs
│       ├── validator-1/
│       │   ├── config.toml             # Preferred over flat structure
│       │   └── nodekey                 # Optional node identification key
│       ├── validator-2/
│       ├── ...
│       ├── sentry-1/
│       │   ├── config.toml
│       │   └── nodekey
│       ├── sentry-2/
│       ├── ...
│       ├── rpc-1/
│       │   ├── config.toml
│       │   └── nodekey
│       └── ...
│
└── keys/
    └── validators/
        ├── validator-1/                ⚠️ REQUIRED - VMID 1000
        │   ├── key                     # Private key (CRITICAL)
        │   ├── key.pub                 # Public key
        │   └── address                 # Account address
        ├── validator-2/                ⚠️ REQUIRED - VMID 1001
        ├── validator-3/                ⚠️ REQUIRED - VMID 1002
        ├── validator-4/                ⚠️ REQUIRED - VMID 1003
        └── validator-5/                ⚠️ REQUIRED - VMID 1004
```

---

## Pre-Deployment Verification

Run this checklist before deployment:

```bash
SOURCE_PROJECT="/home/intlc/projects/smom-dbis-138"

# Check required files
echo "=== Required Files ==="
[ -f "$SOURCE_PROJECT/config/genesis.json" ] && echo "✓ genesis.json" || echo "✗ genesis.json MISSING"
[ -f "$SOURCE_PROJECT/config/permissions-nodes.toml" ] && echo "✓ permissions-nodes.toml" || echo "✗ permissions-nodes.toml MISSING"

# Check validator keys
echo ""
echo "=== Validator Keys ==="
for i in 1 2 3 4 5; do
    if [ -d "$SOURCE_PROJECT/keys/validators/validator-$i" ]; then
        [ -f "$SOURCE_PROJECT/keys/validators/validator-$i/key" ] && echo "✓ validator-$i/key" || echo "✗ validator-$i/key MISSING"
        [ -f "$SOURCE_PROJECT/keys/validators/validator-$i/key.pub" ] && echo "✓ validator-$i/key.pub" || echo "✗ validator-$i/key.pub MISSING"
        [ -f "$SOURCE_PROJECT/keys/validators/validator-$i/address" ] && echo "✓ validator-$i/address" || echo "✗ validator-$i/address MISSING"
    else
        echo "✗ validator-$i/ directory MISSING"
    fi
done

# Check config files (flat structure)
echo ""
echo "=== Config Files (Flat Structure) ==="
[ -f "$SOURCE_PROJECT/config/config-validator.toml" ] && echo "✓ config-validator.toml" || echo "⚠ config-validator.toml (optional if nodes/ structure exists)"
[ -f "$SOURCE_PROJECT/config/config-sentry.toml" ] && echo "✓ config-sentry.toml" || echo "⚠ config-sentry.toml (optional if nodes/ structure exists)"
[ -f "$SOURCE_PROJECT/config/config-rpc-public.toml" ] && echo "✓ config-rpc-public.toml" || echo "⚠ config-rpc-public.toml (optional if nodes/ structure exists)"

# Check config/nodes/ structure (if exists)
echo ""
echo "=== Node-Specific Configs (Optional) ==="
if [ -d "$SOURCE_PROJECT/config/nodes" ]; then
    echo "✓ config/nodes/ structure exists"
    find "$SOURCE_PROJECT/config/nodes" -name "config.toml" | while read f; do
        echo "  ✓ $(basename $(dirname $f))/config.toml"
    done
else
    echo "⚠ config/nodes/ not found (will use flat structure)"
fi
```

---

## Copy Script Reference

**Primary Script**: `scripts/copy-besu-config-with-nodes.sh`

**Usage**:
```bash
cd /home/intlc/projects/proxmox
./smom-dbis-138-proxmox/scripts/copy-besu-config-with-nodes.sh /home/intlc/projects/smom-dbis-138
```

**Features**:
- ✅ Detects `config/nodes/` structure automatically
- ✅ Falls back to flat structure if needed
- ✅ Copies node-specific configs when available
- ✅ Copies validator keys to validators only
- ✅ Sets proper ownership (besu:besu)

---

## Troubleshooting

### Missing genesis.json
**Error**: `genesis.json not found`

**Solution**: Ensure `config/genesis.json` exists in source project

### Missing Validator Keys
**Error**: `Validator keys directory not found`

**Solution**: Verify `keys/validators/validator-*/` directories exist with required files

### Config File Not Found
**Warning**: `No config file found for validator/sentry/rpc`

**Solution**: Ensure either:
1. `config/nodes/<node-name>/config.toml` exists, OR
2. Flat structure file exists (`config/config-validator.toml`, etc.)

