Skip to content

Commit

Permalink
Feature/update substrate (paritytech#238)
Browse files Browse the repository at this point in the history
update substrate for f54f3f5
  • Loading branch information
Aton authored Jan 23, 2019
1 parent 4a6e01e commit a100d80
Show file tree
Hide file tree
Showing 13 changed files with 524 additions and 563 deletions.
167 changes: 96 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ substrate-network = { git = "https://github.com/chainpool/substrate" }
substrate-consensus-aura = { git = "https://github.com/chainpool/substrate" }
substrate-finality-grandpa = { git = "https://github.com/chainpool/substrate" }
substrate-keyring = { git = "https://github.com/chainpool/substrate" }

substrate-inherents = { git = "https://github.com/chainpool/substrate" }
sr-io = { git = "https://github.com/chainpool/substrate" }
sr-primitives = { git = "https://github.com/chainpool/substrate" }

Expand Down Expand Up @@ -51,4 +51,4 @@ msgbus-redis-keyhash = [
]
cache-lru = [
"substrate-cli/cache-lru"
]
]
8 changes: 5 additions & 3 deletions cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright 2019 Chainpool

use chainx_runtime::GenesisConfig;
use genesis_config::{testnet_genesis, GenesisSpec};
use substrate_service;

const STAGING_TELEMETRY_URL: &str = "ws://stats.chainx.org/submit/";
const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

/// Specialised `ChainSpec`.
pub type ChainSpec = substrate_service::ChainSpec<GenesisConfig>;
Expand All @@ -11,8 +13,8 @@ pub type ChainSpec = substrate_service::ChainSpec<GenesisConfig>;
pub fn staging_testnet_config() -> ChainSpec {
let boot_nodes = vec![];
ChainSpec::from_genesis(
"Staging Testnet",
"staging_testnet",
"ChainX Staging Testnet",
"chainx_staging_testnet",
staging_testnet_config_genesis,
boot_nodes,
Some(STAGING_TELEMETRY_URL.into()),
Expand Down
3 changes: 2 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern crate substrate_finality_grandpa as grandpa;
#[macro_use]
extern crate substrate_service;
extern crate chainx_executor;
extern crate substrate_inherents as inherents;
extern crate substrate_rpc_servers as rpc;

#[macro_use]
Expand Down Expand Up @@ -129,7 +130,7 @@ where
// config.roles = ServiceRoles::AUTHORITY;
// }
// }
match cli::execute_default::<service::Factory, _>(spec, exit, &matches, &config, &version)? {
match cli::execute_default::<service::Factory, _>(spec, exit, &matches, &config)? {
cli::Action::ExecutedInternally => (),
cli::Action::RunService(exit) => {
info!("ChainX");
Expand Down
33 changes: 18 additions & 15 deletions cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
use chainx_executor;
use chainx_primitives::{Block, InherentData};
use chainx_primitives::Block;
use chainx_runtime::{GenesisConfig, RuntimeApi};
use client;
use consensus::{import_queue, start_aura, AuraImportQueue, NothingExtra, SlotDuration};
use grandpa;
use inherents::InherentDataProviders;
use primitives::ed25519::Pair;
use std::sync::Arc;
use std::time::Duration;
Expand All @@ -47,6 +48,7 @@ pub struct NodeConfig<F: substrate_service::ServiceFactory> {
Arc<grandpa::BlockImportForService<F>>,
grandpa::LinkHalfForService<F>,
)>,
inherent_data_providers: InherentDataProviders,
}

impl<F> Default for NodeConfig<F>
Expand All @@ -56,6 +58,7 @@ where
fn default() -> NodeConfig<F> {
NodeConfig {
grandpa_import_setup: None,
inherent_data_providers: InherentDataProviders::new(),
}
}
}
Expand Down Expand Up @@ -96,7 +99,8 @@ construct_service_factory! {
proposer,
service.network(),
service.on_exit(),
));
service.config.custom.inherent_data_providers.clone(),
)?);

info!("Running Grandpa session as Authority {}", key.public());
}
Expand All @@ -122,7 +126,6 @@ construct_service_factory! {
Self::Block,
grandpa::BlockImportForService<Self>,
NothingExtra,
::consensus::InherentProducingFn<InherentData>,
>
{ |config: &mut FactoryFullConfiguration<Self> , client: Arc<FullClient<Self>>| {
let slot_duration = SlotDuration::get_or_compute(&*client)?;
Expand All @@ -131,27 +134,27 @@ construct_service_factory! {

config.custom.grandpa_import_setup = Some((block_import.clone(), link_half));

Ok(import_queue(
import_queue(
slot_duration,
block_import,
NothingExtra,
::consensus::make_basic_inherent as _,
))
config.custom.inherent_data_providers.clone(),
).map_err(Into::into)
}},
LightImportQueue = AuraImportQueue<
Self::Block,
LightClient<Self>,
NothingExtra,
::consensus::InherentProducingFn<InherentData>,
>
{ |ref mut config, client: Arc<LightClient<Self>>|
Ok(import_queue(
SlotDuration::get_or_compute(&*client)?,
client,
NothingExtra,
::consensus::make_basic_inherent as _,
))
},
{ |config: &FactoryFullConfiguration<Self>, client: Arc<LightClient<Self>>| {
import_queue(
SlotDuration::get_or_compute(&*client)?,
client,
NothingExtra,
config.custom.inherent_data_providers.clone(),
).map_err(Into::into)
}
},
}
}

