pub struct RoundingError(/* private fields */);Expand description
This type defines a rounding error to use when fetching the current slot from Solana using the JSON-RPC interface, meaning slots will be rounded down to the nearest multiple of this error when being fetched.
This is done to achieve consensus on the HTTP outcalls whose responses contain Solana slots
despite Solana’s fast blocktime and hence fast-changing slot value. However, this solution
does not guarantee consensus on the slot value across nodes and different consensus rates
will be achieved depending on the rounding error value used. A higher rounding error will
lead to a higher consensus rate, but also means the slot value may differ more from the actual
value on the Solana blockchain. This means, for example, that setting a large rounding error
and then fetching the corresponding block with the Solana
getBlock RPC method can result in obtaining a
block whose hash is too old to use in a valid Solana transaction (see more details about using
recent blockhashes here.
The default value given by RoundingError::default
has been experimentally shown to achieve a high HTTP outcall consensus rate.
See the RoundingError::round method for more details and examples.
Implementations§
Source§impl RoundingError
impl RoundingError
Sourcepub fn new(rounding_error: u64) -> Self
pub fn new(rounding_error: u64) -> Self
Create a new instance of RoundingError with the given value.
Sourcepub fn round(&self, slot: u64) -> u64
pub fn round(&self, slot: u64) -> u64
Round the given value down to the nearest multiple of the rounding error. A rounding error of 0 or 1 leads to this method returning the input unchanged.
§Examples
use sol_rpc_types::RoundingError;
assert_eq!(RoundingError::new(0).round(19), 19);
assert_eq!(RoundingError::new(1).round(19), 19);
assert_eq!(RoundingError::new(10).round(19), 10);
assert_eq!(RoundingError::new(20).round(19), 0);Trait Implementations§
Source§impl AsRef<u64> for RoundingError
impl AsRef<u64> for RoundingError
Source§impl CandidType for RoundingError
impl CandidType for RoundingError
Source§impl Clone for RoundingError
impl Clone for RoundingError
Source§fn clone(&self) -> RoundingError
fn clone(&self) -> RoundingError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RoundingError
impl Debug for RoundingError
Source§impl Default for RoundingError
impl Default for RoundingError
Source§impl<'de> Deserialize<'de> for RoundingError
impl<'de> Deserialize<'de> for RoundingError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<RoundingError> for u64
impl From<RoundingError> for u64
Source§fn from(value: RoundingError) -> Self
fn from(value: RoundingError) -> Self
Source§impl From<u64> for RoundingError
impl From<u64> for RoundingError
Source§impl Ord for RoundingError
impl Ord for RoundingError
Source§fn cmp(&self, other: &RoundingError) -> Ordering
fn cmp(&self, other: &RoundingError) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for RoundingError
impl PartialEq for RoundingError
Source§impl PartialOrd for RoundingError
impl PartialOrd for RoundingError
Source§impl Serialize for RoundingError
impl Serialize for RoundingError
impl Copy for RoundingError
impl Eq for RoundingError
impl StructuralPartialEq for RoundingError
Auto Trait Implementations§
impl Freeze for RoundingError
impl RefUnwindSafe for RoundingError
impl Send for RoundingError
impl Sync for RoundingError
impl Unpin for RoundingError
impl UnwindSafe for RoundingError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more