Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 40 additions & 52 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ members = [
"core/session",
"core/sr-api-macros",
"core/sr-arithmetic",
"core/sr-arithmetic/fuzzer",
"core/sr-io",
"core/sr-primitives",
"core/sr-staking-primitives",
Expand Down
16 changes: 11 additions & 5 deletions core/application-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[doc(hidden)]
pub use primitives::{self, crypto::{CryptoType, Public, Derive, IsWrappedBy, Wraps}};
pub use primitives::{self, crypto::{CryptoType, Public, Derive, IsWrappedBy, Wraps}, RuntimeDebug};
#[doc(hidden)]
#[cfg(feature = "std")]
pub use primitives::crypto::{SecretStringError, DeriveJunction, Ss58Codec, Pair};
Expand Down Expand Up @@ -139,10 +139,12 @@ macro_rules! app_crypto {
$crate::wrap!{
/// A generic `AppPublic` wrapper type over $public crypto; this has no specific App.
#[derive(
Clone, Default, Eq, PartialEq, Ord, PartialOrd, $crate::codec::Encode,
Clone, Default, Eq, PartialEq, Ord, PartialOrd,
$crate::codec::Encode,
$crate::codec::Decode,
$crate::RuntimeDebug,
)]
#[cfg_attr(feature = "std", derive(Debug, Hash))]
#[cfg_attr(feature = "std", derive(Hash))]
pub struct Public($public);
}

Expand Down Expand Up @@ -239,8 +241,12 @@ macro_rules! app_crypto {

$crate::wrap! {
/// A generic `AppPublic` wrapper type over $public crypto; this has no specific App.
#[derive(Clone, Default, Eq, PartialEq, $crate::codec::Encode, $crate::codec::Decode)]
#[cfg_attr(feature = "std", derive(Debug, Hash))]
#[derive(Clone, Default, Eq, PartialEq,
$crate::codec::Encode,
$crate::codec::Decode,
$crate::RuntimeDebug,
)]
#[cfg_attr(feature = "std", derive(Hash))]
pub struct Signature($sig);
}

Expand Down
30 changes: 17 additions & 13 deletions core/application-crypto/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

use primitives::crypto::{KeyTypeId, CryptoType, IsWrappedBy, Public};
#[cfg(feature = "std")]
use primitives::crypto::Pair;

use codec::Codec;
use primitives::crypto::{KeyTypeId, CryptoType, IsWrappedBy, Public};
use rstd::fmt::Debug;

/// An application-specific key.
pub trait AppKey: 'static + Send + Sync + Sized + CryptoType + Clone {
Expand All @@ -38,23 +40,25 @@ pub trait AppKey: 'static + Send + Sync + Sized + CryptoType + Clone {
const ID: KeyTypeId;
}

/// Type which implements Debug and Hash in std, not when no-std (std variant).
/// Type which implements Hash in std, not when no-std (std variant).
#[cfg(feature = "std")]
pub trait MaybeDebugHash: std::fmt::Debug + std::hash::Hash {}
pub trait MaybeHash: std::hash::Hash {}
#[cfg(feature = "std")]
impl<T: std::fmt::Debug + std::hash::Hash> MaybeDebugHash for T {}
impl<T: std::hash::Hash> MaybeHash for T {}

/// Type which implements Debug and Hash in std, not when no-std (no-std variant).
/// Type which implements Hash in std, not when no-std (no-std variant).
#[cfg(not(feature = "std"))]
pub trait MaybeDebugHash {}
pub trait MaybeHash {}
#[cfg(not(feature = "std"))]
impl<T> MaybeDebugHash for T {}
impl<T> MaybeHash for T {}

