solana-recover 1.1.3

A comprehensive Solana wallet recovery and account management tool
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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
//! Error Recovery System with Circuit Breaker Pattern
//! 
//! This module provides comprehensive error recovery mechanisms including circuit breakers,
//! retry policies, fallback strategies, and graceful degradation.

use crate::core::{Result, SolanaRecoverError};
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::RwLock;
use tracing::{info, warn, error};
use serde::{Deserialize, Serialize};
use async_trait::async_trait;

/// Circuit breaker states
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CircuitState {
    /// Circuit is closed and allowing requests
    Closed,
    /// Circuit is open and rejecting requests
    Open,
    /// Circuit is half-open and testing requests
    HalfOpen,
}

/// Circuit breaker configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CircuitBreakerConfig {
    /// Number of failures before opening the circuit
    pub failure_threshold: usize,
    
    /// Time to wait before transitioning from Open to HalfOpen
    pub recovery_timeout: Duration,
    
    /// Number of successful requests in HalfOpen before closing
    pub success_threshold: usize,
    
    /// Percentage of requests that can fail before opening
    pub failure_rate_threshold: f64,
    
    /// Minimum number of requests before considering failure rate
    pub minimum_requests: usize,
    
    /// Time window for tracking requests
    pub sliding_window_size: Duration,
}

impl Default for CircuitBreakerConfig {
    fn default() -> Self {
        Self {
            failure_threshold: 5,
            recovery_timeout: Duration::from_secs(60),
            success_threshold: 3,
            failure_rate_threshold: 0.5,
            minimum_requests: 10,
            sliding_window_size: Duration::from_secs(300), // 5 minutes
        }
    }
}

/// Request tracking for circuit breaker
#[derive(Debug, Clone)]
struct RequestRecord {
    timestamp: Instant,
    success: bool,
}

/// Circuit breaker implementation
pub struct CircuitBreaker {
    config: CircuitBreakerConfig,
    state: Arc<RwLock<CircuitState>>,
    failure_count: Arc<RwLock<usize>>,
    success_count: Arc<RwLock<usize>>,
    last_failure_time: Arc<RwLock<Option<Instant>>>,
    request_history: Arc<RwLock<Vec<RequestRecord>>>,
}

impl CircuitBreaker {
    /// Create a new circuit breaker with default configuration
    pub fn new() -> Self {
        Self::with_config(CircuitBreakerConfig::default())
    }
    
    /// Create a new circuit breaker with custom configuration
    pub fn with_config(config: CircuitBreakerConfig) -> Self {
        Self {
            config,
            state: Arc::new(RwLock::new(CircuitState::Closed)),
            failure_count: Arc::new(RwLock::new(0)),
            success_count: Arc::new(RwLock::new(0)),
            last_failure_time: Arc::new(RwLock::new(None)),
            request_history: Arc::new(RwLock::new(Vec::new())),
        }
    }
    
    /// Execute an operation with circuit breaker protection
    pub async fn execute<F, T, Fut>(&self, operation: F) -> Result<T>
    where
        F: FnOnce() -> Fut,
        Fut: std::future::Future<Output = Result<T>>,
    {
        // Check if circuit allows the request
        if !self.can_execute().await {
            return Err(SolanaRecoverError::CircuitBreakerOpen(
                "Circuit breaker is open, rejecting request".to_string()
            ));
        }
        
        // Execute the operation
        let result = operation().await;
        
        // Record the result
        self.record_result(result.is_ok()).await;
        
        result
    }
    
    /// Check if the circuit breaker allows requests
    async fn can_execute(&self) -> bool {
        let state = self.state.read().await;
        
        match *state {
            CircuitState::Closed => true,
            CircuitState::Open => {
                // Check if recovery timeout has passed
                let last_failure = self.last_failure_time.read().await;
                if let Some(failure_time) = *last_failure {
                    failure_time.elapsed() >= self.config.recovery_timeout
                } else {
                    true
                }
            }
            CircuitState::HalfOpen => true,
        }
    }
    
    /// Record the result of an operation
    async fn record_result(&self, success: bool) {
        let now = Instant::now();
        
        // Record the request
        {
            let mut history = self.request_history.write().await;
            history.push(RequestRecord { timestamp: now, success });
            
            // Clean old records outside the sliding window
            let cutoff = now - self.config.sliding_window_size;
            history.retain(|record| record.timestamp >= cutoff);
        }
        
        // Update counters and state
        if success {
            self.record_success().await;
        } else {
            self.record_failure().await;
        }
    }
    
