Skip to content

Latest commit

 

History

History
429 lines (328 loc) · 11.3 KB

File metadata and controls

429 lines (328 loc) · 11.3 KB

Deployment Plan - Crypto Processing Services

Generated: 2026-04-22 17:14:45+02:00 Environment: Mainnet (Bitcoin, Litecoin, Solana) Status: Ready for deployment


Overview

This document outlines the deployment process for the Crypto Processing Services on mainnet with real funds. The system includes RPC caching to respect free tier rate limits (5 req/min).

Architecture Summary

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   Frontend   │     │     API     │     │   Backend   │
│   (VueJS)    │◄───►│   (Go)      │◄───►│  (Go)       │
└─────────────┘     └─────────────┘     └─────────────┘
                           │                   │
                           ▼                   ▼
                    ┌─────────────┐     ┌─────────────┐
                    │ PostgreSQL  │     │  Blockchains │
                    └─────────────┘     │  (BTC,LTC,SOL)
                                        └─────────────┘
                                               │
                                        ┌─────────────┐
                                        │ RPC Cache    │
                                        │ (15s gap)    │
                                        └─────────────┘

Prerequisites

Infrastructure

  • VPS with Docker and Docker Compose installed
  • PostgreSQL 14+ (or use managed service)
  • Domain name with DNS configured
  • Cloudflare account (for tunnel)

Wallet Requirements

  • BTC wallet with mnemonic seed (for payment address derivation)
  • LTC wallet with mnemonic seed (for payment address derivation)
  • SOL wallet with mnemonic seed (for payment address derivation)
  • Each wallet should have limited funds (hot wallet principle)

RPC Configuration

  • Tatum.io free tier accounts (or preferred RPC providers)
  • RPC endpoints configured for mainnet

Environment Variables

Required Variables

# Database
DATABASE_URL=postgresql://user:password@host:5432/crypto_services

# Bitcoin (BTC)
BTC_RPC_URL=https://bitcoin-mainnet.gateway.tatum.io
BTC_RPC_USER=
BTC_RPC_PASS=
BTC_WALLET_ADDRESS=bc1q...        # Mainnet address for wallet

# Litecoin (LTC)
LTC_RPC_URL=https://litecoin-mainnet.gateway.tatum.io
LTC_RPC_USER=
LTC_RPC_PASS=
LTC_WALLET_ADDRESS=ltc1q...      # Mainnet address for wallet

# Solana (SOL)
SOL_RPC_URL=https://solana-mainnet.gateway.tatum.io
SOL_WALLET_ADDRESS=SolanaAddress  # Base58 encoded address

# Fiat API (for conversions)
FIAT_API_URL=https://api.coingecko.com/api/v3

# Logging
LOG_LEVEL=INFO

Optional Variables

# Rate Limiting (defaults shown)
API_RATE_LIMIT=100              # requests per minute per IP
API_RATE_WINDOW=60               # window in seconds

# RPC Cache (defaults shown)
RPC_MIN_GAP=15                  # seconds between RPC calls
TX_CACHE_TTL=60                  # transaction cache TTL
CONF_CACHE_TTL=30                # confirmation cache TTL

Pre-Deployment Checklist

Security

  • All environment variables stored securely (not in git)
  • wallets.keys file encrypted at rest
  • Database password strong and unique
  • Cloudflare tunnel properly secured
  • No exposed API keys in code

Functional

  • RPC endpoints tested and responsive
  • Database migrations ready
  • Wallets funded with small test amounts
  • Callback URLs accessible (for testing)

Monitoring

  • Logging configured (JSON structured)
  • Log rotation configured
  • Disk space monitoring enabled

Deployment Steps

1. Server Setup

# SSH to your VPS
ssh user@your-server

# Install Docker if not present
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Install Docker Compose
sudo apt-get install docker-compose

# Create application directory
mkdir -p /opt/crypto-services
cd /opt/crypto-services

2. Environment Configuration

# Create .env file
cat > .env << 'EOF'
DATABASE_URL=postgresql://crypto_user:secure_password@db:5432/crypto_services
BTC_RPC_URL=https://bitcoin-mainnet.gateway.tatum.io
BTC_RPC_USER=
BTC_RPC_PASS=
BTC_WALLET_ADDRESS=bc1q...your-btc-address
LTC_RPC_URL=https://litecoin-mainnet.gateway.tatum.io
LTC_RPC_USER=
LTC_RPC_PASS=
LTC_WALLET_ADDRESS=ltc1q...your-ltc-address
SOL_RPC_URL=https://solana-mainnet.gateway.tatum.io
SOL_WALLET_ADDRESS=your-sol-address
FIAT_API_URL=https://api.coingecko.com/api/v3
LOG_LEVEL=INFO
EOF

# Secure the file
chmod 600 .env

3. Wallet Configuration

# Create wallets.keys (encrypted mnemonic storage)
cat > wallets.keys << 'EOF'
btc_mnemonic=your-24-word-btc-mnemonic
ltc_mnemonic=your-24-word-ltc-mnemonic
sol_mnemonic=your-24-word-sol-mnemonic
EOF

# Encrypt if needed (optional but recommended)
# gpg --symmetric wallets.keys
chmod 600 wallets.keys

4. Database Setup

