Trait StateProviderFactory
pub trait StateProviderFactory:
BlockIdReader
+ Send
+ Sync {
// Required methods
fn latest(&self) -> Result<Box<dyn StateProvider>, ProviderError>;
fn state_by_block_number_or_tag(
&self,
number_or_tag: BlockNumberOrTag,
) -> Result<Box<dyn StateProvider>, ProviderError>;
fn history_by_block_number(
&self,
block: u64,
) -> Result<Box<dyn StateProvider>, ProviderError>;
fn history_by_block_hash(
&self,
block: FixedBytes<32>,
) -> Result<Box<dyn StateProvider>, ProviderError>;
fn state_by_block_hash(
&self,
block: FixedBytes<32>,
) -> Result<Box<dyn StateProvider>, ProviderError>;
fn pending(&self) -> Result<Box<dyn StateProvider>, ProviderError>;
fn pending_state_by_hash(
&self,
block_hash: FixedBytes<32>,
) -> Result<Option<Box<dyn StateProvider>>, ProviderError>;
// Provided method
fn state_by_block_id(
&self,
block_id: BlockId,
) -> Result<Box<dyn StateProvider>, ProviderError> { ... }
}
Expand description
Light wrapper that returns StateProvider
implementations that correspond to the given
BlockNumber
, the latest state, or the pending state.
This type differentiates states into historical
, latest
and pending
, where the latest
block determines what is historical or pending: [historical..latest..pending]
.
The latest
state represents the state after the most recent block has been committed to the
database, historical
states are states that have been committed to the database before the
latest
state, and pending
states are states that have not yet been committed to the
database which may or may not become the latest
state, depending on consensus.
Note: the pending
block is considered the block that extends the canonical chain but one and
has the latest
block as its parent.
All states are inclusive, meaning they include all all changes made (executed transactions)
in their respective blocks. For example StateProviderFactory::history_by_block_number for
block number n
will return the state after block n
was executed (transactions, withdrawals).
In other words, all states point to the end of the state’s respective block, which is equivalent
to state at the beginning of the child block.
This affects tracing, or replaying blocks, which will need to be executed on top of the state of
the parent block. For example, in order to trace block n
, the state after block n - 1
needs
to be used, since block n
was executed on its parent block’s state.
Required Methods§
fn latest(&self) -> Result<Box<dyn StateProvider>, ProviderError>
fn latest(&self) -> Result<Box<dyn StateProvider>, ProviderError>
Storage provider for latest block.
fn state_by_block_number_or_tag(
&self,
number_or_tag: BlockNumberOrTag,
) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_number_or_tag( &self, number_or_tag: BlockNumberOrTag, ) -> Result<Box<dyn StateProvider>, ProviderError>
Returns a StateProvider indexed by the given block number or tag.
Note: if a number is provided this will only look at historical(canonical) state.
fn history_by_block_number(
&self,
block: u64,
) -> Result<Box<dyn StateProvider>, ProviderError>
fn history_by_block_number( &self, block: u64, ) -> Result<Box<dyn StateProvider>, ProviderError>
Returns a historical StateProvider indexed by the given historic block number.
Note: this only looks at historical blocks, not pending blocks.
fn history_by_block_hash(
&self,
block: FixedBytes<32>,
) -> Result<Box<dyn StateProvider>, ProviderError>
fn history_by_block_hash( &self, block: FixedBytes<32>, ) -> Result<Box<dyn StateProvider>, ProviderError>
Returns a historical StateProvider indexed by the given block hash.
Note: this only looks at historical blocks, not pending blocks.
fn state_by_block_hash(
&self,
block: FixedBytes<32>,
) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_hash( &self, block: FixedBytes<32>, ) -> Result<Box<dyn StateProvider>, ProviderError>
Returns any StateProvider with matching block hash.
This will return a StateProvider for either a historical or pending block.
fn pending(&self) -> Result<Box<dyn StateProvider>, ProviderError>
fn pending(&self) -> Result<Box<dyn StateProvider>, ProviderError>
Storage provider for pending state.
Represents the state at the block that extends the canonical chain by one.
If there’s no pending
block, then this is equal to StateProviderFactory::latest
fn pending_state_by_hash(
&self,
block_hash: FixedBytes<32>,
) -> Result<Option<Box<dyn StateProvider>>, ProviderError>
fn pending_state_by_hash( &self, block_hash: FixedBytes<32>, ) -> Result<Option<Box<dyn StateProvider>>, ProviderError>
Storage provider for pending state for the given block hash.
Represents the state at the block that extends the canonical chain.
If the block couldn’t be found, returns None
.
Provided Methods§
fn state_by_block_id(
&self,
block_id: BlockId,
) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_id( &self, block_id: BlockId, ) -> Result<Box<dyn StateProvider>, ProviderError>
Returns a StateProvider
indexed by the given [BlockId
].
Note: if a number or hash is provided this will only look at historical(canonical) state.
Implementations on Foreign Types§
§impl<'a, T> StateProviderFactory for &'a T
impl<'a, T> StateProviderFactory for &'a T
fn latest(&self) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_id( &self, block_id: BlockId, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_number_or_tag( &self, number_or_tag: BlockNumberOrTag, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn history_by_block_number( &self, block: u64, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn history_by_block_hash( &self, block: FixedBytes<32>, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_hash( &self, block: FixedBytes<32>, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn pending(&self) -> Result<Box<dyn StateProvider>, ProviderError>
fn pending_state_by_hash( &self, block_hash: FixedBytes<32>, ) -> Result<Option<Box<dyn StateProvider>>, ProviderError>
§impl<T> StateProviderFactory for Box<T>
impl<T> StateProviderFactory for Box<T>
fn latest(&self) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_id( &self, block_id: BlockId, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_number_or_tag( &self, number_or_tag: BlockNumberOrTag, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn history_by_block_number( &self, block: u64, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn history_by_block_hash( &self, block: FixedBytes<32>, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_hash( &self, block: FixedBytes<32>, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn pending(&self) -> Result<Box<dyn StateProvider>, ProviderError>
fn pending_state_by_hash( &self, block_hash: FixedBytes<32>, ) -> Result<Option<Box<dyn StateProvider>>, ProviderError>
§impl<T> StateProviderFactory for Arc<T>
impl<T> StateProviderFactory for Arc<T>
fn latest(&self) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_id( &self, block_id: BlockId, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_number_or_tag( &self, number_or_tag: BlockNumberOrTag, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn history_by_block_number( &self, block: u64, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn history_by_block_hash( &self, block: FixedBytes<32>, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn state_by_block_hash( &self, block: FixedBytes<32>, ) -> Result<Box<dyn StateProvider>, ProviderError>
fn pending(&self) -> Result<Box<dyn StateProvider>, ProviderError>
fn pending_state_by_hash( &self, block_hash: FixedBytes<32>, ) -> Result<Option<Box<dyn StateProvider>>, ProviderError>
Implementors§
impl StateProviderFactory for MockEthProvider
test-utils
only.