    async fn record_success(&self) {
        {
            let mut success_count = self.success_count.write().await;
            *success_count += 1;
        }
        
        let mut state = self.state.write().await;
        match *state {
            CircuitState::HalfOpen => {
                // Check if we've reached success threshold
                let success_count = *self.success_count.read().await;
                if success_count >= self.config.success_threshold {
                    info!("Circuit breaker closing after {} successful requests", success_count);
                    *state = CircuitState::Closed;
                    self.reset_counters().await;
                }
            }
            CircuitState::Closed => {
                // Reset failure count on success
                let mut failure_count = self.failure_count.write().await;
                *failure_count = 0;
            }
            _ => {}
        }
    }
    
    async fn record_failure(&self) {
        {
            let mut failure_count = self.failure_count.write().await;
            *failure_count += 1;
        }
        
        {
            let mut last_failure = self.last_failure_time.write().await;
            *last_failure = Some(Instant::now());
        }
        
        let mut state = self.state.write().await;
        match *state {
            CircuitState::Closed => {
                if self.should_open_circuit().await {
                    warn!("Circuit breaker opening after {} failures", *self.failure_count.read().await);
                    *state = CircuitState::Open;
                }
            }
            CircuitState::HalfOpen => {
                // Any failure in half-open state opens the circuit again
                warn!("Circuit breaker opening again due to failure in half-open state");
                *state = CircuitState::Open;
            }
            _ => {}
        }
    }
    
    async fn should_open_circuit(&self) -> bool {
        let failure_count = *self.failure_count.read().await;
        
        // Check absolute failure threshold
        if failure_count >= self.config.failure_threshold {
            return true;
        }
        
        // Check failure rate threshold
        let history = self.request_history.read().await;
        if history.len() >= self.config.minimum_requests {
            let failure_rate = history.iter()
                .filter(|record| !record.success)
                .count() as f64 / history.len() as f64;
            
            if failure_rate >= self.config.failure_rate_threshold {
                return true;
            }
        }
        
        false
    }
    
    async fn reset_counters(&self) {
        let mut failure_count = self.failure_count.write().await;
        let mut success_count = self.success_count.write().await;
        *failure_count = 0;
        *success_count = 0;
    }
    
    /// Get the current circuit state
    pub async fn get_state(&self) -> CircuitState {
        self.state.read().await.clone()
    }
    
    /// Force the circuit to open
    pub async fn force_open(&self) {
        let mut state = self.state.write().await;
        *state = CircuitState::Open;
        info!("Circuit breaker forced open");
    }
    
    /// Force the circuit to close
    pub async fn force_close(&self) {
        let mut state = self.state.write().await;
        *state = CircuitState::Closed;
        self.reset_counters().await;
        info!("Circuit breaker forced closed");
    }
}

/// Retry policy configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RetryPolicy {
    /// Maximum number of retry attempts
    pub max_attempts: usize,
    
    /// Base delay between retries
    pub base_delay: Duration,
    
    /// Maximum delay between retries
    pub max_delay: Duration,
    
    /// Backoff multiplier (for exponential backoff)
    pub backoff_multiplier: f64,
    
    /// Jitter factor to add randomness
    pub jitter_factor: f64,
    
    /// Retryable error types
    pub retryable_errors: Vec<String>,
}

impl Default for RetryPolicy {
    fn default() -> Self {
        Self {
            max_attempts: 3,
            base_delay: Duration::from_millis(100),
            max_delay: Duration::from_secs(30),
            backoff_multiplier: 2.0,
            jitter_factor: 0.1,
            retryable_errors: vec![
                "timeout".to_string(),
                "network".to_string(),
                "rate_limit".to_string(),
                "temporary".to_string(),
            ],
        }
    }
}

impl RetryPolicy {
    /// Calculate delay for the given attempt number
    pub fn calculate_delay(&self, attempt: usize) -> Duration {
        let multiplier = self.backoff_multiplier.powi(attempt as i32 - 1);
        let exponential_delay_ms = self.base_delay.as_millis() as f64 * multiplier;
        let delay_ms = exponential_delay_ms.min(self.max_delay.as_millis() as f64);
        
        // Add jitter
        let jitter = delay_ms * self.jitter_factor;
        let jitter_delay_ms = delay_ms + jitter;
        
        Duration::from_millis(jitter_delay_ms as u64)
    }
    
