pub(crate) struct SpeculativeRollState {
final_state: Arc<RwLock<dyn FinalStateController>>,
active_history: Arc<RwLock<ActiveHistory>>,
pub(crate) added_changes: PoSChanges,
transfers_history: Arc<RwLock<Vec<TransferInfo>>>,
}Expand description
Speculative state of the rolls
Fields§
§final_state: Arc<RwLock<dyn FinalStateController>>Thread-safe shared access to the final state. For reading only.
active_history: Arc<RwLock<ActiveHistory>>History of the outputs of recently executed slots. Slots should be consecutive, newest at the back.
added_changes: PoSChangesList of changes to the state after settling roll sell/buy
transfers_history: Arc<RwLock<Vec<TransferInfo>>>Implementations§
source§impl SpeculativeRollState
impl SpeculativeRollState
sourcepub fn new(
final_state: Arc<RwLock<dyn FinalStateController>>,
active_history: Arc<RwLock<ActiveHistory>>,
transfers_history: Arc<RwLock<Vec<TransferInfo>>>,
) -> Self
pub fn new( final_state: Arc<RwLock<dyn FinalStateController>>, active_history: Arc<RwLock<ActiveHistory>>, transfers_history: Arc<RwLock<Vec<TransferInfo>>>, ) -> Self
Creates a new SpeculativeRollState
§Arguments
active_history: thread-safe shared access the speculative execution history
sourcepub fn take(&mut self) -> PoSChanges
pub fn take(&mut self) -> PoSChanges
Returns the changes caused to the SpeculativeRollState since its creation,
and resets their local value to nothing.
sourcepub fn get_snapshot(&self) -> PoSChanges
pub fn get_snapshot(&self) -> PoSChanges
Takes a snapshot (clone) of the changes caused to the SpeculativeRollState since its creation
sourcepub fn reset_to_snapshot(&mut self, snapshot: PoSChanges)
pub fn reset_to_snapshot(&mut self, snapshot: PoSChanges)
Resets the SpeculativeRollState to a snapshot (see get_snapshot method)
sourcefn get_rolls(&self, addr: &Address) -> u64
fn get_rolls(&self, addr: &Address) -> u64
Internal function to retrieve the rolls of a given address
sourcepub fn add_rolls(
&mut self,
buyer_addr: &Address,
roll_count: u64,
_operation_id: OperationId,
)
pub fn add_rolls( &mut self, buyer_addr: &Address, roll_count: u64, _operation_id: OperationId, )
Add roll_count rolls to the buyer address.
Validity checks must be performed outside of this function.
§Arguments
buyer_addr: address that will receive the rollsroll_count: number of rolls it will receive
sourcepub fn try_sell_rolls(
&mut self,
seller_addr: &Address,
slot: Slot,
roll_count: u64,
periods_per_cycle: u64,
thread_count: u8,
roll_price: Amount,
_operation_id: OperationId,
) -> Result<(), ExecutionError>
pub fn try_sell_rolls( &mut self, seller_addr: &Address, slot: Slot, roll_count: u64, periods_per_cycle: u64, thread_count: u8, roll_price: Amount, _operation_id: OperationId, ) -> Result<(), ExecutionError>
sourcepub fn try_slash_rolls(
&mut self,
addr: &Address,
roll_count: u64,
) -> Result<u64, ExecutionError>
pub fn try_slash_rolls( &mut self, addr: &Address, roll_count: u64, ) -> Result<u64, ExecutionError>
Try to slash roll_count rolls from the given address. If not enough roll, slash
the available amount and return the value.
§Arguments
addr: address to slash the rolls fromroll_count: number of rolls to slash
sourcepub fn try_slash_deferred_credits(
&mut self,
slot: &Slot,
addr: &Address,
amount: &Amount,
_denunciation_idx: &DenunciationIndex,
) -> Amount
pub fn try_slash_deferred_credits( &mut self, slot: &Slot, addr: &Address, amount: &Amount, _denunciation_idx: &DenunciationIndex, ) -> Amount
Try to slash amount credits from the given address. If not enough credits, slash
the available amount and return the value.
§Arguments
addr: address to slash the deferred credits fromamount: number of deferred credits to slash
sourcepub fn update_production_stats(
&mut self,
creator: &Address,
slot: Slot,
block_id: Option<BlockId>,
)
pub fn update_production_stats( &mut self, creator: &Address, slot: Slot, block_id: Option<BlockId>, )
Update production statistics of an address.
§Arguments
creator: the supposed creatorslot: current slotblock_id: id of the block (if some)
sourcepub fn settle_production_stats(
&mut self,
slot: &Slot,
periods_per_cycle: u64,
thread_count: u8,
roll_price: Amount,
max_miss_ratio: Ratio<u64>,
) -> Vec<(Address, Amount)>
pub fn settle_production_stats( &mut self, slot: &Slot, periods_per_cycle: u64, thread_count: u8, roll_price: Amount, max_miss_ratio: Ratio<u64>, ) -> Vec<(Address, Amount)>
Settle the production statistics at slot.
IMPORTANT: This function should only be used at the end of a cycle.
§Arguments:
slot: the final slot of the cycle to compute
sourcepub fn get_address_deferred_credits<R>(
&self,
address: &Address,
slot_range: R,
) -> BTreeMap<Slot, Amount>
pub fn get_address_deferred_credits<R>( &self, address: &Address, slot_range: R, ) -> BTreeMap<Slot, Amount>
Get deferred credits of an address starting from a given slot
sourcefn get_address_deferred_credit_for_slot(
&self,
addr: &Address,
slot: &Slot,
) -> Option<Amount>
fn get_address_deferred_credit_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_address_cycle_infos(
&self,
address: &Address,
periods_per_cycle: u64,
cur_slot: Slot,
) -> Vec<ExecutionAddressCycleInfo>
pub fn get_address_cycle_infos( &self, address: &Address, periods_per_cycle: u64, cur_slot: Slot, ) -> Vec<ExecutionAddressCycleInfo>
Get the production statistics for a given address at a given cycle.
sourcepub fn get_production_stats_at_cycle(
&self,
cycle: u64,
periods_per_cycle: u64,
thread_count: u8,
cur_slot: &Slot,
) -> (PreHashMap<Address, ProductionStats>, bool)
pub fn get_production_stats_at_cycle( &self, cycle: u64, periods_per_cycle: u64, thread_count: u8, cur_slot: &Slot, ) -> (PreHashMap<Address, ProductionStats>, bool)
Get the production statistics for a given cycle. Returns a 2nd boolean result indicating whether the cycle was fetched fully and successfully, or just partially.
sourcepub fn take_unexecuted_deferred_credits(
&mut self,
slot: &Slot,
) -> DeferredCredits
pub fn take_unexecuted_deferred_credits( &mut self, slot: &Slot, ) -> DeferredCredits
Take the non-zero deferred credits at or before slot.
Set them to zero in the speculative state.
§Arguments
slot: associated slot of the deferred credits to be executed
Auto Trait Implementations§
impl Freeze for SpeculativeRollState
impl !RefUnwindSafe for SpeculativeRollState
impl Send for SpeculativeRollState
impl Sync for SpeculativeRollState
impl Unpin for SpeculativeRollState
impl !UnwindSafe for SpeculativeRollState
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
§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> 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 moresource§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> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§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> Pointable for T
impl<T> Pointable for T
§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.