diff --git a/node/src/inherents.rs b/node/src/inherents.rs index d0e2cf3df5..5d59232c3f 100644 --- a/node/src/inherents.rs +++ b/node/src/inherents.rs @@ -19,11 +19,10 @@ //! A service builder can call the `build_inherent_data_providers` function to get the providers //! the node needs based on the parameters it passed in. //! -//! This module also includes MOCK inherent data providers for both the timestamp and validataion -//! data inherents. These mock providers provide stub data that does not represent anything "real" +//! This module also includes a MOCK inherent data provider for the validataion +//! data inherent. This mock provider provides stub data that does not represent anything "real" //! about the external world, but can pass the runtime's checks. This is useful in testing -//! for example, running the --dev service without a relay chain backbone, or authoring block -//! extremely quickly in testing scenarios. +//! for example, running the --dev service without a relay chain backbone. use cumulus_primitives::{ inherents::{SystemInherentData, SYSTEM_INHERENT_IDENTIFIER}, @@ -32,17 +31,14 @@ use cumulus_primitives::{ use parity_scale_codec::Encode; use sp_core::H160; use sp_inherents::{InherentData, InherentDataProviders, InherentIdentifier, ProvideInherentData}; -use sp_timestamp::{InherentError, INHERENT_IDENTIFIER as TIMESTAMP_IDENTIFIER}; -use std::cell::RefCell; +use sp_timestamp::InherentError; use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; -use moonbeam_runtime::MINIMUM_PERIOD; /// Build the inherent data providers for the node. /// /// Not all nodes will need all inherent data providers: /// - The author provider is only necessary for block producing nodes -/// - The timestamp provider can be mocked. /// - The validation data provider can be mocked. pub fn build_inherent_data_providers( author: Option, @@ -50,6 +46,13 @@ pub fn build_inherent_data_providers( ) -> Result { let providers = InherentDataProviders::new(); + // Timestamp provider. Needed in all nodes. + providers + .register_provider(sp_timestamp::InherentDataProvider) + .map_err(Into::into) + .map_err(sp_consensus::error::Error::InherentData)?; + + // Author ID Provider for authoring node only. if let Some(account) = author { providers .register_provider(author_inherent::InherentDataProvider(account.encode())) @@ -57,60 +60,19 @@ pub fn build_inherent_data_providers( .map_err(sp_consensus::error::Error::InherentData)?; } + // Parachain inherent provider, only for dev-service nodes. if mock { - providers - .register_provider(MockTimestampInherentDataProvider { - duration: MINIMUM_PERIOD * 2, - }) - .map_err(Into::into) - .map_err(sp_consensus::error::Error::InherentData)?; - providers .register_provider(MockValidationDataInherentDataProvider) .map_err(Into::into) .map_err(sp_consensus::error::Error::InherentData)?; - } else { - providers - .register_provider(sp_timestamp::InherentDataProvider) - .map_err(Into::into) - .map_err(sp_consensus::error::Error::InherentData)?; - - // When we are not mocking the validation data ,we do not register a real validation data - // provider here. The validation data inherent is inserted manually by the cumulus colaltor - // https://github.com/paritytech/cumulus/blob/c3e3f443/collator/src/lib.rs#L274-L321 - } - - Ok(providers) -} - -/// Mocked timestamp inherent data provider. -/// Provides a fake duration starting at 0 in millisecond for timestamp inherent. -/// Each call will increment timestamp by slot_duration making the runtime think time has passed. -/// This code was inspired by https://github.com/paritytech/frontier/pull/170 -struct MockTimestampInherentDataProvider { - duration: u64, -} - -thread_local!(static TIMESTAMP: RefCell = RefCell::new(0)); - -impl ProvideInherentData for MockTimestampInherentDataProvider { - fn inherent_identifier(&self) -> &'static InherentIdentifier { - &TIMESTAMP_IDENTIFIER } - fn provide_inherent_data( - &self, - inherent_data: &mut InherentData, - ) -> Result<(), sp_inherents::Error> { - TIMESTAMP.with(|x| { - *x.borrow_mut() += self.duration; - inherent_data.put_data(TIMESTAMP_IDENTIFIER, &*x.borrow()) - }) - } + // When we are not mocking the validation data, we do not register a real validation data + // provider here. The validation data inherent is inserted manually by the cumulus colaltor + // https://github.com/paritytech/cumulus/blob/c3e3f443/collator/src/lib.rs#L274-L321 - fn error_to_string(&self, error: &[u8]) -> Option { - InherentError::try_from(&TIMESTAMP_IDENTIFIER, error).map(|e| format!("{:?}", e)) - } + Ok(providers) } /// Inherent data provider that supplies mocked validation data. diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index ccd6f663f0..3609082b91 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -89,9 +89,6 @@ pub type Hash = sp_core::H256; /// Digest item type. pub type DigestItem = generic::DigestItem; -/// Minimum time between blocks. Slot duration is double this. -pub const MINIMUM_PERIOD: u64 = 3000; - /// Maximum weight per block pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2; @@ -115,7 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("moonbeam"), impl_name: create_runtime_str!("moonbeam"), authoring_version: 3, - spec_version: 22, + spec_version: 23, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 2, @@ -186,7 +183,7 @@ impl frame_system::Config for Runtime { } parameter_types! { - pub const MinimumPeriod: u64 = MINIMUM_PERIOD; + pub const MinimumPeriod: u64 = 1; } impl pallet_timestamp::Config for Runtime { diff --git a/tests/tests/test-polkadot-api.ts b/tests/tests/test-polkadot-api.ts index 849c6e2af2..7c21b4b304 100644 --- a/tests/tests/test-polkadot-api.ts +++ b/tests/tests/test-polkadot-api.ts @@ -55,7 +55,7 @@ describeWithMoonbeam("Moonbeam Polkadot API", `simple-specs.json`, (context) => const message = `${section}.${method}(${args.map((a) => a.toString()).join(", ")})`; switch (index) { case 0: - expect(message).to.eq(`timestamp.set(6000)`); + expect(message.substring(0, 13)).to.eq(`timestamp.set`); break; case 1: expect(message.substring(0, 33)).to.eq(`parachainSystem.setValidationData`);