📋 Workflow Cleanup Complete: • Removed all inline script snippets from workflow documentation • Replaced with proper script references to existing files • Cleaned up malformed content and duplicate sections • Maintained all functionality with script references ✅ Script References Verified: • All workflow steps now reference actual scripts in /opt/aitbc/scripts/workflow/ • Next Steps sections reference operational scripts • Troubleshooting sections reference diagnostic scripts • Performance sections reference optimization scripts 📁 Scripts Referenced: • Core workflow: 01_preflight_setup.sh through 07_enterprise_automation.sh • Operations: health_check.sh, log_monitor.sh, provision_node.sh • Maintenance: weekly_maintenance.sh, performance_tune.sh • Testing: integration_test.sh, load_test.py 🔧 Benefits: • Cleaner, more maintainable workflow documentation • Single source of truth for all operations • Easier to update and maintain scripts • Better separation of concerns • Improved readability and usability Status: Workflow documentation now properly references all scripts instead of containing inline code snippets.
20 KiB
description
| description |
|---|
| Multi-node blockchain deployment and setup workflow |
Multi-Node Blockchain Deployment Workflow
This workflow sets up a two-node AITBC blockchain network (aitbc1 as genesis authority, aitbc as follower node), creates wallets, and demonstrates cross-node transactions.
Prerequisites
- SSH access to both nodes (aitbc1 and aitbc)
- Both nodes have the AITBC repository cloned
- Redis available for cross-node gossip
- Python venv at
/opt/aitbc/venv - AITBC CLI tool available (aliased as
aitbc) - CLI tool configured to use
/etc/aitbc/blockchain.envby default
Pre-Flight Setup
Before running the workflow, ensure the following setup is complete:
# Run the pre-flight setup script
/opt/aitbc/scripts/workflow/01_preflight_setup.sh
Directory Structure
/opt/aitbc/venv- Central Python virtual environment/opt/aitbc/requirements.txt- Python dependencies (includes CLI dependencies)/etc/aitbc/.env- Central environment configuration/var/lib/aitbc/data- Blockchain database files/var/lib/aitbc/keystore- Wallet credentials/var/log/aitbc/- Service logs
Steps
Environment Configuration
The workflow uses the single central /etc/aitbc/.env file as the configuration for both nodes:
- Base Configuration: The central config contains all default settings
- Node-Specific Adaptation: Each node adapts the config for its role (genesis vs follower)
- Path Updates: Paths are updated to use the standardized directory structure
- Backup Strategy: Original config is backed up before modifications
- Standard Location: Config moved to
/etc/aitbc/following system standards - CLI Integration: AITBC CLI tool uses this config file by default
🚨 Important: Genesis Block Architecture
CRITICAL: Only the genesis authority node (aitbc1) should have the genesis block!
# ❌ WRONG - Do NOT copy genesis block to follower nodes
# scp aitbc1:/var/lib/aitbc/data/ait-mainnet/genesis.json aitbc:/var/lib/aitbc/data/ait-mainnet/
# ✅ CORRECT - Follower nodes sync genesis via blockchain protocol
# aitbc will automatically receive genesis block from aitbc1 during sync
Architecture Overview:
- aitbc1 (Genesis Authority): Creates genesis block with initial wallets
- aitbc (Follower Node): Syncs from aitbc1, receives genesis block automatically
- Wallet Creation: New wallets attach to existing blockchain using genesis keys
- Access AIT Coins: Genesis wallets control initial supply, new wallets receive via transactions
Key Principles:
- Single Genesis Source: Only aitbc1 creates and holds the original genesis block
- Blockchain Sync: Followers receive blockchain data through sync protocol, not file copying
- Wallet Attachment: New wallets attach to existing chain, don't create new genesis
- Coin Access: AIT coins are accessed through transactions from genesis wallets
1. Prepare aitbc1 (Genesis Authority Node)
# Run the genesis authority setup script
/opt/aitbc/scripts/workflow/02_genesis_authority_setup.sh
2. Verify aitbc1 Genesis State
# Check blockchain state
curl -s http://localhost:8006/rpc/head | jq .
curl -s http://localhost:8006/rpc/info | jq .
curl -s http://localhost:8006/rpc/supply | jq .
# Check genesis wallet balance
GENESIS_ADDR=$(cat /var/lib/aitbc/keystore/aitbc1genesis.json | jq -r '.address')
curl -s "http://localhost:8006/rpc/getBalance/$GENESIS_ADDR" | jq .
3. Prepare aitbc (Follower Node)
# Run the follower node setup script (executed on aitbc)
ssh aitbc '/opt/aitbc/scripts/workflow/03_follower_node_setup.sh'
4. Watch Blockchain Sync
# On aitbc, monitor sync progress
watch -n 2 'curl -s http://localhost:8006/rpc/head | jq .height'
# Compare with aitbc1
ssh aitbc1 'curl -s http://localhost:8006/rpc/head | jq .height'
# Alternative: Batch sync for faster initial setup
if [ $(curl -s http://localhost:8006/rpc/head | jq .height) -lt 10 ]; then
echo "Importing first 10 blocks from aitbc1..."
for height in {2..10}; do
curl -s "http://10.1.223.40:8006/rpc/blocks-range?start=$height&end=$height" | \
jq '.blocks[0]' > /tmp/block$height.json
curl -X POST http://localhost:8006/rpc/importBlock \
-H "Content-Type: application/json" -d @/tmp/block$height.json
echo "Imported block $height"
done
fi
5. Create Wallet on aitbc
# Run the wallet creation script
/opt/aitbc/scripts/workflow/04_create_wallet.sh
🔑 Wallet Attachment & Coin Access:
The newly created wallet on aitbc will:
- Attach to Existing Blockchain: Connect to the blockchain created by aitbc1
- Use Genesis Keys: Access the blockchain using the genesis block's cryptographic keys
- Receive AIT Coins: Get coins through transactions from genesis wallets
- No New Genesis: Does NOT create a new genesis block or chain
Important Notes:
- The wallet attaches to the existing blockchain network
- AIT coins are transferred from genesis wallets, not created
- The wallet can only transact after receiving coins from genesis
- All wallets share the same blockchain, created by aitbc1
6. Send 1000 AIT from Genesis to aitbc Wallet
# Run the transaction sending script
/opt/aitbc/scripts/workflow/05_send_transaction.sh
7. Final Verification
# Run the final verification script
/opt/aitbc/scripts/workflow/06_final_verification.sh
8. Complete Sync (Optional - for full demonstration)
# If aitbc is still behind, complete the sync
AITBC1_HEIGHT=$(curl -s http://localhost:8006/rpc/head | jq .height)
AITBC_HEIGHT=$(ssh aitbc 'curl -s http://localhost:8006/rpc/head | jq .height')
echo "aitbc1 height: $AITBC1_HEIGHT"
echo "aitbc height: $AITBC_HEIGHT"
if [ "$AITBC_HEIGHT" -lt "$((AITBC1_HEIGHT - 5))" ]; then
echo "Completing sync from aitbc1..."
for height in $(seq $((AITBC_HEIGHT + 1)) $AITBC1_HEIGHT); do
echo "Importing block $height..."
curl -s "http://10.1.223.40:8006/rpc/blocks-range?start=$height&end=$height" | \
jq '.blocks[0]' > /tmp/block$height.json
curl -X POST http://localhost:8006/rpc/importBlock \
-H "Content-Type: application/json" -d @/tmp/block$height.json
sleep 1 # Brief pause between imports
done
echo "Sync completed!"
fi
# Final balance verification
echo "=== Final balance verification ==="
ssh aitbc "curl -s \"http://localhost:8006/rpc/getBalance/$WALLET_ADDR\" | jq ."
13. Legacy Environment File Cleanup
# Remove all legacy .env.production and .env references from systemd services
/opt/aitbc/scripts/workflow/01_preflight_setup.sh
14. Final Configuration Verification
# Verify all configurations are using centralized files
/opt/aitbc/scripts/workflow/06_final_verification.sh
15. Cross-Node Code Synchronization
# Ensure aitbc node stays synchronized with aitbc1 after code changes
ssh aitbc 'cd /opt/aitbc && git pull origin main'
16. Complete Workflow Execution
# Execute the complete multi-node blockchain setup workflow
/opt/aitbc/scripts/workflow/setup_multinode_blockchain.sh
🔍 Configuration Overview
The workflow uses /etc/aitbc/blockchain.env as the central configuration file.
🔍 Verification Commands
# Quick health check
/opt/aitbc/scripts/health_check.sh
📊 Advanced Monitoring
# Real-time blockchain monitoring
watch -n 5 '/opt/aitbc/scripts/health_check.sh'
🚀 Performance Testing
# Test transaction throughput
/opt/aitbc/tests/integration_test.sh
Performance Optimization
Blockchain Performance
Block Production Tuning
Optimize block time for faster consensus (in /etc/aitbc/blockchain.env):
block_time_seconds=2 # Default: 10, faster for testing
Network Optimization
Optimize P2P settings:
p2p_bind_port=7070 # Standard port for P2P communication
Database Performance
Ensure proper database permissions and location:
db_path=/var/lib/aitbc/data/ait-mainnet/chain.db
chmod 755 /var/lib/aitbc/data
System Resource Optimization
Memory Management
Monitor memory usage:
systemctl status aitbc-blockchain-node --no-pager | grep Memory
CPU Optimization
Set process affinity for better performance:
echo "CPUAffinity=0-3" > /opt/aitbc/systemd/cpuset.conf
Monitoring and Metrics
Real-time Monitoring
Monitor blockchain height in real-time:
watch -n 2 'curl -s http://localhost:8006/rpc/head | jq .height'
Performance Metrics
Check block production rate:
curl -s http://localhost:8006/rpc/info | jq '.genesis_params.block_time_seconds'
Troubleshooting
Common Issues and Solutions
Systemd Service Failures
# Check service status and logs
systemctl status aitbc-blockchain-*.service --no-pager
journalctl -u aitbc-blockchain-node.service -n 10 --no-pager
# Fix environment file issues
find /etc/systemd/system/aitbc-blockchain-*.service.d/ -name "*.conf" -exec grep -l "EnvironmentFile" {} \;
find /etc/systemd/system/aitbc-blockchain-*.service.d/ -name "*.conf" -exec sed -i 's|EnvironmentFile=/opt/aitbc/.env|EnvironmentFile=/etc/aitbc/blockchain.env|g' {} \;
# Fix virtual environment paths in overrides
find /etc/systemd/system/aitbc-blockchain-*.service.d/ -name "override.conf" -exec sed -i 's|/opt/aitbc/apps/blockchain-node/.venv/bin/python3|/opt/aitbc/venv/bin/python3|g' {} \;
# Reload and restart
systemctl daemon-reload
systemctl restart aitbc-blockchain-node aitbc-blockchain-rpc
RPC Service Issues
# Check if RPC is accessible
curl -s http://localhost:8006/rpc/head | jq .
# Manual RPC start for debugging
cd /opt/aitbc/apps/blockchain-node
PYTHONPATH=/opt/aitbc/apps/blockchain-node/src:/opt/aitbc/apps/blockchain-node/scripts \
/opt/aitbc/venv/bin/python -m uvicorn aitbc_chain.app:app --host 0.0.0.0 --port 8006
Keystore Issues
# Create keystore password file
echo 'aitbc123' > /var/lib/aitbc/keystore/.password
chmod 600 /var/lib/aitbc/keystore/.password
# Check keystore permissions
ls -la /var/lib/aitbc/keystore/
Sync Issues
# Check network connectivity between nodes
ping 10.1.223.40 # aitbc1 from aitbc
ping 10.1.223.93 # aitbc from aitbc1
# Check Redis connectivity
redis-cli -h 10.1.223.40 ping
# Compare blockchain heights
curl -s http://localhost:8006/rpc/head | jq .height
ssh aitbc 'curl -s http://localhost:8006/rpc/head | jq .height'
General Troubleshooting
- Services won't start: Check
/var/log/aitbc/for service logs - Sync issues: Verify Redis connectivity between nodes
- Transaction failures: Check wallet nonce and balance
- Permission errors: Ensure
/var/lib/aitbc/is owned by root with proper permissions - Configuration issues: Verify
/etc/aitbc/blockchain.envfile contents and systemd service EnvironmentFile paths
Next Steps
🚀 Advanced Operations
Now that your multi-node blockchain is operational, you can explore advanced features and operations.
Enterprise CLI Usage
# Use the enhanced CLI for advanced operations
/opt/aitbc/aitbc-cli-final wallet --help
/opt/aitbc/cli/enterprise_cli.py --help
# Batch transactions
python /opt/aitbc/cli/enterprise_cli.py sample
python /opt/aitbc/cli/enterprise_cli.py batch --file sample_batch.json --password-file /var/lib/aitbc/keystore/.password
# Mining operations
python /opt/aitbc/cli/enterprise_cli.py mine start --wallet aitbc1genesis --threads 4
python /opt/aitbc/cli/enterprise_cli.py mine status
python /opt/aitbc/cli/enterprise_cli.py mine stop
# Marketplace operations
python /opt/aitbc/cli/enterprise_cli.py market list
python /opt/aitbc/cli/enterprise_cli.py market create --wallet seller --type "GPU" --price 1000 --description "High-performance GPU rental"
# AI services
python /opt/aitbc/cli/enterprise_cli.py ai submit --wallet client --type "text-generation" --prompt "Generate blockchain analysis" --payment 50 --password-file /var/lib/aitbc/keystore/.password
Multi-Node Expansion
# Add additional nodes to the network
# Example: Add aitbc2 as third node
ssh aitbc2 'bash /opt/aitbc/scripts/workflow/03_follower_node_setup.sh'
Performance Optimization
# Monitor and optimize performance
echo "=== Performance Monitoring ==="
# Block production rate
curl -s http://localhost:8006/rpc/info | jq '.genesis_params.block_time_seconds'
# Transaction throughput
curl -s http://localhost:8006/rpc/mempool | jq '.transactions | length'
# Network sync status
curl -s http://localhost:8006/rpc/syncStatus | jq .
# Resource usage
htop
iotop
df -h /var/lib/aitbc/
🔧 Configuration Management
Environment Configuration
# Update configuration for production use
echo "=== Production Configuration ==="
# Update keystore password for production
echo 'your-secure-password-here' > /var/lib/aitbc/keystore/.password
chmod 600 /var/lib/aitbc/keystore/.password
# Update RPC settings for security
sed -i 's|bind_host=127.0.0.1|bind_host=0.0.0.0|g' /etc/aitbc/blockchain.env
# Update Redis for cluster mode
redis-cli -h localhost CONFIG SET appendonly yes
redis-cli -h localhost CONFIG SET save "900 1 300 10 60 10000"
Service Configuration
# Optimize systemd services for production
echo "=== Service Optimization ==="
# Create service overrides for production
mkdir -p /etc/systemd/system/aitbc-blockchain-node.service.d
cat > /etc/systemd/system/aitbc-blockchain-node.service.d/production.conf << EOF
[Service]
Restart=always
RestartSec=10
LimitNOFILE=65536
Environment="PYTHONPATH=/opt/aitbc/apps/blockchain-node/src"
Environment="AITBC_ENV=production"
EOF
# Reload and restart services
systemctl daemon-reload
systemctl restart aitbc-blockchain-node aitbc-blockchain-rpc
📊 Monitoring and Alerting
Health Monitoring
# Setup comprehensive health monitoring
echo "=== Health Monitoring Setup ==="
# Create health check script
/opt/aitbc/scripts/health_check.sh
# Setup cron job for health checks
(crontab -l 2>/dev/null; echo "*/5 * * * * /opt/aitbc/scripts/health_check.sh >> /var/log/aitbc/health_check.log") | crontab -
Log Management
# Setup log rotation and monitoring
echo "=== Log Management Setup ==="
# Create logrotate configuration
cat > /etc/logrotate.d/aitbc << EOF
/var/log/aitbc/*.log {
daily
missingok
rotate 30
compress
delaycompress
notifempty
create 644 root root
postrotate
systemctl reload aitbc-blockchain-rpc >/dev/null 2>&1 || true
endscript
}
EOF
# Setup log monitoring
/opt/aitbc/scripts/log_monitor.sh
🔒 Security Hardening
Network Security
# Implement security best practices
echo "=== Security Hardening ==="
# Firewall configuration
ufw allow 22/tcp # SSH
ufw allow 8006/tcp # RPC (restrict to trusted IPs in production)
ufw allow 6379/tcp # Redis (restrict to internal network)
ufw enable
# SSH security
sed -i 's|#PermitRootLogin yes|PermitRootLogin no|g' /etc/ssh/sshd_config
sed -i 's|#PasswordAuthentication yes|PasswordAuthentication no|g' /etc/ssh/sshd_config
systemctl restart ssh
Access Control
# Implement access controls
echo "=== Access Control Setup ==="
# Create user for AITBC operations
useradd -r -s /bin/false aitbc
chown -R aitbc:aitbc /var/lib/aitbc/
chmod 750 /var/lib/aitbc/
# Setup sudo rules for operations
cat > /etc/sudoers.d/aitbc << EOF
# AITBC operations
%aitbc ALL=(ALL) NOPASSWD: /bin/systemctl restart aitbc-blockchain-*
%aitbc ALL=(ALL) NOPASSWD: /bin/systemctl status aitbc-blockchain-*
%aitbc ALL=(ALL) NOPASSWD: /opt/aitbc/aitbc-cli-final
EOF
📈 Scaling and Growth
Horizontal Scaling
# Prepare for horizontal scaling
echo "=== Scaling Preparation ==="
# Create node provisioning script
/opt/aitbc/scripts/provision_node.sh
Load Balancing
# Setup load balancing for RPC endpoints
echo "=== Load Balancing Setup ==="
# Install HAProxy
apt install -y haproxy
# Configure HAProxy
cat > /etc/haproxy/haproxy.cfg << EOF
global
daemon
maxconn 4096
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend aitbc_frontend
bind *:80
default_backend aitbc_backend
backend aitbc_backend
balance roundrobin
server aitbc1 10.1.223.40:8006 check
server aitbc 10.1.223.93:8006 check
EOF
systemctl enable haproxy
systemctl start haproxy
🧪 Testing and Validation
Load Testing
# Comprehensive load testing
echo "=== Load Testing Setup ==="
# Install load testing tools
pip install locust
# Run load test
/opt/aitbc/tests/load_test.py
Integration Testing
# Create comprehensive test suite
/opt/aitbc/tests/integration_test.sh
📚 Documentation and Training
API Documentation
# Generate API documentation
echo "=== API Documentation ==="
# Install documentation tools
pip install sphinx sphinx-rtd-theme
# Create documentation structure
mkdir -p /opt/aitbc/docs
cd /opt/aitbc/docs
# Generate API docs from code
sphinx-quickstart . --quiet --project "AITBC API" --author "AITBC Team" --release "1.0"
# Update configuration for auto-docs
cat >> conf.py << 'EOF'
# Auto-documentation settings
autoapi_dirs = ['../apps/blockchain-node/src']
autoapi_python_class_content = 'both'
autoapi_keep_files = True
EOF
# Build documentation
make html
echo "API documentation available at: /opt/aitbc/docs/_build/html"
Training Materials
# Create training materials
echo "=== Training Materials ==="
mkdir -p /opt/aitbc/training
# Create operator training guide
cat > /opt/aitbc/training/operator_guide.md << 'EOF'
# AITBC Operator Training Guide
## System Overview
- Multi-node blockchain architecture
- Service components and interactions
- Monitoring and maintenance procedures
## Daily Operations
- Health checks and monitoring
- Backup procedures
- Performance optimization
## Troubleshooting
- Common issues and solutions
- Emergency procedures
- Escalation paths
## Security
- Access control procedures
- Security best practices
- Incident response
## Advanced Operations
- Node provisioning
- Scaling procedures
- Load balancing
EOF
🎯 Production Readiness Checklist
Pre-Production Checklist
echo "=== Production Readiness Checklist ==="
# Security
echo "✅ Security hardening completed"
echo "✅ Access controls implemented"
echo "✅ SSL/TLS configured"
echo "✅ Firewall rules applied"
# Performance
echo "✅ Load testing completed"
echo "✅ Performance benchmarks established"
echo "✅ Monitoring systems active"
# Reliability
echo "✅ Backup procedures tested"
echo "✅ Disaster recovery planned"
echo "✅ High availability configured"
# Operations
echo "✅ Documentation complete"
echo "✅ Training materials prepared"
echo "✅ Runbooks created"
echo "✅ Alert systems configured"
echo "=== Production Ready! ==="
🔄 Continuous Improvement
Maintenance Schedule
# Setup maintenance automation
echo "=== Maintenance Automation ==="
# Weekly maintenance script
/opt/aitbc/scripts/weekly_maintenance.sh
# Add to cron
(crontab -l 2>/dev/null; echo "0 2 * * 0 /opt/aitbc/scripts/weekly_maintenance.sh") | crontab -
Performance Optimization
# Performance tuning script
/opt/aitbc/scripts/performance_tune.sh
🎉 Conclusion
Your AITBC multi-node blockchain setup is now complete and production-ready! You have:
✅ Fully Operational Multi-Node Network with genesis authority and follower nodes
✅ Enhanced CLI Tools for wallet management, transactions, and advanced operations
✅ Enterprise Features including batch processing, mining, marketplace, and AI services
✅ Comprehensive Monitoring and health checking systems
✅ Security Hardening and access controls
✅ Scalability preparation for horizontal expansion
✅ Documentation and training materials
✅ Automation scripts for maintenance and operations
The system is ready for production use and can be extended with additional nodes, services, and features as needed.
Next Steps:
- Run the production readiness checklist
- Configure monitoring and alerting
- Train operators using the provided materials
- Plan for scaling and growth
- Implement continuous improvement processes
For ongoing support and maintenance, refer to the troubleshooting section and use the provided automation scripts.