Struct cfxcore::consensus::ConsensusGraph
source · pub struct ConsensusGraph {
pub inner: Arc<RwLock<ConsensusGraphInner>>,
pub txpool: SharedTransactionPool,
pub data_man: Arc<BlockDataManager>,
pub new_block_handler: ConsensusNewBlockHandler,
pub confirmation_meter: ConfirmationMeter,
pub ready_for_mining: AtomicBool,
pub synced_epoch_id: Mutex<Option<EpochId>>,
pub config: ConsensusConfig,
pub params: CommonParams,
/* private fields */
}
Expand description
ConsensusGraph is a layer on top of SynchronizationGraph. A SyncGraph collect all blocks that the client has received so far, but a block can only be delivered to the ConsensusGraph if 1) the whole block content is available and 2) all of its past blocks are also in the ConsensusGraph.
ConsensusGraph maintains the TreeGraph structure of the client and implements Timer Chain GHAST/Conflux algorithm to determine the block total order. It dispatches transactions in epochs to ConsensusExecutor to process. To avoid executing too many execution reroll caused by transaction order oscillation. It defers the transaction execution for a few epochs.
When recovery from database, ConsensusGraph requires that 1) the data manager is in a consistent state, 2) the data manager stores the correct era genesis and era stable hash, and 3) the data manager contains correct block status for all blocks before era stable block (more restrictively speaking, whose past sets do not contain the stable block).
Fields§
§inner: Arc<RwLock<ConsensusGraphInner>>
§txpool: SharedTransactionPool
§data_man: Arc<BlockDataManager>
§new_block_handler: ConsensusNewBlockHandler
§confirmation_meter: ConfirmationMeter
§ready_for_mining: AtomicBool
Set to true
when we enter NormalPhase
synced_epoch_id: Mutex<Option<EpochId>>
The epoch id of the remotely synchronized state.
This is always None
for archive nodes.
config: ConsensusConfig
§params: CommonParams
Implementations§
source§impl ConsensusGraph
impl ConsensusGraph
sourcepub fn with_era_genesis(
conf: ConsensusConfig,
txpool: SharedTransactionPool,
statistics: SharedStatistics,
data_man: Arc<BlockDataManager>,
pow_config: ProofOfWorkConfig,
pow: Arc<PowComputer>,
era_genesis_block_hash: &H256,
era_stable_block_hash: &H256,
notifications: Arc<Notifications>,
execution_conf: ConsensusExecutionConfiguration,
verification_config: VerificationConfig,
node_type: NodeType,
pos_verifier: Arc<PosVerifier>,
pivot_hint: Option<Arc<PivotHint>>,
params: CommonParams
) -> Self
pub fn with_era_genesis( conf: ConsensusConfig, txpool: SharedTransactionPool, statistics: SharedStatistics, data_man: Arc<BlockDataManager>, pow_config: ProofOfWorkConfig, pow: Arc<PowComputer>, era_genesis_block_hash: &H256, era_stable_block_hash: &H256, notifications: Arc<Notifications>, execution_conf: ConsensusExecutionConfiguration, verification_config: VerificationConfig, node_type: NodeType, pos_verifier: Arc<PosVerifier>, pivot_hint: Option<Arc<PivotHint>>, params: CommonParams ) -> Self
Build the ConsensusGraph with a specific era genesis block and various other components. The execution will be skipped if bench_mode sets to true.
sourcepub fn new(
conf: ConsensusConfig,
txpool: SharedTransactionPool,
statistics: SharedStatistics,
data_man: Arc<BlockDataManager>,
pow_config: ProofOfWorkConfig,
pow: Arc<PowComputer>,
notifications: Arc<Notifications>,
execution_conf: ConsensusExecutionConfiguration,
verification_conf: VerificationConfig,
node_type: NodeType,
pos_verifier: Arc<PosVerifier>,
pivot_hint: Option<Arc<PivotHint>>,
params: CommonParams
) -> Self
pub fn new( conf: ConsensusConfig, txpool: SharedTransactionPool, statistics: SharedStatistics, data_man: Arc<BlockDataManager>, pow_config: ProofOfWorkConfig, pow: Arc<PowComputer>, notifications: Arc<Notifications>, execution_conf: ConsensusExecutionConfiguration, verification_conf: VerificationConfig, node_type: NodeType, pos_verifier: Arc<PosVerifier>, pivot_hint: Option<Arc<PivotHint>>, params: CommonParams ) -> Self
Build the ConsensusGraph with the initial (checkpointed) genesis block in the data manager and various other components. The execution will be skipped if bench_mode sets to true.
sourcepub fn wait_for_generation(&self, hash: &H256)
pub fn wait_for_generation(&self, hash: &H256)
Wait for the generation and the execution completion of a block in the consensus graph. This API is used mainly for testing purpose
sourcepub fn check_mining_adaptive_block(
&self,
inner: &mut ConsensusGraphInner,
parent_hash: &H256,
referees: &Vec<H256>,
difficulty: &U256,
pos_reference: Option<PosBlockId>
) -> bool
pub fn check_mining_adaptive_block( &self, inner: &mut ConsensusGraphInner, parent_hash: &H256, referees: &Vec<H256>, difficulty: &U256, pos_reference: Option<PosBlockId> ) -> bool
Determine whether the next mined block should have adaptive weight or not
sourcepub fn choose_correct_parent(
&self,
parent_hash: &mut H256,
referees: &mut Vec<H256>,
blame_info: &mut StateBlameInfo,
pos_reference: Option<PosBlockId>
)
pub fn choose_correct_parent( &self, parent_hash: &mut H256, referees: &mut Vec<H256>, blame_info: &mut StateBlameInfo, pos_reference: Option<PosBlockId> )
After considering the latest pos_reference
, parent_hash
may become
an invalid choice, so this function tries to update the parent and
referee choices with pos_reference
provided.
sourcepub fn get_height_from_epoch_number(
&self,
epoch_number: EpochNumber
) -> Result<u64, String>
pub fn get_height_from_epoch_number( &self, epoch_number: EpochNumber ) -> Result<u64, String>
Convert EpochNumber to height based on the current ConsensusGraph
sourcepub fn gas_price(&self, space: Space) -> Option<U256>
pub fn gas_price(&self, space: Space) -> Option<U256>
Get the average gas price of the last GAS_PRICE_TRANSACTION_SAMPLE_SIZE blocks
pub fn validate_stated_epoch( &self, epoch_number: &EpochNumber ) -> Result<(), String>
sourcepub fn force_compute_blame_and_deferred_state_for_generation(
&self,
parent_block_hash: &H256
) -> Result<StateBlameInfo, String>
pub fn force_compute_blame_and_deferred_state_for_generation( &self, parent_block_hash: &H256 ) -> Result<StateBlameInfo, String>
Force the engine to recompute the deferred state root for a particular block given a delay.
pub fn get_blame_and_deferred_state_for_generation( &self, parent_block_hash: &H256 ) -> Result<StateBlameInfo, String>
pub fn best_block_hash(&self) -> H256
sourcepub fn best_executed_state_epoch_number(&self) -> u64
pub fn best_executed_state_epoch_number(&self) -> u64
Returns the latest epoch whose state can be exposed safely, which means its state is available and it’s not only visible to optimistic execution.
pub fn get_block_execution_info( &self, block_hash: &H256 ) -> Option<(BlockExecutionResultWithEpoch, Option<H256>)>
pub fn get_block_epoch_number_with_pivot_check( &self, hash: &H256, require_pivot: bool ) -> CoreResult<u64>
pub fn next_nonce( &self, address: AddressWithSpace, block_hash_or_epoch_number: BlockHashOrEpochNumber, rpc_param_name: &str ) -> CoreResult<U256>
pub fn get_log_filter_epoch_range( &self, from_epoch: EpochNumber, to_epoch: EpochNumber, check_range: bool ) -> Result<impl Iterator<Item = u64>, FilterError>
pub fn get_trace_filter_epoch_range( &self, filter: &TraceFilter ) -> Result<impl Iterator<Item = u64>, FilterError>
pub fn logs( &self, filter: LogFilter ) -> Result<Vec<LocalizedLogEntry>, FilterError>
pub fn filter_traces( &self, filter: TraceFilter ) -> Result<Vec<LocalizedTrace>, FilterError>
pub fn call_virtual( &self, tx: &SignedTransaction, epoch: EpochNumber, request: EstimateRequest ) -> CoreResult<(ExecutionOutcome, EstimateExt)>
pub fn collect_epoch_geth_trace( &self, epoch_num: u64, tx_hash: Option<H256>, opts: GethDebugTracingOptions ) -> CoreResult<Vec<GethTraceWithHash>>
pub fn collect_blocks_geth_trace( &self, epoch_id: H256, epoch_num: u64, blocks: &Vec<Arc<Block>>, opts: GethDebugTracingOptions, tx_hash: Option<H256> ) -> CoreResult<Vec<GethTraceWithHash>>
sourcepub fn get_processed_block_count(&self) -> usize
pub fn get_processed_block_count(&self) -> usize
Get the number of processed blocks (i.e., the number of calls to on_new_block()
sourcepub fn collect_traces_single_epoch(
&self,
filter: &TraceFilter,
epoch_number: u64,
assumed_pivot: H256
) -> Result<Vec<(H256, H256, BlockExecTraces, Vec<Arc<SignedTransaction>>)>, FilterError>
pub fn collect_traces_single_epoch( &self, filter: &TraceFilter, epoch_number: u64, assumed_pivot: H256 ) -> Result<Vec<(H256, H256, BlockExecTraces, Vec<Arc<SignedTransaction>>)>, FilterError>
Return Vec<(pivot_hash, block_hash, block_traces, block_txs)>
sourcepub fn filter_block_traces(
&self,
filter: &TraceFilter,
block_traces: Vec<(H256, H256, BlockExecTraces, Vec<Arc<SignedTransaction>>)>
) -> Result<Vec<LocalizedTrace>, FilterError>
pub fn filter_block_traces( &self, filter: &TraceFilter, block_traces: Vec<(H256, H256, BlockExecTraces, Vec<Arc<SignedTransaction>>)> ) -> Result<Vec<LocalizedTrace>, FilterError>
block_traces
is a list of tuple (pivot_hash, block_hash, block_trace)
.
pub fn get_phantom_block_bloom_filter( &self, block_num: EpochNumber, pivot_assumption: H256 ) -> Result<Option<Bloom>, String>
pub fn get_phantom_block_pivot_by_number( &self, block_num: EpochNumber, pivot_assumption: Option<H256>, include_traces: bool ) -> Result<Option<PhantomBlock>, String>
pub fn get_phantom_block_by_number( &self, block_num: EpochNumber, pivot_assumption: Option<H256>, include_traces: bool ) -> Result<Option<PhantomBlock>, String>
pub fn get_phantom_block_by_hash( &self, hash: &H256, include_traces: bool ) -> Result<Option<PhantomBlock>, String>
Trait Implementations§
source§impl ConsensusGraphTrait for ConsensusGraph
impl ConsensusGraphTrait for ConsensusGraph
source§fn on_new_block(&self, hash: &H256)
fn on_new_block(&self, hash: &H256)
This is the main function that SynchronizationGraph calls to deliver a new block to the consensus graph.
source§fn update_total_weight_delta_heartbeat(&self)
fn update_total_weight_delta_heartbeat(&self)
This function is a wrapper function for the function in the confirmation meter. The synchronization layer is supposed to call this function every 2 * BLOCK_PROPAGATION_DELAY seconds
source§fn construct_pivot_state(&self)
fn construct_pivot_state(&self)
construct_pivot_state() rebuild pivot chain state info from db avoiding intermediate redundant computation triggered by on_new_block().
source§fn expected_difficulty(&self, parent_hash: &H256) -> U256
fn expected_difficulty(&self, parent_hash: &H256) -> U256
Compute the expected difficulty of a new block given its parent
source§fn current_era_genesis_seq_num(&self) -> u64
fn current_era_genesis_seq_num(&self) -> u64
Return the sequence number of the current era genesis hash.
source§fn block_count(&self) -> u64
fn block_count(&self) -> u64
Returns the total number of blocks processed in consensus graph.
This function should only be used in tests. If the process crashes and recovered, the blocks in the anticone of the current checkpoint may not be counted since they will not be inserted into consensus in the recover process.
source§fn get_trusted_blame_block_for_snapshot(
&self,
snapshot_epoch_id: &EpochId
) -> Option<H256>
fn get_trusted_blame_block_for_snapshot( &self, snapshot_epoch_id: &EpochId ) -> Option<H256>
Find a trusted blame block for snapshot full sync
source§fn get_to_sync_epoch_id(&self) -> EpochId
fn get_to_sync_epoch_id(&self) -> EpochId
Return the epoch that we are going to sync the state
source§fn get_trusted_blame_block(&self, stable_hash: &H256) -> Option<H256>
fn get_trusted_blame_block(&self, stable_hash: &H256) -> Option<H256>
Find a trusted blame block for checkpoint
source§fn get_blocks_needing_bodies(&self) -> HashSet<H256>
fn get_blocks_needing_bodies(&self) -> HashSet<H256>
Return the blocks without bodies in the subtree of stable genesis and
the blocks in the REWARD_EPOCH_COUNT
epochs before it. Block
bodies of other blocks in the consensus graph will never be needed
for executions after this stable genesis, as long as the checkpoint
is not reverted.
source§fn catch_up_completed(&self, peer_median_epoch: u64) -> bool
fn catch_up_completed(&self, peer_median_epoch: u64) -> bool
Check if we have downloaded all the headers to find the lowest needed
checkpoint. We can enter CatchUpCheckpoint
if it’s true.
source§fn reset(&self)
fn reset(&self)
Reset the information in consensus graph with only checkpoint information kept.
type ConsensusConfig = ConsensusConfig
fn as_any(&self) -> &dyn Any
fn get_config(&self) -> &Self::ConsensusConfig
fn best_info(&self) -> Arc<BestInformation>
fn best_epoch_number(&self) -> u64
fn latest_checkpoint_epoch_number(&self) -> u64
fn latest_confirmed_epoch_number(&self) -> u64
fn latest_finalized_epoch_number(&self) -> u64
fn best_chain_id(&self) -> AllChainID
fn best_block_hash(&self) -> H256
fn get_data_manager(&self) -> &Arc<BlockDataManager>
fn get_tx_pool(&self) -> &SharedTransactionPool
fn get_statistics(&self) -> &SharedStatistics
fn get_hash_from_epoch_number( &self, epoch_number: EpochNumber ) -> Result<H256, String>
fn get_skipped_block_hashes_by_epoch( &self, epoch_number: EpochNumber ) -> Result<Vec<H256>, String>
source§fn get_transaction_info_by_hash(
&self,
hash: &H256
) -> Option<(SignedTransaction, TransactionInfo)>
fn get_transaction_info_by_hash( &self, hash: &H256 ) -> Option<(SignedTransaction, TransactionInfo)>
fn get_block_number(&self, block_hash: &H256) -> Result<Option<u64>, String>
fn set_initial_sequence_number(&self, initial_sn: u64)
fn get_storage_state_by_epoch_number( &self, epoch_number: EpochNumber, rpc_param_name: &str ) -> CoreResult<StorageState>
fn get_state_db_by_epoch_number( &self, epoch_number: EpochNumber, rpc_param_name: &str ) -> CoreResult<StateDb>
fn get_eth_state_db_by_epoch_number( &self, epoch_number: EpochNumber, rpc_param_name: &str ) -> CoreResult<StateDb>
fn enter_normal_phase(&self)
fn get_block_epoch_number(&self, hash: &H256) -> Option<u64>
fn get_block_hashes_by_epoch( &self, epoch_number: EpochNumber ) -> Result<Vec<H256>, String>
fn to_arc_consensus(self: Arc<Self>) -> Arc<ConsensusGraph>
source§impl Drop for ConsensusGraph
impl Drop for ConsensusGraph
source§impl MallocSizeOf for ConsensusGraph
impl MallocSizeOf for ConsensusGraph
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl !RefUnwindSafe for ConsensusGraph
impl Send for ConsensusGraph
impl Sync for ConsensusGraph
impl Unpin for ConsensusGraph
impl !UnwindSafe for ConsensusGraph
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.