osvm 0.8.3

OpenSVM CLI tool for managing SVM nodes and deployments
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# eBPF Deployment

The eBPF Deployment module provides comprehensive tools for deploying, upgrading, and managing Solana programs (smart contracts) across different networks and environments.

## Overview

OSVM CLI offers advanced eBPF program deployment capabilities with support for large programs, buffer accounts, upgrade procedures, and comprehensive validation. It handles the complexity of Solana program deployment while providing safety mechanisms and deployment strategies.

## Quick Start

```bash
# Deploy a new program
osvm deploy-program --program myprogram.so --keypair authority.json

# Upgrade existing program
osvm deploy-program --program myprogram.so --keypair authority.json --upgrade

# Deploy to remote host
osvm deploy-program --host user@example.com --program myprogram.so --keypair authority.json

# Deploy with buffer account (for large programs)
osvm deploy-program --program myprogram.so --keypair authority.json --use-buffer
```

## Architecture

```mermaid
flowchart TD
    subgraph "eBPF Deployment System"
        CLI[Deploy CLI]
        
        subgraph "Deployment Types"
            NEW[New Program]
            UPGRADE[Program Upgrade]
            BUFFER[Buffer Deployment]
            REMOTE[Remote Deployment]
        end
        
        subgraph "Validation Layer"
            SIZE[Size Validation]
            FORMAT[Format Validation]
            AUTH[Authority Validation]
            NETWORK[Network Validation]
        end
        
        subgraph "Deployment Strategies"
            DIRECT[Direct Deployment]
            CHUNKED[Chunked Upload]
            BUFFERED[Buffer-based]
            STAGED[Staged Deployment]
        end
        
        subgraph "Safety Systems"
            BACKUP[Program Backup]
            VERIFY[Deployment Verification]
            ROLLBACK[Rollback System]
            MONITOR[Post-deploy Monitor]
        end
        
        subgraph "Target Networks"
            DEVNET[Devnet]
            TESTNET[Testnet]
            MAINNET[Mainnet]
            LOCAL[Local Validator]
        end
    end
    
    CLI --> NEW
    CLI --> UPGRADE
    CLI --> BUFFER
    CLI --> REMOTE
    
    NEW --> SIZE
    UPGRADE --> FORMAT
    BUFFER --> AUTH
    REMOTE --> NETWORK
    
    SIZE --> DIRECT
    FORMAT --> CHUNKED
    AUTH --> BUFFERED
    NETWORK --> STAGED
    
    DIRECT --> BACKUP
    CHUNKED --> VERIFY
    BUFFERED --> ROLLBACK
    STAGED --> MONITOR
    
    BACKUP --> DEVNET
    VERIFY --> TESTNET
    ROLLBACK --> MAINNET
    MONITOR --> LOCAL
    
    classDef techDebt fill:#f6f6f6,stroke:#d9534f,color:#d9534f,font-family:Consolas,monospace,font-weight:bold
```

## Deployment Commands

### Basic Program Deployment

Deploy a new Solana program to the network.

```bash
osvm deploy-program [OPTIONS]
```

**Required Options:**
- `--program <PROGRAM>` - Path to program binary (.so file)
- `--keypair <KEYPAIR>` - Program authority keypair

**Common Options:**
- `--network <NETWORK>` - Target network (devnet, testnet, mainnet)
- `--upgrade` - Upgrade existing program
- `--buffer-keypair <KEYPAIR>` - Use specific buffer keypair
- `--max-sign-attempts <NUM>` - Maximum signing attempts
- `--use-buffer` - Use buffer account for deployment

**Examples:**
```bash
# Deploy to devnet
osvm deploy-program \
  --program target/deploy/myprogram.so \
  --keypair ~/.config/solana/id.json \
  --network devnet

# Upgrade existing program
osvm deploy-program \
  --program target/deploy/myprogram.so \
  --keypair ~/.config/solana/id.json \
  --upgrade \
  --network mainnet

# Deploy large program with buffer
osvm deploy-program \
  --program target/deploy/large_program.so \
  --keypair ~/.config/solana/id.json \
  --use-buffer \
  --buffer-keypair buffer.json
```