    /// Check if an error is retryable
    pub fn is_retryable(&self, error: &SolanaRecoverError) -> bool {
        let error_string = format!("{:?}", error).to_lowercase();
        
        self.retryable_errors.iter().any(|retryable_error| {
            error_string.contains(&retryable_error.to_lowercase())
        })
    }
}

/// Retry mechanism with exponential backoff
pub struct RetryMechanism {
    policy: RetryPolicy,
}

impl RetryMechanism {
    pub fn new(policy: RetryPolicy) -> Self {
        Self { policy }
    }
    
    pub fn with_default_policy() -> Self {
        Self::new(RetryPolicy::default())
    }
    
    /// Execute an operation with retry logic
    pub async fn execute<F, T, Fut>(&self, mut operation: F) -> Result<T>
    where
        F: FnMut() -> Fut,
        Fut: std::future::Future<Output = Result<T>>,
    {
        let mut last_error = None;
        
        for attempt in 1..=self.policy.max_attempts {
            match operation().await {
                Ok(result) => {
                    if attempt > 1 {
                        info!("Operation succeeded on attempt {}", attempt);
                    }
                    return Ok(result);
                }
                Err(error) => {
                    last_error = Some(error.clone());
                    
                    if attempt == self.policy.max_attempts {
                        error!("Operation failed after {} attempts", attempt);
                        break;
                    }
                    
                    if !self.policy.is_retryable(&error) {
                        warn!("Error is not retryable: {:?}", error);
                        break;
                    }
                    
                    let delay = self.policy.calculate_delay(attempt);
                    warn!("Attempt {} failed, retrying in {:?}: {:?}", attempt, delay, error);
                    tokio::time::sleep(delay).await;
                }
            }
        }
        
        Err(last_error.unwrap_or_else(|| {
            SolanaRecoverError::InternalError("Operation failed with no error recorded".to_string())
        }))
    }
}

/// Fallback strategy trait
#[async_trait]
pub trait FallbackStrategy: Send + Sync {
    async fn execute_fallback(&self, wallet_address: &str) -> Result<crate::core::WalletInfo>;
    fn name(&self) -> &str;
}

/// Simple RPC fallback strategy
pub struct SimpleRpcFallback {
    rpc_endpoint: String,
}

impl SimpleRpcFallback {
    pub fn new(rpc_endpoint: String) -> Self {
        Self { rpc_endpoint }
    }
}

#[async_trait]
impl FallbackStrategy for SimpleRpcFallback {
    async fn execute_fallback(&self, wallet_address: &str) -> Result<crate::core::WalletInfo> {
        use crate::core::scanner::WalletScanner;
        use crate::rpc::ConnectionPool;
        use crate::core::types::RpcEndpoint;
        use std::sync::Arc;
        
        info!("Executing simple RPC fallback for wallet: {}", wallet_address);
        
        // Create a simple connection pool with fallback endpoint
        let rpc_endpoint = RpcEndpoint {
            url: self.rpc_endpoint.clone(),
            priority: 1,
            rate_limit_rps: 50, // Conservative rate limit for fallback
            timeout_ms: 60000,  // Longer timeout for fallback
            healthy: true,
        };
        
        let connection_pool = Arc::new(ConnectionPool::new(vec![rpc_endpoint], 2));
        let scanner = WalletScanner::new(connection_pool);
        
        // Perform simple scan
        let scan_result = scanner.scan_wallet(wallet_address).await?;
        
        scan_result.result.ok_or_else(|| {
            SolanaRecoverError::InternalError("Fallback scan returned empty result".to_string())
        })
    }
    
    fn name(&self) -> &str {
        "SimpleRpcFallback"
    }
}

/// Cache-only fallback strategy
pub struct CacheOnlyFallback {
    cache: Arc<dyn crate::utils::cache::CacheTrait>,
}

impl CacheOnlyFallback {
    pub fn new(cache: Arc<dyn crate::utils::cache::CacheTrait>) -> Self {
        Self { cache }
    }
}

