Skip to content

Commit 712b897

Browse files
committed
fix: remove tolerance in window size check
1 parent 2c6359c commit 712b897

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

target_chains/solana/pyth_solana_receiver_sdk/src/price_update.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ impl TwapUpdate {
103103
Ok(self.twap)
104104
}
105105
/// Get a `TwapPrice` from a `TwapUpdate` account for a given `FeedId` no older than `maximum_age` with a specific window size.
106-
/// The window size check includes a tolerance of ±1 second to account for Solana block time variations.
107106
///
108107
/// # Example
109108
/// ```
@@ -148,11 +147,9 @@ impl TwapUpdate {
148147
);
149148

150149
// Ensure the twap window size is as expected
151-
// Allow for +/- 1 second tolerance to account for the imprecision introduced by Solana block times
152-
const TOLERANCE: i64 = 1;
153150
let actual_window = twap_price.end_time.saturating_sub(twap_price.start_time);
154151
check!(
155-
(actual_window - i64::try_from(window_seconds).unwrap()).abs() <= TOLERANCE,
152+
actual_window == i64::try_from(window_seconds).unwrap(),
156153
GetPriceError::InvalidWindowSize
157154
);
158155

@@ -594,27 +591,15 @@ pub mod tests {
594591
Ok(expected_twap)
595592
);
596593

597-
// Test with window size within tolerance (+1 second)
594+
// Test with incorrect window size
598595
assert_eq!(
599596
update.get_twap_no_older_than(&mock_clock, 100, 101, &feed_id),
600-
Ok(expected_twap)
601-
);
602-
603-
// Test with window size within tolerance (-1 second)
604-
assert_eq!(
605-
update.get_twap_no_older_than(&mock_clock, 100, 99, &feed_id),
606-
Ok(expected_twap)
607-
);
608-
609-
// Test with incorrect window size (outside tolerance)
610-
assert_eq!(
611-
update.get_twap_no_older_than(&mock_clock, 100, 103, &feed_id),
612597
Err(GetPriceError::InvalidWindowSize)
613598
);
614599

615-
// Test with incorrect window size (outside tolerance)
600+
// Test with incorrect window size
616601
assert_eq!(
617-
update.get_twap_no_older_than(&mock_clock, 100, 97, &feed_id),
602+
update.get_twap_no_older_than(&mock_clock, 100, 99, &feed_id),
618603
Err(GetPriceError::InvalidWindowSize)
619604
);
620605

0 commit comments

Comments
 (0)