# Create PostgreSQL container
cat > docker-compose.yml << 'EOF'
version: '3.8'

services:
  api:
    build: ./api
    ports:
      - "8080:8080"
    env_file:
      - .env
    depends_on:
      - db
    restart: unless-stopped

  backend:
    build: ./backend
    env_file:
      - .env
    depends_on:
      - db
    restart: unless-stopped

  frontend:
    build: ./frontend
    ports:
      - "3000:80"
    depends_on:
      - api
    restart: unless-stopped

  db:
    image: postgres:14-alpine
    environment:
      POSTGRES_USER: crypto_user
      POSTGRES_PASSWORD: secure_password
      POSTGRES_DB: crypto_services
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: unless-stopped

volumes:
  pgdata:
EOF

5. Application Configuration

# Create cmd/api/main.go and cmd/backend/main.go environment loading
# Ensure they read from .env file

6. Docker Build and Start

# Build images
docker-compose build

# Run database migrations
docker-compose run --rm api ./migrate

# Start services
docker-compose up -d

# Check status
docker-compose ps

# View logs
docker-compose logs -f api
docker-compose logs -f backend

7. Cloudflare Tunnel Setup

# Install cloudflared
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o cloudflared
chmod +x cloudflared

# Create tunnel
./cloudflared tunnel create crypto-services

# Configure tunnel
./cloudflared tunnel run --name crypto-services --url http://localhost:8080

# Or use docker network mode
docker run cloudflare/cloudflared tunnel run --name crypto-services crypto-services

RPC Cache Configuration

How It Works

Request → Cache Check → [Gap < 15s?]
              │
              ├─ Yes (gap not elapsed) → Return error "rate limit: must wait X seconds"
              │
              └─ No (gap elapsed) → Fetch from RPC → Store in cache → Return result

Cache Behavior by Operation

Operation Cache Key TTL Gap
GetTransactions txs_{address} 60s 15s
GetConfirmations conf_{txHash} 30s 15s
SendTransaction Invalidates txs_{sender} - -

Monitoring Cache

# Check cache stats via logs
docker-compose logs backend | grep "cache"

# Expected output
{"level":"info","msg":"Cache stats","total_entries":10,"active_entries":8,"min_gap_seconds":15}

Testing Procedure

Phase 1: Component Tests

# Test database connection
docker-compose exec api curl http://localhost:8080/health

# Test API ticker endpoint
curl http://localhost:8080/tickers

# Test conversion
curl "http://localhost:8080/tickers/btc/convert-to/eur/0.001"

Phase 2: Small Fund Tests

# Generate a payment address for BTC
curl -X POST http://localhost:8080/tickers/btc/generate-payment-address \
  -H "Content-Type: application/json" \
  -d '{
    "outputs": [
      {"address": "your-output-address", "percentage": 100}
    ],
    "callback_url": "https://your-callback.com/callback"
  }'

# Send small amount (0.0001 BTC) to generated address

# Monitor forwarding
curl "http://localhost:8080/tickers/btc/payment-address/{address}?payment_uid={uid}"

# Verify:
# - Callback received
# - 4 confirmations observed
# - Funds forwarded to output address

Phase 3: Full Integration Test

# Test all three chains
# 1. BTC: Send 0.001 BTC, verify forwarding
# 2. LTC: Send 0.01 LTC, verify forwarding  
# 3. SOL: Send 0.1 SOL, verify forwarding

# Monitor logs for any errors
docker-compose logs -f | grep -E "(error|warning|failed)"

Mainnet Wallet Security

Hot Wallet Principle

┌─────────────────────────────────────────────────────────┐
│                    FUNDS ALLOCATION                     │
├─────────────────────────────────────────────────────────┤
│                                                          │
│   Cold Storage (80%)  ──►  Hardware wallet, offline      │
│         │                                                   │
│         ▼                                                   │
│   Exchange/Wallet (15%)  ──►  Refill hot wallet          │
│         │                                                   │
│         ▼                                                   │
│   Hot Wallet (5%)  ──►  VPS deployment, operational     │
│                          Only this amount at risk         │
│                                                          │
└─────────────────────────────────────────────────────────┘

Recommended Limits

Chain Hot Wallet Limit Recommended Balance
BTC 0.01 BTC $500-1000 USD
LTC 0.5 LTC $50-100 USD
SOL 5 SOL $500-1000 USD

Monitoring Alerts

Set up alerts for:

  • Wallet balance < threshold
  • Unusual transaction patterns
  • Failed RPC calls (rate limiting)
  • High error rate in logs

Post-Deployment Checklist

  • All services running
  • Health checks passing
  • RPC connections stable
  • Cache working (monitor logs)
  • Callback URLs responsive
  • Small test transactions successful
  • Monitoring/alerting configured
  • Log rotation working
  • Backup strategy in place

Notes

  1. Free tier RPC: Limited to 5 req/min, cache helps but may still hit limits
  2. Solana mainnet: Requires SOL for transaction fees
  3. Bitcoin/Litecoin: Higher fees during network congestion
  4. Confirmation times: BTC ~10 min, LTC ~5 min, SOL ~1 sec
  5. Cache hit rate: Expected 70-80% for active payment addresses

Version History

Version Date Changes
1.0 2026-04-22 Initial deployment plan with RPC cache