### Remote Deployment

Deploy programs via SSH to remote hosts with access to target networks.

```bash
osvm deploy-program --host <HOST> [OPTIONS]
```

**Remote Deployment Features:**
- Transfer program binary to remote host
- Execute deployment from remote environment
- Handle network connectivity from remote location
- Manage keypairs securely during remote deployment

### Buffer-based Deployment

For programs larger than the transaction size limit, use buffer accounts.

```mermaid
sequenceDiagram
    participant DEV as Developer
    participant CLI as OSVM CLI
    participant BUF as Buffer Account
    participant SOL as Solana Network
    participant PROG as Program Account
    
    DEV->>CLI: deploy-program --use-buffer
    CLI->>BUF: Create buffer account
    BUF->>CLI: Buffer account created
    CLI->>BUF: Upload program data in chunks
    BUF->>CLI: All chunks uploaded
    CLI->>SOL: Deploy from buffer
    SOL->>PROG: Program deployed
    PROG->>CLI: Deployment confirmed
    CLI->>BUF: Close buffer account
    CLI->>DEV: Deployment complete
    
    classDef techDebt fill:#f6f6f6,stroke:#d9534f,color:#d9534f,font-family:Solana,monospace,font-weight:bold
```

## Deployment Strategies

### Direct Deployment

For small programs that fit within transaction limits.

**Characteristics:**
- Single transaction deployment
- Immediate deployment
- Lower cost
- Simple process

**Best for:**
- Small programs (<100KB)
- Testing and development
- Simple smart contracts

### Chunked Deployment

For medium-sized programs requiring multiple transactions.

**Process:**
1. Split program into chunks
2. Upload chunks sequentially
3. Verify chunk integrity
4. Finalize deployment

**Best for:**
- Medium programs (100KB-1MB)
- Production deployments
- Programs with size constraints

### Buffer Account Deployment

For large programs exceeding transaction limits.

**Process:**
1. Create dedicated buffer account
2. Upload program data to buffer
3. Deploy from buffer to program account
4. Close buffer account

**Best for:**
- Large programs (>1MB)
- Complex applications
- Enterprise deployments

## Program Validation

### Pre-deployment Validation

Comprehensive validation before deployment execution.

**Validation Checks:**
- **Binary Format:** ELF format validation
- **Program Size:** Size limit verification
- **Authority:** Keypair validation
- **Network Access:** Network connectivity check
- **SOL Balance:** Sufficient balance for deployment
- **Program Account:** Account state verification

### Runtime Validation

Validation during deployment process.

```mermaid
flowchart LR
    subgraph "Validation Pipeline"
        START[Start Deployment]
        PRECHECK[Pre-deployment Checks]
        UPLOAD[Upload Validation]
        DEPLOY[Deployment Validation]
        VERIFY[Post-deployment Verification]
        COMPLETE[Deployment Complete]
    end
    
    START --> PRECHECK
    PRECHECK --> UPLOAD
    UPLOAD --> DEPLOY
    DEPLOY --> VERIFY
    VERIFY --> COMPLETE
    
    classDef techDebt fill:#f6f6f6,stroke:#d9534f,color:#d9534f,font-family:Consolas,monospace,font-weight:bold
```

### Post-deployment Verification

Verification after successful deployment.

**Verification Steps:**
- Program account state validation
- Executable data verification
- Authority confirmation
- Upgrade authority check
- Program ID validation

## Upgrade Management

### Program Upgrades

Safe upgrade procedures for existing programs.

**Upgrade Process:**
1. Validate upgrade authority
2. Create program backup
3. Upload new program data
4. Verify upgrade success
5. Update program metadata

**Upgrade Options:**
```bash
# Standard upgrade
osvm deploy-program --upgrade --program new_version.so --keypair authority.json

# Upgrade with backup
osvm deploy-program --upgrade --program new_version.so --keypair authority.json --backup

# Staged upgrade (test first)
osvm deploy-program --upgrade --program new_version.so --keypair authority.json --stage-test
```

