pub struct ValidatedState {
pub block_merkle_tree: BlockMerkleTree,
pub fee_merkle_tree: FeeMerkleTree,
pub reward_merkle_tree: RewardMerkleTree,
pub chain_config: ResolvableChainConfig,
}
Expand description
State to be validated by replicas.
Fields§
§block_merkle_tree: BlockMerkleTree
Frontier of BlockMerkleTree
fee_merkle_tree: FeeMerkleTree
Frontier of FeeMerkleTree
reward_merkle_tree: RewardMerkleTree
§chain_config: ResolvableChainConfig
Configuration Header
proposals will be validated against.
Implementations§
Source§impl ValidatedState
impl ValidatedState
Sourcepub fn prefund_account(&mut self, account: FeeAccount, amount: FeeAmount)
pub fn prefund_account(&mut self, account: FeeAccount, amount: FeeAmount)
Prefund an account with a given amount. Only for demo purposes.
pub fn balance(&mut self, account: FeeAccount) -> Option<FeeAmount>
Sourcepub fn forgotten_accounts(
&self,
accounts: impl IntoIterator<Item = FeeAccount>,
) -> Vec<FeeAccount>
pub fn forgotten_accounts( &self, accounts: impl IntoIterator<Item = FeeAccount>, ) -> Vec<FeeAccount>
Find accounts that are not in memory.
As an optimization we could try to apply updates and return the forgotten accounts to be fetched from peers and update them later.
pub fn forgotten_reward_accounts( &self, accounts: impl IntoIterator<Item = RewardAccount>, ) -> Vec<RewardAccount>
Sourcepub fn need_to_fetch_blocks_mt_frontier(&self) -> bool
pub fn need_to_fetch_blocks_mt_frontier(&self) -> bool
Check if the merkle tree is available
Sourcepub fn insert_fee_deposit(
&mut self,
fee_info: FeeInfo,
) -> Result<LookupResult<FeeAmount, (), ()>>
pub fn insert_fee_deposit( &mut self, fee_info: FeeInfo, ) -> Result<LookupResult<FeeAmount, (), ()>>
Insert a fee deposit receipt
pub fn apply_proposal( &mut self, delta: &mut Delta, parent_leaf: &Leaf2, l1_deposits: Vec<FeeInfo>, )
pub fn charge_fees( &mut self, delta: &mut Delta, fee_info: Vec<FeeInfo>, recipient: FeeAccount, ) -> Result<(), FeeError>
pub fn distribute_rewards( &mut self, delta: &mut Delta, validator: Validator<BLSPubKey>, ) -> Result<()>
Sourcepub fn charge_fee(
&mut self,
fee_info: FeeInfo,
recipient: FeeAccount,
) -> Result<(), FeeError>
pub fn charge_fee( &mut self, fee_info: FeeInfo, recipient: FeeAccount, ) -> Result<(), FeeError>
Charge a fee to an account, transferring the funds to the fee recipient account.
Source§impl ValidatedState
impl ValidatedState
Sourcepub async fn apply_header(
&self,
instance: &NodeState,
peers: &impl StateCatchup,
parent_leaf: &Leaf2,
proposed_header: &Header,
version: Version,
view_number: ViewNumber,
) -> Result<(Self, Delta)>
pub async fn apply_header( &self, instance: &NodeState, peers: &impl StateCatchup, parent_leaf: &Leaf2, proposed_header: &Header, version: Version, view_number: ViewNumber, ) -> Result<(Self, Delta)>
Updates state with Header
proposal.
- Clones and updates
ValidatedState
(avoiding mutation). - Resolves
ChainConfig
. - Performs catchup.
- Charges fees.
Sourcepub(crate) fn apply_upgrade(&mut self, instance: &NodeState, version: Version)
pub(crate) fn apply_upgrade(&mut self, instance: &NodeState, version: Version)
Updates the ValidatedState
if a protocol upgrade has occurred.
Sourcepub(crate) async fn get_chain_config(
&self,
instance: &NodeState,
peers: &impl StateCatchup,
header_cf: &ResolvableChainConfig,
) -> Result<ChainConfig>
pub(crate) async fn get_chain_config( &self, instance: &NodeState, peers: &impl StateCatchup, header_cf: &ResolvableChainConfig, ) -> Result<ChainConfig>
Retrieves the ChainConfig
.
Returns the NodeState
ChainConfig
if the ValidatedState
ChainConfig
commitment matches the NodeState
ChainConfig`` commitment. If the commitments do not match, it returns the
ChainConfigavailable in either
ValidatedStateor proposed header. If neither has the
ChainConfig`, it fetches the config from the peers.
Returns an error if it fails to fetch the ChainConfig
from the peers.
Trait Implementations§
Source§impl Clone for ValidatedState
impl Clone for ValidatedState
Source§fn clone(&self) -> ValidatedState
fn clone(&self) -> ValidatedState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ValidatedState
impl Debug for ValidatedState
Source§impl Default for ValidatedState
impl Default for ValidatedState
Source§impl<'de> Deserialize<'de> for ValidatedState
impl<'de> Deserialize<'de> for ValidatedState
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 Hash for ValidatedState
impl Hash for ValidatedState
Source§impl PartialEq for ValidatedState
impl PartialEq for ValidatedState
Source§impl Serialize for ValidatedState
impl Serialize for ValidatedState
Source§impl ValidatedState<SeqTypes> for ValidatedState
impl ValidatedState<SeqTypes> for ValidatedState
Source§async fn validate_and_apply_header(
&self,
instance: &Self::Instance,
parent_leaf: &Leaf2,
proposed_header: &Header,
payload_byte_len: u32,
version: Version,
view_number: u64,
) -> Result<(Self, Self::Delta), Self::Error>
async fn validate_and_apply_header( &self, instance: &Self::Instance, parent_leaf: &Leaf2, proposed_header: &Header, payload_byte_len: u32, version: Version, view_number: u64, ) -> Result<(Self, Self::Delta), Self::Error>
Validate parent against known values (from state) and validate
proposal descends from parent. Returns updated ValidatedState
.
Source§fn from_header(block_header: &Header) -> Self
fn from_header(block_header: &Header) -> Self
Construct the state with the given block header.
This can also be used to rebuild the state for catchup.
Source§fn genesis(instance: &Self::Instance) -> (Self, Self::Delta)
fn genesis(instance: &Self::Instance) -> (Self, Self::Delta)
Construct a genesis validated state.
Source§type Error = BlockError
type Error = BlockError
Source§type Time = ViewNumber
type Time = ViewNumber
impl Eq for ValidatedState
impl StructuralPartialEq for ValidatedState
Auto Trait Implementations§
impl Freeze for ValidatedState
impl RefUnwindSafe for ValidatedState
impl Send for ValidatedState
impl Sync for ValidatedState
impl Unpin for ValidatedState
impl UnwindSafe for ValidatedState
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
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 more§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.