diff --git a/node/Cargo.toml b/node/Cargo.toml index 84d22ff..ba6951e 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -29,12 +29,9 @@ sc-keystore = { git = "/~https://github.com/paritytech/substrate", package = "sc-k sp-inherents = { git = "/~https://github.com/paritytech/substrate", package = "sp-inherents" } sc-transaction-pool = { git = "/~https://github.com/paritytech/substrate", package = "sc-transaction-pool" } sc-transaction-pool-api = { git = "/~https://github.com/paritytech/substrate", package = "sc-transaction-pool-api" } -sc-consensus-aura = { git = "/~https://github.com/paritytech/substrate", package = "sc-consensus-aura" } -sp-consensus-aura = { git = "/~https://github.com/paritytech/substrate", package = "sp-consensus-aura" } sp-consensus = { git = "/~https://github.com/paritytech/substrate", package = "sp-consensus" } sc-consensus = { git = "/~https://github.com/paritytech/substrate", package = "sc-consensus" } -sc-finality-grandpa = { git = "/~https://github.com/paritytech/substrate", package = "sc-finality-grandpa" } -sp-finality-grandpa = { git = "/~https://github.com/paritytech/substrate", package = "sp-finality-grandpa" } +sc-consensus-manual-seal = { git = "/~https://github.com/paritytech/substrate", package = "sc-consensus-manual-seal" } sc-client-api = { git = "/~https://github.com/paritytech/substrate", package = "sc-client-api" } sp-runtime = { git = "/~https://github.com/paritytech/substrate", package = "sp-runtime" } sp-timestamp = { git = "/~https://github.com/paritytech/substrate", package = "sp-timestamp" } diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 005082b..fe2c110 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,11 +1,8 @@ use contracts_node_runtime::{ - AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig, - SystemConfig, WASM_BINARY, + AccountId, BalancesConfig, GenesisConfig, Signature, SudoConfig, SystemConfig, WASM_BINARY, }; use sc_service::ChainType; -use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{sr25519, Pair, Public}; -use sp_finality_grandpa::AuthorityId as GrandpaId; use sp_runtime::traits::{IdentifyAccount, Verify}; // The URL for the telemetry server. @@ -31,11 +28,6 @@ where AccountPublic::from(get_from_seed::(seed)).into_account() } -/// Generate an Aura authority key. -pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { - (get_from_seed::(s), get_from_seed::(s)) -} - pub fn development_config() -> Result { let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; @@ -48,8 +40,6 @@ pub fn development_config() -> Result { move || { testnet_genesis( wasm_binary, - // Initial PoA authorities - vec![authority_keys_from_seed("Alice")], // Sudo account get_account_id_from_seed::("Alice"), // Pre-funded accounts @@ -97,8 +87,6 @@ pub fn local_testnet_config() -> Result { move || { testnet_genesis( wasm_binary, - // Initial PoA authorities - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], // Sudo account get_account_id_from_seed::("Alice"), // Pre-funded accounts @@ -137,7 +125,6 @@ pub fn local_testnet_config() -> Result { /// Configure initial storage state for FRAME modules. fn testnet_genesis( wasm_binary: &[u8], - initial_authorities: Vec<(AuraId, GrandpaId)>, root_key: AccountId, endowed_accounts: Vec, _enable_println: bool, @@ -151,12 +138,6 @@ fn testnet_genesis( // Configure endowed accounts with initial balance of 1 << 60. balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), }, - aura: AuraConfig { - authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), - }, - grandpa: GrandpaConfig { - authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), - }, sudo: SudoConfig { // Assign network admin rights. key: Some(root_key), diff --git a/node/src/service.rs b/node/src/service.rs index 2b5a1f5..bbf3ff3 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -1,15 +1,11 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. use contracts_node_runtime::{self, opaque::Block, RuntimeApi}; -use sc_client_api::{BlockBackend, ExecutorProvider}; -use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; pub use sc_executor::NativeElseWasmExecutor; -use sc_finality_grandpa::SharedVoterState; use sc_keystore::LocalKeystore; use sc_service::{error::Error as ServiceError, Configuration, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; -use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; -use std::{sync::Arc, time::Duration}; +use std::sync::Arc; // Our native executor instance. pub struct ExecutorDispatch; @@ -45,16 +41,7 @@ pub fn new_partial( FullSelectChain, sc_consensus::DefaultImportQueue, sc_transaction_pool::FullPool, - ( - sc_finality_grandpa::GrandpaBlockImport< - FullBackend, - Block, - FullClient, - FullSelectChain, - >, - sc_finality_grandpa::LinkHalf, - Option, - ), + (Option,), >, ServiceError, > { @@ -88,12 +75,18 @@ pub fn new_partial( )?; let client = Arc::new(client); + let select_chain = sc_consensus::LongestChain::new(backend.clone()); + let telemetry = telemetry.map(|(worker, telemetry)| { task_manager.spawn_handle().spawn("telemetry", None, worker.run()); telemetry }); - let select_chain = sc_consensus::LongestChain::new(backend.clone()); + let import_queue = sc_consensus_manual_seal::import_queue( + Box::new(client.clone()), + &task_manager.spawn_essential_handle(), + config.prometheus_registry(), + ); let transaction_pool = sc_transaction_pool::BasicPool::new_full( config.transaction_pool.clone(), @@ -103,40 +96,6 @@ pub fn new_partial( client.clone(), ); - let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import( - client.clone(), - &(client.clone() as Arc<_>), - select_chain.clone(), - telemetry.as_ref().map(|x| x.handle()), - )?; - - let slot_duration = sc_consensus_aura::slot_duration(&*client)?; - - let import_queue = - sc_consensus_aura::import_queue::(ImportQueueParams { - block_import: grandpa_block_import.clone(), - justification_import: Some(Box::new(grandpa_block_import.clone())), - client: client.clone(), - create_inherent_data_providers: move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); - - Ok((timestamp, slot)) - }, - spawner: &task_manager.spawn_essential_handle(), - can_author_with: sp_consensus::CanAuthorWithNativeVersion::new( - client.executor().clone(), - ), - registry: config.prometheus_registry(), - check_for_equivocation: Default::default(), - telemetry: telemetry.as_ref().map(|x| x.handle()), - })?; - Ok(sc_service::PartialComponents { client, backend, @@ -145,7 +104,7 @@ pub fn new_partial( keystore_container, select_chain, transaction_pool, - other: (grandpa_block_import, grandpa_link, telemetry), + other: (telemetry,), }) } @@ -157,7 +116,7 @@ fn remote_keystore(_url: &String) -> Result, &'static str> { } /// Builds a new service for a full client. -pub fn new_full(mut config: Configuration) -> Result { +pub fn new_full(config: Configuration) -> Result { let sc_service::PartialComponents { client, backend, @@ -166,7 +125,7 @@ pub fn new_full(mut config: Configuration) -> Result mut keystore_container, select_chain, transaction_pool, - other: (block_import, grandpa_link, mut telemetry), + other: (mut telemetry,), } = new_partial(&config)?; if let Some(url) = &config.keystore_remote { @@ -179,20 +138,6 @@ pub fn new_full(mut config: Configuration) -> Result ))), }; } - let grandpa_protocol_name = sc_finality_grandpa::protocol_standard_name( - &client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"), - &config.chain_spec, - ); - - config - .network - .extra_sets - .push(sc_finality_grandpa::grandpa_peers_set_config(grandpa_protocol_name.clone())); - let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new( - backend.clone(), - grandpa_link.shared_authority_set().clone(), - Vec::default(), - )); let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams { @@ -202,7 +147,7 @@ pub fn new_full(mut config: Configuration) -> Result spawn_handle: task_manager.spawn_handle(), import_queue, block_announce_validator_builder: None, - warp_sync: Some(warp_sync), + warp_sync: None, })?; if config.offchain_worker.enabled { @@ -214,13 +159,6 @@ pub fn new_full(mut config: Configuration) -> Result ); } - let role = config.role.clone(); - let force_authoring = config.force_authoring; - let backoff_authoring_blocks: Option<()> = None; - let name = config.network.node_name.clone(); - let enable_grandpa = !config.disable_grandpa; - let prometheus_registry = config.prometheus_registry().cloned(); - let rpc_extensions_builder = { let client = client.clone(); let pool = transaction_pool.clone(); @@ -232,9 +170,10 @@ pub fn new_full(mut config: Configuration) -> Result Ok(crate::rpc::create_full(deps)) }) }; + let prometheus_registry = config.prometheus_registry().cloned(); let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams { - network: network.clone(), + network, client: client.clone(), keystore: keystore_container.sync_keystore(), task_manager: &mut task_manager, @@ -246,99 +185,31 @@ pub fn new_full(mut config: Configuration) -> Result telemetry: telemetry.as_mut(), })?; - if role.is_authority() { - let proposer_factory = sc_basic_authorship::ProposerFactory::new( - task_manager.spawn_handle(), - client.clone(), - transaction_pool, - prometheus_registry.as_ref(), - telemetry.as_ref().map(|x| x.handle()), - ); - - let can_author_with = - sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()); - - let slot_duration = sc_consensus_aura::slot_duration(&*client)?; - - let aura = sc_consensus_aura::start_aura::( - StartAuraParams { - slot_duration, - client: client.clone(), - select_chain, - block_import, - proposer_factory, - create_inherent_data_providers: move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); - - Ok((timestamp, slot)) - }, - force_authoring, - backoff_authoring_blocks, - keystore: keystore_container.sync_keystore(), - can_author_with, - sync_oracle: network.clone(), - justification_sync_link: network.clone(), - block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32), - max_block_proposal_slot_portion: None, - telemetry: telemetry.as_ref().map(|x| x.handle()), - }, - )?; - - // the AURA authoring task is considered essential, i.e. if it - // fails we take down the service with it. - task_manager - .spawn_essential_handle() - .spawn_blocking("aura", Some("block-authoring"), aura); - } - - // if the node isn't actively participating in consensus then it doesn't - // need a keystore, regardless of which protocol we use below. - let keystore = - if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None }; + let proposer = sc_basic_authorship::ProposerFactory::new( + task_manager.spawn_handle(), + client.clone(), + transaction_pool.clone(), + prometheus_registry.as_ref(), + telemetry.as_ref().map(|x| x.handle()), + ); - let grandpa_config = sc_finality_grandpa::Config { - // FIXME #1578 make this available through chainspec - gossip_duration: Duration::from_millis(333), - justification_period: 512, - name: Some(name), - observer_enabled: false, - keystore, - local_role: role, - telemetry: telemetry.as_ref().map(|x| x.handle()), - protocol_name: grandpa_protocol_name.clone(), + let params = sc_consensus_manual_seal::InstantSealParams { + block_import: client.clone(), + env: proposer, + client, + pool: transaction_pool, + select_chain, + consensus_data_provider: None, + create_inherent_data_providers: move |_, ()| async move { + Ok(sp_timestamp::InherentDataProvider::from_system_time()) + }, }; - if enable_grandpa { - // start the full GRANDPA voter - // NOTE: non-authorities could run the GRANDPA observer protocol, but at - // this point the full voter should provide better guarantees of block - // and vote data availability than the observer. The observer has not - // been tested extensively yet and having most nodes in a network run it - // could lead to finality stalls. - let grandpa_config = sc_finality_grandpa::GrandpaParams { - config: grandpa_config, - link: grandpa_link, - network, - voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(), - prometheus_registry, - shared_voter_state: SharedVoterState::empty(), - telemetry: telemetry.as_ref().map(|x| x.handle()), - }; + let authorship_future = sc_consensus_manual_seal::run_instant_seal(params); - // the GRANDPA voter task is considered infallible, i.e. - // if it fails we take down the service with it. - task_manager.spawn_essential_handle().spawn_blocking( - "grandpa-voter", - None, - sc_finality_grandpa::run_grandpa_voter(grandpa_config)?, - ); - } + task_manager + .spawn_essential_handle() + .spawn_blocking("instant-seal", None, authorship_future); network_starter.start_network(); Ok(task_manager) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 6125603..209ccb3 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -16,10 +16,9 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } scale-info = { version = "2.0.1", default-features = false, features = ["derive"] } -pallet-aura = { git = "/~https://github.com/paritytech/substrate", package = "pallet-aura", default-features = false } +pallet-authorship = { git = "/~https://github.com/paritytech/substrate", package = "pallet-authorship", default-features = false } pallet-balances = { git = "/~https://github.com/paritytech/substrate", package = "pallet-balances", default-features = false } frame-support = { git = "/~https://github.com/paritytech/substrate", package = "frame-support", default-features = false } -pallet-grandpa = { git = "/~https://github.com/paritytech/substrate", package = "pallet-grandpa", default-features = false } pallet-randomness-collective-flip = { git = "/~https://github.com/paritytech/substrate", package = "pallet-randomness-collective-flip", default-features = false } pallet-sudo = { git = "/~https://github.com/paritytech/substrate", package = "pallet-sudo", default-features = false } frame-system = { git = "/~https://github.com/paritytech/substrate", package = "frame-system", default-features = false } @@ -29,7 +28,6 @@ pallet-transaction-payment = { git = "/~https://github.com/paritytech/substrate", frame-executive = { git = "/~https://github.com/paritytech/substrate", package = "frame-executive", default-features = false } sp-api = { git = "/~https://github.com/paritytech/substrate", package = "sp-api", default-features = false } sp-block-builder = { git = "/~https://github.com/paritytech/substrate", package = "sp-block-builder", default-features = false } -sp-consensus-aura = { git = "/~https://github.com/paritytech/substrate", package = "sp-consensus-aura", default-features = false } sp-core = { git = "/~https://github.com/paritytech/substrate", package = "sp-core", default-features = false } sp-inherents = { git = "/~https://github.com/paritytech/substrate", package = "sp-inherents", default-features = false } sp-offchain = { git = "/~https://github.com/paritytech/substrate", package = "sp-offchain", default-features = false } @@ -69,9 +67,8 @@ std = [ "frame-support/std", "frame-system-rpc-runtime-api/std", "frame-system/std", - "pallet-aura/std", + "pallet-authorship/std", "pallet-balances/std", - "pallet-grandpa/std", "pallet-randomness-collective-flip/std", "pallet-sudo/std", "pallet-timestamp/std", @@ -79,7 +76,6 @@ std = [ "pallet-transaction-payment/std", "sp-api/std", "sp-block-builder/std", - "sp-consensus-aura/std", "sp-core/std", "sp-inherents/std", "sp-offchain/std", @@ -107,7 +103,6 @@ try-runtime = [ "frame-try-runtime", "frame-system/try-runtime", "pallet-balances/try-runtime", - "pallet-grandpa/try-runtime", "pallet-randomness-collective-flip/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b497dc9..a535e53 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -9,15 +9,11 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use frame_support::weights::DispatchClass; use frame_system::limits::{BlockLength, BlockWeights}; use pallet_contracts::weights::WeightInfo; -use pallet_grandpa::{ - fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, -}; use sp_api::impl_runtime_apis; -use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, Verify}, + traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, MultiSignature, }; @@ -79,10 +75,7 @@ pub mod opaque { pub type BlockId = generic::BlockId; impl_opaque_keys! { - pub struct SessionKeys { - pub aura: Aura, - pub grandpa: Grandpa, - } + pub struct SessionKeys {} } } // To learn more about runtime versioning and what each of the following value means: @@ -104,23 +97,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { state_version: 1, }; -/// This determines the average expected block time that we are targeting. -/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`. -/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked -/// up by `pallet_aura` to implement `fn slot_duration()`. -/// -/// Change this to adjust the block time. -pub const MILLISECS_PER_BLOCK: u64 = 6000; - -// NOTE: Currently it is not possible to change the slot duration after the chain has started. -// Attempting to do so will brick block production. -pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; - -// Time is measured by number of blocks. -pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); -pub const HOURS: BlockNumber = MINUTES * 60; -pub const DAYS: BlockNumber = HOURS * 24; - /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { @@ -235,46 +211,27 @@ impl frame_system::Config for Runtime { type MaxConsumers = ConstU32<16>; } -impl pallet_randomness_collective_flip::Config for Runtime {} - parameter_types! { - pub const MaxAuthorities: u32 = 32; + pub const UncleGenerations: u32 = 0; } -impl pallet_aura::Config for Runtime { - type AuthorityId = AuraId; - type DisabledValidators = (); - type MaxAuthorities = MaxAuthorities; +impl pallet_authorship::Config for Runtime { + type FindAuthor = (); + type UncleGenerations = UncleGenerations; + type FilterUncle = (); + type EventHandler = (); } -impl pallet_grandpa::Config for Runtime { - type Event = Event; - type Call = Call; - - type KeyOwnerProofSystem = (); - - type KeyOwnerProof = - >::Proof; - - type KeyOwnerIdentification = >::IdentificationTuple; - - type HandleEquivocation = (); - - type WeightInfo = (); - type MaxAuthorities = MaxAuthorities; -} +impl pallet_randomness_collective_flip::Config for Runtime {} parameter_types! { - pub const MinimumPeriod: u64 = SLOT_DURATION / 2; + pub const MinimumPeriod: u64 = 5; } impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; - type OnTimestampSet = Aura; + type OnTimestampSet = (); type MinimumPeriod = MinimumPeriod; type WeightInfo = (); } @@ -377,9 +334,8 @@ construct_runtime!( System: frame_system, RandomnessCollectiveFlip: pallet_randomness_collective_flip, Timestamp: pallet_timestamp, - Aura: pallet_aura, - Grandpa: pallet_grandpa, Balances: pallet_balances, + Authorship: pallet_authorship, TransactionPayment: pallet_transaction_payment, Sudo: pallet_sudo, Contracts: pallet_contracts, @@ -471,16 +427,6 @@ impl_runtime_apis! { } } - impl sp_consensus_aura::AuraApi for Runtime { - fn slot_duration() -> sp_consensus_aura::SlotDuration { - sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) - } - - fn authorities() -> Vec { - Aura::authorities().into_inner() - } - } - impl sp_session::SessionKeys for Runtime { fn generate_session_keys(seed: Option>) -> Vec { opaque::SessionKeys::generate(seed) @@ -493,36 +439,6 @@ impl_runtime_apis! { } } - impl fg_primitives::GrandpaApi for Runtime { - fn grandpa_authorities() -> GrandpaAuthorityList { - Grandpa::grandpa_authorities() - } - - fn current_set_id() -> fg_primitives::SetId { - Grandpa::current_set_id() - } - - fn submit_report_equivocation_unsigned_extrinsic( - _equivocation_proof: fg_primitives::EquivocationProof< - ::Hash, - NumberFor, - >, - _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof, - ) -> Option<()> { - None - } - - fn generate_key_ownership_proof( - _set_id: fg_primitives::SetId, - _authority_id: GrandpaId, - ) -> Option { - // NOTE: this is the only implementation possible since we've - // defined our key owner proof type as a bottom type (i.e. a type - // with no values). - None - } - } - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { fn account_nonce(account: AccountId) -> Index { System::account_nonce(account)