### Version Management

Track and manage program versions.

```yaml
program_versions:
  myprogram:
    current: "v1.2.0"
    deployed: "2023-12-01T10:00:00Z"
    authority: "11111111111111111111111111111111"
    network: "mainnet"
    
  versions:
    - version: "v1.0.0"
      deployed: "2023-10-01T10:00:00Z"
      program_id: "PROG1111111111111111111111111111111"
    - version: "v1.1.0"
      deployed: "2023-11-01T10:00:00Z"
      program_id: "PROG2222222222222222222222222222222"
```

### Rollback Capabilities

Emergency rollback procedures for failed upgrades.

**Rollback Types:**
- **Immediate Rollback:** Revert to previous version
- **Staged Rollback:** Gradual rollback with validation
- **Emergency Rollback:** Fast rollback for critical issues

## Security Features

### Authority Management

Secure handling of program authorities and keypairs.

**Authority Types:**
- **Deploy Authority:** Can deploy new programs
- **Upgrade Authority:** Can upgrade existing programs
- **Close Authority:** Can close program accounts

**Security Practices:**
- Keypair encryption at rest
- Secure keypair transfer for remote deployment
- Authority validation before operations
- Multi-signature support for critical operations

### Deployment Safety

Safety mechanisms to prevent deployment failures.

**Safety Features:**
- **Dry Run Mode:** Test deployment without execution
- **Backup Creation:** Automatic backup before upgrades
- **Verification Checks:** Comprehensive post-deployment validation
- **Rollback Procedures:** Emergency rollback capabilities

### Network Security

Secure communication for remote deployments.

**Security Measures:**
- SSH key authentication
- Encrypted data transfer
- Secure keypair handling
- Network connectivity validation

## Configuration Management

### Deployment Configuration

```yaml
deployment:
  # Default settings
  network: "devnet"
  confirmation_commitment: "confirmed"
  max_retries: 3
  retry_delay_ms: 1000
  
  # Buffer settings
  buffer_size_limit: 1048576  # 1MB
  chunk_size: 1000
  use_buffer_threshold: 100000  # 100KB
  
  # Safety settings
  create_backups: true
  verify_deployment: true
  require_confirmation: false
  
  # Performance settings
  parallel_uploads: true
  max_concurrent_chunks: 5
  timeout_seconds: 300
```

### Network-specific Configuration

```yaml
networks:
  devnet:
    rpc_url: "https://api.devnet.solana.com"
    commitment: "confirmed"
    max_program_size: 1000000
    
  testnet:
    rpc_url: "https://api.testnet.solana.com"
    commitment: "finalized"
    max_program_size: 1000000
    
  mainnet:
    rpc_url: "https://api.mainnet-beta.solana.com"
    commitment: "finalized"
    max_program_size: 1000000
    backup_required: true
    confirmation_required: true
```

## Advanced Features

### Deployment Analytics

Track deployment metrics and performance.

**Metrics Collected:**
- Deployment success rates
- Average deployment time
- Network-specific performance
- Error patterns and frequencies
- Resource utilization

### CI/CD Integration

Integration with continuous integration and deployment pipelines.

```yaml
# GitHub Actions example
name: Deploy Program
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    
    - name: Build Program
      run: cargo build-bpf
      
    - name: Deploy to Devnet
      run: |
        osvm deploy-program \
          --program target/deploy/program.so \
          --keypair ${{ secrets.DEPLOY_KEYPAIR }} \
          --network devnet
          
    - name: Verify Deployment
      run: |
        osvm verify-program \
          --program-id ${{ env.PROGRAM_ID }} \
          --network devnet
```

### Batch Deployment

Deploy multiple programs in coordinated batches.

```bash
# Batch deployment configuration
osvm deploy-batch --config batch-config.yaml
```

