Struct ethcore_blockchain::BlockChain
source · [−]pub struct BlockChain {
pub eip1559_transition: BlockNumber,
/* private fields */
}
Expand description
Structure providing fast access to blockchain data.
Does not do input data verification.
Fields
eip1559_transition: BlockNumber
Number of first block where EIP-1559 rules begin. New encoding/decoding block format.
Implementations
sourceimpl BlockChain
impl BlockChain
sourcepub fn new(
config: Config,
genesis: &[u8],
db: Arc<dyn BlockChainDB>,
eip1559_transition: BlockNumber
) -> BlockChain
pub fn new(
config: Config,
genesis: &[u8],
db: Arc<dyn BlockChainDB>,
eip1559_transition: BlockNumber
) -> BlockChain
Create new instance of blockchain from given Genesis.
sourcepub fn tree_route(&self, from: H256, to: H256) -> Option<TreeRoute>
pub fn tree_route(&self, from: H256, to: H256) -> Option<TreeRoute>
Returns a tree route between from
and to
, which is a tuple of:
-
a vector of hashes of all blocks, ordered from
from
toto
. -
common ancestor of these blocks.
-
an index where best common ancestor would be
1.) from newer to older
-
bc:
A1 -> A2 -> A3 -> A4 -> A5
-
from: A5, to: A4
-
route:
{ blocks: [A5], ancestor: A4, index: 1 }
2.) from older to newer
-
bc:
A1 -> A2 -> A3 -> A4 -> A5
-
from: A3, to: A4
-
route:
{ blocks: [A4], ancestor: A3, index: 0 }
3.) fork:
-
bc:
A1 -> A2 -> A3 -> A4 -> B3 -> B4
-
from: B4, to: A4
-
route:
{ blocks: [B4, B3, A3, A4], ancestor: A2, index: 2 }
If the tree route verges into pruned or unknown blocks,
None
is returned.
is_from_route_finalized
returns whether the from
part of the
route contains a finalized block. This only holds if the two parts (from
and to) are on different branches, ie. on 2 different forks.
sourcepub fn insert_unordered_block(
&self,
batch: &mut DBTransaction,
block: Block,
receipts: Vec<TypedReceipt>,
parent_td: Option<U256>,
is_best: bool,
is_ancient: bool
) -> bool
pub fn insert_unordered_block(
&self,
batch: &mut DBTransaction,
block: Block,
receipts: Vec<TypedReceipt>,
parent_td: Option<U256>,
is_best: bool,
is_ancient: bool
) -> bool
Inserts a verified, known block from the canonical chain.
Can be performed out-of-order, but care must be taken that the final chain is in a correct state.
This is used by snapshot restoration and when downloading missing blocks for the chain gap.
is_best
forces the best block to be updated to this block.
is_ancient
forces the best block of the first block sequence to be updated to this block.
parent_td
is a parent total diffuculty
Supply a dummy parent total difficulty when the parent block may not be in the chain.
Returns true if the block is disconnected.
sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
clears all caches, re-loads best block from disk for testing purposes
sourcepub fn update_best_ancient_block(&self, hash: &H256)
pub fn update_best_ancient_block(&self, hash: &H256)
Update the best ancient block to the given hash, after checking that it’s directly linked to the currently known best ancient block
sourcepub fn insert_epoch_transition(
&self,
batch: &mut DBTransaction,
epoch_num: u64,
transition: EpochTransition
)
pub fn insert_epoch_transition(
&self,
batch: &mut DBTransaction,
epoch_num: u64,
transition: EpochTransition
)
Insert an epoch transition. Provide an epoch number being transitioned to and epoch transition object.
The block the transition occurred at should have already been inserted into the chain.
sourcepub fn epoch_transitions(&self) -> EpochTransitionIter<'_>
pub fn epoch_transitions(&self) -> EpochTransitionIter<'_>
Iterate over all epoch transitions. This will only return transitions within the canonical chain.
sourcepub fn epoch_transition(
&self,
block_num: u64,
block_hash: H256
) -> Option<EpochTransition>
pub fn epoch_transition(
&self,
block_num: u64,
block_hash: H256
) -> Option<EpochTransition>
Get a specific epoch transition by block number and provided block hash.
sourcepub fn epoch_transition_for(&self, parent_hash: H256) -> Option<EpochTransition>
pub fn epoch_transition_for(&self, parent_hash: H256) -> Option<EpochTransition>
Get the transition to the epoch the given parent hash is part of or transitions to. This will give the epoch that any children of this parent belong to.
The block corresponding the the parent hash must be stored already.
sourcepub fn insert_pending_transition(
&self,
batch: &mut DBTransaction,
hash: H256,
t: PendingEpochTransition
)
pub fn insert_pending_transition(
&self,
batch: &mut DBTransaction,
hash: H256,
t: PendingEpochTransition
)
Write a pending epoch transition by block hash.
sourcepub fn get_pending_transition(
&self,
hash: H256
) -> Option<PendingEpochTransition>
pub fn get_pending_transition(
&self,
hash: H256
) -> Option<PendingEpochTransition>
Get a pending epoch transition by block hash.
sourcepub fn add_child(
&self,
batch: &mut DBTransaction,
block_hash: H256,
child_hash: H256
)
pub fn add_child(
&self,
batch: &mut DBTransaction,
block_hash: H256,
child_hash: H256
)
Add a child to a given block. Assumes that the block hash is in the chain and the child’s parent is this block.
Used in snapshots to glue the chunks together at the end.
sourcepub fn insert_block(
&self,
batch: &mut DBTransaction,
block: Block,
receipts: Vec<TypedReceipt>,
extras: ExtrasInsert
) -> ImportRoute
pub fn insert_block(
&self,
batch: &mut DBTransaction,
block: Block,
receipts: Vec<TypedReceipt>,
extras: ExtrasInsert
) -> ImportRoute
Inserts the block into backing cache database. Expects the block to be valid and already verified. If the block is already known, does nothing.
sourcepub fn insert_block_with_route(
&self,
batch: &mut DBTransaction,
block: Block,
receipts: Vec<TypedReceipt>,
route: TreeRoute,
extras: ExtrasInsert
) -> ImportRoute
pub fn insert_block_with_route(
&self,
batch: &mut DBTransaction,
block: Block,
receipts: Vec<TypedReceipt>,
route: TreeRoute,
extras: ExtrasInsert
) -> ImportRoute
Inserts the block into backing cache database with already generated route information. Expects the block to be valid and already verified and route is tree route information from current best block to new block’s parent. If the block is already known, does nothing.
sourcepub fn mark_finalized(
&self,
batch: &mut DBTransaction,
block_hash: H256
) -> Option<()>
pub fn mark_finalized(
&self,
batch: &mut DBTransaction,
block_hash: H256
) -> Option<()>
Mark a block to be considered finalized. Returns Some(())
if the operation succeeds, and None
if the block
hash is not found.
sourcepub fn commit(&self)
pub fn commit(&self)
t_nb 9.12 commit changed to become current greatest by applying pending insertion updates
sourcepub fn ancestry_iter(&self, first: H256) -> Option<AncestryIter<'_>>
pub fn ancestry_iter(&self, first: H256) -> Option<AncestryIter<'_>>
Iterator that lists first
and then all of first
’s ancestors, by hash.
sourcepub fn ancestry_with_metadata_iter<'a>(
&'a self,
first: H256
) -> AncestryWithMetadataIter<'_>
pub fn ancestry_with_metadata_iter<'a>(
&'a self,
first: H256
) -> AncestryWithMetadataIter<'_>
Iterator that lists first
and then all of first
’s ancestors, by extended header.
sourcepub fn find_uncle_headers(
&self,
parent: &H256,
uncle_generations: usize
) -> Option<Vec<Header>>
pub fn find_uncle_headers(
&self,
parent: &H256,
uncle_generations: usize
) -> Option<Vec<Header>>
Given a block’s parent
, find every block header which represents a valid possible uncle.
sourcepub fn find_uncle_hashes(
&self,
parent: &H256,
uncle_generations: usize
) -> Option<Vec<H256>>
pub fn find_uncle_hashes(
&self,
parent: &H256,
uncle_generations: usize
) -> Option<Vec<H256>>
Given a block’s parent
, find every block hash which represents a valid possible uncle.
sourcepub fn best_block_hash(&self) -> H256
pub fn best_block_hash(&self) -> H256
Get best block hash.
sourcepub fn best_block_number(&self) -> BlockNumber
pub fn best_block_number(&self) -> BlockNumber
Get best block number.
sourcepub fn best_block_timestamp(&self) -> u64
pub fn best_block_timestamp(&self) -> u64
Get best block timestamp.
sourcepub fn best_block_total_difficulty(&self) -> U256
pub fn best_block_total_difficulty(&self) -> U256
Get best block total difficulty.
sourcepub fn best_block_header(&self) -> Header
pub fn best_block_header(&self) -> Header
Get best block header
sourcepub fn cache_size(&self) -> CacheSize
pub fn cache_size(&self) -> CacheSize
Get current cache size.
sourcepub fn collect_garbage(&self)
pub fn collect_garbage(&self)
Ticks our cache system and throws out any old data.
sourcepub fn chain_info(&self) -> BlockChainInfo
pub fn chain_info(&self) -> BlockChainInfo
Returns general blockchain information
Trait Implementations
sourceimpl BlockProvider for BlockChain
impl BlockProvider for BlockChain
sourcefn is_known(&self, hash: &H256) -> bool
fn is_known(&self, hash: &H256) -> bool
Returns true if the given block is known (though not necessarily a part of the canon chain).
sourcefn block_header_data(&self, hash: &H256) -> Option<Header>
fn block_header_data(&self, hash: &H256) -> Option<Header>
Get block header data
sourcefn block_body(&self, hash: &H256) -> Option<Body>
fn block_body(&self, hash: &H256) -> Option<Body>
Get block body data
sourcefn block_details(&self, hash: &H256) -> Option<BlockDetails>
fn block_details(&self, hash: &H256) -> Option<BlockDetails>
Get the familial details concerning a block.
sourcefn block_hash(&self, index: BlockNumber) -> Option<H256>
fn block_hash(&self, index: BlockNumber) -> Option<H256>
Get the hash of given block’s number.
sourcefn transaction_address(&self, hash: &H256) -> Option<TransactionAddress>
fn transaction_address(&self, hash: &H256) -> Option<TransactionAddress>
Get the address of transaction with given hash.
sourcefn block_receipts(&self, hash: &H256) -> Option<BlockReceipts>
fn block_receipts(&self, hash: &H256) -> Option<BlockReceipts>
Get receipts of block with given hash.
sourcefn blocks_with_bloom<'a, B, I, II>(
&self,
blooms: II,
from_block: BlockNumber,
to_block: BlockNumber
) -> Vec<BlockNumber>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
where
BloomRef<'a>: From<B>,
II: IntoIterator<Item = B, IntoIter = I> + Copy,
I: Iterator<Item = B>,
fn blocks_with_bloom<'a, B, I, II>(
&self,
blooms: II,
from_block: BlockNumber,
to_block: BlockNumber
) -> Vec<BlockNumber>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
where
BloomRef<'a>: From<B>,
II: IntoIterator<Item = B, IntoIter = I> + Copy,
I: Iterator<Item = B>,
A: Allocator,
Returns numbers of blocks containing given bloom.
sourcefn logs<F>(
&self,
blocks: Vec<H256>,
matches: F,
limit: Option<usize>
) -> Vec<LocalizedLogEntry>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
where
F: Fn(&LogEntry) -> bool + Send + Sync,
Self: Sized,
fn logs<F>(
&self,
blocks: Vec<H256>,
matches: F,
limit: Option<usize>
) -> Vec<LocalizedLogEntry>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
where
F: Fn(&LogEntry) -> bool + Send + Sync,
Self: Sized,
A: Allocator,
Returns logs matching given filter. The order of logs returned will be the same as the order of the blocks provided. And it’s the callers responsibility to sort blocks provided in advance.
sourcefn first_block(&self) -> Option<H256>
fn first_block(&self) -> Option<H256>
Get the first block of the best part of the chain.
Return None
if there is no gap and the first block is the genesis.
Any queries of blocks which precede this one are not guaranteed to
succeed. Read more
sourcefn best_ancient_block(&self) -> Option<H256>
fn best_ancient_block(&self) -> Option<H256>
Get the best block of an first block sequence if there is a gap.
sourcefn best_ancient_number(&self) -> Option<BlockNumber>
fn best_ancient_number(&self) -> Option<BlockNumber>
Get the number of the first block.
sourcefn is_canon(&self, hash: &H256) -> bool
fn is_canon(&self, hash: &H256) -> bool
Returns true if the given block is known and in the canon chain.
sourcefn first_block_number(&self) -> Option<BlockNumber>
fn first_block_number(&self) -> Option<BlockNumber>
Get the number of the first block.
sourcefn uncles(
&self,
hash: &H256,
eip1559_transition: BlockNumber
) -> Option<Vec<Header>>
fn uncles(
&self,
hash: &H256,
eip1559_transition: BlockNumber
) -> Option<Vec<Header>>
Get a list of uncles for a given block. Returns None if block does not exist. Read more
sourcefn uncle_hashes(&self, hash: &H256) -> Option<Vec<H256>>
fn uncle_hashes(&self, hash: &H256) -> Option<Vec<H256>>
Get a list of uncle hashes for a given block. Returns None if block does not exist. Read more
sourcefn block_number(&self, hash: &H256) -> Option<BlockNumber>
fn block_number(&self, hash: &H256) -> Option<BlockNumber>
Get the number of given block’s hash.
sourcefn transaction(
&self,
address: &TransactionAddress
) -> Option<LocalizedTransaction>
fn transaction(
&self,
address: &TransactionAddress
) -> Option<LocalizedTransaction>
Get transaction with given transaction hash.
sourcefn transactions(&self, hash: &H256) -> Option<Vec<LocalizedTransaction>>
fn transactions(&self, hash: &H256) -> Option<Vec<LocalizedTransaction>>
Get a list of transactions for a given block. Returns None if block does not exist. Read more
sourcefn genesis_hash(&self) -> H256
fn genesis_hash(&self) -> H256
Returns reference to genesis hash.
sourcefn genesis_header(&self) -> Header
fn genesis_header(&self) -> Header
Returns the header of the genesis block.
Auto Trait Implementations
impl !RefUnwindSafe for BlockChain
impl Send for BlockChain
impl Sync for BlockChain
impl Unpin for BlockChain
impl !UnwindSafe for BlockChain
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more