diff --git a/substrate/core/client/src/client.rs b/substrate/core/client/src/client.rs index b076d24b18..59af1b6419 100644 --- a/substrate/core/client/src/client.rs +++ b/substrate/core/client/src/client.rs @@ -482,7 +482,7 @@ impl Client where if first > last_num { return Err(error::Error::ChangesTrieAccessFailed("Invalid changes trie range".into())); } - let finalized_number = self.backend.blockchain().info().finalized_number; + let finalized_number = self.backend.blockchain().info().finalized_number; let oldest = storage.oldest_changes_trie_block(&config, finalized_number); let first = ::std::cmp::max(first, oldest); Ok(Some((first, last))) diff --git a/substrate/core/sr-primitives/src/generic/digest.rs b/substrate/core/sr-primitives/src/generic/digest.rs index 79a2991e5f..c0724bb134 100644 --- a/substrate/core/sr-primitives/src/generic/digest.rs +++ b/substrate/core/sr-primitives/src/generic/digest.rs @@ -58,34 +58,151 @@ impl traits::Digest for Digest where } } -/// Digest item that is able to encode/decode 'system' digest items and -/// provide opaque access to other items. -#[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Debug))] -pub enum DigestItem { - /// System digest item announcing that authorities set has been changed - /// in the block. Contains the new set of authorities. - AuthoritiesChange(Vec), - /// System digest item that contains the root of changes trie at given - /// block. It is created for every block iff runtime supports changes - /// trie creation. - ChangesTrieRoot(Hash), - /// A message from the runtime to the consensus engine. This should *never* - /// be generated by the native code of any consensus engine, but this is not - /// checked (yet). - Consensus(ConsensusEngineId, Vec), - /// Put a Seal on it. This is only used by native code, and is never seen - /// by runtimes. - Seal(ConsensusEngineId, SealSignature), - /// A pre-runtime digest. +// Macro black magic. +macro_rules! gen_digest_type { + ( + $( #[doc = $main_docs:tt] )* + pub enum $main:ident $(<$($main_params: tt),+>)? { } + $( + $( #[doc = $doc_attr:tt] )* + pub enum $n:ident $(<$($t: tt),+>)? { + $( + $( #[doc = $variant_doc:tt] )* + $variant:ident(($($interior: ty),*), $q: tt), + )* + } + )+ + ) => { + $( #[doc = $main_docs] )* + #[derive(PartialEq, Eq, Clone)] + #[cfg_attr(feature = "std", derive(Debug))] + pub enum $main $(<$($main_params),+>)? { + $( + $( + $( #[doc = $variant_doc] )* + $variant($($interior),*), + )* + )* + } + + gen_digest_type! { + @internal + $main : $main $(<$($main_params),+>)? => $( + $( #[doc = $doc_attr] )* + pub enum $n $(<$($t),+>)? { + $( + $( #[doc = $variant_doc] )* + $variant(($($interior),*), $q), + )* + } + )+ + } + }; + ( + @internal + $main_id:tt : $main:ty => $( + $( #[doc = $doc_attr:tt] )* + pub enum $n:ident $(<$($t: tt),+>)? { + $( + $( #[doc = $variant_doc:tt] )* + $variant:ident(($($interior: ty),*), $q: tt), + )* + } + )+ + ) => { + $( + $( #[doc = $doc_attr] )* + #[derive(PartialEq, Eq, Clone)] + #[cfg_attr(feature = "std", derive(Debug))] + pub enum $n $(<$($t),+>)? { + $( + $( #[doc = $variant_doc] )* + $variant($($interior),*), + )* + } + + impl From<$n $(<$($t),*>)?> + for $main { + fn from(digest: $n $(<$($t),+>)?) -> Self { + match digest { + $( + $n::$variant $q => $main_id::$variant $q, + )* + } + } + } + )* + }; +} + +gen_digest_type! { + /// Digest item that is able to encode/decode 'system' digest items and + /// provide opaque access to other items. /// - /// These are messages from the consensus engine to the runtime, although - /// the consensus engine can (and should) read them itself to avoid - /// code and state duplication. It is erroneous for a runtime to produce - /// these, but this is not (yet) checked. - PreRuntime(ConsensusEngineId, Vec), - /// Any 'non-system' digest item, opaque to the native code. - Other(Vec), + /// For all variants that include a `ConsensusEngineId`, consensus engine + /// implementations **MUST** ignore digests that have a `ConsensusEngineId` + /// that is not theirs. Node implementations **MUST** reject digests that + /// have a `ConsensusEngineId` that corresponds to a consensus engine not in + /// use. Node implementations **MUST** reject blocks as malformed if they + /// reject any of the block’s digest. If the runtime supports this, the + /// node that issued the block **SHOULD** be reported as having committed + /// severe misbehavior and punished accordingly. The invalid block, or its + /// hash, **SHOULD** constitute adequate proof of such misbehavior. + pub enum DigestItem {} + + /// A digest item that can be produced by consensus engines. Consensus + /// engine implementations **MUST NOT** push digests not in this variant. + /// This **SHOULD** be detected at compile time. If it is not, the behavior + /// of the blockchain is undefined. + pub enum ConsensusDigest { + /// Put a Seal on it. This **MUST** come after all other `DigestItem` + /// variants. There **MUST** be exactly one `Seal` per consensus engine, + /// and its `ConsensusEngineId` **MUST** be that of the consensus engine + /// that produced it. Runtimes will not see this variant. + Seal((ConsensusEngineId, SealSignature), (a, b)), + /// An inherent digest. + /// + /// These are messages from the consensus engine to the runtime, + /// although the consensus engine can (and should) read them itself to + /// avoid code and state duplication. It is erroneous for a runtime to + /// produce these, but this is checked at compile time. Runtimes can + /// (and should) trust these, as with any other inherent. Consensus + /// engines MUST verify them. + PreRuntime((ConsensusEngineId, Vec), (a, b)), + } + + /// A digest item that can be produced by runtimes. Runtime mplementations + /// **MUST NOT** push digests not in this variant. This **SHOULD** be + /// detected at compile time. If it is not, the behavior of the blockchain + /// is undefined. + pub enum RuntimeDigest { + /// A message from the runtime to the consensus engine. This MUST NOT be + /// generated by the native code of any consensus engine, but this is + /// caught at compile time. The `ConsensusEngineId` is that of the + /// consensus engine for which this digest is intended. Consensus + /// engines MUST ignore digests with `ConsensusEngineId`s other than + /// their own. + Consensus((ConsensusEngineId, Vec), (a, b)), + /// Any 'non-system' digest item, opaque to the native code. Runtimes + /// MUST verify these, and reject any they did not produce. These MUST + /// NOT be produced by native code. + Other((Vec), (a)), + } + + /// A digest item that is reserved for the SRML. Only the SRML is allowed to + /// push these digests. Consensus engines and third-party runtime code + /// **MUST NOT** push digests in this variant. This **SHOULD** be detected + /// at compile time. If it is not, the behavior of the blockchain is + /// undefined. + pub enum SystemDigest { + /// System digest item announcing that authorities set has been changed + /// in the block. Contains the new set of authorities. + AuthoritiesChange((Vec), (a)), + /// System digest item that contains the root of changes trie at given + /// block. It is created for every block iff runtime supports changes + /// trie creation. + ChangesTrieRoot((Hash), (a)), + } } #[cfg(feature = "std")] diff --git a/substrate/core/sr-primitives/src/generic/mod.rs b/substrate/core/sr-primitives/src/generic/mod.rs index 89c4291d79..d9c53c5fd4 100644 --- a/substrate/core/sr-primitives/src/generic/mod.rs +++ b/substrate/core/sr-primitives/src/generic/mod.rs @@ -36,7 +36,9 @@ pub use self::era::{Era, Phase}; pub use self::checked_extrinsic::CheckedExtrinsic; pub use self::header::Header; pub use self::block::{Block, SignedBlock, BlockId}; -pub use self::digest::{Digest, DigestItem, DigestItemRef}; +pub use self::digest::{ + Digest, DigestItem, DigestItemRef, ConsensusDigest, RuntimeDigest, SystemDigest, +}; use crate::codec::Encode; use rstd::prelude::*; diff --git a/substrate/core/test-runtime/wasm/Cargo.lock b/substrate/core/test-runtime/wasm/Cargo.lock index cbbc8402dc..be1e3ab84f 100644 --- a/substrate/core/test-runtime/wasm/Cargo.lock +++ b/substrate/core/test-runtime/wasm/Cargo.lock @@ -111,7 +111,7 @@ dependencies = [ "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2006,7 +2006,7 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3638,7 +3638,7 @@ dependencies = [ "checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" "checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" -"checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288" +"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f271e3552cd835fa28c541c34a7e8fdd8cdff09d77fe4eb8f6c42e87a11b096e" diff --git a/substrate/node-template/runtime/wasm/Cargo.lock b/substrate/node-template/runtime/wasm/Cargo.lock index 14398725e5..c94150dc5b 100644 --- a/substrate/node-template/runtime/wasm/Cargo.lock +++ b/substrate/node-template/runtime/wasm/Cargo.lock @@ -111,7 +111,7 @@ dependencies = [ "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2040,7 +2040,7 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3731,7 +3731,7 @@ dependencies = [ "checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" "checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" -"checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288" +"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f271e3552cd835fa28c541c34a7e8fdd8cdff09d77fe4eb8f6c42e87a11b096e" diff --git a/substrate/node/runtime/wasm/Cargo.lock b/substrate/node/runtime/wasm/Cargo.lock index ab9b39afbd..050cbdcb7e 100644 --- a/substrate/node/runtime/wasm/Cargo.lock +++ b/substrate/node/runtime/wasm/Cargo.lock @@ -111,7 +111,7 @@ dependencies = [ "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2072,7 +2072,7 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3879,7 +3879,7 @@ dependencies = [ "checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" "checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" -"checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288" +"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f271e3552cd835fa28c541c34a7e8fdd8cdff09d77fe4eb8f6c42e87a11b096e" diff --git a/substrate/scripts/update-deps.sh b/substrate/scripts/update-deps.sh new file mode 100755 index 0000000000..cd6b7c8538 --- /dev/null +++ b/substrate/scripts/update-deps.sh @@ -0,0 +1,9 @@ +#!/bin/sh -- +set -eu +case $0 in + (/*) dir=${0%/*}/;; + (*/*) dir=./${0%/*};; + (*) dir=.;; +esac + +find "$dir/.." -name Cargo.lock -execdir cargo update \;