Advanced Setup

Configure advanced features, deployment options, and production environments for the Neo Service Layer.

Docker Deployment

Production Docker Setup

Deploy the Neo Service Layer using Docker for production environments.

docker-compose.yml
version: '3.8'
services:
  neo-service-layer:
    build: .
    ports:
      - "8080:8080"
    environment:
      - NEO_NETWORK=mainnet
      - NEO_RPC_URL=http://seed1.neo.org:10332
      - LOG_LEVEL=info
    volumes:
      - ./data:/app/data
      - ./logs:/app/logs
    restart: unless-stopped
    
  neo-express:
    image: cityofzion/neo-express:latest
    ports:
      - "50012:50012"
    volumes:
      - ./blockchain:/blockchain
    command: ["run", "-i", "/blockchain/default.neo-express"]

Build and Deploy

Terminal
# Build the Docker image
docker build -t neo-service-layer .

# Run with Docker Compose
docker-compose up -d

# View logs
docker-compose logs -f neo-service-layer

# Scale services
docker-compose up -d --scale neo-service-layer=3

Environment Configuration

Environment Variables

.env
# Neo Network Configuration
NEO_NETWORK=mainnet
NEO_RPC_URL=http://seed1.neo.org:10332
NEO_WEBSOCKET_URL=ws://seed1.neo.org:10333

# Security Settings
ENCRYPTION_KEY=your-256-bit-encryption-key
JWT_SECRET=your-jwt-secret-key
CORS_ORIGINS=https://yourdomain.com,https://app.yourdomain.com

# Database Configuration
DATABASE_URL=postgresql://user:password@localhost:5432/neo_service_layer
REDIS_URL=redis://localhost:6379

# Logging
LOG_LEVEL=info
LOG_FORMAT=json
LOG_FILE=/app/logs/neo-service-layer.log

# Performance
MAX_CONCURRENT_REQUESTS=100
REQUEST_TIMEOUT=30000
CACHE_TTL=3600

Network Configurations

MainNet

NEO_NETWORK=mainnet
NEO_RPC_URL=http://seed1.neo.org:10332
MAGIC_NUMBER=860833102

TestNet

NEO_NETWORK=testnet
NEO_RPC_URL=http://seed1t.neo.org:20332
MAGIC_NUMBER=894710606

Security Configuration

Intel SGX Setup

Configure Intel SGX for secure enclave execution.

SGX Configuration
# Install SGX SDK
wget https://download.01.org/intel-sgx/sgx-linux/2.17/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.17.101.1.bin
chmod +x sgx_linux_x64_sdk_2.17.101.1.bin
sudo ./sgx_linux_x64_sdk_2.17.101.1.bin

# Configure SGX in appsettings.json
{
  "SGX": {
    "Enabled": true,
    "EnclaveFile": "/app/enclaves/neo-service-layer.signed.so",
    "SpidFile": "/app/config/spid.txt",
    "AttestationMode": "EPID"
  }
}

SSL/TLS Configuration

nginx.conf
server {
    listen 443 ssl http2;
    server_name api.yourdomain.com;
    
    ssl_certificate /etc/ssl/certs/yourdomain.crt;
    ssl_certificate_key /etc/ssl/private/yourdomain.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512;
    
    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Monitoring & Logging

Prometheus Metrics

prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'neo-service-layer'
    static_configs:
      - targets: ['localhost:8080']
    metrics_path: '/metrics'
    scrape_interval: 10s
    
  - job_name: 'neo-node'
    static_configs:
      - targets: ['localhost:10332']
    metrics_path: '/metrics'

Structured Logging

appsettings.Production.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    },
    "Console": {
      "FormatterName": "json"
    },
    "File": {
      "Path": "/app/logs/neo-service-layer-.log",
      "RollingInterval": "Day",
      "RetainedFileCountLimit": 30,
      "FormatterName": "json"
    }
  }
}

Performance Optimization

Database Optimization

  • Connection pooling configuration
  • Index optimization strategies
  • Query performance monitoring
  • Read replica setup

Memory Management

  • Garbage collection tuning
  • Memory pool configuration
  • Cache optimization
  • Memory leak detection

Network Optimization

  • Connection keep-alive settings
  • Request batching strategies
  • Load balancing configuration
  • CDN integration

Troubleshooting

Common Issues

Contract Deployment Failures

Diagnostic Commands
# Check Neo node connectivity
curl -X POST http://localhost:10332 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"getversion","params":[],"id":1}'

# Verify contract compilation
dotnet build --verbosity detailed

# Check gas balance
neo-express wallet list

Performance Issues

  • Monitor CPU and memory usage with htop or docker stats
  • Check database connection pool status
  • Analyze slow query logs
  • Review garbage collection metrics

Network Connectivity

  • Verify firewall rules for ports 10332, 10333
  • Check DNS resolution for Neo seed nodes
  • Test WebSocket connections
  • Validate SSL certificate chain