difftreelog
refactor ethereum RPC/tasks initialization
in: master
7 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6507,11 +6507,13 @@
"frame-benchmarking",
"frame-support",
"frame-system",
+ "hex-literal",
"parity-scale-codec",
"scale-info",
"smallvec",
"sp-arithmetic",
"sp-core",
+ "sp-io",
"sp-std",
"xcm",
]
@@ -13841,9 +13843,11 @@
"fc-rpc",
"fc-rpc-core",
"fp-rpc",
+ "fp-storage",
"frame-benchmarking",
"frame-benchmarking-cli",
"futures",
+ "jsonrpsee",
"log",
"opal-runtime",
"pallet-transaction-payment-rpc-runtime-api",
@@ -13861,6 +13865,7 @@
"sc-executor",
"sc-network",
"sc-network-sync",
+ "sc-rpc",
"sc-service",
"sc-sysinfo",
"sc-telemetry",
@@ -13906,9 +13911,9 @@
"fp-rpc",
"fp-storage",
"jsonrpsee",
+ "pallet-ethereum",
"pallet-transaction-payment-rpc",
"sc-client-api",
- "sc-consensus-grandpa",
"sc-network",
"sc-network-sync",
"sc-rpc",
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -125,7 +125,6 @@
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
-sc-consensus-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -21,7 +21,7 @@
[dependencies]
clap = "4.1"
-futures = '0.3.17'
+futures = '0.3.28'
tokio = { version = "1.24", features = ["time"] }
serde_json = "1.0"
@@ -94,6 +94,9 @@
unique-rpc = { workspace = true }
up-pov-estimate-rpc = { workspace = true }
up-rpc = { workspace = true }
+jsonrpsee.workspace = true
+fp-storage.workspace = true
+sc-rpc.workspace = true
[build-dependencies]
substrate-build-script-utils = { workspace = true }
node/cli/src/chain_spec.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};18use sc_service::ChainType;19use sp_core::{sr25519, Pair, Public};20use sp_runtime::traits::{IdentifyAccount, Verify};21use std::collections::BTreeMap;2223use serde::{Deserialize, Serialize};24use serde_json::map::Map;2526use up_common::types::opaque::*;2728#[cfg(feature = "unique-runtime")]29pub use unique_runtime as default_runtime;3031#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]32pub use quartz_runtime as default_runtime;3334#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]35pub use opal_runtime as default_runtime;3637/// The `ChainSpec` parameterized for the unique runtime.38#[cfg(feature = "unique-runtime")]39pub type UniqueChainSpec = sc_service::GenericChainSpec<unique_runtime::GenesisConfig, Extensions>;4041/// The `ChainSpec` parameterized for the quartz runtime.42#[cfg(feature = "quartz-runtime")]43pub type QuartzChainSpec = sc_service::GenericChainSpec<quartz_runtime::GenesisConfig, Extensions>;4445/// The `ChainSpec` parameterized for the opal runtime.46pub type OpalChainSpec = sc_service::GenericChainSpec<opal_runtime::GenesisConfig, Extensions>;4748#[cfg(feature = "unique-runtime")]49pub type DefaultChainSpec = UniqueChainSpec;5051#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]52pub type DefaultChainSpec = QuartzChainSpec;5354#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]55pub type DefaultChainSpec = OpalChainSpec;5657#[cfg(not(feature = "unique-runtime"))]58/// PARA_ID for Opal/Sapphire/Quartz59const PARA_ID: u32 = 2095;6061#[cfg(feature = "unique-runtime")]62/// PARA_ID for Unique63const PARA_ID: u32 = 2037;6465pub trait RuntimeIdentification {66 fn runtime_id(&self) -> RuntimeId;67}6869impl RuntimeIdentification for Box<dyn sc_service::ChainSpec> {70 fn runtime_id(&self) -> RuntimeId {71 #[cfg(feature = "unique-runtime")]72 if self.id().starts_with("unique") || self.id().starts_with("unq") {73 return RuntimeId::Unique;74 }7576 #[cfg(feature = "quartz-runtime")]77 if self.id().starts_with("quartz")78 || self.id().starts_with("qtz")79 || self.id().starts_with("sapphire")80 {81 return RuntimeId::Quartz;82 }8384 if self.id().starts_with("opal") || self.id() == "dev" || self.id() == "local_testnet" {85 return RuntimeId::Opal;86 }8788 RuntimeId::Unknown(self.id().into())89 }90}9192pub enum ServiceId {93 Prod,94 Dev,95}9697pub trait ServiceIdentification {98 fn service_id(&self) -> ServiceId;99}100101impl ServiceIdentification for Box<dyn sc_service::ChainSpec> {102 fn service_id(&self) -> ServiceId {103 if self.id().ends_with("dev") {104 ServiceId::Dev105 } else {106 ServiceId::Prod107 }108 }109}110111/// Helper function to generate a crypto pair from seed112pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {113 TPublic::Pair::from_string(&format!("//{seed}"), None)114 .expect("static values are valid; qed")115 .public()116}117118/// The extensions for the [`DefaultChainSpec`].119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]120#[serde(deny_unknown_fields)]121pub struct Extensions {122 /// The relay chain of the Parachain.123 pub relay_chain: String,124 /// The id of the Parachain.125 pub para_id: u32,126}127128impl Extensions {129 /// Try to get the extension from the given `ChainSpec`.130 pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {131 sc_chain_spec::get_extension(chain_spec.extensions())132 }133}134135type AccountPublic = <Signature as Verify>::Signer;136137/// Helper function to generate an account ID from seed138pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId139where140 AccountPublic: From<<TPublic::Pair as Pair>::Public>,141{142 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()143}144145#[cfg(not(feature = "unique-runtime"))]146macro_rules! testnet_genesis {147 (148 $runtime:path,149 $root_key:expr,150 $initial_invulnerables:expr,151 $endowed_accounts:expr,152 $id:expr153 ) => {{154 use $runtime::*;155156 GenesisConfig {157 system: SystemConfig {158 code: WASM_BINARY159 .expect("WASM binary was not build, please build it!")160 .to_vec(),161 },162 balances: BalancesConfig {163 balances: $endowed_accounts164 .iter()165 .cloned()166 // 1e13 UNQ167 .map(|k| (k, 1 << 100))168 .collect(),169 },170 common: Default::default(),171 nonfungible: Default::default(),172 treasury: Default::default(),173 tokens: TokensConfig { balances: vec![] },174 sudo: SudoConfig {175 key: Some($root_key),176 },177 vesting: VestingConfig { vesting: vec![] },178 parachain_info: ParachainInfoConfig {179 parachain_id: $id.into(),180 },181 parachain_system: Default::default(),182 collator_selection: CollatorSelectionConfig {183 invulnerables: $initial_invulnerables184 .iter()185 .cloned()186 .map(|(acc, _)| acc)187 .collect(),188 },189 session: SessionConfig {190 keys: $initial_invulnerables191 .into_iter()192 .map(|(acc, aura)| {193 (194 acc.clone(), // account id195 acc, // validator id196 SessionKeys { aura }, // session keys197 )198 })199 .collect(),200 },201 aura: Default::default(),202 aura_ext: Default::default(),203 evm: EVMConfig {204 accounts: BTreeMap::new(),205 },206 ethereum: EthereumConfig {},207 polkadot_xcm: Default::default(),208 transaction_payment: Default::default(),209 }210 }};211}212213#[cfg(feature = "unique-runtime")]214macro_rules! testnet_genesis {215 (216 $runtime:path,217 $root_key:expr,218 $initial_invulnerables:expr,219 $endowed_accounts:expr,220 $id:expr221 ) => {{222 use $runtime::*;223224 GenesisConfig {225 system: SystemConfig {226 code: WASM_BINARY227 .expect("WASM binary was not build, please build it!")228 .to_vec(),229 },230 common: Default::default(),231 nonfungible: Default::default(),232 balances: BalancesConfig {233 balances: $endowed_accounts234 .iter()235 .cloned()236 // 1e13 UNQ237 .map(|k| (k, 1 << 100))238 .collect(),239 },240 treasury: Default::default(),241 tokens: TokensConfig { balances: vec![] },242 sudo: SudoConfig {243 key: Some($root_key),244 },245 vesting: VestingConfig { vesting: vec![] },246 parachain_info: ParachainInfoConfig {247 parachain_id: $id.into(),248 },249 parachain_system: Default::default(),250 aura: AuraConfig {251 authorities: $initial_invulnerables252 .into_iter()253 .map(|(_, aura)| aura)254 .collect(),255 },256 aura_ext: Default::default(),257 evm: EVMConfig {258 accounts: BTreeMap::new(),259 },260 ethereum: EthereumConfig {},261 polkadot_xcm: Default::default(),262 transaction_payment: Default::default(),263 }264 }};265}266267pub fn development_config() -> DefaultChainSpec {268 let mut properties = Map::new();269 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());270 properties.insert("tokenDecimals".into(), default_runtime::DECIMALS.into());271 properties.insert(272 "ss58Format".into(),273 default_runtime::SS58Prefix::get().into(),274 );275276 DefaultChainSpec::from_genesis(277 // Name278 format!(279 "{}{}",280 default_runtime::RUNTIME_NAME.to_uppercase(),281 if cfg!(feature = "unique-runtime") {282 ""283 } else {284 " by UNIQUE"285 }286 )287 .as_str(),288 // ID289 format!("{}_dev", default_runtime::RUNTIME_NAME).as_str(),290 ChainType::Local,291 move || {292 testnet_genesis!(293 default_runtime,294 // Sudo account295 get_account_id_from_seed::<sr25519::Public>("Alice"),296 vec![297 (298 get_account_id_from_seed::<sr25519::Public>("Alice"),299 get_from_seed::<AuraId>("Alice"),300 ),301 (302 get_account_id_from_seed::<sr25519::Public>("Bob"),303 get_from_seed::<AuraId>("Bob"),304 ),305 ],306 // Pre-funded accounts307 vec![308 get_account_id_from_seed::<sr25519::Public>("Alice"),309 get_account_id_from_seed::<sr25519::Public>("Bob"),310 get_account_id_from_seed::<sr25519::Public>("Charlie"),311 get_account_id_from_seed::<sr25519::Public>("Dave"),312 get_account_id_from_seed::<sr25519::Public>("Eve"),313 get_account_id_from_seed::<sr25519::Public>("Ferdie"),314 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),315 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),316 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),317 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),318 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),319 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),320 ],321 PARA_ID322 )323 },324 // Bootnodes325 vec![],326 // Telemetry327 None,328 // Protocol ID329 None,330 None,331 // Properties332 Some(properties),333 // Extensions334 Extensions {335 relay_chain: "rococo-dev".into(),336 para_id: PARA_ID,337 },338 )339}340341pub fn local_testnet_config() -> DefaultChainSpec {342 let mut properties = Map::new();343 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());344 properties.insert("tokenDecimals".into(), default_runtime::DECIMALS.into());345 properties.insert(346 "ss58Format".into(),347 default_runtime::SS58Prefix::get().into(),348 );349350 DefaultChainSpec::from_genesis(351 // Name352 format!(353 "{}{}",354 default_runtime::RUNTIME_NAME.to_uppercase(),355 if cfg!(feature = "unique-runtime") {356 ""357 } else {358 " by UNIQUE"359 }360 )361 .as_str(),362 // ID363 format!("{}_local", default_runtime::RUNTIME_NAME).as_str(),364 ChainType::Local,365 move || {366 testnet_genesis!(367 default_runtime,368 // Sudo account369 get_account_id_from_seed::<sr25519::Public>("Alice"),370 vec![371 (372 get_account_id_from_seed::<sr25519::Public>("Alice"),373 get_from_seed::<AuraId>("Alice"),374 ),375 (376 get_account_id_from_seed::<sr25519::Public>("Bob"),377 get_from_seed::<AuraId>("Bob"),378 ),379 ],380 // Pre-funded accounts381 vec![382 get_account_id_from_seed::<sr25519::Public>("Alice"),383 get_account_id_from_seed::<sr25519::Public>("Bob"),384 get_account_id_from_seed::<sr25519::Public>("Charlie"),385 get_account_id_from_seed::<sr25519::Public>("Dave"),386 get_account_id_from_seed::<sr25519::Public>("Eve"),387 get_account_id_from_seed::<sr25519::Public>("Ferdie"),388 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),389 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),390 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),391 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),392 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),393 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),394 ],395 PARA_ID396 )397 },398 // Bootnodes399 vec![],400 // Telemetry401 None,402 // Protocol ID403 None,404 None,405 // Properties406 Some(properties),407 // Extensions408 Extensions {409 relay_chain: "westend-local".into(),410 para_id: PARA_ID,411 },412 )413}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};18use sc_service::ChainType;19use sp_core::{sr25519, Pair, Public};20use sp_runtime::traits::{IdentifyAccount, Verify};21use std::collections::BTreeMap;2223use serde::{Deserialize, Serialize};24use serde_json::map::Map;2526use up_common::types::opaque::*;2728#[cfg(feature = "unique-runtime")]29pub use unique_runtime as default_runtime;3031#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]32pub use quartz_runtime as default_runtime;3334#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]35pub use opal_runtime as default_runtime;3637/// The `ChainSpec` parameterized for the unique runtime.38#[cfg(feature = "unique-runtime")]39pub type UniqueChainSpec = sc_service::GenericChainSpec<unique_runtime::GenesisConfig, Extensions>;4041/// The `ChainSpec` parameterized for the quartz runtime.42#[cfg(feature = "quartz-runtime")]43pub type QuartzChainSpec = sc_service::GenericChainSpec<quartz_runtime::GenesisConfig, Extensions>;4445/// The `ChainSpec` parameterized for the opal runtime.46pub type OpalChainSpec = sc_service::GenericChainSpec<opal_runtime::GenesisConfig, Extensions>;4748#[cfg(feature = "unique-runtime")]49pub type DefaultChainSpec = UniqueChainSpec;5051#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]52pub type DefaultChainSpec = QuartzChainSpec;5354#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]55pub type DefaultChainSpec = OpalChainSpec;5657#[cfg(not(feature = "unique-runtime"))]58/// PARA_ID for Opal/Sapphire/Quartz59const PARA_ID: u32 = 2095;6061#[cfg(feature = "unique-runtime")]62/// PARA_ID for Unique63const PARA_ID: u32 = 2037;6465pub trait RuntimeIdentification {66 fn runtime_id(&self) -> RuntimeId;67}6869impl RuntimeIdentification for Box<dyn sc_service::ChainSpec> {70 fn runtime_id(&self) -> RuntimeId {71 #[cfg(feature = "unique-runtime")]72 if self.id().starts_with("unique") || self.id().starts_with("unq") {73 return RuntimeId::Unique;74 }7576 #[cfg(feature = "quartz-runtime")]77 if self.id().starts_with("quartz")78 || self.id().starts_with("qtz")79 || self.id().starts_with("sapphire")80 {81 return RuntimeId::Quartz;82 }8384 if self.id().starts_with("opal") || self.id() == "dev" || self.id() == "local_testnet" {85 return RuntimeId::Opal;86 }8788 RuntimeId::Unknown(self.id().into())89 }90}9192pub enum ServiceId {93 Prod,94 Dev,95}9697pub trait ServiceIdentification {98 fn service_id(&self) -> ServiceId;99}100101impl ServiceIdentification for Box<dyn sc_service::ChainSpec> {102 fn service_id(&self) -> ServiceId {103 if self.id().ends_with("dev") {104 ServiceId::Dev105 } else {106 ServiceId::Prod107 }108 }109}110111/// Helper function to generate a crypto pair from seed112pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {113 TPublic::Pair::from_string(&format!("//{seed}"), None)114 .expect("static values are valid; qed")115 .public()116}117118/// The extensions for the [`DefaultChainSpec`].119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]120#[serde(deny_unknown_fields)]121pub struct Extensions {122 /// The relay chain of the Parachain.123 pub relay_chain: String,124 /// The id of the Parachain.125 pub para_id: u32,126}127128impl Extensions {129 /// Try to get the extension from the given `ChainSpec`.130 pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {131 sc_chain_spec::get_extension(chain_spec.extensions())132 }133}134135type AccountPublic = <Signature as Verify>::Signer;136137/// Helper function to generate an account ID from seed138pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId139where140 AccountPublic: From<<TPublic::Pair as Pair>::Public>,141{142 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()143}144145#[cfg(not(feature = "unique-runtime"))]146macro_rules! testnet_genesis {147 (148 $runtime:path,149 $root_key:expr,150 $initial_invulnerables:expr,151 $endowed_accounts:expr,152 $id:expr153 ) => {{154 use $runtime::*;155156 GenesisConfig {157 system: SystemConfig {158 code: WASM_BINARY159 .expect("WASM binary was not build, please build it!")160 .to_vec(),161 },162 balances: BalancesConfig {163 balances: $endowed_accounts164 .iter()165 .cloned()166 // 1e13 UNQ167 .map(|k| (k, 1 << 100))168 .collect(),169 },170 common: Default::default(),171 configuration: Default::default(),172 nonfungible: Default::default(),173 treasury: Default::default(),174 tokens: TokensConfig { balances: vec![] },175 sudo: SudoConfig {176 key: Some($root_key),177 },178 vesting: VestingConfig { vesting: vec![] },179 parachain_info: ParachainInfoConfig {180 parachain_id: $id.into(),181 },182 parachain_system: Default::default(),183 collator_selection: CollatorSelectionConfig {184 invulnerables: $initial_invulnerables185 .iter()186 .cloned()187 .map(|(acc, _)| acc)188 .collect(),189 },190 session: SessionConfig {191 keys: $initial_invulnerables192 .into_iter()193 .map(|(acc, aura)| {194 (195 acc.clone(), // account id196 acc, // validator id197 SessionKeys { aura }, // session keys198 )199 })200 .collect(),201 },202 aura: Default::default(),203 aura_ext: Default::default(),204 evm: EVMConfig {205 accounts: BTreeMap::new(),206 },207 ethereum: EthereumConfig {},208 polkadot_xcm: Default::default(),209 transaction_payment: Default::default(),210 }211 }};212}213214#[cfg(feature = "unique-runtime")]215macro_rules! testnet_genesis {216 (217 $runtime:path,218 $root_key:expr,219 $initial_invulnerables:expr,220 $endowed_accounts:expr,221 $id:expr222 ) => {{223 use $runtime::*;224225 GenesisConfig {226 system: SystemConfig {227 code: WASM_BINARY228 .expect("WASM binary was not build, please build it!")229 .to_vec(),230 },231 common: Default::default(),232 configuration: Default::default(),233 nonfungible: Default::default(),234 balances: BalancesConfig {235 balances: $endowed_accounts236 .iter()237 .cloned()238 // 1e13 UNQ239 .map(|k| (k, 1 << 100))240 .collect(),241 },242 treasury: Default::default(),243 tokens: TokensConfig { balances: vec![] },244 sudo: SudoConfig {245 key: Some($root_key),246 },247 vesting: VestingConfig { vesting: vec![] },248 parachain_info: ParachainInfoConfig {249 parachain_id: $id.into(),250 },251 parachain_system: Default::default(),252 aura: AuraConfig {253 authorities: $initial_invulnerables254 .into_iter()255 .map(|(_, aura)| aura)256 .collect(),257 },258 aura_ext: Default::default(),259 evm: EVMConfig {260 accounts: BTreeMap::new(),261 },262 ethereum: EthereumConfig {},263 polkadot_xcm: Default::default(),264 transaction_payment: Default::default(),265 }266 }};267}268269pub fn development_config() -> DefaultChainSpec {270 let mut properties = Map::new();271 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());272 properties.insert("tokenDecimals".into(), default_runtime::DECIMALS.into());273 properties.insert(274 "ss58Format".into(),275 default_runtime::SS58Prefix::get().into(),276 );277278 DefaultChainSpec::from_genesis(279 // Name280 format!(281 "{}{}",282 default_runtime::RUNTIME_NAME.to_uppercase(),283 if cfg!(feature = "unique-runtime") {284 ""285 } else {286 " by UNIQUE"287 }288 )289 .as_str(),290 // ID291 format!("{}_dev", default_runtime::RUNTIME_NAME).as_str(),292 ChainType::Local,293 move || {294 testnet_genesis!(295 default_runtime,296 // Sudo account297 get_account_id_from_seed::<sr25519::Public>("Alice"),298 vec![299 (300 get_account_id_from_seed::<sr25519::Public>("Alice"),301 get_from_seed::<AuraId>("Alice"),302 ),303 (304 get_account_id_from_seed::<sr25519::Public>("Bob"),305 get_from_seed::<AuraId>("Bob"),306 ),307 ],308 // Pre-funded accounts309 vec![310 get_account_id_from_seed::<sr25519::Public>("Alice"),311 get_account_id_from_seed::<sr25519::Public>("Bob"),312 get_account_id_from_seed::<sr25519::Public>("Charlie"),313 get_account_id_from_seed::<sr25519::Public>("Dave"),314 get_account_id_from_seed::<sr25519::Public>("Eve"),315 get_account_id_from_seed::<sr25519::Public>("Ferdie"),316 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),317 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),318 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),319 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),320 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),321 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),322 ],323 PARA_ID324 )325 },326 // Bootnodes327 vec![],328 // Telemetry329 None,330 // Protocol ID331 None,332 None,333 // Properties334 Some(properties),335 // Extensions336 Extensions {337 relay_chain: "rococo-dev".into(),338 para_id: PARA_ID,339 },340 )341}342343pub fn local_testnet_config() -> DefaultChainSpec {344 let mut properties = Map::new();345 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());346 properties.insert("tokenDecimals".into(), default_runtime::DECIMALS.into());347 properties.insert(348 "ss58Format".into(),349 default_runtime::SS58Prefix::get().into(),350 );351352 DefaultChainSpec::from_genesis(353 // Name354 format!(355 "{}{}",356 default_runtime::RUNTIME_NAME.to_uppercase(),357 if cfg!(feature = "unique-runtime") {358 ""359 } else {360 " by UNIQUE"361 }362 )363 .as_str(),364 // ID365 format!("{}_local", default_runtime::RUNTIME_NAME).as_str(),366 ChainType::Local,367 move || {368 testnet_genesis!(369 default_runtime,370 // Sudo account371 get_account_id_from_seed::<sr25519::Public>("Alice"),372 vec![373 (374 get_account_id_from_seed::<sr25519::Public>("Alice"),375 get_from_seed::<AuraId>("Alice"),376 ),377 (378 get_account_id_from_seed::<sr25519::Public>("Bob"),379 get_from_seed::<AuraId>("Bob"),380 ),381 ],382 // Pre-funded accounts383 vec![384 get_account_id_from_seed::<sr25519::Public>("Alice"),385 get_account_id_from_seed::<sr25519::Public>("Bob"),386 get_account_id_from_seed::<sr25519::Public>("Charlie"),387 get_account_id_from_seed::<sr25519::Public>("Dave"),388 get_account_id_from_seed::<sr25519::Public>("Eve"),389 get_account_id_from_seed::<sr25519::Public>("Ferdie"),390 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),391 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),392 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),393 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),394 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),395 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),396 ],397 PARA_ID398 )399 },400 // Bootnodes401 vec![],402 // Telemetry403 None,404 // Protocol ID405 None,406 None,407 // Properties408 Some(properties),409 // Extensions410 Extensions {411 relay_chain: "westend-local".into(),412 para_id: PARA_ID,413 },414 )415}node/cli/src/service.rsdiffbeforeafterboth--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -20,16 +20,19 @@
use std::collections::BTreeMap;
use std::time::Duration;
use std::pin::Pin;
+use fc_mapping_sync::EthereumBlockNotificationSinks;
+use fc_rpc::EthBlockDataCacheTask;
+use fc_rpc::EthTask;
use fc_rpc_core::types::FeeHistoryCache;
use futures::{
Stream, StreamExt,
stream::select,
task::{Context, Poll},
};
+use sc_rpc::SubscriptionTaskExecutor;
use sp_keystore::KeystorePtr;
use tokio::time::Interval;
-
-use unique_rpc::overrides_handle;
+use jsonrpsee::RpcModule;
use serde::{Serialize, Deserialize};
@@ -49,7 +52,7 @@
use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;
// Substrate Imports
-use sp_api::BlockT;
+use sp_api::{BlockT, HeaderT, ProvideRuntimeApi, StateBackend};
use sc_executor::NativeElseWasmExecutor;
use sc_executor::NativeExecutionDispatch;
use sc_network::NetworkBlock;
@@ -58,14 +61,23 @@
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sp_runtime::traits::BlakeTwo256;
use substrate_prometheus_endpoint::Registry;
-use sc_client_api::BlockchainEvents;
+use sc_client_api::{BlockchainEvents, BlockOf, Backend, AuxStore, StorageProvider};
+use sp_blockchain::{HeaderBackend, HeaderMetadata, Error as BlockChainError};
use sc_consensus::ImportQueue;
+use sp_core::H256;
+use sp_block_builder::BlockBuilder;
use polkadot_service::CollatorPair;
// Frontier Imports
use fc_rpc_core::types::FilterPool;
use fc_mapping_sync::{kv::MappingSyncWorker, SyncStrategy};
+use fc_rpc::{
+ StorageOverride, OverrideHandle, SchemaV1Override, SchemaV2Override, SchemaV3Override,
+ RuntimeApiStorageOverride,
+};
+use fp_rpc::EthereumRuntimeRPCApi;
+use fp_storage::EthereumStorageSchema;
use up_common::types::opaque::*;
@@ -173,7 +185,7 @@
}
}
-pub fn open_frontier_backend<Block: BlockT, C: sp_blockchain::HeaderBackend<Block>>(
+pub fn open_frontier_backend<Block: BlockT, C: HeaderBackend<Block>>(
client: Arc<C>,
config: &Configuration,
) -> Result<Arc<fc_db::kv::Backend<Block>>, String> {
@@ -213,13 +225,7 @@
FullSelectChain,
sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
- (
- Option<Telemetry>,
- Option<FilterPool>,
- Arc<fc_db::kv::Backend<Block>>,
- Option<TelemetryWorkerHandle>,
- FeeHistoryCache,
- ),
+ OtherPartial,
>,
sc_service::Error,
>
@@ -242,17 +248,6 @@
sc_service::Error,
>,
{
- let _telemetry = config
- .telemetry_endpoints
- .clone()
- .filter(|x| !x.is_empty())
- .map(|endpoints| -> Result<_, sc_telemetry::Error> {
- let worker = TelemetryWorker::new(16)?;
- let telemetry = worker.handle().new_telemetry(endpoints);
- Ok((worker, telemetry))
- })
- .transpose()?;
-
let telemetry = config
.telemetry_endpoints
.clone()
@@ -293,9 +288,9 @@
client.clone(),
);
- let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));
+ let eth_filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));
- let frontier_backend = open_frontier_backend(client.clone(), config)?;
+ let eth_backend = open_frontier_backend(client.clone(), config)?;
let import_queue = build_import_queue(
client.clone(),
@@ -304,7 +299,6 @@
telemetry.as_ref().map(|telemetry| telemetry.handle()),
&task_manager,
)?;
- let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));
let params = PartialComponents {
backend,
@@ -314,13 +308,12 @@
task_manager,
transaction_pool,
select_chain,
- other: (
+ other: OtherPartial {
telemetry,
- filter_pool,
- frontier_backend,
+ eth_filter_pool,
+ eth_backend,
telemetry_worker_handle,
- fee_history_cache,
- ),
+ },
};
Ok(params)
@@ -427,8 +420,12 @@
let params =
new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(¶chain_config, build_import_queue)?;
- let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =
- params.other;
+ let OtherPartial {
+ mut telemetry,
+ telemetry_worker_handle,
+ eth_filter_pool,
+ eth_backend,
+ } = params.other;
let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network);
let client = params.client.clone();
@@ -470,69 +467,72 @@
let select_chain = params.select_chain.clone();
- let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(
- task_manager.spawn_handle(),
- overrides_handle::<_, _, Runtime>(client.clone()),
- 50,
- 50,
- prometheus_registry.clone(),
- ));
+ let runtime_id = parachain_config.chain_spec.runtime_id();
- let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<
- fc_mapping_sync::EthereumBlockNotification<Block>,
+ // Frontier
+ let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));
+ let fee_history_limit = 2048;
+
+ let eth_pubsub_notification_sinks: Arc<
+ EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,
> = Default::default();
- let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);
- task_manager.spawn_essential_handle().spawn(
- "frontier-mapping-sync-worker",
- Some("frontier"),
- MappingSyncWorker::new(
- client.import_notification_stream(),
- Duration::new(6, 0),
- client.clone(),
- backend.clone(),
- overrides_handle::<_, _, Runtime>(client.clone()),
- frontier_backend.clone(),
- 3,
- 0,
- SyncStrategy::Parachain,
- sync_service.clone(),
- pubsub_notification_sinks.clone(),
- )
- .for_each(|()| futures::future::ready(())),
+ let overrides = overrides_handle(client.clone());
+ let eth_block_data_cache = spawn_frontier_tasks(
+ FrontierTaskParams {
+ client: client.clone(),
+ substrate_backend: backend.clone(),
+ eth_filter_pool: eth_filter_pool.clone(),
+ eth_backend: eth_backend.clone(),
+ fee_history_limit,
+ fee_history_cache: fee_history_cache.clone(),
+ task_manager: &task_manager,
+ prometheus_registry: prometheus_registry.clone(),
+ overrides: overrides.clone(),
+ sync_strategy: SyncStrategy::Parachain,
+ },
+ sync_service.clone(),
+ eth_pubsub_notification_sinks.clone(),
);
- let runtime_id = parachain_config.chain_spec.runtime_id();
-
+ // Rpc
let rpc_builder = Box::new({
clone!(
client,
backend,
- pubsub_notification_sinks,
+ eth_backend,
+ eth_pubsub_notification_sinks,
+ fee_history_cache,
+ eth_block_data_cache,
+ overrides,
transaction_pool,
network,
sync_service,
- frontier_backend,
);
- move |deny_unsafe, subscription_task_executor| {
+ move |deny_unsafe, subscription_task_executor: SubscriptionTaskExecutor| {
clone!(
backend,
- runtime_id,
+ eth_block_data_cache,
client,
- transaction_pool,
- filter_pool,
+ eth_backend,
+ eth_filter_pool,
+ eth_pubsub_notification_sinks,
+ fee_history_cache,
+ eth_block_data_cache,
network,
+ runtime_id,
+ transaction_pool,
select_chain,
- block_data_cache,
- fee_history_cache,
- pubsub_notification_sinks,
- frontier_backend,
+ overrides,
);
#[cfg(not(feature = "pov-estimate"))]
let _ = backend;
+ let mut rpc_handle = RpcModule::new(());
+
let full_deps = unique_rpc::FullDeps {
+ client: client.clone(),
runtime_id,
#[cfg(feature = "pov-estimate")]
@@ -546,32 +546,40 @@
#[cfg(feature = "pov-estimate")]
backend,
- eth_backend: frontier_backend,
deny_unsafe,
+ pool: transaction_pool.clone(),
+ select_chain,
+ };
+
+ unique_rpc::create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_handle, full_deps)?;
+
+ let eth_deps = unique_rpc::EthDeps {
client,
graph: transaction_pool.pool().clone(),
pool: transaction_pool,
- // TODO: Unhardcode
- enable_dev_signer: false,
- filter_pool,
+ is_authority: validator,
network,
- sync: sync_service.clone(),
- select_chain,
- is_authority: validator,
+ eth_backend,
// TODO: Unhardcode
max_past_logs: 10000,
- block_data_cache,
+ fee_history_limit,
fee_history_cache,
+ eth_block_data_cache,
// TODO: Unhardcode
- fee_history_limit: 2048,
- pubsub_notification_sinks,
+ enable_dev_signer: false,
+ eth_filter_pool,
+ eth_pubsub_notification_sinks,
+ overrides,
+ sync: sync_service.clone(),
};
- unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(
- full_deps,
- subscription_task_executor,
- )
- .map_err(Into::into)
+ unique_rpc::create_eth(
+ &mut rpc_handle,
+ eth_deps,
+ subscription_task_executor.clone(),
+ )?;
+
+ Ok(rpc_handle)
}
});
@@ -866,6 +874,13 @@
))
}
+pub struct OtherPartial {
+ pub telemetry: Option<Telemetry>,
+ pub telemetry_worker_handle: Option<TelemetryWorkerHandle>,
+ pub eth_filter_pool: Option<FilterPool>,
+ pub eth_backend: Arc<fc_db::kv::Backend<Block>>,
+}
+
/// Builds a new development service. This service uses instant seal, and mocks
/// the parachain inherent
pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(
@@ -899,7 +914,6 @@
{
use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};
use fc_consensus::FrontierBlockImport;
- use sc_client_api::HeaderBackend;
let sc_service::PartialComponents {
client,
@@ -910,7 +924,12 @@
select_chain: maybe_select_chain,
transaction_pool,
other:
- (telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),
+ OtherPartial {
+ telemetry,
+ eth_filter_pool,
+ eth_backend,
+ telemetry_worker_handle: _,
+ },
} = new_partial::<RuntimeApi, ExecutorDispatch, _>(
&config,
dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,
@@ -918,19 +937,6 @@
let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);
let prometheus_registry = config.prometheus_registry().cloned();
- let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(
- task_manager.spawn_handle(),
- overrides_handle::<_, _, Runtime>(client.clone()),
- 50,
- 50,
- prometheus_registry.clone(),
- ));
-
- let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks<
- fc_mapping_sync::EthereumBlockNotification<Block>,
- > = Default::default();
- let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks);
-
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
@@ -1046,57 +1052,76 @@
}),
);
}
-
- task_manager.spawn_essential_handle().spawn(
- "frontier-mapping-sync-worker",
- Some("block-authoring"),
- MappingSyncWorker::new(
- client.import_notification_stream(),
- Duration::new(6, 0),
- client.clone(),
- backend.clone(),
- overrides_handle::<_, _, Runtime>(client.clone()),
- frontier_backend.clone(),
- 3,
- 0,
- SyncStrategy::Normal,
- sync_service.clone(),
- pubsub_notification_sinks.clone(),
- )
- .for_each(|()| futures::future::ready(())),
- );
#[cfg(feature = "pov-estimate")]
let rpc_backend = backend.clone();
let runtime_id = config.chain_spec.runtime_id();
+ // Frontier
+ let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));
+ let fee_history_limit = 2048;
+
+ let eth_pubsub_notification_sinks: Arc<
+ EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,
+ > = Default::default();
+
+ let overrides = overrides_handle(client.clone());
+ let eth_block_data_cache = spawn_frontier_tasks(
+ FrontierTaskParams {
+ client: client.clone(),
+ substrate_backend: backend.clone(),
+ eth_filter_pool: eth_filter_pool.clone(),
+ eth_backend: eth_backend.clone(),
+ fee_history_limit,
+ fee_history_cache: fee_history_cache.clone(),
+ task_manager: &task_manager,
+ prometheus_registry,
+ overrides: overrides.clone(),
+ sync_strategy: SyncStrategy::Normal,
+ },
+ sync_service.clone(),
+ eth_pubsub_notification_sinks.clone(),
+ );
+
+ // Rpc
let rpc_builder = Box::new({
clone!(
- backend,
client,
- sync_service,
- frontier_backend,
+ backend,
+ eth_backend,
+ eth_pubsub_notification_sinks,
+ fee_history_cache,
+ eth_block_data_cache,
+ overrides,
+ transaction_pool,
network,
- transaction_pool,
- pubsub_notification_sinks
+ sync_service,
);
- move |deny_unsafe, subscription_executor| {
+ move |deny_unsafe, subscription_task_executor: SubscriptionTaskExecutor| {
clone!(
backend,
- block_data_cache,
+ eth_block_data_cache,
client,
+ eth_backend,
+ eth_filter_pool,
+ eth_pubsub_notification_sinks,
fee_history_cache,
- filter_pool,
+ eth_block_data_cache,
network,
- pubsub_notification_sinks,
+ runtime_id,
+ transaction_pool,
+ select_chain,
+ overrides,
);
#[cfg(not(feature = "pov-estimate"))]
let _ = backend;
+ let mut rpc_module = RpcModule::new(());
+
let full_deps = unique_rpc::FullDeps {
- runtime_id: runtime_id.clone(),
+ runtime_id,
#[cfg(feature = "pov-estimate")]
exec_params: uc_rpc::pov_estimate::ExecutorParams {
@@ -1108,32 +1133,42 @@
#[cfg(feature = "pov-estimate")]
backend,
- eth_backend: frontier_backend.clone(),
+ // eth_backend,
deny_unsafe,
- client,
+ client: client.clone(),
pool: transaction_pool.clone(),
+ select_chain,
+ };
+
+ unique_rpc::create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_module, full_deps)?;
+
+ let eth_deps = unique_rpc::EthDeps {
+ client,
graph: transaction_pool.pool().clone(),
- // TODO: Unhardcode
- enable_dev_signer: false,
- filter_pool,
+ pool: transaction_pool,
+ is_authority: true,
network,
- sync: sync_service.clone(),
- select_chain: select_chain.clone(),
- is_authority: collator,
+ eth_backend,
// TODO: Unhardcode
max_past_logs: 10000,
- block_data_cache,
+ fee_history_limit,
fee_history_cache,
+ eth_block_data_cache,
// TODO: Unhardcode
- fee_history_limit: 2048,
- pubsub_notification_sinks,
+ enable_dev_signer: false,
+ eth_filter_pool,
+ eth_pubsub_notification_sinks,
+ overrides,
+ sync: sync_service.clone(),
};
- unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(
- full_deps,
- subscription_executor,
- )
- .map_err(Into::into)
+ unique_rpc::create_eth(
+ &mut rpc_module,
+ eth_deps,
+ subscription_task_executor.clone(),
+ )?;
+
+ Ok(rpc_module)
}
});
@@ -1155,3 +1190,130 @@
network_starter.start_network();
Ok(task_manager)
}
+
+fn overrides_handle<C, BE>(client: Arc<C>) -> Arc<OverrideHandle<Block>>
+where
+ C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,
+ C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,
+ C: Send + Sync + 'static,
+ C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
+ BE: Backend<Block> + 'static,
+ BE::State: StateBackend<BlakeTwo256>,
+{
+ let mut overrides_map = BTreeMap::new();
+ overrides_map.insert(
+ EthereumStorageSchema::V1,
+ Box::new(SchemaV1Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,
+ );
+ overrides_map.insert(
+ EthereumStorageSchema::V2,
+ Box::new(SchemaV2Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,
+ );
+ overrides_map.insert(
+ EthereumStorageSchema::V3,
+ Box::new(SchemaV3Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,
+ );
+
+ Arc::new(OverrideHandle {
+ schemas: overrides_map,
+ fallback: Box::new(RuntimeApiStorageOverride::new(client)),
+ })
+}
+
+pub struct FrontierTaskParams<'a, B: BlockT, C, BE> {
+ pub task_manager: &'a TaskManager,
+ pub client: Arc<C>,
+ pub substrate_backend: Arc<BE>,
+ pub eth_backend: Arc<fc_db::kv::Backend<B>>,
+ pub eth_filter_pool: Option<FilterPool>,
+ pub overrides: Arc<OverrideHandle<B>>,
+ pub fee_history_limit: u64,
+ pub fee_history_cache: FeeHistoryCache,
+ pub sync_strategy: SyncStrategy,
+ pub prometheus_registry: Option<Registry>,
+}
+
+pub fn spawn_frontier_tasks<B, C, BE>(
+ params: FrontierTaskParams<B, C, BE>,
+ sync: Arc<SyncingService<B>>,
+ pubsub_notification_sinks: Arc<
+ EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<B>>,
+ >,
+) -> Arc<EthBlockDataCacheTask<B>>
+where
+ C: ProvideRuntimeApi<B> + BlockOf,
+ C: HeaderBackend<B> + HeaderMetadata<B, Error = BlockChainError> + 'static,
+ C: BlockchainEvents<B> + StorageProvider<B, BE>,
+ C: Send + Sync + 'static,
+ C::Api: EthereumRuntimeRPCApi<B>,
+ C::Api: BlockBuilder<B>,
+ B: BlockT<Hash = H256> + Send + Sync + 'static,
+ B::Header: HeaderT<Number = u32>,
+ BE: Backend<B> + 'static,
+ BE::State: StateBackend<BlakeTwo256>,
+{
+ let FrontierTaskParams {
+ task_manager,
+ client,
+ substrate_backend,
+ eth_backend,
+ eth_filter_pool,
+ overrides,
+ fee_history_limit,
+ fee_history_cache,
+ sync_strategy,
+ prometheus_registry,
+ } = params;
+ // Frontier offchain DB task. Essential.
+ // Maps emulated ethereum data to substrate native data.
+ params.task_manager.spawn_essential_handle().spawn(
+ "frontier-mapping-sync-worker",
+ Some("frontier"),
+ MappingSyncWorker::new(
+ client.import_notification_stream(),
+ Duration::new(6, 0),
+ client.clone(),
+ substrate_backend,
+ overrides.clone(),
+ eth_backend,
+ 3,
+ 0,
+ sync_strategy,
+ sync,
+ pubsub_notification_sinks,
+ )
+ .for_each(|()| futures::future::ready(())),
+ );
+
+ // Frontier `EthFilterApi` maintenance.
+ // Manages the pool of user-created Filters.
+ if let Some(eth_filter_pool) = eth_filter_pool {
+ // Each filter is allowed to stay in the pool for 100 blocks.
+ const FILTER_RETAIN_THRESHOLD: u64 = 100;
+ params.task_manager.spawn_essential_handle().spawn(
+ "frontier-filter-pool",
+ Some("frontier"),
+ EthTask::filter_pool_task(client.clone(), eth_filter_pool, FILTER_RETAIN_THRESHOLD),
+ );
+ }
+
+ // Spawn Frontier FeeHistory cache maintenance task.
+ params.task_manager.spawn_essential_handle().spawn(
+ "frontier-fee-history",
+ Some("frontier"),
+ EthTask::fee_history_task(
+ client,
+ overrides.clone(),
+ fee_history_cache,
+ fee_history_limit,
+ ),
+ );
+
+ Arc::new(EthBlockDataCacheTask::new(
+ task_manager.spawn_handle(),
+ overrides,
+ 50,
+ 50,
+ prometheus_registry,
+ ))
+}
node/rpc/Cargo.tomldiffbeforeafterboth--- a/node/rpc/Cargo.toml
+++ b/node/rpc/Cargo.toml
@@ -14,7 +14,6 @@
# pallet-contracts-rpc = { git = 'https://github.com/paritytech/substrate', branch = 'master' }
pallet-transaction-payment-rpc = { workspace = true }
sc-client-api = { workspace = true }
-sc-consensus-grandpa = { workspace = true }
sc-network = { workspace = true }
sc-network-sync = { workspace = true }
sc-rpc = { workspace = true }
@@ -41,6 +40,7 @@
up-data-structs = { workspace = true }
up-pov-estimate-rpc = { workspace = true, default-features = true }
up-rpc = { workspace = true }
+pallet-ethereum.workspace = true
[features]
default = []
node/rpc/src/lib.rsdiffbeforeafterboth--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+use fc_mapping_sync::{EthereumBlockNotificationSinks, EthereumBlockNotification};
use sp_runtime::traits::BlakeTwo256;
use fc_rpc::{
EthBlockDataCacheTask, OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override,
@@ -26,9 +27,6 @@
backend::{AuxStore, StorageProvider},
client::BlockchainEvents,
StateBackend, Backend,
-};
-use sc_consensus_grandpa::{
- FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,
};
use sc_network::NetworkService;
use sc_network_sync::SyncingService;
@@ -46,42 +44,16 @@
#[cfg(feature = "pov-estimate")]
type FullBackend = sc_service::TFullBackend<Block>;
-/// Extra dependencies for GRANDPA
-pub struct GrandpaDeps<B> {
- /// Voting round info.
- pub shared_voter_state: SharedVoterState,
- /// Authority set info.
- pub shared_authority_set: SharedAuthoritySet<Hash, BlockNumber>,
- /// Receives notifications about justification events from Grandpa.
- pub justification_stream: GrandpaJustificationStream<Block>,
- /// Executor to drive the subscription manager in the Grandpa RPC handler.
- pub subscription_executor: SubscriptionTaskExecutor,
- /// Finality proof provider.
- pub finality_provider: Arc<FinalityProofProvider<B, Block>>,
-}
-
/// Full client dependencies.
-pub struct FullDeps<C, P, SC, CA: ChainApi> {
+pub struct FullDeps<C, P, SC> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
- /// Graph pool instance.
- pub graph: Arc<Pool<CA>>,
/// The SelectChain Strategy
pub select_chain: SC,
- /// The Node authority flag
- pub is_authority: bool,
- /// Whether to enable dev signer
- pub enable_dev_signer: bool,
- /// Network service
- pub network: Arc<NetworkService<Block, Hash>>,
- /// Syncing service
- pub sync: Arc<SyncingService<Block>>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
- /// EthFilterApi pool.
- pub filter_pool: Option<FilterPool>,
/// Runtime identification (read from the chain spec)
pub runtime_id: RuntimeId,
@@ -91,23 +63,6 @@
/// Substrate Backend.
#[cfg(feature = "pov-estimate")]
pub backend: Arc<FullBackend>,
-
- /// Ethereum Backend.
- pub eth_backend: Arc<dyn fc_db::BackendReader<Block> + Send + Sync>,
- /// Maximum number of logs in a query.
- pub max_past_logs: u32,
- /// Maximum fee history cache size.
- pub fee_history_limit: u64,
- /// Fee history cache.
- pub fee_history_cache: FeeHistoryCache,
- /// Cache for Ethereum block data.
- pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,
-
- pub pubsub_notification_sinks: Arc<
- fc_mapping_sync::EthereumBlockNotificationSinks<
- fc_mapping_sync::EthereumBlockNotification<Block>,
- >,
- >,
}
pub fn overrides_handle<C, BE, R>(client: Arc<C>) -> Arc<OverrideHandle<Block>>
@@ -142,10 +97,10 @@
}
/// Instantiate all Full RPC extensions.
-pub fn create_full<C, P, SC, CA, R, A, B>(
- deps: FullDeps<C, P, SC, CA>,
- subscription_task_executor: SubscriptionTaskExecutor,
-) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
+pub fn create_full<C, P, SC, R, A, B>(
+ io: &mut RpcModule<()>,
+ deps: FullDeps<C, P, SC>,
+) -> Result<(), Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
@@ -155,8 +110,6 @@
C::Api: BlockBuilder<Block>,
// C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber, Hash>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
- C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
- C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,
C::Api: up_rpc::UniqueApi<Block, <R as RuntimeInstance>::CrossAccountId, AccountId>,
C::Api: app_promotion_rpc::AppPromotionApi<
Block,
@@ -168,7 +121,6 @@
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
P: TransactionPool<Block = Block> + 'static,
- CA: ChainApi<Block = Block> + 'static,
R: RuntimeInstance + Send + Sync + 'static,
<R as RuntimeInstance>::CrossAccountId: serde::Serialize,
C: sp_api::CallApiAt<
@@ -179,10 +131,6 @@
>,
for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,
{
- use fc_rpc::{
- Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,
- EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer, TxPool, TxPoolApiServer
- };
use uc_rpc::{UniqueApiServer, Unique};
use uc_rpc::{AppPromotionApiServer, AppPromotion};
@@ -194,21 +142,11 @@
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
- let mut io = RpcModule::new(());
let FullDeps {
client,
pool,
- graph,
select_chain: _,
- fee_history_limit,
- fee_history_cache,
- block_data_cache,
- enable_dev_signer,
- is_authority,
- network,
- sync,
deny_unsafe,
- filter_pool,
runtime_id: _,
@@ -217,37 +155,137 @@
#[cfg(feature = "pov-estimate")]
backend,
-
- eth_backend,
- max_past_logs,
- pubsub_notification_sinks,
} = deps;
io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;
io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;
- // io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));
+ io.merge(Unique::new(client.clone()).into_rpc())?;
+
+ io.merge(AppPromotion::new(client.clone()).into_rpc())?;
+
+ #[cfg(feature = "pov-estimate")]
+ io.merge(
+ PovEstimate::new(
+ client.clone(),
+ backend,
+ deny_unsafe,
+ exec_params,
+ runtime_id,
+ )
+ .into_rpc(),
+ )?;
+
+ Ok(())
+}
+
+pub struct EthDeps<C, P, CA: ChainApi> {
+ /// The client instance to use.
+ pub client: Arc<C>,
+ /// Transaction pool instance.
+ pub pool: Arc<P>,
+ /// Graph pool instance.
+ pub graph: Arc<Pool<CA>>,
+ /// Syncing service
+ pub sync: Arc<SyncingService<Block>>,
+ /// The Node authority flag
+ pub is_authority: bool,
+ /// Network service
+ pub network: Arc<NetworkService<Block, Hash>>,
+
+ /// Ethereum Backend.
+ pub eth_backend: Arc<dyn fc_db::BackendReader<Block> + Send + Sync>,
+ /// Maximum number of logs in a query.
+ pub max_past_logs: u32,
+ /// Maximum fee history cache size.
+ pub fee_history_limit: u64,
+ /// Fee history cache.
+ pub fee_history_cache: FeeHistoryCache,
+ pub eth_block_data_cache: Arc<EthBlockDataCacheTask<Block>>,
+ /// EthFilterApi pool.
+ pub eth_filter_pool: Option<FilterPool>,
+ pub eth_pubsub_notification_sinks: Arc<EthereumBlockNotificationSinks<EthereumBlockNotification<Block>>>,
+ /// Whether to enable eth dev signer
+ pub enable_dev_signer: bool,
+
+ pub overrides: Arc<OverrideHandle<Block>>,
+}
+
+/// This converter is never used, but we have a generic
+/// Option<T>, where T should implement ConvertTransaction
+///
+/// TODO: remove after never-type (`!`) stabilization
+enum NeverConvert {}
+impl<T> fp_rpc::ConvertTransaction<T> for NeverConvert {
+ fn convert_transaction(&self, _transaction: pallet_ethereum::Transaction) -> T {
+ unreachable!()
+ }
+}
+pub fn create_eth<C, P, CA, B>(
+ io: &mut RpcModule<()>,
+ deps: EthDeps<C, P, CA>,
+ subscription_task_executor: SubscriptionTaskExecutor,
+) -> Result<(), Box<dyn std::error::Error + Send + Sync>>
+where
+ C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,
+ C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
+ C: Send + Sync + 'static,
+ C: BlockchainEvents<Block>,
+ C::Api: BlockBuilder<Block>,
+ C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
+ C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,
+ P: TransactionPool<Block = Block> + 'static,
+ CA: ChainApi<Block = Block> + 'static,
+ B: sc_client_api::Backend<Block> + Send + Sync + 'static,
+ C: sp_api::CallApiAt<
+ sp_runtime::generic::Block<
+ sp_runtime::generic::Header<u32, BlakeTwo256>,
+ sp_runtime::OpaqueExtrinsic,
+ >,
+ >,
+{
+ use fc_rpc::{
+ Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,
+ EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer, TxPool, TxPoolApiServer,
+ };
+
+ let EthDeps {
+ client,
+ pool,
+ graph,
+ eth_backend,
+ max_past_logs,
+ fee_history_limit,
+ fee_history_cache,
+ eth_block_data_cache,
+ eth_filter_pool,
+ eth_pubsub_notification_sinks,
+ enable_dev_signer,
+ sync,
+ is_authority,
+ network,
+ overrides,
+ } = deps;
+
let mut signers = Vec::new();
if enable_dev_signer {
signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);
}
-
- let overrides = overrides_handle::<_, _, R>(client.clone());
-
let execute_gas_limit_multiplier = 10;
io.merge(
Eth::new(
client.clone(),
pool.clone(),
graph.clone(),
- Some(<R as RuntimeInstance>::get_transaction_converter()),
+ // We have no runtimes old enough to only accept converted transactions
+ None::<NeverConvert>,
sync.clone(),
signers,
overrides.clone(),
eth_backend.clone(),
is_authority,
- block_data_cache.clone(),
+ eth_block_data_cache.clone(),
fee_history_cache,
fee_history_limit,
execute_gas_limit_multiplier,
@@ -256,24 +294,12 @@
.into_rpc(),
)?;
- io.merge(Unique::new(client.clone()).into_rpc())?;
-
- io.merge(AppPromotion::new(client.clone()).into_rpc())?;
+ let tx_pool = TxPool::new(
+ client.clone(),
+ graph,
+ );
- #[cfg(feature = "pov-estimate")]
- io.merge(
- PovEstimate::new(
- client.clone(),
- backend,
- deny_unsafe,
- exec_params,
- runtime_id,
- )
- .into_rpc(),
- )?;
-
- let tx_pool = TxPool::new(client.clone(), graph);
- if let Some(filter_pool) = filter_pool {
+ if let Some(filter_pool) = eth_filter_pool {
io.merge(
EthFilter::new(
client.clone(),
@@ -282,12 +308,11 @@
filter_pool,
500_usize, // max stored filters
max_past_logs,
- block_data_cache,
+ eth_block_data_cache,
)
.into_rpc(),
)?;
}
-
io.merge(
Net::new(
client.clone(),
@@ -297,9 +322,7 @@
)
.into_rpc(),
)?;
-
io.merge(Web3::new(client.clone()).into_rpc())?;
-
io.merge(
EthPubSub::new(
pool,
@@ -307,12 +330,11 @@
sync,
subscription_task_executor,
overrides,
- pubsub_notification_sinks,
+ eth_pubsub_notification_sinks,
)
.into_rpc(),
)?;
-
io.merge(tx_pool.into_rpc())?;
- Ok(io)
+ Ok(())
}