From 88094e8cdd22cc27fb6cf79a427731dd903ae4a4 Mon Sep 17 00:00:00 2001 From: Raj Raorane <41839716+Raj-RR1@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:43:52 +0530 Subject: [PATCH] cli, cli-opt, consensus transition and rpc changes --- node/cli-opt/src/lib.rs | 4 ++-- node/cli/src/service.rs | 2 ++ .../aura/src/import_queue.rs | 23 +++++++++++++++---- node/consensus-transition/aura/src/lib.rs | 19 ++++++++++++--- node/rpc/src/client.rs | 6 +++++ node/rpc/src/lib.rs | 11 +++++++++ node/rpc/src/tracing.rs | 2 +- 7 files changed, 57 insertions(+), 10 deletions(-) diff --git a/node/cli-opt/src/lib.rs b/node/cli-opt/src/lib.rs index e419820c..21bc7086 100644 --- a/node/cli-opt/src/lib.rs +++ b/node/cli-opt/src/lib.rs @@ -16,7 +16,7 @@ use std::{fmt, str::FromStr}; /// Block authoring scheme to be used by the dev service. -#[derive(Debug)] +#[derive(Debug, Copy, Clone)] pub enum Sealing { /// Author a block immediately upon receiving a transaction into the /// transaction pool @@ -85,6 +85,6 @@ pub struct RpcConfig { pub eth_statuses_cache: usize, pub fee_history_limit: u64, pub max_past_logs: u32, - pub relay_chain_rpc_url: Option, + pub relay_chain_rpc_url: Vec, pub tracing_raw_max_memory_usage: usize, } diff --git a/node/cli/src/service.rs b/node/cli/src/service.rs index 6a12c26b..ad4f0bc9 100644 --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -309,6 +309,8 @@ pub struct NewFullBase { pub client: Arc, /// The networking service of the node. pub network: Arc::Hash>>, + /// The syncing service of the node. + pub sync: Arc>, /// The transaction pool of the node. pub transaction_pool: Arc, /// The rpc handlers of the node. diff --git a/node/consensus-transition/aura/src/import_queue.rs b/node/consensus-transition/aura/src/import_queue.rs index 116f4297..01a2384c 100644 --- a/node/consensus-transition/aura/src/import_queue.rs +++ b/node/consensus-transition/aura/src/import_queue.rs @@ -19,7 +19,7 @@ //! Module implementing the logic for verifying and importing AuRa blocks. use crate::{ - aura_err, authorities, find_pre_digest, slot_author, AuthorityId, CompatibilityMode, Error, + aura_err, authorities, standalone::SealVerificationError, find_pre_digest, slot_author, AuthorityId, CompatibilityMode, Error, }; use parity_scale_codec::{Codec, Decode, Encode}; use log::{debug, info, trace}; @@ -145,6 +145,7 @@ where async fn check_inherents( &self, block: B, + //at_hash: B::Hash, --Raj block_id: BlockId, inherent_data: sp_inherents::InherentData, create_inherent_data_providers: CIDP::InherentDataProviders, @@ -201,6 +202,19 @@ where &mut self, mut block: BlockImportParams, ) -> Result<(BlockImportParams, Option)>>), String> { + + // Skip checks that include execution, if being told so or when importing only state. + // + // This is done for example when gap syncing and it is expected that the block after the gap + // was checked/chosen properly, e.g. by warp syncing to this block using a finality proof. + // Or when we are importing state only and can not verify the seal. + if block.with_state() || block.state_action.skip_execution_checks() { + // When we are importing only the state of a block, it will be the best block. + block.fork_choice = Some(ForkChoiceStrategy::Custom(block.with_state())); + + return Ok(block) + } + let hash = block.header.hash(); let parent_hash = *block.header.parent_hash(); let authorities = authorities( @@ -219,6 +233,7 @@ where let mut inherent_data = create_inherent_data_providers .create_inherent_data() + .await .map_err(Error::::Inherent)?; let slot_now = create_inherent_data_providers.slot(); @@ -250,14 +265,14 @@ where .client .runtime_api() .has_api_with::, _>( - &BlockId::Hash(parent_hash), + parent_hash, |v| v >= 2, ) .map_err(|e| e.to_string())? { self.check_inherents( new_block.clone(), - BlockId::Hash(parent_hash), + parent_hash, inherent_data, create_inherent_data_providers, block.origin.into(), @@ -283,7 +298,7 @@ where block.fork_choice = Some(ForkChoiceStrategy::LongestChain); block.post_hash = Some(hash); - Ok((block, None)) + Ok(block) }, CheckedHeader::Deferred(a, b) => { debug!(target: "aura", "Checking {:?} failed; {:?}, {:?}.", hash, a, b); diff --git a/node/consensus-transition/aura/src/lib.rs b/node/consensus-transition/aura/src/lib.rs index cc192780..89d6e22d 100644 --- a/node/consensus-transition/aura/src/lib.rs +++ b/node/consensus-transition/aura/src/lib.rs @@ -251,9 +251,13 @@ where } /// Parameters of [`build_aura_worker`]. -pub struct BuildAuraWorkerParams { +pub struct BuildAuraWorkerParams { + /// The duration of a slot. + pub slot_duration: SlotDuration, /// The client to interact with the chain. pub client: Arc, + /// A select chain implementation to select the best block. + pub select_chain: SC, /// The block import. pub block_import: I, /// The proposer factory to build proposer instances. @@ -262,6 +266,8 @@ pub struct BuildAuraWorkerParams { pub sync_oracle: SO, /// Hook into the sync module to control the justification sync process. pub justification_sync_link: L, + /// Something that can create the inherent data providers. + pub create_inherent_data_providers: CIDP, /// Should we force the authoring of blocks? pub force_authoring: bool, /// The backoff strategy when we miss slots. @@ -303,7 +309,14 @@ pub fn build_aura_worker( force_authoring, compatibility_mode, }: BuildAuraWorkerParams>, -) -> impl sc_consensus_slots::SlotWorker>::Proof> +) -> impl sc_consensus_slots::SlotWorker>, + > where B: BlockT, @@ -315,7 +328,7 @@ where P::Public: AppPublic + Hash + Member + Encode + Decode, P::Signature: TryFrom> + Hash + Member + Encode + Decode, I: BlockImport> + Send + Sync + 'static, - Error: std::error::Error + Send + From + 'static, + Error: std::error::Error + Send + From + 'static, SO: SyncOracle + Send + Sync + Clone, L: sc_consensus::JustificationSyncLink, BS: BackoffAuthoringBlocksStrategy> + Send + Sync + 'static, diff --git a/node/rpc/src/client.rs b/node/rpc/src/client.rs index 29766ee9..2f5d74b8 100644 --- a/node/rpc/src/client.rs +++ b/node/rpc/src/client.rs @@ -33,6 +33,9 @@ pub trait RuntimeApiCollection: + fp_rpc::EthereumRuntimeRPCApi + edgeware_rpc_primitives_debug::DebugRuntimeApi + edgeware_rpc_primitives_txpool::TxPoolRuntimeApi + + nimbus_primitives::NimbusApi + + cumulus_primitives_core::CollectCollationInfo + + session_keys_primitives::VrfApi where >::StateBackend: sp_api::StateBackend, { @@ -52,6 +55,9 @@ where + fp_rpc::EthereumRuntimeRPCApi + edgeware_rpc_primitives_debug::DebugRuntimeApi + edgeware_rpc_primitives_txpool::TxPoolRuntimeApi, + + nimbus_primitives::NimbusApi + + cumulus_primitives_core::CollectCollationInfo + + session_keys_primitives::VrfApi, >::StateBackend: sp_api::StateBackend, { } diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 5261b570..34a69fbb 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -51,10 +51,12 @@ use sc_client_api::{ client::BlockchainEvents, BlockOf, }; +use sc_consensus_babe::BabeWorkerHandle; use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApi}; use sc_network::NetworkService; use sc_transaction_pool::{ChainApi, Pool}; use sp_runtime::traits::{BlakeTwo256, Block as BlockT}; +use sp_keystore::KeystorePtr; // Frontier use fc_rpc::{ EthBlockDataCacheTask, EthTask, OverrideHandle, RuntimeApiStorageOverride, @@ -73,6 +75,15 @@ pub mod client; pub mod tracing; use client::RuntimeApiCollection; + +/// Extra dependencies for BABE. +pub struct BabeDeps { + /// A handle to the BABE worker for issuing requests. + pub babe_worker_handle: BabeWorkerHandle, + /// The keystore that manages the keys of the node. + pub keystore: KeystorePtr, +} + /// Extra dependencies for GRANDPA pub struct GrandpaDeps { /// Voting round info. diff --git a/node/rpc/src/tracing.rs b/node/rpc/src/tracing.rs index 156e9ffd..485e75e9 100644 --- a/node/rpc/src/tracing.rs +++ b/node/rpc/src/tracing.rs @@ -76,7 +76,7 @@ pub fn extend_with_tracing( } } -/// Spawn the tasks that are required to run a Moonbeam tracing node. +/// Spawn the tasks that are required to run an Edgeware tracing node. pub fn spawn_tracing_tasks( rpc_config: &edgeware_cli_opt::RpcConfig, params: SpawnTasksParams,