Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit ef03e8a

Browse files
committed
Merge branch 'gav-fix-telemetry' into v0.9
2 parents c695efe + 89f2d9b commit ef03e8a

File tree

150 files changed

+4045
-2567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+4045
-2567
lines changed

Cargo.lock

Lines changed: 759 additions & 690 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ path = "node/src/main.rs"
44

55
[package]
66
name = "substrate"
7-
version = "0.9.1"
7+
version = "0.9.2"
88
authors = ["Parity Technologies <admin@parity.io>"]
99
build = "build.rs"
1010

@@ -57,6 +57,7 @@ members = [
5757
"core/sr-primitives",
5858
"srml/session",
5959
"srml/staking",
60+
"srml/sudo",
6061
"srml/system",
6162
"srml/timestamp",
6263
"srml/treasury",

README.adoc

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,35 @@ Other examples include the parachain-heads extrinsic in Polkadot and the "note-m
4848

4949
=== Runtime and API
5050

51-
Substrate chains all have a runtime. The runtime is a WebAssembly "blob" that includes a number of entry-points. Some entry-points are required as part of the underlying Substrate specification. Others are merely convention and required for the default implementation of the Substrate client to be able to author blocks. In short these two sets are:
51+
Substrate chains all have a runtime. The runtime is a WebAssembly "blob" that includes a number of entry-points. Some entry-points are required as part of the underlying Substrate specification. Others are merely convention and required for the default implementation of the Substrate client to be able to author blocks.
5252

53-
The runtime is API entry points are expected to be in the runtime's `api` module. There is a specific ABI based upon the Substrate Simple Codec (`codec`), which is used to encode and decode the arguments for these functions and specify where and how they should be passed. A special macro is provided called `impl_stubs`, which prepares all functionality for marshalling arguments and basically just allows you to write the functions as you would normally (except for the fact that there must be example one argument - tuples are allowed to workaround).
53+
If you want to develop a chain with Substrate, you will need to implement the `Core` trait. This `Core` trait generates an API with the minimum necessary functionality to interact with your runtime. A special macro is provided called `impl_runtime_apis!` that help you implement runtime API traits. All runtime API trait implementations need to be done in one call of the `impl_runtime_apis!` macro. All parameters and return values need to implement https://crates.io/crates/parity-codec[`parity-codec`] to be encodable and decodable.
5454

55-
Here's the Polkadot API implementation as of PoC-2:
55+
Here's a snippet of the Polkadot API implementation as of PoC-3:
5656

5757
```rust
58-
pub mod api {
59-
impl_stubs!(
60-
61-
// Standard: Required.
62-
version => |()| super::Version::version(),
63-
authorities => |()| super::Consensus::authorities(),
64-
execute_block => |block| super::Executive::execute_block(block),
65-
66-
// Conventional: Needed for Substrate client's reference block authoring logic to work.
67-
initialise_block => |header| super::Executive::initialise_block(&header),
68-
apply_extrinsic => |extrinsic| super::Executive::apply_extrinsic(extrinsic),
69-
finalise_block => |()| super::Executive::finalise_block(),
70-
inherent_extrinsics => |inherent| super::inherent_extrinsics(inherent),
71-
72-
// Non-standard (Polkadot-specific). This just exposes some stuff that Polkadot client
73-
// finds useful.
74-
validator_count => |()| super::Session::validator_count(),
75-
validators => |()| super::Session::validators()
76-
);
58+
impl_runtime_apis! {
59+
impl client_api::Core<Block> for Runtime {
60+
fn version() -> RuntimeVersion {
61+
VERSION
62+
}
63+
64+
fn authorities() -> Vec<SessionKey> {
65+
Consensus::authorities()
66+
}
67+
68+
fn execute_block(block: Block) {
69+
Executive::execute_block(block)
70+
}
71+
72+
fn initialise_block(header: <Block as BlockT>::Header) {
73+
Executive::initialise_block(&header)
74+
}
75+
}
76+
// ---snip---
7777
}
7878
```
7979

80-
As you can see, at the minimum there are only three API calls to implement. If you want to reuse as much of Substrate's reference block authoring client code, then you'll want to provide the next four entrypoints (though three of them you probably already implemented as part of `execute_block`).
81-
82-
Of the first three, there is `execute_block`, which contains the actions to be taken to execute a block and pretty much defines the blockchain. Then there is `authorities` which tells the AfG consensus algorithm sitting in the Substrate client who the given authorities (known as "validators" in some contexts) are that can finalise the next block. Finally, there is `version`, which is a fairly sophisticated version identifier. This includes a key distinction between *specification version* and *authoring version*, with the former essentially versioning the logic of `execute_block` and the latter versioning only the logic of `inherent_extrinsics` and core aspects of extrinsic validity.
8380

8481
=== Inherent Extrinsics
8582

@@ -175,7 +172,7 @@ You can distribute `mychain.json` so that everyone can synchronise and (dependin
175172

176173
=== Hacking on Substrate
177174

178-
If you'd actually like hack on Substrate, you can just grab the source code and
175+
If you'd actually like to hack on Substrate, you can just grab the source code and
179176
build it. Ensure you have Rust and the support software installed:
180177

181178
[source, shell]
@@ -223,7 +220,6 @@ You can start a development chain with:
223220
[source, shell]
224221
cargo run -- --dev
225222

226-
227223
Detailed logs may be shown by running the node with the following environment variables set: `RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- --dev`.
228224

229225
If you want to see the multi-node consensus algorithm in action locally, then you can create a local testnet with two validator nodes for Alice and Bob, who are the initial authorities of the genesis chain specification that have been endowed with a testnet DOTs. We'll give each node a name and expose them so they are listed on [Telemetry](https://telemetry.polkadot.io/#/Local%20Testnet). You'll need two terminals windows open.
@@ -255,6 +251,39 @@ cargo run -- \
255251

256252
Additional Substate CLI usage options are available and may be shown by running `cargo run -- --help`.
257253

254+
=== Joining the Charred Cherry Testnet
255+
256+
Charred Cherry is the new testnet for Substrate 1.0 beta. Please note that 1.0 beta is not compatible with the BBQ-Birch testnet. Ensure you have the dependencies listed above before compiling.
257+
258+
[source, shell]
259+
----
260+
git clone https://github.com/paritytech/substrate.git
261+
cd substrate
262+
----
263+
264+
You can run the tests if you like:
265+
266+
[source, shell]
267+
cargo test --all
268+
269+
Start your node:
270+
271+
[source, shell]
272+
cargo run --release
273+
274+
To see a list of command line options, enter:
275+
276+
[source, shell]
277+
cargo run --release -- --help
278+
279+
For example, you can choose a custom node name:
280+
281+
[source, shell]
282+
cargo run --release -- --name my_custom_name
283+
284+
If you are successful, you will see your node syncing at https://telemetry.polkadot.io/#/Charred%20Cherry
285+
286+
258287
== Documentation
259288

260289
=== Viewing documentation for Substrate packages

core/basic-authorship/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "substrate-basic-authorship"
3+
version = "0.1.0"
4+
authors = ["Parity Technologies <admin@parity.io>"]
5+
6+
[dependencies]
7+
log = "0.4"
8+
parity-codec = "2.1"
9+
sr-primitives = { path = "../../core/sr-primitives" }
10+
substrate-client = { path = "../../core/client" }
11+
substrate-consensus-aura-primitives = { path = "../../core/consensus/aura/primitives" }
12+
substrate-consensus-common = { path = "../../core/consensus/common" }
13+
substrate-primitives = { path = "../../core/primitives" }
14+
substrate-transaction-pool = { path = "../../core/transaction-pool" }

core/service/src/consensus.rs renamed to core/basic-authorship/src/basic_authorship.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use client::{self, error, Client as SubstrateClient, CallExecutor};
2626
use client::{block_builder::api::BlockBuilder as BlockBuilderApi, runtime_api::Core};
2727
use codec::{Decode, Encode};
2828
use consensus_common::{self, evaluation};
29-
use primitives::{H256, AuthorityId, ed25519, Blake2Hasher};
30-
use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi};
29+
use primitives::{H256, Blake2Hasher};
30+
use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi, AuthorityIdFor};
3131
use runtime_primitives::generic::BlockId;
3232
use runtime_primitives::BasicInherentData;
3333
use transaction_pool::txpool::{self, Pool as TransactionPool};
@@ -125,8 +125,7 @@ impl<C, A, ConsensusData> consensus_common::Environment<<C as AuthoringApi>::Blo
125125
fn init(
126126
&self,
127127
parent_header: &<<C as AuthoringApi>::Block as BlockT>::Header,
128-
_: &[AuthorityId],
129-
_: Arc<ed25519::Pair>,
128+
_: &[AuthorityIdFor<<C as AuthoringApi>::Block>],
130129
) -> Result<Self::Proposer, error::Error> {
131130
let parent_hash = parent_header.hash();
132131

core/basic-authorship/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017-2018 Parity Technologies (UK) Ltd.
2+
// This file is part of Substrate.
3+
4+
// Substrate is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Substrate is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! Basic implementation of block-authoring logic.
18+
19+
#![warn(unused_extern_crates)]
20+
21+
extern crate substrate_consensus_aura_primitives as aura_primitives;
22+
extern crate substrate_primitives as primitives;
23+
extern crate sr_primitives as runtime_primitives;
24+
extern crate substrate_consensus_common as consensus_common;
25+
extern crate substrate_client as client;
26+
extern crate parity_codec as codec;
27+
extern crate substrate_transaction_pool as transaction_pool;
28+
29+
#[macro_use]
30+
extern crate log;
31+
32+
mod basic_authorship;
33+
34+
pub use basic_authorship::{ProposerFactory, BlockBuilder, AuthoringApi, Proposer};

core/cli/src/informant.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use tokio::runtime::TaskExecutor;
2424
use tokio::timer::Interval;
2525
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
2626
use network::{SyncState, SyncProvider};
27-
use client::BlockchainEvents;
27+
use client::{backend::Backend, BlockchainEvents};
28+
29+
use runtime_primitives::generic::BlockId;
2830
use runtime_primitives::traits::{Header, As};
2931

3032
const TIMER_INTERVAL_MS: u64 = 5000;
@@ -92,7 +94,36 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
9294
});
9395