#[async_trait]
impl FallbackStrategy for CacheOnlyFallback {
    async fn execute_fallback(&self, wallet_address: &str) -> Result<crate::core::WalletInfo> {
        info!("Executing cache-only fallback for wallet: {}", wallet_address);
        
        // Try to get cached result
        let cache_key = format!("wallet_scan:{}", wallet_address);
        if let Some(cached_data) = self.cache.get(&cache_key).await? {
            // Try to deserialize cached wallet info
            if let Ok(wallet_info) = bincode::deserialize::<crate::core::WalletInfo>(&cached_data) {
                info!("Found cached result for wallet: {}", wallet_address);
                return Ok(wallet_info);
            }
        }
        
        Err(SolanaRecoverError::InternalError(
            "No cached data found for wallet".to_string()
        ))
    }
    
    fn name(&self) -> &str {
        "CacheOnlyFallback"
    }
}

/// Minimal fallback strategy
pub struct MinimalFallback;

impl MinimalFallback {
    pub fn new() -> Self {
        Self
    }
}

#[async_trait]
impl FallbackStrategy for MinimalFallback {
    async fn execute_fallback(&self, wallet_address: &str) -> Result<crate::core::WalletInfo> {
        use solana_sdk::pubkey::Pubkey;
        use std::str::FromStr;
        
        info!("Executing minimal fallback for wallet: {}", wallet_address);
        
        // Very minimal scan - just validate the address and return empty result
        let _pubkey = Pubkey::from_str(wallet_address)
            .map_err(|_| SolanaRecoverError::InvalidWalletAddress(wallet_address.to_string()))?;
        
        // Return minimal wallet info with no accounts found
        let wallet_info = crate::core::WalletInfo {
            address: wallet_address.to_string(),
            pubkey: _pubkey,
            total_accounts: 0,
            empty_accounts: 0,
            recoverable_lamports: 0,
            recoverable_sol: 0.0,
            empty_account_addresses: vec![],
            scan_time_ms: 0,
        };
        
        Ok(wallet_info)
    }
    
    fn name(&self) -> &str {
        "MinimalFallback"
    }
}

/// Resilient scanner with error recovery
pub struct ResilientScanner {
    primary_scanner: Arc<dyn crate::core::unified_scanner::ScanStrategy>,
    circuit_breaker: CircuitBreaker,
    retry_mechanism: RetryMechanism,
    fallback_strategies: Vec<Arc<dyn FallbackStrategy>>,
    // Store context for fallback operations
    connection_pool: Option<Arc<dyn crate::rpc::ConnectionPoolTrait>>,
    config: Option<crate::core::unified_scanner::UnifiedScannerConfig>,
}

impl ResilientScanner {
    pub fn new(
        primary_scanner: Arc<dyn crate::core::unified_scanner::ScanStrategy>,
        circuit_breaker_config: CircuitBreakerConfig,
        retry_policy: RetryPolicy,
    ) -> Self {
        Self {
            primary_scanner,
            circuit_breaker: CircuitBreaker::with_config(circuit_breaker_config),
            retry_mechanism: RetryMechanism::new(retry_policy),
            fallback_strategies: Vec::new(),
            connection_pool: None,
            config: None,
        }
    }
    
    pub fn with_context(
        primary_scanner: Arc<dyn crate::core::unified_scanner::ScanStrategy>,
        circuit_breaker_config: CircuitBreakerConfig,
        retry_policy: RetryPolicy,
        connection_pool: Arc<dyn crate::rpc::ConnectionPoolTrait>,
        config: crate::core::unified_scanner::UnifiedScannerConfig,
    ) -> Self {
        Self {
            primary_scanner,
            circuit_breaker: CircuitBreaker::with_config(circuit_breaker_config),
            retry_mechanism: RetryMechanism::new(retry_policy),
            fallback_strategies: Vec::new(),
            connection_pool: Some(connection_pool),
            config: Some(config),
        }
    }
    
    pub fn add_fallback_strategy(mut self, strategy: Arc<dyn FallbackStrategy>) -> Self {
        self.fallback_strategies.push(strategy);
        self
    }
    
    /// Create a resilient scanner with default fallback strategies
    pub fn with_defaults(
        primary_scanner: Arc<dyn crate::core::unified_scanner::ScanStrategy>,
    ) -> Self {
        let circuit_breaker_config = CircuitBreakerConfig::default();
        let retry_policy = RetryPolicy::default();
        
        let mut scanner = Self::new(primary_scanner, circuit_breaker_config, retry_policy);
        
        // Add default fallback strategies
        scanner = scanner.add_fallback_strategy(Arc::new(SimpleRpcFallback::new(
            "https://api.mainnet-beta.solana.com".to_string()
        )));
        scanner = scanner.add_fallback_strategy(Arc::new(MinimalFallback::new()));
        
        scanner
    }
    
