Skip to content

Commit

Permalink
soroban-rpc: preflight: Exclude temporary expired entries from Snapsh…
Browse files Browse the repository at this point in the history
…otSource
  • Loading branch information
2opremio committed Sep 20, 2023
1 parent 1c49aed commit 8765760
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/soroban-rpc/lib/preflight/src/ledger_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,22 @@ impl LedgerStorage {

impl SnapshotSource for LedgerStorage {
fn get(&self, key: &Rc<LedgerKey>) -> Result<(Rc<LedgerEntry>, Option<u32>), HostError> {
let mut entry_and_expiration =
<LedgerStorage>::get(self, key, self.restore_tracker.is_some())?;
let include_expired = self.restore_tracker.is_some();
let mut entry_and_expiration = <LedgerStorage>::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))
}

Expand Down

0 comments on commit 8765760

Please sign in to comment.