From c9ddbd1d268b600709687b9c60aa556a3f939d7e Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 6 Jan 2025 11:18:16 +1100 Subject: [PATCH] move aura consensus data provider to the node --- Cargo.lock | 3 -- client/rpc/Cargo.toml | 3 -- client/rpc/src/eth/pending.rs | 67 +-------------------------------- template/node/src/rpc/eth.rs | 70 +++++++++++++++++++++++++++++++++-- 4 files changed, 68 insertions(+), 75 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a234bf9e7..685733c1e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2373,7 +2373,6 @@ dependencies = [ "sc-block-builder", "sc-client-api", "sc-client-db", - "sc-consensus-aura", "sc-network", "sc-network-sync", "sc-rpc", @@ -2387,7 +2386,6 @@ dependencies = [ "sp-block-builder", "sp-blockchain", "sp-consensus", - "sp-consensus-aura", "sp-core", "sp-externalities", "sp-inherents", @@ -2395,7 +2393,6 @@ dependencies = [ "sp-runtime", "sp-state-machine", "sp-storage", - "sp-timestamp", "substrate-prometheus-endpoint", "substrate-test-runtime-client", "tempfile", diff --git a/client/rpc/Cargo.toml b/client/rpc/Cargo.toml index 4db1948c5e..9c42ec885e 100644 --- a/client/rpc/Cargo.toml +++ b/client/rpc/Cargo.toml @@ -31,7 +31,6 @@ tokio = { workspace = true, features = ["sync"] } # Substrate prometheus-endpoint = { workspace = true } sc-client-api = { workspace = true } -sc-consensus-aura = { workspace = true } sc-network = { workspace = true } sc-network-sync = { workspace = true } sc-rpc = { workspace = true } @@ -43,7 +42,6 @@ sp-api = { workspace = true, features = ["default"] } sp-block-builder = { workspace = true, features = ["default"] } sp-blockchain = { workspace = true } sp-consensus = { workspace = true } -sp-consensus-aura = { workspace = true, features = ["default"] } sp-core = { workspace = true, features = ["default"] } sp-externalities = { workspace = true, features = ["default"] } sp-inherents = { workspace = true, features = ["default"] } @@ -51,7 +49,6 @@ sp-io = { workspace = true, features = ["default"] } sp-runtime = { workspace = true, features = ["default"] } sp-state-machine = { workspace = true, features = ["default"] } sp-storage = { workspace = true, features = ["default"] } -sp-timestamp = { workspace = true, features = ["default"] } # Frontier fc-api = { workspace = true } fc-mapping-sync = { workspace = true } diff --git a/client/rpc/src/eth/pending.rs b/client/rpc/src/eth/pending.rs index f03522c9a3..186e6e868d 100644 --- a/client/rpc/src/eth/pending.rs +++ b/client/rpc/src/eth/pending.rs @@ -16,13 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::{marker::PhantomData, sync::Arc}; - // Substrate -use sc_client_api::{ - backend::{AuxStore, Backend, StorageProvider}, - UsageProvider, -}; +use sc_client_api::backend::{Backend, StorageProvider}; use sc_transaction_pool::ChainApi; use sc_transaction_pool_api::InPoolTransaction; use sp_api::{ApiExt, ApiRef, Core, ProvideRuntimeApi}; @@ -30,11 +25,10 @@ use sp_block_builder::BlockBuilder as BlockBuilderApi; use sp_blockchain::{ApplyExtrinsicFailed, HeaderBackend}; use sp_inherents::{CreateInherentDataProviders, InherentData, InherentDataProvider}; use sp_runtime::{ - generic::{Digest, DigestItem}, + generic::Digest, traits::{Block as BlockT, Header as HeaderT, One}, TransactionOutcome, }; -use sp_timestamp::TimestampInherentData; use crate::eth::Eth; use fp_rpc::EthereumRuntimeRPCApi; @@ -168,60 +162,3 @@ impl ConsensusDataProvider for () { Ok(Default::default()) } } - -pub use self::aura::AuraConsensusDataProvider; -mod aura { - use super::*; - use sp_consensus_aura::{ - digests::CompatibleDigestItem, - sr25519::{AuthorityId, AuthoritySignature}, - AuraApi, Slot, SlotDuration, - }; - - /// Consensus data provider for Aura. - pub struct AuraConsensusDataProvider { - // slot duration - slot_duration: SlotDuration, - // phantom data for required generics - _phantom: PhantomData<(B, C)>, - } - - impl AuraConsensusDataProvider - where - B: BlockT, - C: AuxStore + ProvideRuntimeApi + UsageProvider, - C::Api: AuraApi, - { - /// Creates a new instance of the [`AuraConsensusDataProvider`], requires that `client` - /// implements [`sp_consensus_aura::AuraApi`] - pub fn new(client: Arc) -> Self { - let slot_duration = sc_consensus_aura::slot_duration(&*client) - .expect("slot_duration is always present; qed."); - Self { - slot_duration, - _phantom: PhantomData, - } - } - } - - impl ConsensusDataProvider for AuraConsensusDataProvider { - fn create_digest( - &self, - _parent: &B::Header, - data: &InherentData, - ) -> Result { - let timestamp = data - .timestamp_inherent_data()? - .expect("Timestamp is always present; qed"); - - let digest_item = - >::aura_pre_digest( - Slot::from_timestamp(timestamp, self.slot_duration), - ); - - Ok(Digest { - logs: vec![digest_item], - }) - } - } -} diff --git a/template/node/src/rpc/eth.rs b/template/node/src/rpc/eth.rs index 59f956b69d..3396cfb443 100644 --- a/template/node/src/rpc/eth.rs +++ b/template/node/src/rpc/eth.rs @@ -66,6 +66,67 @@ pub struct EthDeps { pub pending_create_inherent_data_providers: CIDP, } +mod aura { + use super::*; + use fc_rpc::pending::ConsensusDataProvider; + use sp_consensus_aura::{ + digests::CompatibleDigestItem, + sr25519::{AuthorityId, AuthoritySignature}, + AuraApi, Slot, SlotDuration, + }; + use sp_inherents::InherentData; + use sp_runtime::{Digest, DigestItem}; + use sp_timestamp::TimestampInherentData; + use std::marker::PhantomData; + + /// Consensus data provider for Aura. + pub struct AuraConsensusDataProvider { + // slot duration + slot_duration: SlotDuration, + // phantom data for required generics + _phantom: PhantomData<(B, C)>, + } + + impl AuraConsensusDataProvider + where + B: BlockT, + C: AuxStore + ProvideRuntimeApi + UsageProvider, + C::Api: AuraApi, + { + /// Creates a new instance of the [`AuraConsensusDataProvider`], requires that `client` + /// implements [`sp_consensus_aura::AuraApi`] + pub fn new(client: Arc) -> Self { + let slot_duration = sc_consensus_aura::slot_duration(&*client) + .expect("slot_duration is always present; qed."); + Self { + slot_duration, + _phantom: PhantomData, + } + } + } + + impl ConsensusDataProvider for AuraConsensusDataProvider { + fn create_digest( + &self, + _parent: &B::Header, + data: &InherentData, + ) -> Result { + let timestamp = data + .timestamp_inherent_data()? + .expect("Timestamp is always present; qed"); + + let digest_item = + >::aura_pre_digest( + Slot::from_timestamp(timestamp, self.slot_duration), + ); + + Ok(Digest { + logs: vec![digest_item], + }) + } + } +} + /// Instantiate Ethereum-compatible RPC extensions. pub fn create_eth( mut io: RpcModule<()>, @@ -94,9 +155,8 @@ where EC: EthConfig, { use fc_rpc::{ - pending::AuraConsensusDataProvider, Debug, DebugApiServer, Eth, EthApiServer, EthDevSigner, - EthFilter, EthFilterApiServer, EthPubSub, EthPubSubApiServer, EthSigner, Net, NetApiServer, - Web3, Web3ApiServer, + Debug, DebugApiServer, Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, + EthPubSub, EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer, }; #[cfg(feature = "txpool")] use fc_rpc::{TxPool, TxPoolApiServer}; @@ -144,7 +204,9 @@ where execute_gas_limit_multiplier, forced_parent_hashes, pending_create_inherent_data_providers, - Some(Box::new(AuraConsensusDataProvider::new(client.clone()))), + Some(Box::new(aura::AuraConsensusDataProvider::new( + client.clone(), + ))), ) .replace_config::() .into_rpc(),