pub struct InMemory<H>where
H: StorageHasher,{Show 18 fields
pub chain_id: ChainId,
pub native_token: Address,
pub block: BlockStorage<H>,
pub header: Option<BlockHeader>,
pub last_block: Option<LastBlock>,
pub last_epoch: Epoch,
pub next_epoch_min_start_height: BlockHeight,
pub next_epoch_min_start_time: DateTimeUtc,
pub address_gen: EstablishedAddressGen,
pub update_epoch_blocks_delay: Option<u32>,
pub tx_index: TxIndex,
pub conversion_state: ConversionState,
pub expired_txs_queue: ExpiredTxsQueue,
pub ethereum_height: Option<BlockHeight>,
pub eth_events_queue: EthEventsQueue,
pub storage_read_past_height_limit: Option<u64>,
pub commit_only_data: CommitOnlyData,
pub block_proposals_cache: CLruCache<Hash, ProcessProposalCachedResult>,
}Expand description
The ledger’s state
Fields§
§chain_id: ChainIdThe ID of the chain
native_token: AddressThe address of the native token - this is not stored in DB, but read from genesis
block: BlockStorage<H>Block storage data
header: Option<BlockHeader>During FinalizeBlock, this is the header of the block that is
going to be committed. After a block is committed, this is reset to
None until the next FinalizeBlock phase is reached.
last_block: Option<LastBlock>The most recently committed block, if any.
last_epoch: EpochThe epoch of the most recently committed block. If it is Epoch(0),
then no block may have been committed for this chain yet.
next_epoch_min_start_height: BlockHeightMinimum block height at which the next epoch may start
next_epoch_min_start_time: DateTimeUtcMinimum block time at which the next epoch may start
address_gen: EstablishedAddressGenThe current established address generator
update_epoch_blocks_delay: Option<u32>We delay the switch to a new epoch by the number of blocks set in here.
This is Some when minimum number of blocks has been created and
minimum time has passed since the beginning of the last epoch.
Once the value is Some(0), we’re ready to switch to a new epoch and
this is reset back to None.
tx_index: TxIndexThe shielded transaction index
conversion_state: ConversionStateThe currently saved conversion state
expired_txs_queue: ExpiredTxsQueueQueue of expired transactions that need to be retransmitted.
These transactions do not need to be persisted, as they are retransmitted at the COMMIT phase immediately following the block when they were queued.
ethereum_height: Option<BlockHeight>The latest block height on Ethereum processed, if the bridge is enabled.
eth_events_queue: EthEventsQueueThe queue of Ethereum events to be processed in order.
storage_read_past_height_limit: Option<u64>How many block heights in the past can the storage be queried
commit_only_data: CommitOnlyDataData that needs to be committed to the merkle tree
block_proposals_cache: CLruCache<Hash, ProcessProposalCachedResult>Cache of the results of process proposal for the next height to decide. A LRU cache is used to prevent consuming too much memory at times where a node cannot make progress and keeps evaluating new proposals. The different proposed blocks are indexed by their hash. This is used to avoid running process proposal more than once internally because of the shim or the recheck option (comet only calls it at most once for a given height/round)
Implementations§
Source§impl<H> InMemory<H>where
H: StorageHasher,
impl<H> InMemory<H>where
H: StorageHasher,
Sourcepub fn new(
chain_id: ChainId,
native_token: Address,
storage_read_past_height_limit: Option<u64>,
) -> Self
pub fn new( chain_id: ChainId, native_token: Address, storage_read_past_height_limit: Option<u64>, ) -> Self
Create a new instance of the state
Sourcepub fn get_state(&self) -> Option<(MerkleRoot, u64)>
pub fn get_state(&self) -> Option<(MerkleRoot, u64)>
Returns the Merkle root hash and the height of the committed block. If no block exists, returns None.
Sourcepub fn merkle_root(&self) -> MerkleRoot
pub fn merkle_root(&self) -> MerkleRoot
Find the root hash of the merkle tree
Sourcepub fn set_header(&mut self, header: BlockHeader) -> Result<()>
pub fn set_header(&mut self, header: BlockHeader) -> Result<()>
Set the block header. The header is not in the Merkle tree as it’s tracked by Tendermint. Hence, we don’t update the tree when this is set.
Sourcepub fn begin_block(&mut self, height: BlockHeight) -> Result<()>
pub fn begin_block(&mut self, height: BlockHeight) -> Result<()>
Block data is in the Merkle tree as it’s tracked by Tendermint in the block header. Hence, we don’t update the tree when this is set.
Sourcepub fn add_tx_gas(&mut self, tx_hash: Hash, gas: Gas)
pub fn add_tx_gas(&mut self, tx_hash: Hash, gas: Gas)
Store in memory a total gas of a transaction with the given hash.
Sourcepub fn get_chain_id(&self) -> (ChainId, Gas)
pub fn get_chain_id(&self) -> (ChainId, Gas)
Get the chain ID as a raw string
Sourcepub fn get_block_height(&self) -> (BlockHeight, Gas)
pub fn get_block_height(&self) -> (BlockHeight, Gas)
Get the block height. The height is that of the block to which the
current transaction is being applied if we are in between the
FinalizeBlock and the Commit phases. For all the other phases we
return the block height of next block that the consensus process
will decide upon (i.e. the block height of the last committed block
Sourcepub fn get_current_epoch(&self) -> (Epoch, Gas)
pub fn get_current_epoch(&self) -> (Epoch, Gas)
Get the current (yet to be committed) block epoch
Sourcepub fn get_last_epoch(&self) -> (Epoch, Gas)
pub fn get_last_epoch(&self) -> (Epoch, Gas)
Get the epoch of the last committed block
Sourcepub fn init_genesis_epoch(
&mut self,
initial_height: BlockHeight,
genesis_time: DateTimeUtc,
parameters: &Parameters,
) -> Result<()>
pub fn init_genesis_epoch( &mut self, initial_height: BlockHeight, genesis_time: DateTimeUtc, parameters: &Parameters, ) -> Result<()>
Initialize the first epoch. The first epoch begins at genesis time.
Sourcepub fn get_conversion_state(&self) -> &ConversionState
pub fn get_conversion_state(&self) -> &ConversionState
Get the current conversions
Sourcepub fn update_epoch_in_merkle_tree(&mut self) -> Result<()>
pub fn update_epoch_in_merkle_tree(&mut self) -> Result<()>
Update the merkle tree with epoch data
Sourcepub fn get_last_block_height(&self) -> BlockHeight
pub fn get_last_block_height(&self) -> BlockHeight
Get the height of the last committed block or 0 if no block has been committed yet. The first block is at height 1.
Sourcepub fn get_oldest_epoch(&self) -> Epoch
pub fn get_oldest_epoch(&self) -> Epoch
Get the oldest epoch where we can read a value
Trait Implementations§
Auto Trait Implementations§
impl<H> Freeze for InMemory<H>
impl<H> RefUnwindSafe for InMemory<H>where
H: RefUnwindSafe,
impl<H> Send for InMemory<H>where
H: Send,
impl<H> Sync for InMemory<H>where
H: Sync,
impl<H> Unpin for InMemory<H>where
H: Unpin,
impl<H> UnwindSafe for InMemory<H>where
H: UnwindSafe,
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> FmtForward for T
impl<T> FmtForward for T
Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§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 moreSource§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 moreSource§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
Source§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
Source§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.Source§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.Source§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.Source§impl<T> Tap for T
impl<T> Tap for T
Source§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.