mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
paranoid underflow protection without error handling (#14044)
Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
This commit is contained in:
@@ -124,6 +124,14 @@ func (s Slot) SubSlot(x Slot) Slot {
|
||||
return s.Sub(uint64(x))
|
||||
}
|
||||
|
||||
// FlooredSubSlot safely subtracts x from the slot, returning 0 if the result would underflow.
|
||||
func (s Slot) FlooredSubSlot(x Slot) Slot {
|
||||
if s < x {
|
||||
return 0
|
||||
}
|
||||
return s - x
|
||||
}
|
||||
|
||||
// SafeSubSlot finds difference between two slot values.
|
||||
// In case of arithmetic issues (overflow/underflow/div by zero) error is returned.
|
||||
func (s Slot) SafeSubSlot(x Slot) (Slot, error) {
|
||||
|
||||
Reference in New Issue
Block a user