Expand Down
22 changes: 0 additions & 22 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,6 @@ use primitives::bytes;
use rstd::prelude::*;
use runtime_primitives::generic;
use runtime_primitives::traits::{self, BlakeTwo256};
pub use runtime_primitives::BasicInherentData as InherentData;

pub static mut LOCAL_KEY: Option<AccountId> = None;

pub fn set_blockproducer(producer: AccountId) {
unsafe {
LOCAL_KEY = Some(producer);
}
}

pub trait BlockProducer {
fn block_producer() -> Option<&'static AccountId> {
unsafe {
match LOCAL_KEY {
None => None,
Some(ref k) => Some(k),
}
}
}
}

impl BlockProducer for InherentData {}

/// Signature on candidate's block data by a collator.
pub type CandidateSignature = ::runtime_primitives::Ed25519Signature;
Expand Down
17 changes: 10 additions & 7 deletions rpc/src/chainx/impl_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ where
B: client::backend::Backend<Block, Blake2Hasher> + Send + Sync + 'static,
E: client::CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync + 'static,
Block: BlockT<Hash = H256> + 'static,
RA: Metadata<Block> + XAssetsApi<Block> + XMiningApi<Block>,
RA: std::marker::Send + std::marker::Sync + 'static,
Client<B, E, Block, RA>: ProvideRuntimeApi,
<Client<B, E, Block, RA> as ProvideRuntimeApi>::Api:
Metadata<Block> + XAssetsApi<Block> + XMiningApi<Block>,
{
fn block_info(&self, number: Trailing<NumberFor<Block>>) -> Result<Option<SignedBlock<Block>>> {
let hash = match number.into() {
Expand Down Expand Up @@ -218,7 +221,7 @@ where
let b = self.best_number()?;
self.client
.runtime_api()
.verify_address(&b, &token, &addr, &memo)
.verify_address(&b, token, addr, memo)
.and_then(|r| match r {
Ok(()) => Ok(None),
Err(s) => Ok(Some(String::from_utf8_lossy(s.as_ref()).into_owned())),
Expand All @@ -236,7 +239,7 @@ where
let b = self.best_number()?;
self.client
.runtime_api()
.minimal_withdrawal_value(&b, &token)
.minimal_withdrawal_value(&b, token)
.map_err(|e| e.into())
}

Expand All @@ -252,7 +255,7 @@ where
let list: Result<Vec<xrecords::Application<AccountId, Balance, Timestamp>>> = self
.client
.runtime_api()
.withdrawal_list_of(&best_number, c)
.withdrawal_list_of(&best_number, *c)
.map_err(|e| e.into());

let list = list?;
Expand All @@ -275,7 +278,7 @@ where
let list: Result<Vec<xrecords::Application<AccountId, Balance, Timestamp>>> = self
.client
.runtime_api()
.withdrawal_list_of(&b, c)
.withdrawal_list_of(&b, *c)
.map_err(|e| e.into());
let list = list?;
v.extend(list);
Expand Down Expand Up @@ -335,7 +338,7 @@ where
let jackpot_addr_list: Result<Vec<H256>> = self
.client
.runtime_api()
.multi_jackpot_accountid_for(&self.best_number()?, &intentions)
.multi_jackpot_accountid_for(&self.best_number()?, intentions.clone())
.map_err(|e| e.into());
let jackpot_addr_list: Vec<H256> = jackpot_addr_list?;

Expand Down Expand Up @@ -396,7 +399,7 @@ where
let jackpot_addr_list: Result<Vec<H256>> = self
.client
.runtime_api()
.multi_token_jackpot_accountid_for(&self.best_number()?, &tokens)
.multi_token_jackpot_accountid_for(&self.best_number()?, tokens.clone())
.map_err(|e| e.into());
let jackpot_addr_list: Vec<H256> = jackpot_addr_list?;

Expand Down
3 changes: 0 additions & 3 deletions rpc/src/chainx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use codec::Decode;
use jsonrpc_macros::Trailing;
use serde::Serialize;

use client::runtime_api::Core as CoreAPI;
use client::{self, runtime_api::Metadata, Client};
use keys::Address;
use primitives::storage::{StorageData, StorageKey};
Expand Down Expand Up @@ -120,7 +119,6 @@ where
B: client::backend::Backend<Block, Blake2Hasher>,
E: client::CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync,
Block: BlockT<Hash = H256>,
RA: CoreAPI<Block> + XAssetsApi<Block> + XMiningApi<Block>,
{
client: Arc<Client<B, E, Block, RA>>,
}
Expand All @@ -130,7 +128,6 @@ where
B: client::backend::Backend<Block, Blake2Hasher> + Send + Sync + 'static,
E: client::CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync,
Block: BlockT<Hash = H256> + 'static,
RA: Metadata<Block> + XAssetsApi<Block> + XMiningApi<Block>,
{
/// Create new ChainX API RPC handler.
pub fn new(client: Arc<Client<B, E, Block, RA>>) -> Self {
Expand Down
4 changes: 3 additions & 1 deletion rpc/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ where
Block: BlockT<Hash = H256> + 'static,
B: client::backend::Backend<Block, Blake2Hasher> + Send + Sync + 'static,
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + 'static + Clone,
RA: Metadata<Block>,
RA: Send + Sync + 'static,
Client<B, E, Block, RA>: ProvideRuntimeApi,
<Client<B, E, Block, RA> as ProvideRuntimeApi>::Api: Metadata<Block>,
{
type Metadata = ::metadata::Metadata;

Expand Down
Loading

0 comments on commit a100d80

Please sign in to comment.