Struct cfxcore::block_data_manager::BlockDataManager
source · pub struct BlockDataManager {
pub db_manager: DBManager,
pub pow: Arc<PowComputer>,
pub true_genesis: Arc<Block>,
pub storage_manager: Arc<StorageManager>,
pub target_difficulty_manager: TargetDifficultyManager,
pub state_availability_boundary: RwLock<StateAvailabilityBoundary>,
/* private fields */
}
Fields§
§db_manager: DBManager
§pow: Arc<PowComputer>
§true_genesis: Arc<Block>
This is the original genesis block.
storage_manager: Arc<StorageManager>
§target_difficulty_manager: TargetDifficultyManager
§state_availability_boundary: RwLock<StateAvailabilityBoundary>
This maintains the boundary height of available state and commitments
(executed but not deleted or in ExecutionTaskQueue
).
The upper bound always equal to latest executed epoch height.
As for the lower bound:
- For archive node, it always equals
cur_era_stable_height
. - For full node, it equals the height of remotely synchronized state
at start, and equals
cur_era_stable_height
after making a new checkpoint.
The lower boundary height will be updated when:
- New checkpoint
- Full Node snapshot syncing
- New Snapshot
The upper boundary height will be updated when:
- Pivot chain switch
- Execution of new epoch
The state of an epoch is valid if and only if the height of the epoch is inside the boundary.
Implementations§
source§impl BlockDataManager
impl BlockDataManager
pub fn new( cache_conf: CacheConfig, true_genesis: Arc<Block>, db: Arc<SystemDB>, storage_manager: Arc<StorageManager>, worker_pool: Arc<Mutex<ThreadPool>>, config: DataManagerConfiguration, pow: Arc<PowComputer> ) -> Self
pub fn get_instance_id(&self) -> u64
pub fn initialize_instance_id(&self)
sourcepub fn true_genesis_state_root(&self) -> StateRootWithAuxInfo
pub fn true_genesis_state_root(&self) -> StateRootWithAuxInfo
This will return the state root of true genesis block.
pub fn transaction_by_hash(&self, hash: &H256) -> Option<Arc<SignedTransaction>>
sourcepub fn insert_block_body(&self, hash: H256, block: Arc<Block>, persistent: bool)
pub fn insert_block_body(&self, hash: H256, block: Arc<Block>, persistent: bool)
insert block body in memory cache and db
sourcepub fn remove_block_body(&self, hash: &H256, remove_db: bool)
pub fn remove_block_body(&self, hash: &H256, remove_db: bool)
remove block body in memory cache and db
sourcepub fn block_by_hash(
&self,
hash: &H256,
update_cache: bool
) -> Option<Arc<Block>>
pub fn block_by_hash( &self, hash: &H256, update_cache: bool ) -> Option<Arc<Block>>
TODO Also set block header
sourcepub fn block_from_db(&self, hash: &H256) -> Option<Block>
pub fn block_from_db(&self, hash: &H256) -> Option<Block>
This function returns the block from db without wrapping it in Arc
.
pub fn blocks_by_hash_list( &self, hashes: &Vec<H256>, update_cache: bool ) -> Option<Vec<Arc<Block>>>
sourcepub fn insert_block(&self, block: Arc<Block>, persistent: bool)
pub fn insert_block(&self, block: Arc<Block>, persistent: bool)
insert block/header into memory cache, block/header into db
sourcepub fn remove_useless_block(&self, hash: &H256, remove_db: bool)
pub fn remove_useless_block(&self, hash: &H256, remove_db: bool)
Remove block body and block header in memory cache and db. This is used to delete invalid blocks or dangling blocks never connected to the pivot chain.
sourcepub fn block_traces_by_hash(&self, hash: &H256) -> Option<BlockTracesWithEpoch>
pub fn block_traces_by_hash(&self, hash: &H256) -> Option<BlockTracesWithEpoch>
Get the traces for a single block without checking the assumed pivot block
sourcepub fn transactions_traces_by_block_hash(
&self,
hash: &H256
) -> Option<(H256, Vec<TransactionExecTraces>)>
pub fn transactions_traces_by_block_hash( &self, hash: &H256 ) -> Option<(H256, Vec<TransactionExecTraces>)>
Return (pivot_hash, tx_traces)
.
pub fn block_traces_by_hash_with_epoch( &self, hash: &H256, assumed_epoch: &H256, update_pivot_assumption: bool, update_cache: bool ) -> Option<BlockExecTraces>
pub fn insert_block_traces( &self, hash: H256, trace: BlockExecTraces, pivot_hash: H256, persistent: bool )
sourcepub fn remove_block_traces(&self, hash: &H256, remove_db: bool)
pub fn remove_block_traces(&self, hash: &H256, remove_db: bool)
remove block traces in memory cache and db
pub fn block_header_by_hash(&self, hash: &H256) -> Option<Arc<BlockHeader>>
pub fn insert_block_header( &self, hash: H256, header: Arc<BlockHeader>, persistent: bool )
sourcepub fn remove_block_header(&self, hash: &H256, remove_db: bool)
pub fn remove_block_header(&self, hash: &H256, remove_db: bool)
remove block header in memory cache and db
pub fn block_height_by_hash(&self, hash: &H256) -> Option<u64>
sourcepub fn pos_reference_by_hash(&self, hash: &H256) -> Option<Option<PosBlockId>>
pub fn pos_reference_by_hash(&self, hash: &H256) -> Option<Option<PosBlockId>>
Return None
if the header does not exist.
Return Some(None)
if the header exist but it does not have a PoS
reference field.
pub fn compact_block_by_hash(&self, hash: &H256) -> Option<CompactBlock>
pub fn insert_compact_block(&self, cb: CompactBlock)
pub fn contains_compact_block(&self, hash: &H256) -> bool
sourcepub fn block_execution_result_by_hash_with_epoch(
&self,
hash: &H256,
assumed_epoch: &H256,
update_pivot_assumption: bool,
update_cache: bool
) -> Option<BlockExecutionResult>
pub fn block_execution_result_by_hash_with_epoch( &self, hash: &H256, assumed_epoch: &H256, update_pivot_assumption: bool, update_cache: bool ) -> Option<BlockExecutionResult>
Return None if receipts for corresponding epoch is not computed before
or has been overwritten by another new pivot chain in db.
If update_pivot_assumption
is true and we have execution results of
assumed_epoch
in memory, we will also ensure assumed_epoch
is persisted as the pivot hash in db.
This function will require lock of block_receipts.
pub fn block_execution_result_by_hash_from_db( &self, hash: &H256 ) -> Option<BlockExecutionResultWithEpoch>
pub fn block_epoch_number(&self, hash: &H256) -> Option<u64>
pub fn insert_block_execution_result( &self, hash: H256, epoch: H256, block_receipts: Arc<BlockReceipts>, persistent: bool )
pub fn insert_block_reward_result( &self, hash: H256, epoch: &H256, block_reward: BlockRewardResult, persistent: bool )
pub fn block_reward_result_by_hash_with_epoch( &self, hash: &H256, assumed_epoch_later: &H256, update_pivot_assumption: bool, update_cache: bool ) -> Option<BlockRewardResult>
pub fn remove_block_result(&self, hash: &H256, remove_db: bool)
pub fn transaction_index_by_hash( &self, hash: &H256, update_cache: bool ) -> Option<TransactionIndex>
pub fn insert_transaction_index(&self, hash: &H256, tx_index: &TransactionIndex)
pub fn hash_by_block_number( &self, block_number: u64, update_cache: bool ) -> Option<H256>
pub fn insert_hash_by_block_number(&self, block_number: u64, block_hash: &H256)
pub fn insert_local_block_info(&self, hash: &H256, info: LocalBlockInfo)
pub fn local_block_info_by_hash(&self, hash: &H256) -> Option<LocalBlockInfo>
pub fn insert_blamed_header_verified_roots( &self, height: u64, roots: BlamedHeaderVerifiedRoots )
sourcepub fn verified_blamed_roots_by_height(
&self,
height: u64
) -> Option<BlamedHeaderVerifiedRoots>
pub fn verified_blamed_roots_by_height( &self, height: u64 ) -> Option<BlamedHeaderVerifiedRoots>
Get correct roots of blamed headers from db. These are maintained on light nodes only.
pub fn remove_blamed_header_verified_roots(&self, height: u64)
pub fn insert_terminals_to_db(&self, terminals: Vec<H256>)
pub fn terminals_from_db(&self) -> Option<Vec<H256>>
pub fn insert_executed_epoch_set_hashes_to_db( &self, epoch_number: u64, epoch_set: &Vec<H256> )
pub fn insert_skipped_epoch_set_hashes_to_db( &self, epoch_number: u64, skipped_set: &Vec<H256> )
pub fn executed_epoch_set_hashes_from_db( &self, epoch_number: u64 ) -> Option<Vec<H256>>
pub fn skipped_epoch_set_hashes_from_db( &self, epoch_number: u64 ) -> Option<Vec<H256>>
pub fn all_epoch_set_hashes_from_db( &self, epoch_number: u64 ) -> Option<Vec<H256>>
sourcepub fn receipts_retain_epoch(&self, block_hash: &H256, epoch: &H256) -> bool
pub fn receipts_retain_epoch(&self, block_hash: &H256, epoch: &H256) -> bool
Return false
if there is no executed results for given block_hash
pub fn insert_epoch_execution_context( &self, hash: H256, ctx: EpochExecutionContext, persistent: bool )
sourcepub fn get_epoch_execution_context(
&self,
hash: &H256
) -> Option<EpochExecutionContext>
pub fn get_epoch_execution_context( &self, hash: &H256 ) -> Option<EpochExecutionContext>
The in-memory state will not be updated because it’s only garbage collected explicitly when we make checkpoints.
sourcepub fn insert_epoch_execution_commitment(
&self,
block_hash: H256,
state_root_with_aux_info: StateRootWithAuxInfo,
receipts_root: H256,
logs_bloom_hash: H256
)
pub fn insert_epoch_execution_commitment( &self, block_hash: H256, state_root_with_aux_info: StateRootWithAuxInfo, receipts_root: H256, logs_bloom_hash: H256 )
TODO We can avoid persisting execution_commitments for blocks not on the pivot chain after a checkpoint
sourcepub fn get_epoch_execution_commitment(
&self,
block_hash: &H256
) -> GuardedValue<RwLockReadGuard<'_, HashMap<H256, EpochExecutionCommitment>>, NonCopy<Option<&EpochExecutionCommitment>>>
pub fn get_epoch_execution_commitment( &self, block_hash: &H256 ) -> GuardedValue<RwLockReadGuard<'_, HashMap<H256, EpochExecutionCommitment>>, NonCopy<Option<&EpochExecutionCommitment>>>
Get in-mem execution commitment.
sourcepub fn load_epoch_execution_commitment_from_db(
&self,
block_hash: &H256
) -> Option<EpochExecutionCommitment>
pub fn load_epoch_execution_commitment_from_db( &self, block_hash: &H256 ) -> Option<EpochExecutionCommitment>
Load commitment from db. The caller should ensure that the loaded commitment is after cur_era_genesis and can be garbage-collected by checkpoint.
sourcepub fn get_epoch_execution_commitment_with_db(
&self,
block_hash: &H256
) -> Option<EpochExecutionCommitment>
pub fn get_epoch_execution_commitment_with_db( &self, block_hash: &H256 ) -> Option<EpochExecutionCommitment>
Get persisted execution commitment. It will check db if it’s missing in db.
pub fn insert_pos_reward(&self, pos_epoch: u64, pos_reward: &PosRewardInfo)
pub fn pos_reward_by_pos_epoch(&self, pos_epoch: u64) -> Option<PosRewardInfo>
pub fn remove_epoch_execution_commitment(&self, block_hash: &H256)
pub fn remove_epoch_execution_commitment_from_db(&self, block_hash: &H256)
pub fn remove_epoch_execution_context(&self, block_hash: &H256)
pub fn remove_epoch_execution_context_from_db(&self, block_hash: &H256)
pub fn epoch_executed(&self, epoch_hash: &H256) -> bool
sourcepub fn epoch_executed_and_recovered(
&self,
epoch_hash: &H256,
epoch_block_hashes: &Vec<H256>,
on_local_pivot: bool,
update_trace: bool,
reward_execution_info: &Option<RewardExecutionInfo>,
pos_verifier: &PosVerifier,
evm_chain_id: u32
) -> bool
pub fn epoch_executed_and_recovered( &self, epoch_hash: &H256, epoch_block_hashes: &Vec<H256>, on_local_pivot: bool, update_trace: bool, reward_execution_info: &Option<RewardExecutionInfo>, pos_verifier: &PosVerifier, evm_chain_id: u32 ) -> bool
Check if all executed results of an epoch exist
pub fn invalidate_block(&self, block_hash: H256)
sourcepub fn verified_invalid(
&self,
block_hash: &H256
) -> (bool, Option<LocalBlockInfo>)
pub fn verified_invalid( &self, block_hash: &H256 ) -> (bool, Option<LocalBlockInfo>)
Check if a block is already marked as invalid.
pub fn cached_block_count(&self) -> usize
sourcepub fn cache_size(&self) -> CacheSize
pub fn cache_size(&self) -> CacheSize
Get current cache size.
pub fn cache_gc(&self)
pub fn set_cur_consensus_era_genesis_hash( &self, cur_era_hash: &H256, next_era_hash: &H256 )
pub fn get_cur_consensus_era_genesis_hash(&self) -> H256
pub fn get_cur_consensus_era_stable_hash(&self) -> H256
pub fn recover_unsigned_tx( &self, transactions: &Vec<TransactionWithSignature> ) -> Result<Vec<Arc<SignedTransaction>>, DecoderError>
pub fn recover_block(&self, block: &mut Block) -> Result<(), DecoderError>
pub fn recover_unsigned_tx_with_order( &self, transactions: &Vec<TransactionWithSignature> ) -> Result<Vec<Arc<SignedTransaction>>, DecoderError>
pub fn find_missing_tx_indices_encoded( &self, compact_block: &mut CompactBlock ) -> Vec<usize>
sourcepub fn get_state_readonly_index(
&self,
block_hash: &EpochId
) -> Option<StateIndex>
pub fn get_state_readonly_index( &self, block_hash: &EpochId ) -> Option<StateIndex>
Caller should make sure the state exists.
pub fn get_parent_epochs_for( &self, block: EpochId, count: u64 ) -> (EpochId, Vec<EpochId>)
pub fn get_snapshot_epoch_count(&self) -> u32
pub fn get_snapshot_blame_plus_depth(&self) -> usize
pub fn get_executed_state_root(&self, block_hash: &H256) -> Option<H256>
pub fn earliest_epoch_with_block_body(&self) -> u64
pub fn earliest_epoch_with_execution_result(&self) -> u64
pub fn earliest_epoch_with_trace(&self) -> u64
pub fn new_checkpoint(&self, new_checkpoint_height: u64, best_epoch_number: u64)
pub fn database_gc(&self, best_epoch: u64)
Trait Implementations§
source§impl MallocSizeOf for BlockDataManager
impl MallocSizeOf for BlockDataManager
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl !RefUnwindSafe for BlockDataManager
impl Send for BlockDataManager
impl Sync for BlockDataManager
impl Unpin for BlockDataManager
impl !UnwindSafe for BlockDataManager
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
§impl<T> Conv for T
impl<T> Conv for T
source§impl<T> ElementSatisfy<ElementNoConstrain> for T
impl<T> ElementSatisfy<ElementNoConstrain> for T
fn to_constrain_object(&self) -> &ElementNoConstrain
fn to_constrain_object_mut(&mut self) -> &mut ElementNoConstrain
§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,
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>
§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.