Skip to content

Commit 322dbfb

Browse files
committed
refactor: reuse slots_diff calculation
1 parent 48690ec commit 322dbfb

File tree

1 file changed

+1
-5
lines changed
  • target_chains/solana/programs/pyth-solana-receiver/src

1 file changed

+1
-5
lines changed

target_chains/solana/programs/pyth-solana-receiver/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,18 +575,14 @@ fn calculate_twap(start_msg: &TwapMessage, end_msg: &TwapMessage) -> Result<(i64
575575

576576
// Calculate down_slots_ratio as an integer between 0 and 1_000_000
577577
// A value of 1_000_000 means all slots were missed and 0 means no slots were missed.
578-
let total_slots = end_msg
579-
.publish_slot
580-
.checked_sub(start_msg.publish_slot)
581-
.ok_or(ReceiverError::TwapCalculationOverflow)?;
582578
let total_down_slots = end_msg
583579
.num_down_slots
584580
.checked_sub(start_msg.num_down_slots)
585581
.ok_or(ReceiverError::TwapCalculationOverflow)?;
586582
let down_slots_ratio = total_down_slots
587583
.checked_mul(1_000_000)
588584
.ok_or(ReceiverError::TwapCalculationOverflow)?
589-
.checked_div(total_slots)
585+
.checked_div(slot_diff)
590586
.ok_or(ReceiverError::TwapCalculationOverflow)?;
591587
// down_slots_ratio is a number in [0, 1_000_000], so we only need 32 unsigned bits
592588
let down_slots_ratio =

0 commit comments

Comments
 (0)