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: PoSConfigproof-of-stake configuration
db: ShareableMassaDBControllerAccess 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: DeferredCreditsSerializerdeferred credits serializer
deferred_credits_deserializer: DeferredCreditsDeserializerdeferred credits deserializer
cycle_info_serializer: CycleHistorySerializercycle info serializer
cycle_info_deserializer: CycleHistoryDeserializercycle info deserializer
Implementations§
source§impl PoSFinalState
impl PoSFinalState
sourcepub fn new(
config: PoSConfig,
initial_seed_string: &str,
initial_rolls_path: &PathBuf,
selector: Box<dyn SelectorController>,
db: ShareableMassaDBController,
) -> Result<Self, PosError>
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
sourcepub fn load_initial_deferred_credits(
&mut self,
batch: &mut DBBatch,
) -> Result<(), PosError>
pub fn load_initial_deferred_credits( &mut self, batch: &mut DBBatch, ) -> Result<(), PosError>
Try load initial deferred credits from file
sourcepub fn recompute_pos_state_caches(&mut self)
pub fn recompute_pos_state_caches(&mut self)
After bootstrap or load from disk, recompute the caches
sourcepub fn create_initial_cycle(&mut self, batch: &mut DBBatch)
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.
sourcepub fn create_new_cycle_from_last(
&mut self,
last_cycle_info: &CycleInfo,
first_slot: Slot,
last_slot: Slot,
batch: &mut DBBatch,
) -> Result<(), PosError>
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.
sourcepub fn delete_cycle_info(&mut self, cycle: u64, batch: &mut DBBatch)
pub fn delete_cycle_info(&mut self, cycle: u64, batch: &mut DBBatch)
Deletes a given cycle from RocksDB
sourcepub fn compute_initial_draws(&mut self) -> PosResult<()>
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.
sourcepub fn apply_changes_to_batch(
&mut self,
changes: PoSChanges,
slot: Slot,
feed_selector: bool,
batch: &mut DBBatch,
) -> PosResult<()>
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
sourcepub fn feed_selector(&self, draw_cycle: u64) -> PosResult<()>
pub fn feed_selector(&self, draw_cycle: u64) -> PosResult<()>
Feeds the selector targeting a given draw cycle
sourcepub fn feed_cycle_state_hash(
&self,
cycle: u64,
final_state_hash: HashXof<HASH_XOF_SIZE_BYTES>,
)
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
impl PoSFinalState
sourcepub fn get_rolls_for(&self, addr: &Address) -> u64
pub fn get_rolls_for(&self, addr: &Address) -> u64
Retrieves the amount of rolls a given address has at the latest cycle
sourcepub fn get_address_active_rolls(
&self,
addr: &Address,
cycle: u64,
) -> Option<u64>
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
sourcepub fn get_all_active_rolls(&self, cycle: u64) -> BTreeMap<Address, u64>
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
sourcepub fn get_deferred_credits_range<R>(
&self,
range: R,
addr_filter: Option<&Address>,
) -> DeferredCreditswhere
R: RangeBounds<Slot>,
pub fn get_deferred_credits_range<R>(
&self,
range: R,
addr_filter: Option<&Address>,
) -> DeferredCreditswhere
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)
sourcepub fn get_cycle_index(&self, cycle: u64) -> Option<usize>
pub fn get_cycle_index(&self, cycle: u64) -> Option<usize>
Gets the index of a cycle in history
sourcepub fn get_all_roll_counts(&self, cycle: u64) -> BTreeMap<Address, u64>
pub fn get_all_roll_counts(&self, cycle: u64) -> BTreeMap<Address, u64>
Get all the roll counts for a given cycle
sourcepub fn get_all_production_stats(
&self,
cycle: u64,
) -> Option<PreHashMap<Address, ProductionStats>>
pub fn get_all_production_stats( &self, cycle: u64, ) -> Option<PreHashMap<Address, ProductionStats>>
Retrieves the productions statistics for all addresses on a given cycle
sourcefn get_all_production_stats_private(
&self,
cycle: u64,
) -> PreHashMap<Address, ProductionStats>
fn get_all_production_stats_private( &self, cycle: u64, ) -> PreHashMap<Address, ProductionStats>
Retrieves the productions statistics for all addresses on a given cycle
sourcefn get_cycle_history_rng_seed(&self, cycle: u64) -> Option<BitVec<u8>>
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.
sourcefn get_cycle_history_final_state_hash_snapshot(
&self,
cycle: u64,
) -> Option<HashXof<HASH_XOF_SIZE_BYTES>>
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.
sourcefn get_cycle_history_cycles(&self) -> Vec<(u64, bool)>
fn get_cycle_history_cycles(&self) -> Vec<(u64, bool)>
Used to recompute the cycle cache from the disk.
sourcepub fn get_cycle_info(&self, cycle: u64) -> Option<CycleInfo>
pub fn get_cycle_info(&self, cycle: u64) -> Option<CycleInfo>
Queries a given cycle info in the database
sourcepub fn get_address_credits_for_slot(
&self,
addr: &Address,
slot: &Slot,
) -> Option<Amount>
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
sourcepub fn get_production_stats_for_address(
&self,
cycle: u64,
address: &Address,
) -> Option<ProductionStats>
pub fn get_production_stats_for_address( &self, cycle: u64, address: &Address, ) -> Option<ProductionStats>
Gets the production stats for a given address
sourcepub fn is_cycle_complete(&self, cycle: u64) -> Option<bool>
pub fn is_cycle_complete(&self, cycle: u64) -> Option<bool>
Check if a cycle is complete (all slots finalized)
source§impl PoSFinalState
impl PoSFinalState
sourcepub fn put_new_cycle_info(
&mut self,
cycle_info: &CycleInfo,
batch: &mut DBBatch,
)
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
sourcefn put_cycle_history_complete(
&mut self,
cycle: u64,
value: bool,
batch: &mut DBBatch,
)
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
sourcefn put_cycle_history_final_state_hash_snapshot(
&self,
cycle: u64,
value: Option<HashXof<HASH_XOF_SIZE_BYTES>>,
batch: &mut DBBatch,
)
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
sourcefn put_cycle_history_rng_seed(
&mut self,
cycle: u64,
value: BitVec<u8>,
batch: &mut DBBatch,
)
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
sourcefn put_cycle_history_address_entry(
&self,
cycle: u64,
address: &Address,
roll_count: Option<&u64>,
production_stats: Option<&ProductionStats>,
batch: &mut DBBatch,
)
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
sourcepub fn put_deferred_credits_entry(
&self,
slot: &Slot,
address: &Address,
amount: &Amount,
batch: &mut DBBatch,
)
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
impl PoSFinalState
Helpers for key and value management
sourcefn cycle_history_cycle_prefix(&self, cycle: u64) -> Vec<u8>
fn cycle_history_cycle_prefix(&self, cycle: u64) -> Vec<u8>
Helper function to construct the key prefix associated with a given cycle
sourcepub fn is_cycle_history_key_value_valid(
&self,
serialized_key: &[u8],
serialized_value: &[u8],
) -> bool
pub fn is_cycle_history_key_value_valid( &self, serialized_key: &[u8], serialized_value: &[u8], ) -> bool
Deserializes the key and value, useful after bootstrap
sourcepub fn is_deferred_credits_key_value_valid(
&self,
serialized_key: &[u8],
serialized_value: &[u8],
) -> bool
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
impl Clone for PoSFinalState
source§fn clone(&self) -> PoSFinalState
fn clone(&self) -> PoSFinalState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PoSFinalState
impl !RefUnwindSafe for PoSFinalState
impl Send for PoSFinalState
impl Sync for PoSFinalState
impl Unpin for PoSFinalState
impl !UnwindSafe for PoSFinalState
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
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) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
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
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
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
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
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
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.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
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.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
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.