diff --git a/substrate/core/basic-authorship/Cargo.toml b/substrate/core/basic-authorship/Cargo.toml index e21c0abe68..003eb79349 100644 --- a/substrate/core/basic-authorship/Cargo.toml +++ b/substrate/core/basic-authorship/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] log = "0.4" -futures-preview = "0.3.0-alpha.17" +futures-preview = "=0.3.0-alpha.17" codec = { package = "parity-scale-codec", version = "1.0.0" } sr-primitives = { path = "../../core/sr-primitives" } primitives = { package = "substrate-primitives", path = "../../core/primitives" } diff --git a/substrate/core/cli/Cargo.toml b/substrate/core/cli/Cargo.toml index 53c320035f..a5af736226 100644 --- a/substrate/core/cli/Cargo.toml +++ b/substrate/core/cli/Cargo.toml @@ -18,7 +18,7 @@ lazy_static = "1.3" app_dirs = "1.2" tokio = "0.1.7" futures = "0.1.17" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] } +futures03 = { package = "futures-preview", version = "=0.3.0-alpha.17", features = ["compat"] } fdlimit = "0.1" exit-future = "0.1" serde_json = "1.0" diff --git a/substrate/core/client/Cargo.toml b/substrate/core/client/Cargo.toml index 793db37613..d917427a50 100644 --- a/substrate/core/client/Cargo.toml +++ b/substrate/core/client/Cargo.toml @@ -10,7 +10,7 @@ fnv = { version = "1.0", optional = true } log = { version = "0.4", optional = true } parking_lot = { version = "0.9.0", optional = true } hex = { package = "hex-literal", version = "0.2", optional = true } -futures-preview = { version = "0.3.0-alpha.17", optional = true } +futures-preview = { version = "=0.3.0-alpha.17", optional = true } consensus = { package = "substrate-consensus-common", path = "../consensus/common", optional = true } executor = { package = "substrate-executor", path = "../executor", optional = true } state-machine = { package = "substrate-state-machine", path = "../state-machine", optional = true } diff --git a/substrate/core/consensus/aura/Cargo.toml b/substrate/core/consensus/aura/Cargo.toml index 99ba771693..d6ce48841b 100644 --- a/substrate/core/consensus/aura/Cargo.toml +++ b/substrate/core/consensus/aura/Cargo.toml @@ -21,7 +21,7 @@ substrate-telemetry = { path = "../../telemetry" } keystore = { package = "substrate-keystore", path = "../../keystore" } consensus_common = { package = "substrate-consensus-common", path = "../common" } sr-primitives = { path = "../../sr-primitives" } -futures-preview = { version = "0.3.0-alpha.17", features = ["compat"] } +futures-preview = { version = "=0.3.0-alpha.17", features = ["compat"] } futures01 = { package = "futures", version = "0.1" } futures-timer = "0.2.1" parking_lot = "0.9.0" diff --git a/substrate/core/consensus/babe/Cargo.toml b/substrate/core/consensus/babe/Cargo.toml index 8184033735..9490887ba3 100644 --- a/substrate/core/consensus/babe/Cargo.toml +++ b/substrate/core/consensus/babe/Cargo.toml @@ -26,7 +26,7 @@ uncles = { package = "substrate-consensus-uncles", path = "../uncles" } slots = { package = "substrate-consensus-slots", path = "../slots" } sr-primitives = { path = "../../sr-primitives" } fork-tree = { path = "../../utils/fork-tree" } -futures-preview = { version = "0.3.0-alpha.17", features = ["compat"] } +futures-preview = { version = "=0.3.0-alpha.17", features = ["compat"] } futures01 = { package = "futures", version = "0.1" } futures-timer = "0.2.1" parking_lot = "0.9.0" diff --git a/substrate/core/consensus/babe/src/lib.rs b/substrate/core/consensus/babe/src/lib.rs index eb4b0c5195..ae484de5b6 100644 --- a/substrate/core/consensus/babe/src/lib.rs +++ b/substrate/core/consensus/babe/src/lib.rs @@ -82,7 +82,7 @@ use slots::{SlotWorker, SlotData, SlotInfo, SlotCompatible, SignedDuration}; mod aux_schema; #[cfg(test)] mod tests; -pub use babe_primitives::AuthorityId; +pub use babe_primitives::{AuthorityId, AuthorityPair, AuthoritySignature}; /// A slot duration. Create with `get_or_compute`. // FIXME: Once Rust has higher-kinded types, the duplication between this diff --git a/substrate/core/consensus/common/Cargo.toml b/substrate/core/consensus/common/Cargo.toml index 29f30e363d..46c8121207 100644 --- a/substrate/core/consensus/common/Cargo.toml +++ b/substrate/core/consensus/common/Cargo.toml @@ -11,7 +11,7 @@ libp2p = { version = "0.11.0", default-features = false } log = "0.4" primitives = { package = "substrate-primitives", path= "../../primitives" } inherents = { package = "substrate-inherents", path = "../../inherents" } -futures-preview = "0.3.0-alpha.17" +futures-preview = "=0.3.0-alpha.17" futures-timer = "0.2.1" rstd = { package = "sr-std", path = "../../sr-std" } runtime_version = { package = "sr-version", path = "../../sr-version" } diff --git a/substrate/core/consensus/slots/Cargo.toml b/substrate/core/consensus/slots/Cargo.toml index 857d1e3a6b..f74837a62f 100644 --- a/substrate/core/consensus/slots/Cargo.toml +++ b/substrate/core/consensus/slots/Cargo.toml @@ -12,7 +12,7 @@ primitives = { package = "substrate-primitives", path = "../../primitives" } sr-primitives = { path = "../../sr-primitives" } consensus_common = { package = "substrate-consensus-common", path = "../common" } inherents = { package = "substrate-inherents", path = "../../inherents" } -futures-preview = "0.3.0-alpha.17" +futures-preview = "=0.3.0-alpha.17" futures-timer = "0.2.1" parking_lot = "0.9.0" log = "0.4" diff --git a/substrate/core/finality-grandpa/Cargo.toml b/substrate/core/finality-grandpa/Cargo.toml index 71a0775cd7..22237c5a0b 100644 --- a/substrate/core/finality-grandpa/Cargo.toml +++ b/substrate/core/finality-grandpa/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] fork-tree = { path = "../../core/utils/fork-tree" } futures = "0.1" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] } +futures03 = { package = "futures-preview", version = "=0.3.0-alpha.17", features = ["compat"] } log = "0.4" parking_lot = "0.9.0" tokio-executor = "0.1.7" diff --git a/substrate/core/network/Cargo.toml b/substrate/core/network/Cargo.toml index 0600a60999..dac6ecdd72 100644 --- a/substrate/core/network/Cargo.toml +++ b/substrate/core/network/Cargo.toml @@ -15,7 +15,7 @@ parking_lot = "0.9.0" bitflags = "1.0" fnv = "1.0" futures = "0.1.17" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] } +futures03 = { package = "futures-preview", version = "=0.3.0-alpha.17", features = ["compat"] } futures-timer = "0.2.1" linked-hash-map = "0.5" linked_hash_set = "0.1.3" diff --git a/substrate/core/offchain/Cargo.toml b/substrate/core/offchain/Cargo.toml index 3ee8e8580d..4c8891eb6b 100644 --- a/substrate/core/offchain/Cargo.toml +++ b/substrate/core/offchain/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] client = { package = "substrate-client", path = "../../core/client" } -futures-preview = "0.3.0-alpha.17" +futures-preview = "=0.3.0-alpha.17" log = "0.4" offchain-primitives = { package = "substrate-offchain-primitives", path = "./primitives" } codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] } diff --git a/substrate/core/peerset/Cargo.toml b/substrate/core/peerset/Cargo.toml index 9315ff304f..7bf0617a9e 100644 --- a/substrate/core/peerset/Cargo.toml +++ b/substrate/core/peerset/Cargo.toml @@ -8,7 +8,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -futures-preview = "0.3.0-alpha.17" +futures-preview = "=0.3.0-alpha.17" libp2p = { version = "0.11.0", default-features = false } linked-hash-map = "0.5" log = "0.4" diff --git a/substrate/core/rpc/Cargo.toml b/substrate/core/rpc/Cargo.toml index ab05eb4e24..957fe5be0b 100644 --- a/substrate/core/rpc/Cargo.toml +++ b/substrate/core/rpc/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] derive_more = "0.14.0" futures = "0.1" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] } +futures03 = { package = "futures-preview", version = "=0.3.0-alpha.17", features = ["compat"] } jsonrpc-core = "12.0.0" jsonrpc-core-client = "12.0.0" jsonrpc-pubsub = "12.0.0" @@ -34,4 +34,4 @@ futures = "0.1.17" sr-io = { path = "../sr-io" } test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" } rustc-hex = "2.0" -tokio = "0.1.17" \ No newline at end of file +tokio = "0.1.17" diff --git a/substrate/core/service/Cargo.toml b/substrate/core/service/Cargo.toml index c2a17371da..bd04cd670e 100644 --- a/substrate/core/service/Cargo.toml +++ b/substrate/core/service/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] derive_more = "0.14.0" futures = "0.1.17" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] } +futures03 = { package = "futures-preview", version = "=0.3.0-alpha.17", features = ["compat"] } parking_lot = "0.9.0" lazy_static = "1.0" log = "0.4" diff --git a/substrate/core/sr-primitives/src/traits.rs b/substrate/core/sr-primitives/src/traits.rs index 7370a5074f..de700ffec3 100644 --- a/substrate/core/sr-primitives/src/traits.rs +++ b/substrate/core/sr-primitives/src/traits.rs @@ -303,6 +303,47 @@ pub trait CheckedConversion { } impl CheckedConversion for T {} +/// Multiply and divide by a number that isn't necessarily the same type. Basically just the same +/// as `Mul` and `Div` except it can be used for all basic numeric types. +pub trait Scale { + /// The output type of the product of `self` and `Other`. + type Output; + + /// @return the product of `self` and `other`. + fn mul(self, other: Other) -> Self::Output; + + /// @return the integer division of `self` and `other`. + fn div(self, other: Other) -> Self::Output; + + /// @return the modulo remainder of `self` and `other`. + fn rem(self, other: Other) -> Self::Output; +} +macro_rules! impl_scale { + ($self:ty, $other:ty) => { + impl Scale<$other> for $self { + type Output = Self; + fn mul(self, other: $other) -> Self::Output { self * (other as Self) } + fn div(self, other: $other) -> Self::Output { self / (other as Self) } + fn rem(self, other: $other) -> Self::Output { self % (other as Self) } + } + } +} +impl_scale!(u128, u128); +impl_scale!(u128, u64); +impl_scale!(u128, u32); +impl_scale!(u128, u16); +impl_scale!(u128, u8); +impl_scale!(u64, u64); +impl_scale!(u64, u32); +impl_scale!(u64, u16); +impl_scale!(u64, u8); +impl_scale!(u32, u32); +impl_scale!(u32, u16); +impl_scale!(u32, u8); +impl_scale!(u16, u16); +impl_scale!(u16, u8); +impl_scale!(u8, u8); + /// Trait for things that can be clear (have no bits set). For numeric types, essentially the same /// as `Zero`. pub trait Clear { diff --git a/substrate/core/telemetry/Cargo.toml b/substrate/core/telemetry/Cargo.toml index 8647462739..d4332eb9ec 100644 --- a/substrate/core/telemetry/Cargo.toml +++ b/substrate/core/telemetry/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" bytes = "0.4" parking_lot = "0.9.0" futures01 = { package = "futures", version = "0.1" } -futures-preview = { version = "0.3.0-alpha.17", features = ["compat"] } +futures-preview = { version = "=0.3.0-alpha.17", features = ["compat"] } futures-timer = "0.2.1" libp2p = { version = "0.11.0", default-features = false, features = ["libp2p-websocket"] } log = "0.4" diff --git a/substrate/core/test-client/Cargo.toml b/substrate/core/test-client/Cargo.toml index 163cc2ab14..1af77ce2f0 100644 --- a/substrate/core/test-client/Cargo.toml +++ b/substrate/core/test-client/Cargo.toml @@ -9,7 +9,7 @@ client = { package = "substrate-client", path = "../client" } client-db = { package = "substrate-client-db", path = "../client/db", features = ["test-helpers"] } consensus = { package = "substrate-consensus-common", path = "../consensus/common" } executor = { package = "substrate-executor", path = "../executor" } -futures-preview = "0.3.0-alpha.17" +futures-preview = "=0.3.0-alpha.17" hash-db = "0.15.0" keyring = { package = "substrate-keyring", path = "../keyring" } codec = { package = "parity-scale-codec", version = "1.0.0" } diff --git a/substrate/node-template/runtime/Cargo.toml b/substrate/node-template/runtime/Cargo.toml index 437da9d973..2f41513048 100644 --- a/substrate/node-template/runtime/Cargo.toml +++ b/substrate/node-template/runtime/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Anonymous"] edition = "2018" [dependencies] + serde = { version = "1.0", optional = true, features = ["derive"] } safe-mix = { version = "1.0", default-features = false } codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } diff --git a/substrate/node-template/runtime/src/lib.rs b/substrate/node-template/runtime/src/lib.rs index 2b9220c6e5..16235db118 100644 --- a/substrate/node-template/runtime/src/lib.rs +++ b/substrate/node-template/runtime/src/lib.rs @@ -48,10 +48,10 @@ pub type AccountSignature = sr25519::Signature; pub type Hash = primitives::H256; /// Index of a block number in the chain. -pub type BlockNumber = u64; +pub type BlockNumber = u32; /// Index of an account's extrinsic in the chain. -pub type Nonce = u64; +pub type Nonce = u32; /// Balance type for the node. pub type Balance = u128; diff --git a/substrate/node/cli/Cargo.toml b/substrate/node/cli/Cargo.toml index 184ef9382d..c266427439 100644 --- a/substrate/node/cli/Cargo.toml +++ b/substrate/node/cli/Cargo.toml @@ -49,7 +49,7 @@ keystore = { package = "substrate-keystore", path = "../../core/keystore" } babe = { package = "substrate-consensus-babe", path = "../../core/consensus/babe", features = ["test-helpers"] } consensus-common = { package = "substrate-consensus-common", path = "../../core/consensus/common" } service-test = { package = "substrate-service-test", path = "../../core/service/test" } -futures03 = { package = "futures-preview", version = "0.3.0-alpha.17" } +futures03 = { package = "futures-preview", version = "=0.3.0-alpha.17" } tempfile = "3.1" [build-dependencies] diff --git a/substrate/node/cli/src/factory_impl.rs b/substrate/node/cli/src/factory_impl.rs index 6e72ff08c1..6345a851f2 100644 --- a/substrate/node/cli/src/factory_impl.rs +++ b/substrate/node/cli/src/factory_impl.rs @@ -39,11 +39,11 @@ pub struct FactoryState { block_no: N, mode: Mode, - start_number: u64, - rounds: u64, - round: u64, - block_in_round: u64, - num: u64, + start_number: u32, + rounds: u32, + round: u32, + block_in_round: u32, + num: u32, } type Number = <::Header as HeaderT>::Number; @@ -77,9 +77,9 @@ impl RuntimeAdapter for FactoryState { ) -> FactoryState { FactoryState { mode, - num: num, + num: num as u32, round: 0, - rounds, + rounds: rounds as u32, block_in_round: 0, block_no: 0, start_number: 0, @@ -150,7 +150,7 @@ impl RuntimeAdapter for FactoryState { } fn inherent_extrinsics(&self) -> InherentData { - let timestamp = self.block_no * MINIMUM_PERIOD; + let timestamp = self.block_no as u64 * MINIMUM_PERIOD; let mut inherent = InherentData::new(); inherent.put_data(timestamp::INHERENT_IDENTIFIER, ×tamp) @@ -194,12 +194,12 @@ impl RuntimeAdapter for FactoryState { // This currently prevents the factory from being used // without a preceding purge of the database. if self.mode == Mode::MasterToN || self.mode == Mode::MasterTo1 { - self.block_no() + self.block_no() as Self::Index } else { match self.round() { 0 => // if round is 0 all transactions will be done with master as a sender - self.block_no(), + self.block_no() as Self::Index, _ => // if round is e.g. 1 every sender account will be new and not yet have // any transactions done @@ -215,12 +215,12 @@ impl RuntimeAdapter for FactoryState { // TODO get correct phase via api. See #2587. // This currently prevents the factory from being used // without a preceding purge of the database. - self.block_no + self.block_no() as Self::Phase } } -fn gen_seed_bytes(seed: u64) -> [u8; 32] { - let mut rng: StdRng = SeedableRng::seed_from_u64(seed); +fn gen_seed_bytes(seed: u32) -> [u8; 32] { + let mut rng: StdRng = SeedableRng::seed_from_u64(seed as u64); let mut seed_bytes = [0u8; 32]; for i in 0..32 { diff --git a/substrate/node/cli/src/service.rs b/substrate/node/cli/src/service.rs index 57a360f3ca..35f813efb3 100644 --- a/substrate/node/cli/src/service.rs +++ b/substrate/node/cli/src/service.rs @@ -88,19 +88,32 @@ construct_service_factory! { RuntimeApi = RuntimeApi, NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) }, RuntimeDispatch = node_executor::Executor, - FullTransactionPoolApi = transaction_pool::ChainApi, FullExecutor, Block, RuntimeApi>, Block> - { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, - LightTransactionPoolApi = transaction_pool::ChainApi, LightExecutor, Block, RuntimeApi>, Block> - { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, + FullTransactionPoolApi = + transaction_pool::ChainApi< + client::Client, FullExecutor, Block, RuntimeApi>, + Block + > { + |config, client| + Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) + }, + LightTransactionPoolApi = + transaction_pool::ChainApi< + client::Client, LightExecutor, Block, RuntimeApi>, + Block + > { + |config, client| + Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) + }, Genesis = GenesisConfig, Configuration = NodeConfig, - FullService = FullComponents - { |config: FactoryFullConfiguration| - FullComponents::::new(config) }, + FullService = FullComponents { + |config: FactoryFullConfiguration| FullComponents::::new(config) + }, AuthoritySetup = { |mut service: Self::FullService| { - let (block_import, link_half, babe_link) = service.config_mut().custom.import_setup.take() - .expect("Link Half and Block Import are present for Full Services or setup failed before. qed"); + let (block_import, link_half, babe_link) = + service.config_mut().custom.import_setup.take() + .expect("Link Half and Block Import are present for Full Services or setup failed before. qed"); // spawn any futures that were created in the previous setup steps if let Some(tasks) = service.config_mut().custom.tasks_to_spawn.take() { @@ -120,7 +133,8 @@ construct_service_factory! { }; let client = service.client(); - let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?; + let select_chain = service.select_chain() + .ok_or(ServiceError::SelectChainRequired)?; let babe_config = babe::BabeParams { config: Config::get_or_compute(&*client)?, @@ -130,7 +144,8 @@ construct_service_factory! { block_import, env: proposer, sync_oracle: service.network(), - inherent_data_providers: service.config().custom.inherent_data_providers.clone(), + inherent_data_providers: service.config() + .custom.inherent_data_providers.clone(), force_authoring: service.config().force_authoring, time_source: babe_link, }; @@ -167,7 +182,8 @@ construct_service_factory! { config: config, link: link_half, network: service.network(), - inherent_data_providers: service.config().custom.inherent_data_providers.clone(), + inherent_data_providers: + service.config().custom.inherent_data_providers.clone(), on_exit: service.on_exit(), telemetry_on_connect: Some(telemetry_on_connect), }; @@ -187,8 +203,12 @@ construct_service_factory! { }, LightService = LightComponents { |config| >::new(config) }, - FullImportQueue = BabeImportQueue - { |config: &mut FactoryFullConfiguration , client: Arc>, select_chain: Self::SelectChain| { + FullImportQueue = BabeImportQueue { + | + config: &mut FactoryFullConfiguration, + client: Arc>, + select_chain: Self::SelectChain + | { let (block_import, link_half) = grandpa::block_import::<_, _, _, RuntimeApi, FullClient, _>( client.clone(), client.clone(), select_chain @@ -222,7 +242,8 @@ construct_service_factory! { )?; let finality_proof_import = block_import.clone(); - let finality_proof_request_builder = finality_proof_import.create_finality_proof_request_builder(); + let finality_proof_request_builder = + finality_proof_import.create_finality_proof_request_builder(); // FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`. let (import_queue, ..) = import_queue( @@ -254,7 +275,9 @@ construct_service_factory! { mod tests { use std::sync::Arc; use babe::CompatibleDigestItem; - use consensus_common::{Environment, Proposer, BlockImportParams, BlockOrigin, ForkChoiceStrategy}; + use consensus_common::{ + Environment, Proposer, BlockImportParams, BlockOrigin, ForkChoiceStrategy + }; use node_primitives::DigestItem; use node_runtime::{BalancesCall, Call, UncheckedExtrinsic}; use node_runtime::constants::{currency::CENTS, time::SLOT_DURATION}; @@ -306,7 +329,9 @@ mod tests { auxiliary: Vec::new(), } }; - let extrinsic_factory = |service: &SyncService<::FullService>| { + let extrinsic_factory = + |service: &SyncService<::FullService>| + { let payload = ( 0, Call::Balances(BalancesCall::transfer(RawAddress::Id(bob.public().0.into()), 69.into())), @@ -333,7 +358,8 @@ mod tests { #[ignore] fn test_sync() { let keystore_path = tempfile::tempdir().expect("Creates keystore path"); - let keystore = keystore::Store::open(keystore_path.path(), None).expect("Creates keystore"); + let keystore = keystore::Store::open(keystore_path.path(), None) + .expect("Creates keystore"); let alice = keystore.write().insert_ephemeral_from_seed::("//Alice") .expect("Creates authority pair"); diff --git a/substrate/node/executor/src/lib.rs b/substrate/node/executor/src/lib.rs index 990210696a..167f90feeb 100644 --- a/substrate/node/executor/src/lib.rs +++ b/substrate/node/executor/src/lib.rs @@ -164,7 +164,7 @@ mod tests { }) } - fn from_block_number(n: u64) -> Header { + fn from_block_number(n: u32) -> Header { Header::new(n, Default::default(), Default::default(), [69; 32].into(), Default::default()) } @@ -192,7 +192,7 @@ mod tests { let r = executor().call::<_, NeverNativeValue, fn() -> _>( &mut t, "Core_initialize_block", - &vec![].and(&from_block_number(1u64)), + &vec![].and(&from_block_number(1u32)), true, None, ).0; @@ -228,7 +228,7 @@ mod tests { let r = executor().call::<_, NeverNativeValue, fn() -> _>( &mut t, "Core_initialize_block", - &vec![].and(&from_block_number(1u64)), + &vec![].and(&from_block_number(1u32)), true, None, ).0; @@ -260,7 +260,7 @@ mod tests { let r = executor().call::<_, NeverNativeValue, fn() -> _>( &mut t, "Core_initialize_block", - &vec![].and(&from_block_number(1u64)), + &vec![].and(&from_block_number(1u32)), true, None, ).0; @@ -296,7 +296,7 @@ mod tests { let r = executor().call::<_, NeverNativeValue, fn() -> _>( &mut t, "Core_initialize_block", - &vec![].and(&from_block_number(1u64)), + &vec![].and(&from_block_number(1u32)), true, None, ).0; @@ -523,7 +523,7 @@ mod tests { (block1, block2) } - fn block_with_size(time: u64, nonce: u64, size: usize) -> (Vec, Hash) { + fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec, Hash) { construct_block( &mut new_test_ext(COMPACT_CODE, false), 1, @@ -887,7 +887,7 @@ mod tests { ], map![])); let r = WasmExecutor::new() - .call(&mut t, 8, COMPACT_CODE, "Core_initialize_block", &vec![].and(&from_block_number(1u64))); + .call(&mut t, 8, COMPACT_CODE, "Core_initialize_block", &vec![].and(&from_block_number(1u32))); assert!(r.is_ok()); let r = WasmExecutor::new() .call(&mut t, 8, COMPACT_CODE, "BlockBuilder_apply_extrinsic", &vec![].and(&xt())).unwrap(); @@ -909,7 +909,7 @@ mod tests { ], map![])); let r = WasmExecutor::new() - .call(&mut t, 8, COMPACT_CODE, "Core_initialize_block", &vec![].and(&from_block_number(1u64))); + .call(&mut t, 8, COMPACT_CODE, "Core_initialize_block", &vec![].and(&from_block_number(1u32))); assert!(r.is_ok()); let r = WasmExecutor::new() .call(&mut t, 8, COMPACT_CODE, "BlockBuilder_apply_extrinsic", &vec![].and(&xt())).unwrap(); @@ -1080,7 +1080,7 @@ mod tests { let r = executor().call::<_, NeverNativeValue, fn() -> _>( &mut t, "Core_initialize_block", - &vec![].and(&from_block_number(1u64)), + &vec![].and(&from_block_number(1u32)), true, None, ).0; diff --git a/substrate/node/primitives/src/lib.rs b/substrate/node/primitives/src/lib.rs index 0895a8675d..431ba17c00 100644 --- a/substrate/node/primitives/src/lib.rs +++ b/substrate/node/primitives/src/lib.rs @@ -25,7 +25,7 @@ use sr_primitives::{ }; /// An index to a block. -pub type BlockNumber = u64; +pub type BlockNumber = u32; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. pub type Signature = AnySignature; @@ -45,7 +45,7 @@ pub type Balance = u128; pub type Moment = u64; /// Index of a transaction in the chain. -pub type Index = u64; +pub type Index = u32; /// A hash of some data used by the chain. pub type Hash = primitives::H256; diff --git a/substrate/node/runtime/src/constants.rs b/substrate/node/runtime/src/constants.rs index 03f6e34c93..f728efb3be 100644 --- a/substrate/node/runtime/src/constants.rs +++ b/substrate/node/runtime/src/constants.rs @@ -27,7 +27,7 @@ pub mod currency { /// Time. pub mod time { - use node_primitives::Moment; + use node_primitives::{Moment, BlockNumber}; /// Since BABE is probabilistic this is the average expected block time that /// we are targetting. Blocks will be produced at a minimum duration defined @@ -46,17 +46,17 @@ pub mod time { pub const SLOT_DURATION: Moment = 1650; - pub const EPOCH_DURATION_IN_BLOCKS: Moment = 10 * MINUTES; - pub const EPOCH_DURATION_IN_SLOTS: Moment = { + pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES; + pub const EPOCH_DURATION_IN_SLOTS: u64 = { const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64; - (EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as Moment + (EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64 }; // These time units are defined in number of blocks. - pub const MINUTES: Moment = 60 / SECS_PER_BLOCK; - pub const HOURS: Moment = MINUTES * 60; - pub const DAYS: Moment = HOURS * 24; + pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber); + pub const HOURS: BlockNumber = MINUTES * 60; + pub const DAYS: BlockNumber = HOURS * 24; } // CRITICAL NOTE: The system module maintains two constants: a _maximum_ block weight and a diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index 8b6b4d55bd..086818c51f 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -80,8 +80,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to equal spec_version. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 137, - impl_version: 137, + spec_version: 138, + impl_version: 138, apis: RUNTIME_API_VERSIONS, }; @@ -179,7 +179,7 @@ impl timestamp::Trait for Runtime { } parameter_types! { - pub const UncleGenerations: u64 = 5; + pub const UncleGenerations: BlockNumber = 5; } impl authorship::Trait for Runtime { diff --git a/substrate/srml/authorship/src/lib.rs b/substrate/srml/authorship/src/lib.rs index 44fa04a2f3..32dd140e82 100644 --- a/substrate/srml/authorship/src/lib.rs +++ b/substrate/srml/authorship/src/lib.rs @@ -478,6 +478,10 @@ mod tests { type MaximumBlockLength = MaximumBlockLength; } + parameter_types! { + pub const UncleGenerations: u64 = 5; + } + impl Trait for Test { type FindAuthor = AuthorGiven; type UncleGenerations = UncleGenerations; @@ -506,10 +510,6 @@ mod tests { } } - parameter_types! { - pub const UncleGenerations: u64 = 5; - } - pub struct VerifyBlock; impl VerifySeal for VerifyBlock { @@ -550,7 +550,6 @@ mod tests { header } - fn create_header(number: u64, parent_hash: H256, state_root: H256) -> Header { Header::new( number, diff --git a/substrate/srml/membership/src/lib.rs b/substrate/srml/membership/src/lib.rs index 1545719e20..f56a0ca042 100644 --- a/substrate/srml/membership/src/lib.rs +++ b/substrate/srml/membership/src/lib.rs @@ -80,6 +80,7 @@ decl_storage! { decl_event!( pub enum Event where ::AccountId, + >::Event, { /// The given member was added; see the transaction for who. MemberAdded, @@ -90,7 +91,7 @@ decl_event!( /// The membership was reset; see the transaction for who the new set is. MembersReset, /// Phantom member, never used. - Dummy(sr_std::marker::PhantomData<(AccountId, I)>), + Dummy(sr_std::marker::PhantomData<(AccountId, Event)>), } ); diff --git a/substrate/srml/timestamp/src/lib.rs b/substrate/srml/timestamp/src/lib.rs index bef2e2b876..502acadf61 100644 --- a/substrate/srml/timestamp/src/lib.rs +++ b/substrate/srml/timestamp/src/lib.rs @@ -90,7 +90,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use rstd::{result, ops::{Mul, Div}, cmp}; +use rstd::{result, cmp}; use codec::Encode; #[cfg(feature = "std")] use codec::Decode; @@ -98,7 +98,9 @@ use codec::Decode; use inherents::ProvideInherentData; use srml_support::{StorageValue, Parameter, decl_storage, decl_module, for_each_tuple}; use srml_support::traits::{Time, Get}; -use sr_primitives::traits::{SimpleArithmetic, Zero, SaturatedConversion}; +use sr_primitives::traits::{ + SimpleArithmetic, Zero, SaturatedConversion, Scale +}; use sr_primitives::weights::SimpleDispatchInfo; use system::ensure_none; use inherents::{RuntimeString, InherentIdentifier, ProvideInherent, IsFatalError, InherentData}; @@ -207,8 +209,7 @@ for_each_tuple!(impl_timestamp_set); pub trait Trait: system::Trait { /// Type used for expressing timestamp. type Moment: Parameter + Default + SimpleArithmetic - + Mul - + Div; + + Scale; /// Something which can be notified when the timestamp is set. Set this to `()` if not needed. type OnTimestampSet: OnTimestampSet;