    /// Scan a wallet with full error recovery
    pub async fn scan_wallet(&self, wallet_address: &str) -> Result<crate::core::WalletInfo> {
        // Try primary scanner with circuit breaker and retry
        let result = self.circuit_breaker.execute(|| async {
            self.retry_mechanism.execute(|| async {
                // Create context from stored values or use defaults
                let context = crate::core::unified_scanner::ScanContext {
                    connection_pool: self.connection_pool.clone()
                        .ok_or_else(|| SolanaRecoverError::InternalError(
                            "No connection pool available for resilient scanner".to_string()
                        ))?,
                    config: self.config.clone()
                        .ok_or_else(|| SolanaRecoverError::InternalError(
                            "No config available for resilient scanner".to_string()
                        ))?,
                    cache: None,
                    metrics: None,
                };
                
                let scan_result = self.primary_scanner.scan_wallet(wallet_address, &context).await?;
                scan_result.result.ok_or_else(|| {
                    SolanaRecoverError::InternalError("Scan result is empty".to_string())
                })
            }).await
        }).await;
        
        // If primary scanner fails, try fallback strategies
        if let Err(error) = result {
            warn!("Primary scanner failed for wallet {}: {:?}", wallet_address, error);
            
            for fallback in &self.fallback_strategies {
                info!("Trying fallback strategy: {}", fallback.name());
                match fallback.execute_fallback(wallet_address).await {
                    Ok(result) => {
                        info!("Fallback strategy {} succeeded", fallback.name());
                        return Ok(result);
                    }
                    Err(fallback_error) => {
                        warn!("Fallback strategy {} failed: {:?}", fallback.name(), fallback_error);
                    }
                }
            }
            
            // All strategies failed
            Err(error)
        } else {
            result
        }
    }
    
    /// Get circuit breaker state
    pub async fn circuit_breaker_state(&self) -> CircuitState {
        self.circuit_breaker.get_state().await
    }
    
    /// Force circuit breaker to open
    pub async fn force_circuit_breaker_open(&self) {
        self.circuit_breaker.force_open().await;
    }
    
    /// Force circuit breaker to close
    pub async fn force_circuit_breaker_close(&self) {
        self.circuit_breaker.force_close().await;
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    
    #[test]
    fn test_circuit_breaker_config_default() {
        let config = CircuitBreakerConfig::default();
        assert_eq!(config.failure_threshold, 5);
        assert_eq!(config.recovery_timeout, Duration::from_secs(60));
    }
    
    #[test]
    fn test_retry_policy_delay_calculation() {
        let policy = RetryPolicy {
            max_attempts: 3,
            base_delay: Duration::from_millis(100),
            max_delay: Duration::from_secs(10),
            backoff_multiplier: 2.0,
            jitter_factor: 0.0,
            retryable_errors: vec!["timeout".to_string()],
        };
        
        let delay1 = policy.calculate_delay(1);
        let delay2 = policy.calculate_delay(2);
        let delay3 = policy.calculate_delay(3);
        
        assert_eq!(delay1, Duration::from_millis(100));
        assert_eq!(delay2, Duration::from_millis(200));
        assert_eq!(delay3, Duration::from_millis(400));
    }
    
    #[tokio::test]
    async fn test_circuit_breaker_state_transitions() {
        let circuit_breaker = CircuitBreaker::new();
        
        // Initial state should be closed
        assert_eq!(circuit_breaker.get_state().await, CircuitState::Closed);
        
        // Force open
        circuit_breaker.force_open().await;
        assert_eq!(circuit_breaker.get_state().await, CircuitState::Open);
        
        // Force close
        circuit_breaker.force_close().await;
        assert_eq!(circuit_breaker.get_state().await, CircuitState::Closed);
    }
    
    #[tokio::test]
    async fn test_retry_mechanism_success() {
        let retry = RetryMechanism::with_default_policy();
        let call_count = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
        
        let result = retry.execute(|| {
            let count = call_count.clone();
            async move {
                let current = count.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
                if current < 1 {
                    Err(SolanaRecoverError::InternalError("temporary".to_string()))
                } else {
                    Ok("success")
                }
            }
        }).await;
        
        assert!(result.is_ok());
        assert_eq!(result.unwrap(), "success");
        assert_eq!(call_count.load(std::sync::atomic::Ordering::SeqCst), 2);
    }
}