```yaml
# batch-config.yaml
batch_deployment:
  programs:
    - name: "token_program"
      path: "target/deploy/token.so"
      authority: "token_authority.json"
      
    - name: "nft_program"
      path: "target/deploy/nft.so"
      authority: "nft_authority.json"
      dependencies: ["token_program"]
      
  settings:
    network: "devnet"
    parallel: false
    verify_each: true
```

## Monitoring and Logging

### Deployment Monitoring

Real-time monitoring of deployment progress and status.

```mermaid
flowchart TD
    subgraph "Deployment Monitoring"
        PROGRESS[Progress Tracking]
        STATUS[Status Updates]
        METRICS[Performance Metrics]
        ALERTS[Alert System]
        LOGS[Deployment Logs]
    end
    
    PROGRESS --> STATUS
    STATUS --> METRICS
    METRICS --> ALERTS
    ALERTS --> LOGS
    
    classDef techDebt fill:#f6f6f6,stroke:#d9534f,color:#d9534f,font-family:Consolas,monospace,font-weight:bold
```

**Monitoring Features:**
- Real-time progress updates
- Performance metrics collection
- Error detection and alerting
- Deployment log aggregation
- Success/failure notifications

### Logging Configuration

```yaml
logging:
  level: "info"
  output: "osvm-deployment.log"
  format: "json"
  
  components:
    deployment: "debug"
    validation: "info"
    network: "warn"
    
  retention:
    max_files: 10
    max_size_mb: 100
```

## Troubleshooting

### Common Issues

**Deployment Fails - Insufficient Funds:**
```bash
# Check SOL balance
solana balance

# Get rent estimate
solana program-size target/deploy/program.so

# Fund account if needed
solana airdrop 2  # devnet only
```

**Program Too Large:**
```bash
# Check program size
ls -lh target/deploy/program.so

# Use buffer deployment
osvm deploy-program --use-buffer --program target/deploy/program.so

# Optimize program size
cargo build-bpf --release
```

**Authority Issues:**
```bash
# Verify keypair
solana-keygen verify authority.json

# Check program authority
solana program show <PROGRAM_ID>

# Update authority if needed
solana program set-upgrade-authority <PROGRAM_ID> <NEW_AUTHORITY>
```

**Network Connectivity:**
```bash
# Test network connection
solana cluster-version

# Check RPC endpoint
curl -X POST -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"getHealth"}' \
  https://api.devnet.solana.com

# Switch to different RPC
solana config set --url https://api.devnet.solana.com
```

### Debug Commands

**Deployment Testing:**
```bash
# Dry run deployment
osvm deploy-program --dry-run --program myprogram.so

# Validate program binary
osvm validate-program --program myprogram.so

# Test authority
osvm test-authority --keypair authority.json --program-id <ID>
```

**Network Testing:**
```bash
# Test network connectivity
osvm test-network --network devnet

# Check program deployment limits
osvm network-limits --network devnet

# Verify RPC endpoint
osvm test-rpc --url https://api.devnet.solana.com
```

## Best Practices

### Development Workflow

1. **Testing Strategy**
   - Always test on devnet first
   - Use testnet for staging
   - Deploy to mainnet only after thorough testing

2. **Program Optimization**
   - Optimize program size for deployment
   - Use release builds for production
   - Consider program upgradability

3. **Authority Management**
   - Use separate keypairs for different environments
   - Implement multi-signature for mainnet
   - Regularly rotate authorities

### Production Deployment

1. **Safety Procedures**
   - Create backups before upgrades
   - Implement staged deployments
   - Monitor post-deployment performance

2. **Monitoring Setup**
   - Set up deployment monitoring
   - Configure alerting for failures
   - Track deployment metrics

3. **Emergency Procedures**
   - Prepare rollback procedures
   - Document emergency contacts
   - Test disaster recovery plans

## Related Documentation

- [SSH Deployment]ssh-deployment.md - Remote deployment capabilities
- [Node Management]node-management.md - Node deployment integration
- [Configuration]configuration.md - Deployment configuration
- [Examples]examples.md - Deployment examples and patterns