|
| 1 | +# Solana Snapshot Uploader - Design Document |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The Solana Snapshot Uploader is a robust Go application designed to monitor, process, and upload Solana blockchain snapshots to S3-compatible storage. It provides automated snapshot management with configurable rules, metadata generation, and retention policies. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +### Core Components |
| 10 | + |
| 11 | +1. **Snapshot Monitor (`pkg/monitor`)** |
| 12 | + - Main monitoring service that watches for new snapshot files |
| 13 | + - Implements file system event handling |
| 14 | + - Manages snapshot processing pipeline |
| 15 | + - Handles concurrent upload operations |
| 16 | + |
| 17 | +2. **Snapshot Processor (`pkg/snapshot`)** |
| 18 | + - Validates and processes snapshot files |
| 19 | + - Implements slot gap validation rules |
| 20 | + - Manages snapshot metadata generation |
| 21 | + - Handles snapshot type detection (full vs incremental) |
| 22 | + |
| 23 | +3. **S3 Storage (`pkg/s3`)** |
| 24 | + - Manages S3-compatible storage interactions |
| 25 | + - Implements multipart upload functionality |
| 26 | + - Handles upload retries and resumption |
| 27 | + - Manages cleanup of abandoned uploads |
| 28 | + |
| 29 | +4. **Metadata Management (`pkg/metadata`)** |
| 30 | + - Generates and manages snapshot metadata |
| 31 | + - Tracks upload status and progress |
| 32 | + - Maintains version and feature set information |
| 33 | + - Implements status tracking for concurrent operations |
| 34 | + |
| 35 | +5. **Configuration (`pkg/config`)** |
| 36 | + - Manages application configuration |
| 37 | + - Supports both YAML and environment variable configuration |
| 38 | + - Validates configuration parameters |
| 39 | + - Provides default values and configuration merging |
| 40 | + |
| 41 | +6. **Solana Integration (`pkg/solana`)** |
| 42 | + - Handles Solana RPC interactions |
| 43 | + - Auto-detects Solana version and feature set |
| 44 | + - Manages Solana-specific operations |
| 45 | + |
| 46 | +### Data Flow |
| 47 | + |
| 48 | +1. **Snapshot Detection** |
| 49 | + ``` |
| 50 | + File System → Monitor → Snapshot Processor |
| 51 | + ``` |
| 52 | + |
| 53 | +2. **Snapshot Processing** |
| 54 | + ``` |
| 55 | + Snapshot Processor → Validation → Metadata Generation → S3 Upload |
| 56 | + ``` |
| 57 | + |
| 58 | +3. **Retention Management** |
| 59 | + ``` |
| 60 | + Monitor → Retention Check → S3 Cleanup |
| 61 | + ``` |
| 62 | + |
| 63 | +## Key Features |
| 64 | + |
| 65 | +### 1. Snapshot Monitoring |
| 66 | +- Real-time directory monitoring |
| 67 | +- Automatic detection of new snapshots |
| 68 | +- File exclusion rules for temporary files |
| 69 | +- Concurrent processing support |
| 70 | + |
| 71 | +### 2. Snapshot Validation |
| 72 | +- Full snapshot slot gap validation (configurable) |
| 73 | +- Incremental snapshot validation |
| 74 | +- Slot continuity checking |
| 75 | +- Optional incremental snapshot support |
| 76 | + |
| 77 | +### 3. Metadata Management |
| 78 | +- Automatic metadata generation |
| 79 | +- Version and feature set tracking |
| 80 | +- Upload status tracking |
| 81 | +- Progress reporting |
| 82 | +- Automatic cleanup of orphaned metadata (metadata without corresponding snapshot files) |
| 83 | + |
| 84 | +### 4. Storage Management |
| 85 | +- S3-compatible storage support |
| 86 | +- Multipart upload handling |
| 87 | +- Upload retry and resumption |
| 88 | +- Abandoned upload cleanup |
| 89 | + |
| 90 | +### 5. Retention Management |
| 91 | +- Configurable retention periods |
| 92 | +- Automatic cleanup of old snapshots |
| 93 | +- Retention policy enforcement |
| 94 | +- Orphaned metadata cleanup (removes metadata files when corresponding snapshots are missing) |
| 95 | + |
| 96 | +### 6. Metadata Cleanup |
| 97 | +- Automatic detection of orphaned metadata files |
| 98 | +- Periodic scanning for metadata-snapshot consistency |
| 99 | +- Safe removal of metadata without corresponding snapshots |
| 100 | +- Configurable cleanup intervals |
| 101 | +- Logging of cleanup operations for audit purposes |
| 102 | + |
| 103 | +## Configuration |
| 104 | + |
| 105 | +The application supports configuration through: |
| 106 | +- YAML configuration file |
| 107 | +- Environment variables |
| 108 | +- Command-line arguments |
| 109 | + |
| 110 | +Key configuration parameters: |
| 111 | +- Watch directory |
| 112 | +- S3 credentials and endpoint |
| 113 | +- Solana RPC URL |
| 114 | +- Slot gap settings |
| 115 | +- Retention policies |
| 116 | +- Logging levels |
| 117 | + |
| 118 | +## Deployment Options |
| 119 | + |
| 120 | +1. **Direct Execution** |
| 121 | + - Standalone binary execution |
| 122 | + - Environment variable configuration |
| 123 | + - Custom configuration file support |
| 124 | + |
| 125 | +2. **Systemd Service** |
| 126 | + - Systemd service file included |
| 127 | + - Environment file configuration |
| 128 | + - Automatic startup and recovery |
| 129 | + |
| 130 | +3. **Docker Container** |
| 131 | + - Dockerfile included |
| 132 | + - Volume mounting support |
| 133 | + - Environment variable configuration |
| 134 | + - Docker Compose support |
| 135 | + |
| 136 | +## Error Handling |
| 137 | + |
| 138 | +- Graceful error recovery |
| 139 | +- Upload retry mechanism |
| 140 | +- Failed upload cleanup |
| 141 | +- Logging and monitoring |
| 142 | +- Status tracking for failed operations |
| 143 | +- Metadata consistency checks and cleanup |
| 144 | + |
| 145 | +## Security Considerations |
| 146 | + |
| 147 | +- Secure credential management |
| 148 | +- S3 access key protection |
| 149 | +- File permission management |
| 150 | +- Secure logging practices |
| 151 | + |
| 152 | +## Monitoring and Logging |
| 153 | + |
| 154 | +- Configurable log levels |
| 155 | +- Progress reporting |
| 156 | +- Status tracking |
| 157 | +- Error logging |
| 158 | +- Performance metrics |
| 159 | + |
| 160 | +## Future Considerations |
| 161 | + |
| 162 | +1. **Scalability** |
| 163 | + - Distributed monitoring support |
| 164 | + - Load balancing capabilities |
| 165 | + - Performance optimization |
| 166 | + |
| 167 | +2. **Enhanced Features** |
| 168 | + - Additional storage backend support |
| 169 | + - Advanced retention policies |
| 170 | + - Custom validation rules |
| 171 | + - Enhanced metadata support |
| 172 | + |
| 173 | +3. **Integration** |
| 174 | + - Monitoring system integration |
| 175 | + - Alerting capabilities |
| 176 | + - API endpoints for control |
| 177 | + - Web interface for management |
| 178 | + |
| 179 | +## Dependencies |
| 180 | + |
| 181 | +- Go 1.23 or higher |
| 182 | +- S3-compatible storage |
| 183 | +- Solana RPC access |
| 184 | +- System requirements for deployment method |
| 185 | + |
| 186 | +## Development Guidelines |
| 187 | + |
| 188 | +1. **Code Organization** |
| 189 | + - Package-based structure |
| 190 | + - Clear separation of concerns |
| 191 | + - Modular design |
| 192 | + |
| 193 | +2. **Documentation** |
| 194 | + - Code documentation |
| 195 | + - API documentation |
| 196 | + - Configuration documentation |
| 197 | + - Deployment guides |
0 commit comments