Struct massa_pos_exports::PoSFinalState

source ·
pub struct PoSFinalState {
    pub config: PoSConfig,
    pub db: ShareableMassaDBController,
    pub cycle_history_cache: VecDeque<(u64, bool)>,
    pub rng_seed_cache: Option<(u64, BitVec<u8>)>,
    pub selector: Box<dyn SelectorController>,
    pub initial_rolls: BTreeMap<Address, u64>,
    pub initial_seeds: Vec<Hash>,
    pub deferred_credits_serializer: DeferredCreditsSerializer,
    pub deferred_credits_deserializer: DeferredCreditsDeserializer,
    pub cycle_info_serializer: CycleHistorySerializer,
    pub cycle_info_deserializer: CycleHistoryDeserializer,
}
Expand description

Final state of PoS

Fields§

§config: PoSConfig

proof-of-stake configuration

§db: ShareableMassaDBController

Access to the RocksDB database

§cycle_history_cache: VecDeque<(u64, bool)>

contiguous cycle history, back = newest

§rng_seed_cache: Option<(u64, BitVec<u8>)>

rng_seed cache to get rng_seed for the current cycle

§selector: Box<dyn SelectorController>

selector controller

§initial_rolls: BTreeMap<Address, u64>

initial rolls, used for negative cycle look back

§initial_seeds: Vec<Hash>

initial seeds, used for negative cycle look back (cycles -2, -1 in that order)

§deferred_credits_serializer: DeferredCreditsSerializer

deferred credits serializer

§deferred_credits_deserializer: DeferredCreditsDeserializer

deferred credits deserializer

§cycle_info_serializer: CycleHistorySerializer

cycle info serializer

§cycle_info_deserializer: CycleHistoryDeserializer

cycle info deserializer

Implementations§

source§

impl PoSFinalState

source

pub fn new( config: PoSConfig, initial_seed_string: &str, initial_rolls_path: &PathBuf, selector: Box<dyn SelectorController>, db: ShareableMassaDBController, ) -> Result<Self, PosError>

create a new PoSFinalState

source

pub fn load_initial_deferred_credits( &mut self, batch: &mut DBBatch, ) -> Result<(), PosError>

Try load initial deferred credits from file

source

pub fn recompute_pos_state_caches(&mut self)

After bootstrap or load from disk, recompute the caches

source

pub fn reset(&mut self)

Reset the state of the PoS final state

USED ONLY FOR BOOTSTRAP

source

pub fn create_initial_cycle(&mut self, batch: &mut DBBatch)

Create the initial cycle based off the initial rolls.

This should be called only if bootstrap did not happen.

source

pub fn create_new_cycle_from_last( &mut self, last_cycle_info: &CycleInfo, first_slot: Slot, last_slot: Slot, batch: &mut DBBatch, ) -> Result<(), PosError>

Create the a cycle based off of another cycle_info.

Used for downtime interpolation, when restarting from a snapshot.

source

pub fn delete_cycle_info(&mut self, cycle: u64, batch: &mut DBBatch)

Deletes a given cycle from RocksDB

source

pub fn compute_initial_draws(&mut self) -> PosResult<()>

Sends the current draw inputs (initial or bootstrapped) to the selector. Waits for the initial draws to be performed.

source

pub fn apply_changes_to_batch( &mut self, changes: PoSChanges, slot: Slot, feed_selector: bool, batch: &mut DBBatch, ) -> PosResult<()>

Technical specification of apply_changes_to_batch:

set self.last_final_slot = C if cycle C is absent from self.cycle_history_cache: push a new empty CycleInfo on disk and reflect in self.cycle_history_cache and set its cycle = C pop_front from cycle_history_cache until front() represents cycle C-4 or later (not C-3 because we might need older endorsement draws on the limit between 2 cycles) delete the removed cycles from disk for the cycle C entry in the db: extend seed_bits with changes.seed_bits extend roll_counts with changes.roll_changes delete all entries from roll_counts for which the roll count is zero add each element of changes.production_stats to the cycle’s production_stats for each changes.deferred_credits targeting cycle Ct: overwrite self.deferred_credits entries of cycle Ct in cycle_history with the ones from change remove entries for which Amount = 0 if slot S was the last of cycle C: set complete=true for cycle C in the history compute the seed hash and notifies the PoSDrawer for cycle C+3

source

pub fn feed_selector(&self, draw_cycle: u64) -> PosResult<()>

Feeds the selector targeting a given draw cycle

source

pub fn feed_cycle_state_hash( &self, cycle: u64, final_state_hash: HashXof<HASH_XOF_SIZE_BYTES>, )

Feeds the selector targeting a given draw cycle

source§

impl PoSFinalState

source

pub fn get_rolls_for(&self, addr: &Address) -> u64

