Skip to content

Commit

Permalink
Fix Frontier RPC Compile (#1305)
Browse files Browse the repository at this point in the history
* Fix compile

* Run local ethereum tests
  • Loading branch information
boundless-forest authored Oct 26, 2023
1 parent 411f944 commit 765cab9
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pallet-fee-market = { git = "https://github.com/darwinia-network/darwinia
fc-consensus = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0" }
fc-db = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0" }
fc-mapping-sync = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0", features = ["sql"] }
fc-rpc = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0", features = ["rpc-binary-search-estimate"] }
fc-rpc = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0", features = ["rpc-binary-search-estimate", "txpool"] }
fc-rpc-core = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0" }
fc-storage = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0" }
fp-account = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0", default-features = false, features = ["serde"] }
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ sc-transaction-pool-api = { workspace = true }
sp-api = { workspace = true, features = ["std"] }
sp-block-builder = { workspace = true, features = ["std"] }
sp-blockchain = { workspace = true }
sp-inherents = { workspace = true, features = ["std"] }
sp-consensus-aura = { workspace = true, features = ["std"] }
sp-core = { workspace = true, features = ["std"] }
sp-io = { workspace = true, optional = true, features = ["std"] }
Expand Down
26 changes: 16 additions & 10 deletions node/src/chain_spec/pangolin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use sc_telemetry::TelemetryEndpoints;
use sp_core::{crypto::UncheckedInto, H160};

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, Extensions>;
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig, Extensions>;

fn properties() -> Properties {
super::properties("PRING")
Expand Down Expand Up @@ -144,11 +144,11 @@ pub fn genesis_config() -> ChainSpec {
"pangolin2",
ChainType::Live,
move || {
GenesisConfig {
RuntimeGenesisConfig {
// System stuff.
system: SystemConfig { code: WASM_BINARY.unwrap().to_vec() },
system: SystemConfig { code: WASM_BINARY.unwrap().to_vec(), ..Default::default() },
parachain_system: Default::default(),
parachain_info: ParachainInfoConfig { parachain_id: 2105.into() },
parachain_info: ParachainInfoConfig { parachain_id: 2105.into(), ..Default::default() },

// Monetary stuff.
balances: BalancesConfig {
Expand All @@ -157,6 +157,7 @@ pub fn genesis_config() -> ChainSpec {
(array_bytes::hex_n_into_unchecked(C2), 10_000 * UNIT),
(array_bytes::hex_n_into_unchecked(C3), 10_000 * UNIT),
],
..Default::default()
},
transaction_payment: Default::default(),
assets: AssetsConfig {
Expand Down Expand Up @@ -221,7 +222,7 @@ pub fn genesis_config() -> ChainSpec {
sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(SUDO)) },

// XCM stuff.
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() },

// EVM stuff.
ethereum: Default::default(),
Expand All @@ -241,6 +242,7 @@ pub fn genesis_config() -> ChainSpec {
}),
)
},
..Default::default()
},

// S2S stuff.
Expand Down Expand Up @@ -272,12 +274,12 @@ fn testnet_genesis(
collators: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> GenesisConfig {
GenesisConfig {
) -> RuntimeGenesisConfig {
RuntimeGenesisConfig {
// System stuff.
system: SystemConfig { code: WASM_BINARY.unwrap().to_vec() },
system: SystemConfig { code: WASM_BINARY.unwrap().to_vec(), ..Default::default() },
parachain_system: Default::default(),
parachain_info: ParachainInfoConfig { parachain_id: id },
parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() },

// Monetary stuff.
balances: BalancesConfig {
Expand Down Expand Up @@ -341,7 +343,10 @@ fn testnet_genesis(
sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(ALITH)) },

// XCM stuff.
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
polkadot_xcm: PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},

// EVM stuff.
ethereum: Default::default(),
Expand Down Expand Up @@ -375,6 +380,7 @@ fn testnet_genesis(
]),
)
},
..Default::default()
},

// S2S stuff.
Expand Down
19 changes: 14 additions & 5 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use moonbeam_rpc_trace::{Trace, TraceServer};
pub type RpcExtension = jsonrpsee::RpcModule<()>;

