diff --git a/cmd/soroban-rpc/lib/preflight/src/ledger_storage.rs b/cmd/soroban-rpc/lib/preflight/src/ledger_storage.rs index 2ac3862b8c..3cdacf6bc1 100644 --- a/cmd/soroban-rpc/lib/preflight/src/ledger_storage.rs +++ b/cmd/soroban-rpc/lib/preflight/src/ledger_storage.rs @@ -227,13 +227,22 @@ impl LedgerStorage { impl SnapshotSource for LedgerStorage { fn get(&self, key: &Rc) -> Result<(Rc, Option), HostError> { - let mut entry_and_expiration = - ::get(self, key, self.restore_tracker.is_some())?; + let include_expired = self.restore_tracker.is_some(); + let mut entry_and_expiration = ::get(self, key, include_expired)?; if let Some(ref tracker) = self.restore_tracker { // If the entry expired, we modify the expiration to make it seem like it was restored entry_and_expiration.1 = tracker.track_and_restore(self.current_ledger_sequence, key, &entry_and_expiration); } + if include_expired { + // get(include_expired=true) returns both temporary and persistent expired entries, + // so we need to separately discard any expired temporary entries (which are not restorable) + if let Some(expiration) = entry_and_expiration.1 { + if has_expired(expiration, self.current_ledger_sequence) { + return Err(ScError::Storage(ScErrorCode::MissingValue).into()); + } + } + } Ok((entry_and_expiration.0.into(), entry_and_expiration.1)) }