Retrieves the amount of rolls a given address has at the latest cycle

source

pub fn get_address_active_rolls( &self, addr: &Address, cycle: u64, ) -> Option<u64>

Retrieves the amount of rolls a given address has at a given cycle - 3 if cycle - 3 does not exist, values from initial rolls are returned

source

pub fn get_all_active_rolls(&self, cycle: u64) -> BTreeMap<Address, u64>

Gets all active rolls for a given cycle - 3, use self.initial_rolls if cycle - 3 does not exist

source

pub fn get_deferred_credits_range<R>( &self, range: R, addr_filter: Option<&Address>, ) -> DeferredCredits
where R: RangeBounds<Slot>,

Retrieves every deferred credit in a slot range Warning: this can be quite slow if there is tons of Deferred credits (e.g. just after genesis) to fetch so there is an option to filter by an address to improve the speed (cf json rpc api get_addresses)

source

pub fn get_cycle_index(&self, cycle: u64) -> Option<usize>

Gets the index of a cycle in history

source

pub fn get_all_roll_counts(&self, cycle: u64) -> BTreeMap<Address, u64>

Get all the roll counts for a given cycle

source

pub fn get_all_production_stats( &self, cycle: u64, ) -> Option<PreHashMap<Address, ProductionStats>>

Retrieves the productions statistics for all addresses on a given cycle

source

fn get_all_production_stats_private( &self, cycle: u64, ) -> PreHashMap<Address, ProductionStats>

Retrieves the productions statistics for all addresses on a given cycle

source

fn get_cycle_history_rng_seed(&self, cycle: u64) -> Option<BitVec<u8>>

Getter for the rng_seed of a given cycle, prioritizing the cache and querying the database as fallback.

source

fn get_cycle_history_final_state_hash_snapshot( &self, cycle: u64, ) -> Option<HashXof<HASH_XOF_SIZE_BYTES>>

Getter for the final_state_hash_snapshot of a given cycle.

Panics if the cycle is not in the history.

source

fn get_cycle_history_cycles(&self) -> Vec<(u64, bool)>

Used to recompute the cycle cache from the disk.

source

pub fn get_cycle_info(&self, cycle: u64) -> Option<CycleInfo>

Queries a given cycle info in the database

source

pub fn get_address_credits_for_slot( &self, addr: &Address, slot: &Slot, ) -> Option<Amount>

Gets the deferred credits for a given address that will be credited at a given slot

source

pub fn get_production_stats_for_address( &self, cycle: u64, address: &Address, ) -> Option<ProductionStats>

Gets the production stats for a given address

source

pub fn is_cycle_complete(&self, cycle: u64) -> Option<bool>

Check if a cycle is complete (all slots finalized)

source§

impl PoSFinalState

source

pub fn put_new_cycle_info( &mut self, cycle_info: &CycleInfo, batch: &mut DBBatch, )

Helper function to put a new CycleInfo to RocksDB, and update the cycle_history cache

source

fn put_cycle_history_complete( &mut self, cycle: u64, value: bool, batch: &mut DBBatch, )

Helper function to put a the complete flag for a given cycle

source

fn put_cycle_history_final_state_hash_snapshot( &self, cycle: u64, value: Option<HashXof<HASH_XOF_SIZE_BYTES>>, batch: &mut DBBatch, )

Helper function to put a the final_state_hash_snapshot for a given cycle

source

fn put_cycle_history_rng_seed( &mut self, cycle: u64, value: BitVec<u8>, batch: &mut DBBatch, )

Helper function to put a the rng_seed for a given cycle

source

fn put_cycle_history_address_entry( &self, cycle: u64, address: &Address, roll_count: Option<&u64>, production_stats: Option<&ProductionStats>, batch: &mut DBBatch, )

Internal function to put an entry for a given address in the cycle history

source

pub fn put_deferred_credits_entry( &self, slot: &Slot, address: &Address, amount: &Amount, batch: &mut DBBatch, )

Internal function to put an entry

source§

impl PoSFinalState

Helpers for key and value management

source

fn cycle_history_cycle_prefix(&self, cycle: u64) -> Vec<u8>

Helper function to construct the key prefix associated with a given cycle

source

pub fn is_cycle_history_key_value_valid( &self, serialized_key: &[u8], serialized_value: &[u8], ) -> bool

Deserializes the key and value, useful after bootstrap

source

pub fn is_deferred_credits_key_value_valid( &self, serialized_key: &[u8], serialized_value: &[u8], ) -> bool

Deserializes the key and value, useful after bootstrap

Trait Implementations§

source§

impl Clone for PoSFinalState

source§

fn clone(&self) -> PoSFinalState

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

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§

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

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

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

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

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
source§

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

§

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
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

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

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more