# SMOM-DBIS-138 Proxmox Deployment Guide

Complete guide for deploying the SMOM-DBIS-138 blockchain network on Proxmox VE using LXC containers.

## Table of Contents

1. [Prerequisites](#prerequisites)
2. [Initial Setup](#initial-setup)
3. [Configuration](#configuration)
4. [Deployment](#deployment)
5. [Post-Deployment](#post-deployment)
6. [Maintenance](#maintenance)
7. [Troubleshooting](#troubleshooting)

## Prerequisites

### Hardware Requirements

- **Proxmox VE**: Version 7.0 or later
- **CPU**: Minimum 16 cores (recommended 32+)
- **RAM**: Minimum 64GB (recommended 128GB+)
- **Storage**: Minimum 500GB SSD (recommended 1TB+ NVMe)
- **Network**: 1Gbps+ connection

### Software Requirements

- Proxmox VE installed and configured
- Access to Proxmox host (root or sudo)
- Network connectivity for downloading packages
- Sufficient storage in Proxmox storage pools

## Initial Setup

### 1. Prepare Proxmox Host

```bash
# On Proxmox host
# Update system
apt update && apt upgrade -y

# Install required packages
apt install -y curl wget jq git

# Ensure LXC is enabled
systemctl status lxc
```

### 2. Copy Deployment Package

Copy the `smom-dbis-138-proxmox` directory to your Proxmox host:

```bash
# Option 1: Clone/copy to Proxmox host
scp -r smom-dbis-138-proxmox root@proxmox-host:/opt/

# Option 2: Git clone (if in repository)
cd /opt
git clone <repository-url> smom-dbis-138-proxmox
```

### 3. Install OS Template

Download Debian 12 template:

```bash
# On Proxmox host
pveam download local debian-12-standard_12.2-1_amd64.tar.zst
```

## Configuration

### 1. Configure Proxmox Connection

```bash
cd /opt/smom-dbis-138-proxmox
cp config/proxmox.conf.example config/proxmox.conf
nano config/proxmox.conf
```

Update with your Proxmox details:
- `PROXMOX_HOST`: Your Proxmox hostname or IP
- `PROXMOX_USER`: Usually `root@pam`
- `PROXMOX_TOKEN_NAME` and `PROXMOX_TOKEN_SECRET`: Create API token in Proxmox UI
- `PROXMOX_NODE`: Your Proxmox node name (usually `pve`)
- `PROXMOX_STORAGE`: Storage pool name

### 2. Configure Network

```bash
cp config/network.conf.example config/network.conf
nano config/network.conf
```

Update network settings:
- `SUBNET_BASE`: Base subnet (e.g., `10.3.1`)
- `GATEWAY`: Gateway IP
- `VLAN_*`: VLAN tags for each node type

### 3. Adjust Resource Allocations (Optional)

Edit `config/proxmox.conf` to adjust resources:
- `VALIDATOR_MEMORY`, `VALIDATOR_CORES`, `VALIDATOR_DISK`
- `SENTRY_MEMORY`, `SENTRY_CORES`, `SENTRY_DISK`
- `RPC_MEMORY`, `RPC_CORES`, `RPC_DISK`

## Deployment

### Full Deployment

Deploy everything (Besu nodes, services, monitoring):

```bash
cd /opt/smom-dbis-138-proxmox
./scripts/deployment/deploy-all.sh
```

### Step-by-Step Deployment

#### 1. Deploy Besu Nodes

```bash
./scripts/deployment/deploy-besu-nodes.sh
```

This creates:
- Validator containers (default: 4)
- Sentry containers (default: 3)
- RPC containers (default: 3)

#### 2. Copy Configuration Files

After containers are created, copy configuration files from the original project:

```bash
# From smom-dbis-138 project
SOURCE_PROJECT="/path/to/smom-dbis-138"

# Copy genesis.json to all containers
for vmid in 1000 1001 1002 1003 1004 1500 1501 1502 1503 2500 2501 2502; do
    pct push $vmid "$SOURCE_PROJECT/config/genesis.json" /etc/besu/genesis.json
    pct push $vmid "$SOURCE_PROJECT/config/permissions-nodes.toml" /etc/besu/permissions-nodes.toml
    pct push $vmid "$SOURCE_PROJECT/config/permissions-accounts.toml" /etc/besu/permissions-accounts.toml
done
```

#### 3. Copy Validator Keys

```bash
# Copy validator keys to validator containers only
for vmid in 1000 1001 1002 1003 1004; do
    pct push $vmid "$SOURCE_PROJECT/keys/validators/*" /keys/validators/
    pct exec $vmid -- chown -R besu:besu /keys
done
```

#### 4. Update Static Nodes

```bash
# Generate and update static-nodes.json
./scripts/network/update-static-nodes.sh
```

#### 5. Start Services

```bash
# Start all Besu services
for vmid in 1000 1001 1002 1003 1004 1500 1501 1502 1503 2500 2501 2502; do
    pct exec $vmid -- systemctl start besu-validator.service 2>/dev/null || \
    pct exec $vmid -- systemctl start besu-sentry.service 2>/dev/null || \
    pct exec $vmid -- systemctl start besu-rpc.service 2>/dev/null
done
```

#### 6. Verify Deployment

```bash
# Check container status
pct list

# Check service status
for vmid in 1000 1001 1002 1003 1004 1500 1501 1502 1503 2500 2501 2502; do
    echo "Container $vmid:"
    pct exec $vmid -- systemctl status besu-validator.service 2>/dev/null || \
    pct exec $vmid -- systemctl status besu-sentry.service 2>/dev/null || \
    pct exec $vmid -- systemctl status besu-rpc.service 2>/dev/null
done

# Check metrics endpoint
curl http://10.3.1.40:9545/metrics
```

## Post-Deployment

### 1. Verify Network Connectivity

```bash
# Test P2P connectivity between nodes
pct exec 1000 -- ping -c 3 192.168.11.101  # validator to validator
pct exec 1500 -- ping -c 3 192.168.11.151  # sentry to sentry
```

### 2. Check Blockchain Sync

```bash
# Check block height from RPC node
curl -X POST http://10.3.1.40:8545 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
```

### 3. Monitor Logs

```bash
# View Besu logs
pct exec 1000 -- journalctl -u besu-validator -f
```

## Maintenance

### Upgrade Nodes

Upgrade all nodes to a new Besu version:

```bash
./scripts/upgrade/upgrade-all.sh 24.1.0
```

Upgrade a single node:

```bash
./scripts/upgrade/upgrade-node.sh 1000 24.1.0
```

### Backup

Create backup of all containers:

```bash
./scripts/backup/backup-all.sh
```

Backups are stored in `/var/lib/vz/backup/smom-dbis-138/`

### Restore

Restore from snapshot:

```bash
# List snapshots
pct listsnapshot 1000

# Restore snapshot
pct rollback 1000 <snapshot-name>
```

## Troubleshooting

### Container Won't Start

```bash
# Check container status
pct status 1000

# View container console
pct console 1000

# Check systemd services
pct exec 1000 -- systemctl status besu-validator
```

### Network Issues

```bash
# Check network configuration
pct config 1000

# Test connectivity
pct exec 1000 -- ping -c 3 8.8.8.8
```

### Service Won't Start

```bash
# Check logs
pct exec 1000 -- journalctl -u besu-validator -n 50

# Check configuration
pct exec 1000 -- cat /etc/besu/config-validator.toml

# Verify files exist
pct exec 1000 -- ls -la /etc/besu/
```

### Out of Disk Space

```bash
# Check disk usage
pct exec 1000 -- df -h

# Clean up old logs
pct exec 1000 -- journalctl --vacuum-time=7d
```

## Additional Resources

- [Proxmox VE Documentation](https://pve.proxmox.com/pve-docs/)
- [Hyperledger Besu Documentation](https://besu.hyperledger.org/)
- [Main Project README](/docs/01-getting-started/README.md)