/// A application's public key.
pub trait AppPublic: AppKey + Public + Ord + PartialOrd + Eq + PartialEq + MaybeDebugHash + codec::Codec {
pub trait AppPublic:
AppKey + Public + Ord + PartialOrd + Eq + PartialEq + Debug + MaybeHash + codec::Codec
{
/// The wrapped type which is just a plain instance of `Public`.
type Generic:
IsWrappedBy<Self> + Public + Ord + PartialOrd + Eq + PartialEq + MaybeDebugHash + codec::Codec;
IsWrappedBy<Self> + Public + Ord + PartialOrd + Eq + PartialEq + Debug + MaybeHash + codec::Codec;
}

/// A application's key pair.
Expand All @@ -65,15 +69,15 @@ pub trait AppPair: AppKey + Pair<Public=<Self as AppKey>::Public> {
}

/// A application's signature.
pub trait AppSignature: AppKey + Eq + PartialEq + MaybeDebugHash {
pub trait AppSignature: AppKey + Eq + PartialEq + Debug + MaybeHash {
/// The wrapped type which is just a plain instance of `Signature`.
type Generic: IsWrappedBy<Self> + Eq + PartialEq + MaybeDebugHash;
type Generic: IsWrappedBy<Self> + Eq + PartialEq + Debug + MaybeHash;
}

/// A runtime interface for a public key.
pub trait RuntimePublic: Sized {
/// The signature that will be generated when signing with the corresponding private key.
type Signature: Codec + MaybeDebugHash + Eq + PartialEq + Clone;
type Signature: Codec + Debug + MaybeHash + Eq + PartialEq + Clone;

/// Returns all public keys for the given key type in the keystore.
fn all(key_type: KeyTypeId) -> crate::Vec<Self>;
Expand Down Expand Up @@ -101,7 +105,7 @@ pub trait RuntimeAppPublic: Sized {
const ID: KeyTypeId;

/// The signature that will be generated when signing with the corresponding private key.
type Signature: Codec + MaybeDebugHash + Eq + PartialEq + Clone;
type Signature: Codec + Debug + MaybeHash + Eq + PartialEq + Clone;

/// Returns all public keys for this application in the keystore.
fn all() -> crate::Vec<Self>;
Expand Down
9 changes: 5 additions & 4 deletions core/authority-discovery/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@

use client::decl_runtime_apis;
use rstd::vec::Vec;
use sr_primitives::RuntimeDebug;

#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone)]
#[cfg_attr(feature = "std", derive(Debug, Hash))]
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Hash))]
pub struct Signature(pub Vec<u8>);
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone)]
#[cfg_attr(feature = "std", derive(Debug, Hash))]
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Hash))]
pub struct AuthorityId(pub Vec<u8>);

decl_runtime_apis! {
Expand Down
31 changes: 23 additions & 8 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,6 @@ where
config.database_path = db_path(&base_path, config.chain_spec.id());
config.database_cache_size = cli.database_cache_size;
config.state_cache_size = cli.state_cache_size;
config.pruning = match cli.pruning {
Some(ref s) if s == "archive" => PruningMode::ArchiveAll,
None => PruningMode::default(),
Some(s) => PruningMode::keep_blocks(s.parse()
.map_err(|_| error::Error::Input("Invalid pruning mode specified".to_string()))?
),
};

let is_dev = cli.shared_params.dev;

Expand All @@ -694,6 +687,28 @@ where
service::Roles::FULL
};

// by default we disable pruning if the node is an authority (i.e.
// `ArchiveAll`), otherwise we keep state for the last 256 blocks. if the
// node is an authority and pruning is enabled explicitly, then we error
// unless `unsafe_pruning` is set.
config.pruning = match cli.pruning {
Some(ref s) if s == "archive" => PruningMode::ArchiveAll,
None if role == service::Roles::AUTHORITY => PruningMode::ArchiveAll,
None => PruningMode::default(),
Some(s) => {
if role == service::Roles::AUTHORITY && !cli.unsafe_pruning {
return Err(error::Error::Input(
"Validators should run with state pruning disabled (i.e. archive). \
You can ignore this check with `--unsafe-pruning`.".to_string()
));
}

PruningMode::keep_blocks(s.parse()
.map_err(|_| error::Error::Input("Invalid pruning mode specified".to_string()))?
)
},
};

config.wasm_method = cli.wasm_method.into();

