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

source

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.

source

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.

source

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

source

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

source

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.

source

pub fn get_height_from_epoch_number( &self, epoch_number: EpochNumber ) -> Result<u64, String>

Convert EpochNumber to height based on the current ConsensusGraph

source

pub fn gas_price(&self, space: Space) -> Option<U256>

Get the average gas price of the last GAS_PRICE_TRANSACTION_SAMPLE_SIZE blocks

source

pub fn validate_stated_epoch( &self, epoch_number: &EpochNumber ) -> Result<(), String>

source

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.

source

pub fn get_blame_and_deferred_state_for_generation( &self, parent_block_hash: &H256 ) -> Result<StateBlameInfo, String>

source

pub fn best_block_hash(&self) -> H256

source

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.

source

pub fn get_block_execution_info( &self, block_hash: &H256 ) -> Option<(BlockExecutionResultWithEpoch, Option<H256>)>

source

pub fn get_block_epoch_number_with_pivot_check( &self, hash: &H256, require_pivot: bool ) -> CoreResult<u64>

source

pub fn next_nonce( &self, address: AddressWithSpace, block_hash_or_epoch_number: BlockHashOrEpochNumber, rpc_param_name: &str ) -> CoreResult<U256>

source

pub fn get_log_filter_epoch_range( &self, from_epoch: EpochNumber, to_epoch: EpochNumber, check_range: bool ) -> Result<impl Iterator<Item = u64>, FilterError>

source

pub fn get_trace_filter_epoch_range( &self, filter: &TraceFilter ) -> Result<impl Iterator<Item = u64>, FilterError>

source

pub fn logs( &self, filter: LogFilter ) -> Result<Vec<LocalizedLogEntry>, FilterError>

source

pub fn filter_traces( &self, filter: TraceFilter ) -> Result<Vec<LocalizedTrace>, FilterError>

source

pub fn call_virtual( &self, tx: &SignedTransaction, epoch: EpochNumber, request: EstimateRequest ) -> CoreResult<(ExecutionOutcome, EstimateExt)>

source

pub fn collect_epoch_geth_trace( &self, epoch_num: u64, tx_hash: Option<H256>, opts: GethDebugTracingOptions ) -> CoreResult<Vec<GethTraceWithHash>>

source

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>>

source

pub fn get_processed_block_count(&self) -> usize

Get the number of processed blocks (i.e., the number of calls to on_new_block()

source

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)>

source

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).

source

pub fn get_phantom_block_bloom_filter( &self, block_num: EpochNumber, pivot_assumption: H256 ) -> Result<Option<Bloom>, String>

source

pub fn get_phantom_block_pivot_by_number( &self, block_num: EpochNumber, pivot_assumption: Option<H256>, include_traces: bool ) -> Result<Option<PhantomBlock>, String>

source

pub fn get_phantom_block_by_number( &self, block_num: EpochNumber, pivot_assumption: Option<H256>, include_traces: bool ) -> Result<Option<PhantomBlock>, String>

source

pub fn get_phantom_block_by_hash( &self, hash: &H256, include_traces: bool ) -> Result<Option<PhantomBlock>, String>

Trait Implementations§

source§

impl ConsensusGraphTrait for ConsensusGraph

source§

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)

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)

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

Compute the expected difficulty of a new block given its parent

source§

fn current_era_genesis_seq_num(&self) -> u64

Return the sequence number of the current era genesis hash.

source§

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>

Find a trusted blame block for snapshot full sync

source§

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>

Find a trusted blame block for checkpoint

source§

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

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)

Reset the information in consensus graph with only checkpoint information kept.

§

type ConsensusConfig = ConsensusConfig

source§

fn as_any(&self) -> &dyn Any

source§

fn get_config(&self) -> &Self::ConsensusConfig

source§

fn best_info(&self) -> Arc<BestInformation>

source§

fn best_epoch_number(&self) -> u64

source§

fn latest_checkpoint_epoch_number(&self) -> u64

source§

fn latest_confirmed_epoch_number(&self) -> u64

source§

fn latest_finalized_epoch_number(&self) -> u64

source§

fn best_chain_id(&self) -> AllChainID

source§

fn best_block_hash(&self) -> H256

source§

fn get_data_manager(&self) -> &Arc<BlockDataManager>

source§

fn get_tx_pool(&self) -> &SharedTransactionPool

source§

fn get_statistics(&self) -> &SharedStatistics

source§

fn get_hash_from_epoch_number( &self, epoch_number: EpochNumber ) -> Result<H256, String>

source§

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)>

Return transaction info for clients. Note that the skipped transactions (status == 2) will not be returned.
source§

fn get_block_number(&self, block_hash: &H256) -> Result<Option<u64>, String>

source§

fn set_initial_sequence_number(&self, initial_sn: u64)

source§

fn get_storage_state_by_epoch_number( &self, epoch_number: EpochNumber, rpc_param_name: &str ) -> CoreResult<StorageState>

source§

fn get_state_db_by_epoch_number( &self, epoch_number: EpochNumber, rpc_param_name: &str ) -> CoreResult<StateDb>

source§

fn get_eth_state_db_by_epoch_number( &self, epoch_number: EpochNumber, rpc_param_name: &str ) -> CoreResult<StateDb>

source§

fn enter_normal_phase(&self)

source§

fn get_block_epoch_number(&self, hash: &H256) -> Option<u64>

source§

fn get_block_hashes_by_epoch( &self, epoch_number: EpochNumber ) -> Result<Vec<H256>, String>

source§

fn to_arc_consensus(self: Arc<Self>) -> Arc<ConsensusGraph>

source§

impl Drop for ConsensusGraph

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl MallocSizeOf for ConsensusGraph

source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
source§

impl<T> ElementSatisfy<ElementNoConstrain> for T

§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows 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) -> R
where R: 'a,

Mutably borrows 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
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T

§

impl<T> UnsafeAny for T
where T: Any,