/// Full client dependencies
pub struct FullDeps<C, P, A: sc_transaction_pool::ChainApi> {
pub struct FullDeps<C, P, A: sc_transaction_pool::ChainApi, CIDP> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
Expand Down Expand Up @@ -66,6 +66,8 @@ pub struct FullDeps<C, P, A: sc_transaction_pool::ChainApi> {
pub block_data_cache: Arc<fc_rpc::EthBlockDataCacheTask<Block>>,
/// Mandated parent hashes for a given block hash.
pub forced_parent_hashes: Option<BTreeMap<sp_core::H256, sp_core::H256>>,
/// Something that can create the inherent data providers for pending state
pub pending_create_inherent_data_providers: CIDP,
}

/// EVM tracing rpc server config
Expand All @@ -87,8 +89,8 @@ where
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P, BE, A, EC>(
deps: FullDeps<C, P, A>,
pub fn create_full<C, P, BE, A, EC, CIDP>(
deps: FullDeps<C, P, A, CIDP>,
subscription_task_executor: sc_rpc::SubscriptionTaskExecutor,
pubsub_notification_sinks: Arc<
fc_mapping_sync::EthereumBlockNotificationSinks<
Expand All @@ -109,12 +111,16 @@ where
+ sp_api::CallApiAt<Block>
+ sp_api::ProvideRuntimeApi<Block>
+ sp_blockchain::HeaderBackend<Block>
+ sc_client_api::backend::AuxStore
+ sc_client_api::UsageProvider<Block>
+ sp_blockchain::HeaderMetadata<Block, Error = sp_blockchain::Error>,
C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>
+ fp_rpc::EthereumRuntimeRPCApi<Block>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ sp_block_builder::BlockBuilder<Block>
+ sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
CIDP: sp_inherents::CreateInherentDataProviders<Block, ()> + Send + 'static,
P: 'static + Sync + Send + sc_transaction_pool_api::TransactionPool<Block = Block>,
A: 'static + sc_transaction_pool::ChainApi<Block = Block>,
EC: fc_rpc::EthConfig<Block, C>,
Expand Down Expand Up @@ -146,6 +152,7 @@ where
overrides,
block_data_cache,
forced_parent_hashes,
pending_create_inherent_data_providers,
} = deps;

module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
Expand All @@ -166,18 +173,20 @@ where
fee_history_cache_limit,
10,
forced_parent_hashes,
pending_create_inherent_data_providers,
Some(Box::new(fc_rpc::pending::AuraConsensusDataProvider::new(client.clone()))),
)
.replace_config::<EC>()
.into_rpc(),
)?;

let tx_pool = TxPool::new(client.clone(), graph);
let tx_pool = TxPool::new(client.clone(), graph.clone());
if let Some(filter_pool) = filter_pool {
module.merge(
EthFilter::new(
client.clone(),
frontier_backend,
tx_pool.clone(),
graph.clone(),
filter_pool,
500_usize, // max stored filters
max_past_logs,
Expand Down
34 changes: 30 additions & 4 deletions node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,18 @@ where
let eth_rpc_config = eth_rpc_config.clone();
let sync_service = sync_service.clone();

let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
let pending_create_inherent_data_providers = move |_, ()| async move {
let current = sp_timestamp::InherentDataProvider::from_system_time();
let next_slot = current.timestamp().as_millis() + slot_duration.as_millis();
let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into());
let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
Ok((slot, timestamp))
};

Box::new(move |deny_unsafe, subscription_task_executor| {
let deps = crate::rpc::FullDeps {
client: client.clone(),
Expand All @@ -422,12 +434,13 @@ where
overrides: overrides.clone(),
block_data_cache: block_data_cache.clone(),
forced_parent_hashes: None,
pending_create_inherent_data_providers,
};

if eth_rpc_config.tracing_api.contains(&crate::cli::TracingApi::Debug)
|| eth_rpc_config.tracing_api.contains(&crate::cli::TracingApi::Trace)
{
crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>>(
crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>, _>(
deps,
subscription_task_executor,
pubsub_notification_sinks.clone(),
Expand All @@ -438,7 +451,7 @@ where
)
.map_err(Into::into)
} else {
crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>>(
crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>, _>(
deps,
subscription_task_executor,
pubsub_notification_sinks.clone(),
Expand Down Expand Up @@ -914,6 +927,18 @@ where
let eth_rpc_config = eth_rpc_config.clone();
let sync_service = sync_service.clone();

let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
let pending_create_inherent_data_providers = move |_, ()| async move {
let current = sp_timestamp::InherentDataProvider::from_system_time();
let next_slot = current.timestamp().as_millis() + slot_duration.as_millis();
let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into());
let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
Ok((slot, timestamp))
};

Box::new(move |deny_unsafe, subscription_task_executor| {
let deps = crate::rpc::FullDeps {
client: client.clone(),
Expand All @@ -934,12 +959,13 @@ where
overrides: overrides.clone(),
block_data_cache: block_data_cache.clone(),
forced_parent_hashes: None,
pending_create_inherent_data_providers,
};

if eth_rpc_config.tracing_api.contains(&crate::cli::TracingApi::Debug)
|| eth_rpc_config.tracing_api.contains(&crate::cli::TracingApi::Trace)
{
crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>>(
crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>, _>(
deps,
subscription_task_executor,
pubsub_notification_sinks.clone(),
Expand All @@ -950,7 +976,7 @@ where
)
.map_err(Into::into)
} else {
crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>>(
crate::rpc::create_full::<_, _, _, _, crate::rpc::DefaultEthConfig<_, _>, _>(
deps,
subscription_task_executor,
pubsub_notification_sinks.clone(),
Expand Down

0 comments on commit 765cab9

Please sign in to comment.