agg pub slot was recent even if price was not updated, switch to last slot which seems more relevant (#393)

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2023-01-17 14:48:06 +01:00 committed by GitHub
parent 9346c8e546
commit be15f54225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 8 deletions

View File

@ -167,22 +167,19 @@ pub fn oracle_price(
return Err(MangoError::OracleConfidence.into()); return Err(MangoError::OracleConfidence.into());
} }
// The aggregation pub slot is the time that the aggregate was computed from published data // The last_slot is when the price was actually updated
// that was at most 25 slots old. That means it underestimates the actual staleness, potentially let last_slot = price_account.last_slot;
// significantly.
let agg_pub_slot = price_account.agg.pub_slot;
if config.max_staleness_slots >= 0 if config.max_staleness_slots >= 0
&& price_account && price_account
.agg .last_slot
.pub_slot
.saturating_add(config.max_staleness_slots as u64) .saturating_add(config.max_staleness_slots as u64)
< staleness_slot < staleness_slot
{ {
msg!( msg!(
"Pyth price too stale; pubkey {} price: {} pub slot: {}", "Pyth price too stale; pubkey {} price: {} last slot: {}",
acc_info.key(), acc_info.key(),
price.to_num::<f64>(), price.to_num::<f64>(),
agg_pub_slot, last_slot,
); );
return Err(MangoError::OracleStale.into()); return Err(MangoError::OracleStale.into());