Trait zebra_chain::chain_tip::ChainTip
source · pub trait ChainTip {
// Required methods
fn best_tip_height(&self) -> Option<Height>;
fn best_tip_hash(&self) -> Option<Hash>;
fn best_tip_height_and_hash(&self) -> Option<(Height, Hash)>;
fn best_tip_block_time(&self) -> Option<DateTime<Utc>>;
fn best_tip_height_and_block_time(&self) -> Option<(Height, DateTime<Utc>)>;
fn best_tip_mined_transaction_ids(&self) -> Arc<[Hash]>;
fn best_tip_changed(&mut self) -> BestTipChanged<'_> ⓘ;
fn mark_best_tip_seen(&mut self);
// Provided methods
fn estimate_network_chain_tip_height(
&self,
network: &Network,
now: DateTime<Utc>,
) -> Option<Height> { ... }
fn estimate_distance_to_network_chain_tip(
&self,
network: &Network,
) -> Option<(HeightDiff, Height)> { ... }
}
Expand description
An interface for querying the chain tip.
This trait helps avoid dependencies between:
zebra-chain
andtokio
zebra-network
andzebra-state
Required Methods§
sourcefn best_tip_height(&self) -> Option<Height>
fn best_tip_height(&self) -> Option<Height>
Returns the height of the best chain tip.
Does not mark the best tip as seen.
sourcefn best_tip_hash(&self) -> Option<Hash>
fn best_tip_hash(&self) -> Option<Hash>
Returns the block hash of the best chain tip.
Does not mark the best tip as seen.
sourcefn best_tip_height_and_hash(&self) -> Option<(Height, Hash)>
fn best_tip_height_and_hash(&self) -> Option<(Height, Hash)>
Returns the height and the hash of the best chain tip.
Does not mark the best tip as seen.
sourcefn best_tip_block_time(&self) -> Option<DateTime<Utc>>
fn best_tip_block_time(&self) -> Option<DateTime<Utc>>
Returns the block time of the best chain tip.
Does not mark the best tip as seen.
sourcefn best_tip_height_and_block_time(&self) -> Option<(Height, DateTime<Utc>)>
fn best_tip_height_and_block_time(&self) -> Option<(Height, DateTime<Utc>)>
Returns the height and the block time of the best chain tip. Returning both values at the same time guarantees that they refer to the same chain tip.
Does not mark the best tip as seen.
sourcefn best_tip_mined_transaction_ids(&self) -> Arc<[Hash]>
fn best_tip_mined_transaction_ids(&self) -> Arc<[Hash]>
Returns the mined transaction IDs of the transactions in the best chain tip block.
All transactions with these mined IDs should be rejected from the mempool, even if their authorizing data is different.
Does not mark the best tip as seen.
sourcefn best_tip_changed(&mut self) -> BestTipChanged<'_> ⓘ
fn best_tip_changed(&mut self) -> BestTipChanged<'_> ⓘ
A future that returns when the best chain tip changes.
Can return immediately if the latest value in this ChainTip
has not been seen yet.
Marks the best tip as seen.
Returns an error if Zebra is shutting down, or the state has permanently failed.
See tokio::watch::Receiver::changed()
for details.
sourcefn mark_best_tip_seen(&mut self)
fn mark_best_tip_seen(&mut self)
Mark the current best tip as seen.
Later calls to ChainTip::best_tip_changed()
will wait for the next change
before returning.
Provided Methods§
sourcefn estimate_network_chain_tip_height(
&self,
network: &Network,
now: DateTime<Utc>,
) -> Option<Height>
fn estimate_network_chain_tip_height( &self, network: &Network, now: DateTime<Utc>, ) -> Option<Height>
Return an estimate of the network chain tip’s height.
The estimate is calculated based on the current local time, the block time of the best tip and the height of the best tip.
sourcefn estimate_distance_to_network_chain_tip(
&self,
network: &Network,
) -> Option<(HeightDiff, Height)>
fn estimate_distance_to_network_chain_tip( &self, network: &Network, ) -> Option<(HeightDiff, Height)>
Return an estimate of how many blocks there are ahead of Zebra’s best chain tip until the network chain tip, and Zebra’s best chain tip height.
The first element in the returned tuple is the estimate. The second element in the returned tuple is the current best chain tip.
The estimate is calculated based on the current local time, the block time of the best tip and the height of the best tip.
This estimate may be negative if the current local time is behind the chain tip block’s timestamp.
Returns None
if the state is empty.