Skip to content

Commit

Permalink
upgrade frontier to latest commit.
Browse files Browse the repository at this point in the history
We had to introduce Inherent data providers since upstream introduced `pending` tags for Eth rpc calls.
When an rpc call with pending tag is received, we construct pending block by building a new block with extrinsics from tx pool.
So they use inherent data providers to provide inherent data. For now, we just provide timestamp since that is always required.
I have added an TODO to handle any new inherents that needs to be present. Ex runtime upgrade can be added in later PR
  • Loading branch information
vedhavyas committed Sep 13, 2023
1 parent 69724ae commit a7c09c6
Show file tree
Hide file tree
Showing 15 changed files with 425 additions and 166 deletions.
388 changes: 282 additions & 106 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/subspace-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ domain-eth-service = { version = "0.1.0", path = "../../domains/client/eth-servi
domain-service = { version = "0.1.0", path = "../../domains/service" }
domain-runtime-primitives = { version = "0.1.0", path = "../../domains/primitives/runtime" }
evm-domain-runtime = { version = "0.1.0", path = "../../domains/runtime/evm" }
fp-evm = { version = "3.0.0-dev", git = "https://github.com/subspace/frontier", rev = "068cb2eaae8b732a2a7d2c28e07a920684e19b69" }
fp-evm = { version = "3.0.0-dev", git = "https://github.com/subspace/frontier", rev = "01b56190c0ed019b187c34d23422b9fea7ca4393" }
frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898", default-features = false }
frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898", default-features = false }
frame-support = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
Expand Down
3 changes: 3 additions & 0 deletions domains/client/block-preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include = [
]

[dependencies]
async-trait = { version = "0.1.57" }
codec = { package = "parity-scale-codec", version = "3.6.5", features = [ "derive" ] }
domain-runtime-primitives = { version = "0.1.0", path = "../../primitives/runtime" }
rand = "0.8.5"
Expand All @@ -23,9 +24,11 @@ sp-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate",
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
sp-core = { version = "21.0.0", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
sp-domains = { version = "0.1.0", path = "../../../crates/sp-domains" }
sp-inherents = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
sp-messenger = { version = "0.1.0", path = "../../primitives/messenger" }
sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
sp-state-machine = { version = "0.28.0", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
subspace-core-primitives = { version = "0.1.0", path = "../../../crates/subspace-core-primitives" }
subspace-runtime-primitives = { version = "0.1.0", path = "../../../crates/subspace-runtime-primitives" }
tracing = "0.1.37"
Expand Down
58 changes: 57 additions & 1 deletion domains/client/block-preprocessor/src/inherents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@

use crate::runtime_api::InherentExtrinsicConstructor;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_domains::DomainsApi;
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use sp_timestamp::InherentType;
use std::error::Error;
use std::marker::PhantomData;
use std::sync::Arc;

/// Returns required inherent extrinsics for the domain block based on the primary block.
/// Note: consensus block hash must be used to construct domain block.
pub fn construct_inherent_extrinsics<Block, DomainRuntimeApi, CBlock, CClient>(
pub(crate) fn construct_inherent_extrinsics<Block, DomainRuntimeApi, CBlock, CClient>(
consensus_client: &Arc<CClient>,
domain_runtime_api: &DomainRuntimeApi,
consensus_block_hash: CBlock::Hash,
Expand All @@ -46,3 +51,54 @@ where

Ok(inherent_exts)
}

#[derive(Debug)]
#[allow(dead_code)]
pub struct CreateInherentDataProvider<CClient, CBlock> {
consensus_client: Arc<CClient>,
_marker: PhantomData<CBlock>,
}

impl<CClient, CBlock: Clone> Clone for CreateInherentDataProvider<CClient, CBlock> {
fn clone(&self) -> Self {
Self {
consensus_client: self.consensus_client.clone(),
_marker: Default::default(),
}
}
}

impl<CClient, CBlock> CreateInherentDataProvider<CClient, CBlock> {
pub fn new(consensus_client: Arc<CClient>) -> Self {
Self {
consensus_client,
_marker: Default::default(),
}
}
}

#[async_trait::async_trait]
impl<CClient, CBlock, Block> CreateInherentDataProviders<Block, ()>
for CreateInherentDataProvider<CClient, CBlock>
where
Block: BlockT,
CBlock: BlockT,
CClient: ProvideRuntimeApi<CBlock> + HeaderBackend<CBlock>,
CClient::Api: DomainsApi<CBlock, NumberFor<Block>, Block::Hash>,
{
// TODO: we need to include the runtime upgrade
type InherentDataProviders = sp_timestamp::InherentDataProvider;

async fn create_inherent_data_providers(
&self,
_parent: Block::Hash,
_extra_args: (),
) -> Result<Self::InherentDataProviders, Box<dyn Error + Send + Sync>> {
let best_consensus_hash = self.consensus_client.info().best_hash;
let runtime_api = self.consensus_client.runtime_api();
let timestamp = runtime_api.timestamp(best_consensus_hash)?;
Ok(sp_timestamp::InherentDataProvider::new(InherentType::new(
timestamp,
)))
}
}
2 changes: 1 addition & 1 deletion domains/client/block-preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#![warn(rust_2018_idioms)]

mod inherents;
pub mod inherents;
pub mod runtime_api;
pub mod runtime_api_full;
pub mod runtime_api_light;
Expand Down
15 changes: 8 additions & 7 deletions domains/client/eth-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ include = [
clap = { version = "4.4.3", features = ["derive"] }
domain-runtime-primitives = { version = "0.1.0", path = "../../primitives/runtime" }
domain-service = { version = "0.1.0", path = "../../service" }
fc-consensus = { version = "2.0.0-dev", git = "https://github.com/subspace/frontier", rev = "068cb2eaae8b732a2a7d2c28e07a920684e19b69" }
fc-db = { version = "2.0.0-dev", git = "https://github.com/subspace/frontier", rev = "068cb2eaae8b732a2a7d2c28e07a920684e19b69", default-features = false }
fc-mapping-sync = { version = "2.0.0-dev", git = "https://github.com/subspace/frontier", rev = "068cb2eaae8b732a2a7d2c28e07a920684e19b69", default-features = false }
fc-rpc = { version = "2.0.0-dev", git = "https://github.com/subspace/frontier", rev = "068cb2eaae8b732a2a7d2c28e07a920684e19b69", default-features = false, features = ['rpc-binary-search-estimate'] }
fc-rpc-core = { version = "1.1.0-dev", git = "https://github.com/subspace/frontier", rev = "068cb2eaae8b732a2a7d2c28e07a920684e19b69" }
fc-storage = { version = "1.0.0-dev", git = "https://github.com/subspace/frontier", rev = "068cb2eaae8b732a2a7d2c28e07a920684e19b69" }
fp-rpc = { version = "3.0.0-dev", git = "https://github.com/subspace/frontier", rev = "068cb2eaae8b732a2a7d2c28e07a920684e19b69", features = ['default'] }
fc-consensus = { version = "2.0.0-dev", git = "https://github.com/subspace/frontier", rev = "01b56190c0ed019b187c34d23422b9fea7ca4393" }
fc-db = { version = "2.0.0-dev", git = "https://github.com/subspace/frontier", rev = "01b56190c0ed019b187c34d23422b9fea7ca4393", default-features = false }
fc-mapping-sync = { version = "2.0.0-dev", git = "https://github.com/subspace/frontier", rev = "01b56190c0ed019b187c34d23422b9fea7ca4393", default-features = false }
fc-rpc = { version = "2.0.0-dev", git = "https://github.com/subspace/frontier", rev = "01b56190c0ed019b187c34d23422b9fea7ca4393", default-features = false, features = ['rpc-binary-search-estimate'] }
fc-rpc-core = { version = "1.1.0-dev", git = "https://github.com/subspace/frontier", rev = "01b56190c0ed019b187c34d23422b9fea7ca4393" }
fc-storage = { version = "1.0.0-dev", git = "https://github.com/subspace/frontier", rev = "01b56190c0ed019b187c34d23422b9fea7ca4393" }
fp-rpc = { version = "3.0.0-dev", git = "https://github.com/subspace/frontier", rev = "01b56190c0ed019b187c34d23422b9fea7ca4393", features = ['default'] }
futures = "0.3.28"
jsonrpsee = { version = "0.16.3", features = ["server"] }
pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
Expand All @@ -37,5 +37,6 @@ sp-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate",
sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
sp-core = { version = "21.0.0", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
sp-inherents = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "48c5ebae44b90d45863195b91e0e489eca670898" }
13 changes: 8 additions & 5 deletions domains/client/eth-service/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_core::traits::SpawnEssentialNamed;
use sp_core::H256;
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::codec::{Decode, Encode};
use std::error::Error;
use std::fmt::{Debug, Display};
Expand Down Expand Up @@ -80,8 +81,8 @@ where
}
}

impl<Block, Client, BE, TxPool, CA, AccountId, CT, EC>
RpcProvider<Block, Client, TxPool, CA, BE, AccountId> for EthProvider<CT, EC>
impl<Block, Client, BE, TxPool, CA, AccountId, CT, EC, CIDP>
RpcProvider<Block, Client, TxPool, CA, BE, AccountId, CIDP> for EthProvider<CT, EC>
where
Block: BlockT<Hash = H256>,
BE: Backend<Block> + 'static,
Expand All @@ -107,12 +108,13 @@ where
TxPool: TransactionPool<Block = Block> + Sync + Send + 'static,
CA: ChainApi<Block = Block> + 'static,
AccountId: DeserializeOwned + Encode + Debug + Decode + Display + Clone + Sync + Send + 'static,
CIDP: CreateInherentDataProviders<Block, ()> + Send + Clone + 'static,
{
type Deps = EthDeps<Client, TxPool, CA, CT, Block, BE>;
type Deps = EthDeps<Client, TxPool, CA, CT, Block, BE, CIDP>;

fn deps(
&self,
full_deps: FullDeps<Block, Client, TxPool, CA, BE>,
full_deps: FullDeps<Block, Client, TxPool, CA, BE, CIDP>,
) -> Result<Self::Deps, sc_service::Error> {
let client = full_deps.client.clone();
let overrides = overrides_handle(client.clone());
Expand Down Expand Up @@ -153,6 +155,7 @@ where
fee_history_cache_limit,
execute_gas_limit_multiplier: self.eth_config.execute_gas_limit_multiplier,
forced_parent_hashes: None,
pending_inherent_data_provider: full_deps.create_inherent_data_provider,
})
}

Expand Down Expand Up @@ -185,7 +188,7 @@ where
> = Default::default();
let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);

let io = create_eth_rpc::<Client, BE, TxPool, CA, CT, Block, EC>(
let io = create_eth_rpc::<Client, BE, TxPool, CA, CT, Block, EC, CIDP>(
io,
deps.clone(),
subscription_task_executor,
Expand Down
25 changes: 17 additions & 8 deletions domains/client/eth-service/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use sp_api::{CallApiAt, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_core::H256;
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::traits::Block as BlockT;
use std::collections::BTreeMap;
use std::sync::Arc;
Expand All @@ -38,9 +39,9 @@ where
}

/// Extra dependencies for Ethereum compatibility.
pub struct EthDeps<Client, TxPool, CA: ChainApi, CT, Block: BlockT, BE> {
pub struct EthDeps<Client, TxPool, CA: ChainApi, CT, Block: BlockT, BE, CIDP> {
/// Full Rpc deps
pub full_deps: FullDeps<Block, Client, TxPool, CA, BE>,
pub full_deps: FullDeps<Block, Client, TxPool, CA, BE, CIDP>,
/// Ethereum transaction converter.
pub converter: Option<CT>,
/// Whether to enable dev signer
Expand All @@ -66,10 +67,12 @@ pub struct EthDeps<Client, TxPool, CA: ChainApi, CT, Block: BlockT, BE> {
pub execute_gas_limit_multiplier: u64,
/// Mandated parent hashes for a given block hash.
pub forced_parent_hashes: Option<BTreeMap<H256, H256>>,
/// Pending inherent data provider
pub pending_inherent_data_provider: CIDP,
}

impl<Client, TxPool, CA: ChainApi, CT: Clone, Block: BlockT, BE> Clone
for EthDeps<Client, TxPool, CA, CT, Block, BE>
impl<Client, TxPool, CA: ChainApi, CT: Clone, Block: BlockT, BE, CIDP: Clone> Clone
for EthDeps<Client, TxPool, CA, CT, Block, BE, CIDP>
{
fn clone(&self) -> Self {
Self {
Expand All @@ -86,14 +89,15 @@ impl<Client, TxPool, CA: ChainApi, CT: Clone, Block: BlockT, BE> Clone
fee_history_cache_limit: self.fee_history_cache_limit,
execute_gas_limit_multiplier: self.execute_gas_limit_multiplier,
forced_parent_hashes: self.forced_parent_hashes.clone(),
pending_inherent_data_provider: self.pending_inherent_data_provider.clone(),
}
}
}

/// Instantiate Ethereum-compatible RPC extensions.
pub(crate) fn create_eth_rpc<Client, BE, TxPool, CA, CT, Block, EC: EthConfig<Block, Client>>(
pub(crate) fn create_eth_rpc<Client, BE, TxPool, CA, CT, Block, EC, CIDP>(
mut io: RpcModule<()>,
deps: EthDeps<Client, TxPool, CA, CT, Block, BE>,
deps: EthDeps<Client, TxPool, CA, CT, Block, BE, CIDP>,
subscription_task_executor: SubscriptionTaskExecutor,
pubsub_notification_sinks: Arc<
EthereumBlockNotificationSinks<EthereumBlockNotification<Block>>,
Expand All @@ -112,11 +116,14 @@ where
TxPool: TransactionPool<Block = Block> + 'static,
CA: ChainApi<Block = Block> + 'static,
CT: ConvertTransaction<<Block as BlockT>::Extrinsic> + Send + Sync + 'static,
EC: EthConfig<Block, Client>,
CIDP: CreateInherentDataProviders<Block, ()> + Send + 'static,
{
let EthDeps {
full_deps,
converter,
enable_dev_signer,
sync: _,
frontier_backend,
overrides,
block_data_cache,
Expand All @@ -126,7 +133,7 @@ where
fee_history_cache_limit,
execute_gas_limit_multiplier,
forced_parent_hashes,
..
pending_inherent_data_provider,
} = deps;

let FullDeps {
Expand All @@ -145,7 +152,7 @@ where
}

io.merge(
Eth::<Block, Client, TxPool, CT, BE, CA, EC>::new(
Eth::<Block, Client, TxPool, CT, BE, CA, CIDP, EC>::new(
client.clone(),
pool.clone(),
graph.clone(),
Expand All @@ -160,6 +167,8 @@ where
fee_history_cache_limit,
execute_gas_limit_multiplier,
forced_parent_hashes,
pending_inherent_data_provider,
None,
)
.replace_config::<EC>()
.into_rpc(),
Expand Down
Loading

0 comments on commit a7c09c6

Please sign in to comment.