git.delta.rocks / unique-network / refs/commits / 23062aac0eef

difftreelog

Contracts module rpc call toggle button

str-mv2020-07-10parent: #6ec64fe.patch.diff
in: master

2 files changed

modifiednode/src/chain_spec.rsdiffbeforeafterboth
--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -103,7 +103,8 @@
 fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
 	root_key: AccountId,
 	endowed_accounts: Vec<AccountId>,
-	_enable_println: bool) -> GenesisConfig {
+	_enable_println: bool
+	) -> GenesisConfig {
 	GenesisConfig {
 		system: Some(SystemConfig {
 			code: WASM_BINARY.to_vec(),
@@ -124,7 +125,7 @@
 		contracts: Some(ContractsConfig {
 			gas_price: 1_000,
             current_schedule: ContractsSchedule {
-                 //   enable_println,
+            		// enable_println,
                     ..Default::default()
             },
         }),
modifiednode/src/service.rsdiffbeforeafterboth
before · node/src/service.rs
1//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.23use std::sync::Arc;4use std::time::Duration;5use sc_client::LongestChain;6use sc_client_api::ExecutorProvider;7use nft_runtime::{self, opaque::Block, RuntimeApi};8use sc_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder};9use sp_inherents::InherentDataProviders;10use sc_executor::native_executor_instance;11pub use sc_executor::NativeExecutor;12use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};13use sc_finality_grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider};1415// Our native executor instance.16native_executor_instance!(17	pub Executor,18	nft_runtime::api::dispatch,19	nft_runtime::native_version,20);2122/// Starts a `ServiceBuilder` for a full service.23///24/// Use this macro if you don't actually need the full service, but just the builder in order to25/// be able to perform chain operations.26macro_rules! new_full_start {27	($config:expr) => {{28		use std::sync::Arc;29		let mut import_setup = None;30		let inherent_data_providers = sp_inherents::InherentDataProviders::new();3132		let builder = sc_service::ServiceBuilder::new_full::<33			nft_runtime::opaque::Block, nft_runtime::RuntimeApi, crate::service::Executor34		>($config)?35			.with_select_chain(|_config, backend| {36				Ok(sc_client::LongestChain::new(backend.clone()))37			})?38			.with_transaction_pool(|config, client, _fetcher| {39				let pool_api = sc_transaction_pool::FullChainApi::new(client.clone());40				Ok(sc_transaction_pool::BasicPool::new(config, std::sync::Arc::new(pool_api)))41			})?42			.with_import_queue(|_config, client, mut select_chain, _transaction_pool| {43				let select_chain = select_chain.take()44					.ok_or_else(|| sc_service::Error::SelectChainRequired)?;4546				let (grandpa_block_import, grandpa_link) =47					sc_finality_grandpa::block_import(client.clone(), &(client.clone() as Arc<_>), select_chain)?;4849				let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(50					grandpa_block_import.clone(), client.clone(),51				);5253				let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair>(54					sc_consensus_aura::slot_duration(&*client)?,55					aura_block_import,56					Some(Box::new(grandpa_block_import.clone())),57					None,58					client,59					inherent_data_providers.clone(),60				)?;6162				import_setup = Some((grandpa_block_import, grandpa_link));6364				Ok(import_queue)65			})?;6667		(builder, import_setup, inherent_data_providers)68	}}69}7071/// Builds a new service for a full client.72pub fn new_full(config: Configuration)73	-> Result<impl AbstractService, ServiceError>74{75	let role = config.role.clone();76	let force_authoring = config.force_authoring;77	let name = config.network.node_name.clone();78	let disable_grandpa = config.disable_grandpa;7980	let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config);8182	let (block_import, grandpa_link) =83		import_setup.take()84			.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");8586	let service = builder87		.with_finality_proof_provider(|client, backend| {88			// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider89			let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;90			Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)91		})?92		.build()?;9394	if role.is_authority() {95		let proposer =96			sc_basic_authorship::ProposerFactory::new(service.client(), service.transaction_pool());9798		let client = service.client();99		let select_chain = service.select_chain()100			.ok_or(ServiceError::SelectChainRequired)?;101102		let can_author_with =103			sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());104105		let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _>(106			sc_consensus_aura::slot_duration(&*client)?,107			client,108			select_chain,109			block_import,110			proposer,111			service.network(),112			inherent_data_providers.clone(),113			force_authoring,114			service.keystore(),115			can_author_with,116		)?;117118		// the AURA authoring task is considered essential, i.e. if it119		// fails we take down the service with it.120		service.spawn_essential_task("aura", aura);121	}122123	// if the node isn't actively participating in consensus then it doesn't124	// need a keystore, regardless of which protocol we use below.125	let keystore = if role.is_authority() {126		Some(service.keystore())127	} else {128		None129	};130131	let grandpa_config = sc_finality_grandpa::Config {132		// FIXME #1578 make this available through chainspec133		gossip_duration: Duration::from_millis(333),134		justification_period: 512,135		name: Some(name),136		observer_enabled: false,137		keystore,138		is_authority: role.is_network_authority(),139	};140141	let enable_grandpa = !disable_grandpa;142	if enable_grandpa {143		// start the full GRANDPA voter144		// NOTE: non-authorities could run the GRANDPA observer protocol, but at145		// this point the full voter should provide better guarantees of block146		// and vote data availability than the observer. The observer has not147		// been tested extensively yet and having most nodes in a network run it148		// could lead to finality stalls.149		let grandpa_config = sc_finality_grandpa::GrandpaParams {150			config: grandpa_config,151			link: grandpa_link,152			network: service.network(),153			inherent_data_providers: inherent_data_providers.clone(),154			telemetry_on_connect: Some(service.telemetry_on_connect_stream()),155			voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),156			prometheus_registry: service.prometheus_registry()157		};158159		// the GRANDPA voter task is considered infallible, i.e.160		// if it fails we take down the service with it.161		service.spawn_essential_task(162			"grandpa-voter",163			sc_finality_grandpa::run_grandpa_voter(grandpa_config)?164		);165	} else {166		sc_finality_grandpa::setup_disabled_grandpa(167			service.client(),168			&inherent_data_providers,169			service.network(),170		)?;171	}172173	Ok(service)174}175176/// Builds a new service for a light client.177pub fn new_light(config: Configuration)178	-> Result<impl AbstractService, ServiceError>179{180	let inherent_data_providers = InherentDataProviders::new();181182	ServiceBuilder::new_light::<Block, RuntimeApi, Executor>(config)?183		.with_select_chain(|_config, backend| {184			Ok(LongestChain::new(backend.clone()))185		})?186		.with_transaction_pool(|config, client, fetcher| {187			let fetcher = fetcher188				.ok_or_else(|| "Trying to start light transaction pool without active fetcher")?;189190			let pool_api = sc_transaction_pool::LightChainApi::new(client.clone(), fetcher.clone());191			let pool = sc_transaction_pool::BasicPool::with_revalidation_type(192				config, Arc::new(pool_api), sc_transaction_pool::RevalidationType::Light,193			);194			Ok(pool)195		})?196		.with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _tx_pool| {197			let fetch_checker = fetcher198				.map(|fetcher| fetcher.checker().clone())199				.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;200			let grandpa_block_import = sc_finality_grandpa::light_block_import(201				client.clone(),202				backend,203				&(client.clone() as Arc<_>),204				Arc::new(fetch_checker),205			)?;206			let finality_proof_import = grandpa_block_import.clone();207			let finality_proof_request_builder =208				finality_proof_import.create_finality_proof_request_builder();209210			let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair>(211				sc_consensus_aura::slot_duration(&*client)?,212				grandpa_block_import,213				None,214				Some(Box::new(finality_proof_import)),215				client,216				inherent_data_providers.clone(),217			)?;218219			Ok((import_queue, finality_proof_request_builder))220		})?221		.with_finality_proof_provider(|client, backend| {222			// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider223			let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;224			Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)225		})?226		.build()227}
after · node/src/service.rs
1//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.23use std::sync::Arc;4use std::time::Duration;5use sc_client::LongestChain;6use sc_client_api::ExecutorProvider;7use nft_runtime::{self, opaque::Block, RuntimeApi};8use sc_service::{error::{Error as ServiceError}, AbstractService, Configuration, ServiceBuilder};9use sp_inherents::InherentDataProviders;10use sc_executor::native_executor_instance;11pub use sc_executor::NativeExecutor;12use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};13use sc_finality_grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider};1415// Our native executor instance.16native_executor_instance!(17	pub Executor,18	nft_runtime::api::dispatch,19	nft_runtime::native_version,20);2122/// Starts a `ServiceBuilder` for a full service.23///24/// Use this macro if you don't actually need the full service, but just the builder in order to25/// be able to perform chain operations.26macro_rules! new_full_start {27	($config:expr) => {{28		use jsonrpc_core::IoHandler;29		use std::sync::Arc;30		let mut import_setup = None;31		let inherent_data_providers = sp_inherents::InherentDataProviders::new();3233		let builder = sc_service::ServiceBuilder::new_full::<34			nft_runtime::opaque::Block, nft_runtime::RuntimeApi, crate::service::Executor35		>($config)?36			.with_select_chain(|_config, backend| {37				Ok(sc_client::LongestChain::new(backend.clone()))38			})?39			.with_transaction_pool(|config, client, _fetcher| {40				let pool_api = sc_transaction_pool::FullChainApi::new(client.clone());41				Ok(sc_transaction_pool::BasicPool::new(config, std::sync::Arc::new(pool_api)))42			})?43			.with_import_queue(|_config, client, mut select_chain, _transaction_pool| {44				let select_chain = select_chain.take()45					.ok_or_else(|| sc_service::Error::SelectChainRequired)?;4647				let (grandpa_block_import, grandpa_link) =48					sc_finality_grandpa::block_import(client.clone(), &(client.clone() as Arc<_>), select_chain)?;4950				let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(51					grandpa_block_import.clone(), client.clone(),52				);5354				let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair>(55					sc_consensus_aura::slot_duration(&*client)?,56					aura_block_import,57					Some(Box::new(grandpa_block_import.clone())),58					None,59					client,60					inherent_data_providers.clone(),61				)?;6263				import_setup = Some((grandpa_block_import, grandpa_link));6465				Ok(import_queue)66			})?67			.with_rpc_extensions(|builder| -> Result<IoHandler<sc_rpc::Metadata>, _> {68                let handler = pallet_contracts_rpc::Contracts::new(builder.client().clone());69                let delegate = pallet_contracts_rpc::ContractsApi::to_delegate(handler);7071                let mut io = IoHandler::default();72                io.extend_with(delegate);73                Ok(io)74            })?;7576		(builder, import_setup, inherent_data_providers)77	}}78}7980/// Builds a new service for a full client.81pub fn new_full(config: Configuration)82	-> Result<impl AbstractService, ServiceError>83{84	let role = config.role.clone();85	let force_authoring = config.force_authoring;86	let name = config.network.node_name.clone();87	let disable_grandpa = config.disable_grandpa;8889	let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config);9091	let (block_import, grandpa_link) =92		import_setup.take()93			.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");9495	let service = builder96		.with_finality_proof_provider(|client, backend| {97			// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider98			let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;99			Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)100		})?101		.build()?;102103	if role.is_authority() {104		let proposer =105			sc_basic_authorship::ProposerFactory::new(service.client(), service.transaction_pool());106107		let client = service.client();108		let select_chain = service.select_chain()109			.ok_or(ServiceError::SelectChainRequired)?;110111		let can_author_with =112			sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());113114		let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _>(115			sc_consensus_aura::slot_duration(&*client)?,116			client,117			select_chain,118			block_import,119			proposer,120			service.network(),121			inherent_data_providers.clone(),122			force_authoring,123			service.keystore(),124			can_author_with,125		)?;126127		// the AURA authoring task is considered essential, i.e. if it128		// fails we take down the service with it.129		service.spawn_essential_task("aura", aura);130	}131132	// if the node isn't actively participating in consensus then it doesn't133	// need a keystore, regardless of which protocol we use below.134	let keystore = if role.is_authority() {135		Some(service.keystore())136	} else {137		None138	};139140	let grandpa_config = sc_finality_grandpa::Config {141		// FIXME #1578 make this available through chainspec142		gossip_duration: Duration::from_millis(333),143		justification_period: 512,144		name: Some(name),145		observer_enabled: false,146		keystore,147		is_authority: role.is_network_authority(),148	};149150	let enable_grandpa = !disable_grandpa;151	if enable_grandpa {152		// start the full GRANDPA voter153		// NOTE: non-authorities could run the GRANDPA observer protocol, but at154		// this point the full voter should provide better guarantees of block155		// and vote data availability than the observer. The observer has not156		// been tested extensively yet and having most nodes in a network run it157		// could lead to finality stalls.158		let grandpa_config = sc_finality_grandpa::GrandpaParams {159			config: grandpa_config,160			link: grandpa_link,161			network: service.network(),162			inherent_data_providers: inherent_data_providers.clone(),163			telemetry_on_connect: Some(service.telemetry_on_connect_stream()),164			voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),165			prometheus_registry: service.prometheus_registry()166		};167168		// the GRANDPA voter task is considered infallible, i.e.169		// if it fails we take down the service with it.170		service.spawn_essential_task(171			"grandpa-voter",172			sc_finality_grandpa::run_grandpa_voter(grandpa_config)?173		);174	} else {175		sc_finality_grandpa::setup_disabled_grandpa(176			service.client(),177			&inherent_data_providers,178			service.network(),179		)?;180	}181182	Ok(service)183}184185/// Builds a new service for a light client.186pub fn new_light(config: Configuration)187	-> Result<impl AbstractService, ServiceError>188{189	let inherent_data_providers = InherentDataProviders::new();190191	ServiceBuilder::new_light::<Block, RuntimeApi, Executor>(config)?192		.with_select_chain(|_config, backend| {193			Ok(LongestChain::new(backend.clone()))194		})?195		.with_transaction_pool(|config, client, fetcher| {196			let fetcher = fetcher197				.ok_or_else(|| "Trying to start light transaction pool without active fetcher")?;198199			let pool_api = sc_transaction_pool::LightChainApi::new(client.clone(), fetcher.clone());200			let pool = sc_transaction_pool::BasicPool::with_revalidation_type(201				config, Arc::new(pool_api), sc_transaction_pool::RevalidationType::Light,202			);203			Ok(pool)204		})?205		.with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _tx_pool| {206			let fetch_checker = fetcher207				.map(|fetcher| fetcher.checker().clone())208				.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;209			let grandpa_block_import = sc_finality_grandpa::light_block_import(210				client.clone(),211				backend,212				&(client.clone() as Arc<_>),213				Arc::new(fetch_checker),214			)?;215			let finality_proof_import = grandpa_block_import.clone();216			let finality_proof_request_builder =217				finality_proof_import.create_finality_proof_request_builder();218219			let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair>(220				sc_consensus_aura::slot_duration(&*client)?,221				grandpa_block_import,222				None,223				Some(Box::new(finality_proof_import)),224				client,225				inherent_data_providers.clone(),226			)?;227228			Ok((import_queue, finality_proof_request_builder))229		})?230		.with_finality_proof_provider(|client, backend| {231			// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider232			let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;233			Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)234		})?235		.build()236}