From 6b7300defa13af29c98729b2dd60106fa35cd4da Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 14 Mar 2022 14:53:25 +0000 Subject: [PATCH] Make opal runtime mandatory --- --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -252,7 +252,6 @@ [dependencies.opal-runtime] path = '../../runtime/opal' -optional = true [dependencies.up-data-structs] path = "../../primitives/data-structs" @@ -306,7 +305,7 @@ unique-rpc = { default-features = false, path = "../rpc" } [features] -default = ["unique-runtime", "quartz-runtime", "opal-runtime"] +default = ["unique-runtime", "quartz-runtime"] runtime-benchmarks = [ 'unique-runtime/runtime-benchmarks', 'polkadot-service/runtime-benchmarks', --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -35,7 +35,6 @@ pub type QuartzChainSpec = sc_service::GenericChainSpec; /// The `ChainSpec` parameterized for the opal runtime. -#[cfg(feature = "opal-runtime")] pub type OpalChainSpec = sc_service::GenericChainSpec; pub enum RuntimeId { @@ -61,7 +60,6 @@ return RuntimeId::Quartz; } - #[cfg(feature = "opal-runtime")] if self.id().starts_with("opal") { return RuntimeId::Opal; } --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -44,7 +44,6 @@ #[cfg(feature = "quartz-runtime")] use crate::service::QuartzRuntimeExecutor; -#[cfg(feature = "opal-runtime")] use crate::service::OpalRuntimeExecutor; use codec::Encode; @@ -82,7 +81,7 @@ "" | "local" => Box::new(chain_spec::local_testnet_rococo_config()), path => { let path = std::path::PathBuf::from(path); - let chain_spec = Box::new(sc_service::GenericChainSpec::<()>::from_json_file( + let chain_spec = Box::new(chain_spec::OpalChainSpec::from_json_file( path.clone(), )?) as Box; @@ -93,9 +92,7 @@ #[cfg(feature = "quartz-runtime")] RuntimeId::Quartz => Box::new(chain_spec::QuartzChainSpec::from_json_file(path)?), - #[cfg(feature = "opal-runtime")] RuntimeId::Opal => Box::new(chain_spec::OpalChainSpec::from_json_file(path)?), - RuntimeId::Unknown(chain) => return Err(no_runtime_err!(chain)), } } @@ -147,9 +144,7 @@ #[cfg(feature = "quartz-runtime")] RuntimeId::Quartz => &quartz_runtime::VERSION, - #[cfg(feature = "opal-runtime")] RuntimeId::Opal => &opal_runtime::VERSION, - RuntimeId::Unknown(chain) => panic!("{}", no_runtime_err!(chain)), } } @@ -241,7 +236,6 @@ runner, $components, $cli, $cmd, $config, $( $code )* ), - #[cfg(feature = "opal-runtime")] RuntimeId::Opal => async_run_with_runtime!( opal_runtime::RuntimeApi, OpalRuntimeExecutor, runner, $components, $cli, $cmd, $config, $( $code )* @@ -359,9 +353,7 @@ #[cfg(feature = "quartz-runtime")] RuntimeId::Quartz => cmd.run::(config), - #[cfg(feature = "opal-runtime")] RuntimeId::Opal => cmd.run::(config), - RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into()), }) } else { @@ -438,7 +430,6 @@ .map(|r| r.0) .map_err(Into::into), - #[cfg(feature = "opal-runtime")] RuntimeId::Opal => crate::service::start_node::< opal_runtime::Runtime, opal_runtime::RuntimeApi, --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -95,7 +95,6 @@ } } -#[cfg(feature = "opal-runtime")] impl NativeExecutionDispatch for OpalRuntimeExecutor { type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; --- /dev/null +++ b/node/rpc/src/lib.rs.exp @@ -0,0 +1,294 @@ +// Copyright 2019-2022 Unique Network (Gibraltar) Ltd. +// This file is part of Unique Network. + +// Unique Network is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Unique Network is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Unique Network. If not, see . + +use sp_runtime::traits::BlakeTwo256; +use fc_rpc::{ + EthBlockDataCache, OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, + StorageOverride, SchemaV2Override, SchemaV3Override, +}; +use fc_rpc_core::types::{FilterPool, FeeHistoryCache}; +use jsonrpc_pubsub::manager::SubscriptionManager; +use pallet_ethereum::EthereumStorageSchema; +use sc_client_api::{ + backend::{AuxStore, StorageProvider}, + client::BlockchainEvents, + StateBackend, Backend, +}; +use sc_finality_grandpa::{ + FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState, +}; +use sc_network::NetworkService; +use sc_rpc::SubscriptionTaskExecutor; +pub use sc_rpc_api::DenyUnsafe; +use sc_transaction_pool::{ChainApi, Pool}; +use sp_api::ProvideRuntimeApi; +use sp_block_builder::BlockBuilder; +use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; +use sc_service::TransactionPool; +use std::{collections::BTreeMap, marker::PhantomData, sync::Arc}; + +#[cfg(feature = "unique-runtime")] +use unique_runtime as runtime; + +#[cfg(feature = "quartz-runtime")] +use quartz_runtime as runtime; + +#[cfg(feature = "opal-runtime")] +use opal_runtime as runtime; + +use runtime::opaque::{Hash, AccountId, CrossAccountId, Index, Block, BlockNumber, Balance}; + +/// Public io handler for exporting into other modules +pub type IoHandler = jsonrpc_core::IoHandler; + +/// Extra dependencies for GRANDPA +pub struct GrandpaDeps { + /// Voting round info. + pub shared_voter_state: SharedVoterState, + /// Authority set info. + pub shared_authority_set: SharedAuthoritySet, + /// Receives notifications about justification events from Grandpa. + pub justification_stream: GrandpaJustificationStream, + /// Executor to drive the subscription manager in the Grandpa RPC handler. + pub subscription_executor: SubscriptionTaskExecutor, + /// Finality proof provider. + pub finality_provider: Arc>, +} + +/// Full client dependencies. +pub struct FullDeps { + /// The client instance to use. + pub client: Arc, + /// Transaction pool instance. + pub pool: Arc

, + /// Graph pool instance. + pub graph: Arc>, + /// 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>, + /// Whether to deny unsafe calls + pub deny_unsafe: DenyUnsafe, + /// EthFilterApi pool. + pub filter_pool: Option, + /// Backend. + pub backend: Arc>, + /// 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>, +} + +struct AccountCodes { + client: Arc, + _blk_marker: PhantomData, + _caid_marker: PhantomData, +} + +impl AccountCodes +where + Block: sp_api::BlockT, + C: ProvideRuntimeApi, +{ + fn new(client: Arc) -> Self { + Self { + client, + _blk_marker: PhantomData, + _caid_marker: PhantomData, + } + } +} + +impl fc_rpc::AccountCodeProvider for AccountCodes +where + Block: sp_api::BlockT, + C: ProvideRuntimeApi, + C::Api: up_rpc::UniqueApi, + CAId: pallet_common::account::CrossAccountId, +{ + fn code(&self, block: &sp_api::BlockId, account: sp_core::H160) -> Option> { + use up_rpc::UniqueApi; + self.client + .runtime_api() + .eth_contract_code(block, account) + .ok() + .flatten() + } +} + +pub fn overrides_handle(client: Arc) -> Arc> +where + C: ProvideRuntimeApi + StorageProvider + AuxStore, + C: HeaderBackend + HeaderMetadata, + C: Send + Sync + 'static, + C::Api: fp_rpc::EthereumRuntimeRPCApi, + C::Api: up_rpc::UniqueApi, + BE: Backend + 'static, + BE::State: StateBackend, + CAId: pallet_common::account::CrossAccountId + Sync + Send + 'static, +{ + let mut overrides_map = BTreeMap::new(); + overrides_map.insert( + EthereumStorageSchema::V1, + Box::new(SchemaV1Override::new_with_code_provider( + client.clone(), + Arc::new(AccountCodes::::new(client.clone())), + )) as Box + Send + Sync>, + ); + overrides_map.insert( + EthereumStorageSchema::V2, + Box::new(SchemaV2Override::new(client.clone())) + as Box + Send + Sync>, + ); + overrides_map.insert( + EthereumStorageSchema::V3, + Box::new(SchemaV3Override::new(client.clone())) + as Box + Send + Sync>, + ); + + Arc::new(OverrideHandle { + schemas: overrides_map, + fallback: Box::new(RuntimeApiStorageOverride::new(client)), + }) +} + +/// Instantiate all Full RPC extensions. +pub fn create_full( + deps: FullDeps, + subscription_task_executor: SubscriptionTaskExecutor, +) -> jsonrpc_core::IoHandler +where + C: ProvideRuntimeApi + StorageProvider + AuxStore, + C: HeaderBackend + HeaderMetadata + 'static, + C: Send + Sync + 'static, + C: BlockchainEvents, + C::Api: substrate_frame_rpc_system::AccountNonceApi, + C::Api: BlockBuilder, + // C::Api: pallet_contracts_rpc::ContractsRuntimeApi, + C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, + C::Api: fp_rpc::EthereumRuntimeRPCApi, + C::Api: up_rpc::UniqueApi, + B: sc_client_api::Backend + Send + Sync + 'static, + B::State: sc_client_api::backend::StateBackend>, + P: TransactionPool + 'static, + CA: ChainApi + 'static, + CAId: pallet_common::account::CrossAccountId + Sync + Send + 'static, +{ + use fc_rpc::{ + EthApi, EthApiServer, EthDevSigner, EthFilterApi, EthFilterApiServer, EthPubSubApi, + EthPubSubApiServer, EthSigner, HexEncodedIdProvider, NetApi, NetApiServer, Web3Api, + Web3ApiServer, + }; + use uc_rpc::{UniqueApi, Unique}; + // use pallet_contracts_rpc::{Contracts, ContractsApi}; + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; + use substrate_frame_rpc_system::{FullSystem, SystemApi}; + + let mut io = jsonrpc_core::IoHandler::default(); + let FullDeps { + client, + pool, + graph, + select_chain: _, + fee_history_limit, + fee_history_cache, + block_data_cache, + enable_dev_signer, + is_authority, + network, + deny_unsafe, + filter_pool, + backend, + max_past_logs, + } = deps; + + io.extend_with(SystemApi::to_delegate(FullSystem::new( + client.clone(), + pool.clone(), + deny_unsafe, + ))); + + io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new( + client.clone(), + ))); + + // io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone()))); + + let mut signers = Vec::new(); + if enable_dev_signer { + signers.push(Box::new(EthDevSigner::new()) as Box); + } + + let overrides = overrides_handle::<_, _, CAId>(client.clone()); + + io.extend_with(EthApiServer::to_delegate(EthApi::new( + client.clone(), + pool.clone(), + graph, + runtime::TransactionConverter, + network.clone(), + signers, + overrides.clone(), + backend.clone(), + is_authority, + max_past_logs, + block_data_cache.clone(), + fee_history_limit, + fee_history_cache, + ))); + io.extend_with(UniqueApi::to_delegate(Unique::new(client.clone()))); + + if let Some(filter_pool) = filter_pool { + io.extend_with(EthFilterApiServer::to_delegate(EthFilterApi::new( + client.clone(), + backend, + filter_pool, + 500_usize, // max stored filters + max_past_logs, + block_data_cache, + ))); + } + + io.extend_with(NetApiServer::to_delegate(NetApi::new( + client.clone(), + network.clone(), + // Whether to format the `peer_count` response as Hex (default) or not. + true, + ))); + + io.extend_with(Web3ApiServer::to_delegate(Web3Api::new(client.clone()))); + + io.extend_with(EthPubSubApiServer::to_delegate(EthPubSubApi::new( + pool, + client, + network, + SubscriptionManager::::with_id_provider( + HexEncodedIdProvider::default(), + Arc::new(subscription_task_executor), + ), + overrides, + ))); + + io +} -- gitstuff