Struct cfxcore::sync::SynchronizationGraph
source · pub struct SynchronizationGraph {
pub inner: Arc<RwLock<SynchronizationGraphInner>>,
pub consensus: SharedConsensusGraph,
pub data_man: Arc<BlockDataManager>,
pub pow: Arc<PowComputer>,
pub verification_config: VerificationConfig,
pub sync_config: SyncGraphConfig,
pub statistics: SharedStatistics,
pub future_blocks: FutureBlockContainer,
/* private fields */
}
Fields§
§inner: Arc<RwLock<SynchronizationGraphInner>>
§consensus: SharedConsensusGraph
§data_man: Arc<BlockDataManager>
§pow: Arc<PowComputer>
§verification_config: VerificationConfig
§sync_config: SyncGraphConfig
§statistics: SharedStatistics
§future_blocks: FutureBlockContainer
The blocks whose timestamps are near future. They will be inserted into sync graph inner at their timestamp.
Implementations§
source§impl SynchronizationGraph
impl SynchronizationGraph
pub fn new( consensus: SharedConsensusGraph, verification_config: VerificationConfig, pow_config: ProofOfWorkConfig, pow: Arc<PowComputer>, sync_config: SyncGraphConfig, notifications: Arc<Notifications>, machine: Arc<Machine>, pos_verifier: Arc<PosVerifier> ) -> Self
pub fn is_consortium(&self) -> bool
pub fn machine(&self) -> Arc<Machine>
pub fn get_genesis_hash_and_height_in_current_era(&self) -> (H256, u64)
sourcepub fn expected_difficulty(&self, parent_hash: &H256) -> U256
pub fn expected_difficulty(&self, parent_hash: &H256) -> U256
Compute the expected difficulty for a block given its parent hash
pub fn get_to_propagate_trans(&self) -> HashMap<H256, Arc<SignedTransaction>>
pub fn set_to_propagate_trans( &self, transactions: HashMap<H256, Arc<SignedTransaction>> )
sourcepub fn recover_graph_from_db(&self)
pub fn recover_graph_from_db(&self)
In full/archive node, this function can be invoked during CatchUpRecoverBlockHeaderFromDbPhase phase. It tries to construct the consensus graph based on header information stored in db.
sourcepub fn block_header_by_hash(&self, hash: &H256) -> Option<BlockHeader>
pub fn block_header_by_hash(&self, hash: &H256) -> Option<BlockHeader>
Return None if hash
is not in sync graph
sourcepub fn block_height_by_hash(&self, hash: &H256) -> Option<u64>
pub fn block_height_by_hash(&self, hash: &H256) -> Option<u64>
Return None if hash
is not in sync graph
sourcepub fn block_timestamp_by_hash(&self, hash: &H256) -> Option<u64>
pub fn block_timestamp_by_hash(&self, hash: &H256) -> Option<u64>
Return None if hash
is not in sync graph
sourcepub fn block_by_hash(&self, hash: &H256) -> Option<Arc<Block>>
pub fn block_by_hash(&self, hash: &H256) -> Option<Arc<Block>>
TODO Be more specific about which functions only return in-memory data and which can return the in-database data
pub fn contains_block_header(&self, hash: &H256) -> bool
pub fn insert_block_header( &self, header: &mut BlockHeader, need_to_verify: bool, bench_mode: bool, insert_to_consensus: bool, persistent: bool ) -> (BlockHeaderInsertionResult, Vec<H256>)
pub fn contains_block(&self, hash: &H256) -> bool
pub fn insert_block( &self, block: Block, need_to_verify: bool, persistent: bool, recover_from_db: bool ) -> BlockInsertionResult
pub fn get_all_block_hashes_by_epoch( &self, epoch_number: u64 ) -> Result<Vec<H256>, String>
pub fn log_statistics(&self)
pub fn update_total_weight_delta_heartbeat(&self)
sourcepub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
Get the current number of blocks in the synchronization graph This only returns cached block count, and this is enough since this is only used in test.
sourcepub fn remove_expire_blocks(&self, expire_time: u64)
pub fn remove_expire_blocks(&self, expire_time: u64)
Remove all blocks which have not been updated for a long time. We
maintain a set not_ready_blocks_frontier
which is the root nodes in
the parental tree formed by not graph ready blocks. Find all expire
blocks which can be reached by not_ready_blocks_frontier
.
sourcepub fn remove_blocks_and_future(&self, to_remove_set: &HashSet<H256>)
pub fn remove_blocks_and_future(&self, to_remove_set: &HashSet<H256>)
Remove all blocks in to_remove_set
and their future set from the
graph.
pub fn is_consensus_worker_busy(&self) -> bool
pub fn is_fill_block_completed(&self) -> bool
sourcepub fn complete_filling_block_bodies(&self) -> bool
pub fn complete_filling_block_bodies(&self) -> bool
Construct the states along the pivot chain, set all
BLOCK_HEADER_GRAPH_READY
blocks as BLOCK_GRAPH_READY
and remove all
other blocks. All blocks in the future can be processed normally in
sync graph and consensus graph.
If some blocks become invalid after validating their bodies, we need to
remove them and reconstruct the consensus graph. Return false
if
there are blocks in the new consensus graph whose bodies are missing.
Return true
if we do not need to reconstruct consensus, or all blocks
in the new consensus graph already have bodies.
sourcepub fn check_not_ready_frontier(&self, header_only: bool)
pub fn check_not_ready_frontier(&self, header_only: bool)
TODO(lpl): Only triggered when pos commits new blocks? Check if not_ready_frontier blocks become ready now. Blocks that are not ready because of missing pos references only become ready here.
Trait Implementations§
source§impl MallocSizeOf for SynchronizationGraph
impl MallocSizeOf for SynchronizationGraph
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl !RefUnwindSafe for SynchronizationGraph
impl Send for SynchronizationGraph
impl Sync for SynchronizationGraph
impl Unpin for SynchronizationGraph
impl !UnwindSafe for SynchronizationGraph
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.