let exec = cli.execution_strategies;
Expand Down Expand Up @@ -788,7 +803,7 @@ where
G: RuntimeGenesis,
E: ChainSpecExtension,
{
if spec.boot_nodes().is_empty() {
if spec.boot_nodes().is_empty() && !cli.disable_default_bootnode {
let base_path = base_path(&cli.shared_params, version);
let storage_path = network_path(&base_path, spec.id());
let node_key = node_key_config(cli.node_key_params, &Some(storage_path))?;
Expand Down
23 changes: 20 additions & 3 deletions core/cli/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,22 @@ pub struct RunCmd {
#[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))]
pub rpc_cors: Option<Cors>,

/// Specify the pruning mode, a number of blocks to keep or 'archive'.
/// Specify the state pruning mode, a number of blocks to keep or 'archive'.
///
/// Default is 256.
/// Default is to keep all block states if the node is running as a
/// validator (i.e. 'archive'), otherwise state is only kept for the last
/// 256 blocks.
#[structopt(long = "pruning", value_name = "PRUNING_MODE")]
pub pruning: Option<String>,

/// Force start with unsafe pruning settings.
///
/// When running as a validator it is highly recommended to disable state
/// pruning (i.e. 'archive') which is the default. The node will refuse to
/// start as a validator if pruning is enabled unless this option is set.
#[structopt(long = "unsafe-pruning")]
pub unsafe_pruning: bool,

/// The human-readable name for this node.
///
/// The node name will be reported to the telemetry server, if enabled.
Expand Down Expand Up @@ -604,6 +614,13 @@ pub struct BuildSpecCmd {
#[structopt(long = "raw")]
pub raw: bool,

/// Disable adding the default bootnode to the specification.
///
/// By default the `/ip4/127.0.0.1/tcp/30333/p2p/NODE_PEER_ID` bootnode is added to the
/// specification when no bootnode exists.
#[structopt(long = "disable-default-bootnode")]
pub disable_default_bootnode: bool,

#[allow(missing_docs)]
#[structopt(flatten)]
pub shared_params: SharedParams,
Expand Down Expand Up @@ -753,7 +770,7 @@ impl<CC, RP> StructOpt for CoreParams<CC, RP> where
)
).subcommand(
BuildSpecCmd::augment_clap(SubCommand::with_name("build-spec"))
.about("Build a spec.json file, outputing to stdout.")
.about("Build a spec.json file, outputting to stdout.")
)
.subcommand(
ExportBlocksCmd::augment_clap(SubCommand::with_name("export-blocks"))
Expand Down
3 changes: 1 addition & 2 deletions core/consensus/babe/primitives/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ impl Decode for BabePreDigest {

/// Information about the next epoch. This is broadcast in the first block
/// of the epoch.
#[derive(Decode, Encode, Default, PartialEq, Eq, Clone)]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[derive(Decode, Encode, Default, PartialEq, Eq, Clone, sr_primitives::RuntimeDebug)]
pub struct NextEpochDescriptor {
/// The authorities.
pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
Expand Down
8 changes: 3 additions & 5 deletions core/consensus/babe/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod digest;

use codec::{Encode, Decode};
use rstd::vec::Vec;
use sr_primitives::ConsensusEngineId;
use sr_primitives::{ConsensusEngineId, RuntimeDebug};
use substrate_client::decl_runtime_apis;

#[cfg(feature = "std")]
Expand Down Expand Up @@ -79,8 +79,7 @@ pub type BabeAuthorityWeight = u64;
pub type BabeBlockWeight = u32;

/// BABE epoch information
#[derive(Decode, Encode, Default, PartialEq, Eq, Clone)]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[derive(Decode, Encode, Default, PartialEq, Eq, Clone, RuntimeDebug)]
pub struct Epoch {
/// The epoch index
pub epoch_index: u64,
Expand Down Expand Up @@ -127,8 +126,7 @@ pub enum ConsensusLog {
}

/// Configuration data used by the BABE consensus engine.
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
#[cfg_attr(any(feature = "std", test), derive(Debug))]
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
pub struct BabeConfiguration {
/// The slot duration in milliseconds for BABE. Currently, only
/// the value provided by this type at genesis will be used.
Expand Down
2 changes: 1 addition & 1 deletion core/executor/runtime-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ primitives = { package = "substrate-primitives", path = "../../primitives", def
sr-primitives = { package = "sr-primitives", path = "../../sr-primitives", default-features = false }

[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.2", path = "../../utils/wasm-builder-runner" }
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.4", path = "../../utils/wasm-builder-runner" }

[features]
default = [ "std" ]
Expand Down
2 changes: 1 addition & 1 deletion core/executor/runtime-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
"wasm_binary.rs",
WasmBuilderSource::CratesOrPath {
path: "../../utils/wasm-builder",
version: "1.0.7",
version: "1.0.8",
},
// This instructs LLD to export __heap_base as a global variable, which is used by the
// external memory allocator.
Expand Down
16 changes: 16 additions & 0 deletions core/executor/src/host_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ impl_wasm_host_interface! {
Ok(())
}

ext_log(
level: u32,
target_data: Pointer<u8>,
target_len: WordSize,
message_data: Pointer<u8>,
message_len: WordSize,
) {
let target = context.read_memory(target_data, target_len)
.map_err(|_| "Invalid attempt to determine target in ext_log")?;
let message = context.read_memory(message_data, message_len)
.map_err(|_| "Invalid attempt to determine message in ext_log")?;

runtime_io::log(level.into(), &target, &message);
Ok(())
}

ext_set_storage(
key_data: Pointer<u8>,
key_len: WordSize,
Expand Down
10 changes: 5 additions & 5 deletions core/finality-grandpa/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern crate alloc;
#[cfg(feature = "std")]
use serde::Serialize;
use codec::{Encode, Decode, Codec};
use sr_primitives::ConsensusEngineId;
use sr_primitives::{ConsensusEngineId, RuntimeDebug};
use client::decl_runtime_apis;
use rstd::vec::Vec;

Expand Down Expand Up @@ -59,8 +59,8 @@ pub type SetId = u64;
pub type RoundNumber = u64;

/// A scheduled change of authority set.
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
#[derive(Clone, Eq, PartialEq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug)]
pub struct ScheduledChange<N> {
/// The new authorities after the change, along with their respective weights.
pub next_authorities: Vec<(AuthorityId, AuthorityWeight)>,
Expand All @@ -69,8 +69,8 @@ pub struct ScheduledChange<N> {
}

/// An consensus log item for GRANDPA.
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
#[derive(Decode, Encode, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "std", derive(Serialize))]
#[derive(Decode, Encode, PartialEq, Eq, Clone, RuntimeDebug)]
pub enum ConsensusLog<N: Codec> {
/// Schedule an authority set change.
///
Expand Down
Loading