cuprate_pruning

Struct DecompressedPruningSeed

Source
pub struct DecompressedPruningSeed { /* private fields */ }
Expand description

This represents a valid Monero pruning seed.

It does allow representations of pruning seeds that Monero’s P2P network would not allow, i.e. it does not restrict the seed to only have a log_stripes of 8.

Implementations§

Source§

impl DecompressedPruningSeed

Source

pub const fn new(stripe: u32, log_stripes: u32) -> Result<Self, PruningError>

Creates a new pruning seed from a stripe and log_stripes

§What is a stripe

A stripe is the part of the blockchain this peer will keep.

Monero, when pruning, will split the blockchain into multiple “stripes”, that amount is currently 8 and each pruned peer will keep one of those 8 stripes.

§What is log_stripes

log_stripes is log2 of the amount of stripes used.

For Monero, currently, that amount is 8 so log_stripes will be 3.


note this function allows you to make invalid seeds, this is done to allow the specifics of pruning to change in the future. To make a valid seed you currently MUST pass in a number 1 to 8 for stripe and 3 for log_stripes.

Source

pub const fn decompress(seed: u32) -> Result<Option<Self>, PruningError>

Attempts to decompress a raw pruning seed.

Will return Ok(None) if the pruning seed means no pruning.

An error means the pruning seed was invalid.

Source

pub const fn compress(&self) -> u32

Compresses the pruning seed into a u32.

Source

pub const fn has_full_block( &self, height: usize, blockchain_height: usize, ) -> bool

Returns true if a peer with this pruning seed should have a non-pruned version of a block.

Source

pub fn get_next_unpruned_block( &self, block_height: usize, blockchain_height: usize, ) -> Result<usize, PruningError>

Gets the next unpruned block for a given block_height and blockchain_height

Each seed will store, in a cyclic manner, a portion of blocks while discarding the ones that are out of your stripe. This function is finding the next height for which a specific seed will start storing blocks.

§Errors

This function will return an Error if the inputted block_height or blockchain_height is greater than MAX_BLOCK_HEIGHT_USIZE.

This function will also error if block_height > blockchain_height

Source

pub fn get_next_pruned_block( &self, block_height: usize, blockchain_height: usize, ) -> Result<Option<usize>, PruningError>

Gets the next pruned block for a given block_height and blockchain_height

Each seed will store, in a cyclic manner, a portion of blocks while discarding the ones that are out of your stripe. This function is finding the next height for which a specific seed will start pruning blocks.

§Errors

This function will return an Error if the inputted block_height or blockchain_height is greater than MAX_BLOCK_HEIGHT_USIZE.

This function will also error if block_height > blockchain_height

Trait Implementations§

Source§

impl BorshDeserialize for DecompressedPruningSeed

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for DecompressedPruningSeed

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl Clone for DecompressedPruningSeed

Source§

fn clone(&self) -> DecompressedPruningSeed

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DecompressedPruningSeed

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for DecompressedPruningSeed

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for DecompressedPruningSeed

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for DecompressedPruningSeed

Source§

fn eq(&self, other: &DecompressedPruningSeed) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for DecompressedPruningSeed

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for DecompressedPruningSeed

Source§

impl Eq for DecompressedPruningSeed

Source§

impl StructuralPartialEq for DecompressedPruningSeed

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 8 bytes