Migrate to new substrate (#79)

* new substrate version + actually verify justification

* cargo update + fix remaining stuff

* add weight=0 comments

* cargo fmt --all

* fix hash types
This commit is contained in:
Svyatoslav Nikolsky
2020-04-28 16:40:23 +03:00
committed by Bastian Köcher
parent 4bbef4d45a
commit 50d6ed186f
14 changed files with 282 additions and 235 deletions
+43 -38
View File
@@ -19,95 +19,100 @@ bridge-node-runtime = { version = "0.1.0", path = "../runtime" }
sp-bridge-eth-poa = { version = "0.1.0", path = "../../../primitives/ethereum-poa" }
[dependencies.sc-cli]
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sc-rpc]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sp-core]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sc-executor]
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sc-service]
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sp-inherents]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sc-transaction-pool]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sp-transaction-pool]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sc-network]
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sc-consensus-aura]
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sp-consensus-aura]
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sp-consensus]
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.grandpa]
package = "sc-finality-grandpa"
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.grandpa-primitives]
package = "sp-finality-grandpa"
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sc-client-api]
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sc-client]
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sp-runtime]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.sc-basic-authorship]
version = "0.8.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "0.8.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[dependencies.substrate-frame-rpc-system]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
[build-dependencies]
@@ -115,6 +120,6 @@ vergen = "3.1.0"
[build-dependencies.build-script-utils]
package = "substrate-build-script-utils"
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
version = "2.0.0-alpha.6"
rev = "c13ad41634d0bd7cf07897c2aa062b917d520520"
git = "https://github.com/paritytech/substrate.git"
+3 -16
View File
@@ -25,7 +25,7 @@ use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::ChainSpec<GenesisConfig>;
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
/// The chain specification option. This is expected to come in from the CLI and
/// is little more than one of a number of alternatives which can easily be converted
@@ -71,6 +71,7 @@ impl Alternative {
Alternative::Development => ChainSpec::from_genesis(
"Development",
"dev",
sc_service::ChainType::Development,
|| {
testnet_genesis(
vec![get_authority_keys_from_seed("Alice")],
@@ -93,6 +94,7 @@ impl Alternative {
Alternative::LocalTestnet => ChainSpec::from_genesis(
"Local Testnet",
"local_testnet",
sc_service::ChainType::Local,
|| {
testnet_genesis(
vec![
@@ -128,14 +130,6 @@ impl Alternative {
),
})
}
pub(crate) fn from(s: &str) -> Option<Self> {
match s {
"" | "dev" => Some(Alternative::Development),
"local" => Some(Alternative::LocalTestnet),
_ => None,
}
}
}
fn session_keys(aura: AuraId, grandpa: GrandpaId) -> SessionKeys {
@@ -173,13 +167,6 @@ fn testnet_genesis(
}
}
pub fn load_spec(id: &str) -> Result<Option<ChainSpec>, String> {
Ok(match Alternative::from(id) {
Some(spec) => Some(spec.load()?),
None => None,
})
}
fn load_kovan_config() -> Option<BridgeEthPoAConfig> {
Some(BridgeEthPoAConfig {
initial_header: sp_bridge_eth_poa::Header {
+49 -13
View File
@@ -30,28 +30,64 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
use crate::chain_spec;
use crate::cli::Cli;
use crate::service;
use sc_cli::VersionInfo;
use sc_cli::SubstrateCli;
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
impl SubstrateCli for Cli {
fn impl_name() -> &'static str {
"Bridge Node"
}
fn impl_version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
fn description() -> &'static str {
"Bridge Node"
}
fn author() -> &'static str {
"Parity Technologies"
}
fn support_url() -> &'static str {
"https://github.com/paritytech/parity-bridges-common/"
}
fn copyright_start_year() -> i32 {
2019
}
fn executable_name() -> &'static str {
"bridge-node"
}
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(Box::new(
match id {
"" | "dev" => crate::chain_spec::Alternative::Development,
"local" => crate::chain_spec::Alternative::LocalTestnet,
_ => return Err(format!("Unsupported chain specification: {}", id)),
}
.load()?,
))
}
}
/// Parse and run command line arguments
pub fn run(version: VersionInfo) -> sc_cli::Result<()> {
let opt = sc_cli::from_args::<Cli>(&version);
pub fn run() -> sc_cli::Result<()> {
let cli = Cli::from_args();
let mut config = sc_service::Configuration::from_version(&version);
match opt.subcommand {
match &cli.subcommand {
Some(subcommand) => {
subcommand.init(&version)?;
subcommand.update_config(&mut config, chain_spec::load_spec, &version)?;
subcommand.run(config, |config: _| Ok(new_full_start!(config).0))
let runner = cli.create_runner(subcommand)?;
runner.run_subcommand(subcommand, |config| Ok(new_full_start!(config).0))
}
None => {
opt.run.init(&version)?;
opt.run.update_config(&mut config, chain_spec::load_spec, &version)?;
opt.run.run(config, service::new_light, service::new_full, &version)
let runner = cli.create_runner(&cli.run)?;
runner.run_node(service::new_light, service::new_full, bridge_node_runtime::VERSION)
}
}
}
+1 -12
View File
@@ -24,16 +24,5 @@ mod cli;
mod command;
fn main() -> sc_cli::Result<()> {
let version = sc_cli::VersionInfo {
name: "Bridge Node",
commit: env!("VERGEN_SHA_SHORT"),
version: env!("CARGO_PKG_VERSION"),
executable_name: "bridge-node",
author: "Parity Technologies",
description: "Bridge Node",
support_url: "https://github.com/paritytech/parity-bridges-common/",
copyright_start_year: 2019,
};
command::run(version)
command::run()
}
+30 -26
View File
@@ -16,9 +16,10 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
use bridge_node_runtime::{self, opaque::Block, GenesisConfig, RuntimeApi};
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
use bridge_node_runtime::{self, opaque::Block, RuntimeApi};
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider};
use sc_client::LongestChain;
use sc_client_api::ExecutorProvider;
use sc_executor::native_executor_instance;
pub use sc_executor::NativeExecutor;
use sc_service::{error::Error as ServiceError, AbstractService, Configuration, ServiceBuilder};
@@ -40,6 +41,8 @@ native_executor_instance!(
/// be able to perform chain operations.
macro_rules! new_full_start {
($config:expr) => {{
use std::sync::Arc;
let mut import_setup = None;
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
@@ -49,11 +52,12 @@ macro_rules! new_full_start {
crate::service::Executor,
>($config)?
.with_select_chain(|_config, backend| Ok(sc_client::LongestChain::new(backend.clone())))?
.with_transaction_pool(|config, client, _fetcher| {
.with_transaction_pool(|config, client, _fetcher, prometheus_registry| {
let pool_api = sc_transaction_pool::FullChainApi::new(client.clone());
Ok(sc_transaction_pool::BasicPool::new(
config,
std::sync::Arc::new(pool_api),
prometheus_registry,
))
})?
.with_import_queue(|_config, client, mut select_chain, _transaction_pool| {
@@ -61,7 +65,8 @@ macro_rules! new_full_start {
.take()
.ok_or_else(|| sc_service::Error::SelectChainRequired)?;
let (grandpa_block_import, grandpa_link) = grandpa::block_import(client.clone(), &*client, select_chain)?;
let (grandpa_block_import, grandpa_link) =
grandpa::block_import(client.clone(), &(client.clone() as Arc<_>), select_chain)?;
let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
grandpa_block_import.clone(),
@@ -97,17 +102,12 @@ macro_rules! new_full_start {
}
/// Builds a new service for a full client.
pub fn new_full(config: Configuration<GenesisConfig>) -> Result<impl AbstractService, ServiceError> {
let is_authority = config.roles.is_authority();
pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceError> {
let role = config.role.clone();
let force_authoring = config.force_authoring;
let name = config.name.clone();
let name = config.network.node_name.clone();
let disable_grandpa = config.disable_grandpa;
// sentry nodes announce themselves as authorities to the network
// and should run the same protocols authorities do, but it should
// never actively participate in any consensus process.
let participates_in_consensus = is_authority && !config.sentry_mode;
let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config);
let (block_import, grandpa_link) = import_setup
@@ -116,15 +116,13 @@ pub fn new_full(config: Configuration<GenesisConfig>) -> Result<impl AbstractSer
let service = builder
.with_finality_proof_provider(|client, backend| {
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
})?
.build()?;
if participates_in_consensus {
let proposer = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};
if role.is_authority() {
let proposer = sc_basic_authorship::ProposerFactory::new(service.client(), service.transaction_pool());
let client = service.client();
let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?;
@@ -151,7 +149,7 @@ pub fn new_full(config: Configuration<GenesisConfig>) -> Result<impl AbstractSer
// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if participates_in_consensus {
let keystore = if role.is_authority() {
Some(service.keystore())
} else {
None
@@ -164,7 +162,7 @@ pub fn new_full(config: Configuration<GenesisConfig>) -> Result<impl AbstractSer
name: Some(name),
observer_enabled: false,
keystore,
is_authority,
is_authority: role.is_network_authority(),
};
let enable_grandpa = !disable_grandpa;
@@ -180,9 +178,9 @@ pub fn new_full(config: Configuration<GenesisConfig>) -> Result<impl AbstractSer
link: grandpa_link,
network: service.network(),
inherent_data_providers: inherent_data_providers.clone(),
on_exit: service.on_exit(),
telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
voting_rule: grandpa::VotingRulesBuilder::default().build(),
prometheus_registry: service.prometheus_registry(),
};
// the GRANDPA voter task is considered infallible, i.e.
@@ -196,18 +194,19 @@ pub fn new_full(config: Configuration<GenesisConfig>) -> Result<impl AbstractSer
}
/// Builds a new service for a light client.
pub fn new_light(config: Configuration<GenesisConfig>) -> Result<impl AbstractService, ServiceError> {
pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceError> {
let inherent_data_providers = InherentDataProviders::new();
ServiceBuilder::new_light::<Block, RuntimeApi, Executor>(config)?
.with_select_chain(|_config, backend| Ok(LongestChain::new(backend.clone())))?
.with_transaction_pool(|config, client, fetcher| {
.with_transaction_pool(|config, client, fetcher, prometheus_registry| {
let fetcher = fetcher.ok_or_else(|| "Trying to start light transaction pool without active fetcher")?;
let pool_api = sc_transaction_pool::LightChainApi::new(client.clone(), fetcher.clone());
let pool = sc_transaction_pool::BasicPool::with_revalidation_type(
config,
Arc::new(pool_api),
prometheus_registry,
sc_transaction_pool::RevalidationType::Light,
);
Ok(pool)
@@ -216,8 +215,12 @@ pub fn new_light(config: Configuration<GenesisConfig>) -> Result<impl AbstractSe
let fetch_checker = fetcher
.map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
let grandpa_block_import =
grandpa::light_block_import(client.clone(), backend, &*client.clone(), Arc::new(fetch_checker))?;
let grandpa_block_import = grandpa::light_block_import(
client.clone(),
backend,
&(client.clone() as Arc<_>),
Arc::new(fetch_checker),
)?;
let finality_proof_import = grandpa_block_import.clone();
let finality_proof_request_builder = finality_proof_import.create_finality_proof_request_builder();
@@ -233,7 +236,8 @@ pub fn new_light(config: Configuration<GenesisConfig>) -> Result<impl AbstractSe
Ok((import_queue, finality_proof_request_builder))
})?
.with_finality_proof_provider(|client, backend| {
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, client)) as _)
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
})?
.build()
}