9496
let client = service.client();
95-
let display_block_import = client.import_notification_stream().for_each(|n| {
97+
let mut last = match client.info() {
98+
Ok(info) => Some((info.chain.best_number, info.chain.best_hash)),
99+
Err(e) => { warn!("Error getting best block information: {:?}", e); None }
100+
};
101+
102+
let display_block_import = client.import_notification_stream().for_each(move |n| {
103+
// detect and log reorganizations.
104+
if let Some((ref last_num, ref last_hash)) = last {
105+
if n.header.parent_hash() != last_hash {
106+
let tree_route = ::client::blockchain::tree_route(
107+
client.backend().blockchain(),
108+
BlockId::Hash(last_hash.clone()),
109+
BlockId::Hash(n.hash),
110+
);
111+
112+
match tree_route {
113+
Ok(ref t) if !t.retracted().is_empty() => info!(
114+
"Reorg from #{},{} to #{},{}, common ancestor #{},{}",
115+
last_num, last_hash,
116+
n.header.number(), n.hash,
117+
t.common_block().number, t.common_block().hash,
118+
),
119+
Ok(_) => {},
120+
Err(e) => warn!("Error computing tree route: {}", e),
121+
}
122+
}
123+
}
124+
125+
last = Some((n.header.number().clone(), n.hash.clone()));
126+
96127
info!(target: "substrate", "Imported #{} ({})", n.header.number(), n.hash);
97128
Ok(())
98129
});

core/cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ where
422422
} else if let Some(sub_matches) = matches.subcommand_matches("revert") {
423423
revert_chain::<F>(
424424
get_db_path_for_subcommand(matches, sub_matches)?,
425-
matches,
425+
sub_matches,
426426
spec
427427
)?;
428428
return Ok(Action::ExecutedInternally);

core/cli/src/params.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,17 @@ pub struct CoreParams {
9191

9292
/// Specify the pruning mode, a number of blocks to keep or 'archive'. Default is 256.
9393
#[structopt(long = "pruning", value_name = "PRUNING_MODE")]
94-
pruning: Option<u32>,
94+
pruning: Option<String>,
9595

9696
/// The human-readable name for this node, as reported to the telemetry server, if enabled
9797
#[structopt(long = "name", value_name = "NAME")]
9898
name: Option<String>,
9999

100-
/// Should connect to the Substrate telemetry server (telemetry is off by default on local chains)
101-
#[structopt(short = "t", long = "telemetry")]
102-
telemetry: bool,
103-
104100
/// Should not connect to the Substrate telemetry server (telemetry is on by default on global chains)
105101
#[structopt(long = "no-telemetry")]
106102
no_telemetry: bool,
107103

108-
/// The URL of the telemetry server. Implies --telemetry
104+
/// The URL of the telemetry server to connect to
109105
#[structopt(long = "telemetry-url", value_name = "TELEMETRY_URL")]
110106
telemetry_url: Option<String>,
111107

core/client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
77
error-chain = { version = "0.12", optional = true }
88
fnv = { version = "1.0", optional = true }
99
log = { version = "0.4", optional = true }
10-
parking_lot = { version = "0.4", optional = true }
10+
parking_lot = { version = "0.7.1", optional = true }
1111
hex-literal = { version = "0.1", optional = true }
1212
futures = { version = "0.1.17", optional = true }
1313
slog = { version = "^2", optional = true }

0 commit comments

Comments
 (0)