Skip to content

Commit

Permalink
update substrate (paritytech#195)
Browse files Browse the repository at this point in the history
update substrate for ce83a74
  • Loading branch information
Aton committed Jan 11, 2019
1 parent f60266d commit 47221e6
Show file tree
Hide file tree
Showing 27 changed files with 774 additions and 655 deletions.
508 changes: 279 additions & 229 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ slog = "^2"
substrate-cli = { git = "https://github.com/chainpool/substrate" }
substrate-client = { git = "https://github.com/chainpool/substrate" }
substrate-primitives = { git = "https://github.com/chainpool/substrate" }
substrate-basic-authorship = { git = "https://github.com/chainpool/substrate" }
substrate-service = { git = "https://github.com/chainpool/substrate" }
substrate-transaction-pool = { git = "https://github.com/chainpool/substrate" }
substrate-network = { git = "https://github.com/chainpool/substrate" }
Expand Down
9 changes: 6 additions & 3 deletions cli/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ extern crate substrate_keyring;
extern crate substrate_primitives;

use self::base58::FromBase58;
use chainx_runtime::GrandpaConfig;
use chainx_runtime::xassets;
use chainx_runtime::GrandpaConfig;

use chainx_runtime::{
xassets::{Asset, Chain, ChainT},
Expand All @@ -18,7 +18,7 @@ use chainx_runtime::{
use chainx_runtime::{
BalancesConfig, ConsensusConfig, GenesisConfig, Params, Perbill, Permill, SessionConfig,
TimestampConfig, XAccountsConfig, XAssetsConfig, XBridgeOfBTCConfig, XFeeManagerConfig,
XSpotConfig, XStakingConfig, XSystemConfig,
XSpotConfig, XStakingConfig, XSystemConfig,
};

use ed25519;
Expand Down Expand Up @@ -75,7 +75,10 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
transfer_fee: 0,
creation_fee: 0,
reclaim_rebate: 0,
balances: vec![(Keyring::Alice.to_raw_public().into(), 1_000_000_000),(Keyring::Bob.to_raw_public().into(), 1_000_000_000)],
balances: vec![
(Keyring::Alice.to_raw_public().into(), 1_000_000_000),
(Keyring::Bob.to_raw_public().into(), 1_000_000_000),
],
};
//let balances_config_copy = BalancesConfigCopy::create_from_src(&balances_config).src();

Expand Down
21 changes: 9 additions & 12 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,15 @@ where
let (spec, mut config) =
cli::parse_matches::<service::Factory, _>(load_spec, version, "chainx-node", &matches)?;

if cfg!(feature = "msgbus-redis") == false {
if matches.is_present("grandpa_authority_only") {
config.custom.grandpa_authority = true;
config.custom.grandpa_authority_only = true;
// Authority Setup is only called if validator is set as true
config.roles = ServiceRoles::AUTHORITY;
} else if matches.is_present("grandpa_authority") {
config.custom.grandpa_authority = true;
// Authority Setup is only called if validator is set as true
config.roles = ServiceRoles::AUTHORITY;
}
}
// if cfg!(feature = "msgbus-redis") == false {
// if matches.is_present("grandpa_authority_only") {
// // Authority Setup is only called if validator is set as true
// config.roles = ServiceRoles::AUTHORITY;
// } else if matches.is_present("grandpa_authority") {
// // Authority Setup is only called if validator is set as true
// config.roles = ServiceRoles::AUTHORITY;
// }
// }
match cli::execute_default::<service::Factory, _>(spec, exit, &matches, &config)? {
cli::Action::ExecutedInternally => (),
cli::Action::RunService(exit) => {
Expand Down
37 changes: 7 additions & 30 deletions cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ construct_simple_protocol! {

/// Node specific configuration
pub struct NodeConfig<F: substrate_service::ServiceFactory> {
/// should run as a grandpa authority
pub grandpa_authority: bool,
/// should run as a grandpa authority only, don't validate as usual
pub grandpa_authority_only: bool,
/// grandpa connection to import block
// FIXME: rather than putting this on the config, let's have an actual intermediate setup state
// https://github.com/paritytech/substrate/issues/1134
Expand All @@ -59,8 +55,6 @@ where
{
fn default() -> NodeConfig<F> {
NodeConfig {
grandpa_authority: false,
grandpa_authority_only: false,
grandpa_import_setup: None,
}
}
Expand All @@ -82,16 +76,13 @@ construct_service_factory! {
{ |config: FactoryFullConfiguration<Self>, executor: TaskExecutor|
FullComponents::<Factory>::new(config, executor) },
AuthoritySetup = {
|mut service: Self::FullService, executor: TaskExecutor, key: Option<Arc<Pair>>| {
|mut service: Self::FullService, executor: TaskExecutor, local_key: Option<Arc<Pair>>| {
let (block_import, link_half) = service.config.custom.grandpa_import_setup.take()
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");

let mut producer = None;

let local_key = if let Some(key) = key {
if !service.config.custom.grandpa_authority_only {
if let Some(ref key) = local_key {
info!("Using authority key {}", key.public());
let proposer = Arc::new(substrate_service::ProposerFactory {
let proposer = Arc::new(substrate_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
});
Expand All @@ -104,36 +95,22 @@ construct_service_factory! {
block_import.clone(),
proposer,
service.network(),
service.on_exit(),
));

producer = Some(key.clone());
}

if service.config.custom.grandpa_authority {
info!("Running Grandpa session as Authority {}", key.public());
Some(key)
} else {
None
}
} else {
None
};

if let Some(ref k) = producer {
set_blockproducer(k.public().0.into());
}

let voter = grandpa::run_grandpa(
executor.spawn(grandpa::run_grandpa(
grandpa::Config {
local_key,
gossip_duration: Duration::new(4, 0), // FIXME: make this available through chainspec?
name: Some(service.config.name.clone())
},
link_half,
grandpa::NetworkBridge::new(service.network()),
)?;

executor.spawn(voter);
service.on_exit(),
)?);

Ok(service)
}
Expand Down
2 changes: 1 addition & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ serde_derive = { version = "1.0", optional = true }
parity-codec = { version = "2.0", default-features = false }
parity-codec-derive = { version = "2.0", default-features = false }
substrate-primitives = { git = "https://github.com/chainpool/substrate", default_features = false }
sr-std = { git = "https://github.com/chainpool/substrate/", default_features = false }
sr-std = { git = "https://github.com/chainpool/substrate", default_features = false }
sr-primitives = { git = "https://github.com/chainpool/substrate", default_features = false }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub type CandidateSignature = ::runtime_primitives::Ed25519Signature;

/// The Ed25519 pub key of an session that belongs to an authority of the relay chain. This is
/// exactly equivalent to what the substrate calls an "authority".
pub type SessionKey = primitives::AuthorityId;
pub type SessionKey = primitives::Ed25519AuthorityId;

/// A hash of some data used by the relay chain.
pub type Hash = primitives::H256;
Expand Down
5 changes: 2 additions & 3 deletions rpc-servers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ pub fn rpc_handler<Block: BlockT, ExHash, S, C, A, Y>(
where
Block: BlockT + 'static,
ExHash: Send + Sync + 'static + sr_primitives::Serialize + sr_primitives::DeserializeOwned,
SignedBlock<Block>: serde::Serialize + sr_primitives::DeserializeOwned,
S: apis::state::StateApi<Block::Hash, Metadata = Metadata>,
C: apis::chain::ChainApi<
NumberFor<Block>,
Block::Hash,
Block::Header,
NumberFor<Block>,
SignedBlock<Block>,
Metadata = Metadata,
>,
A: apis::author::AuthorApi<ExHash, Block::Hash, Metadata = Metadata>,
Y: apis::system::SystemApi,
Y: apis::system::SystemApi<Block::Hash, NumberFor<Block>>,
{
let mut io = pubsub::PubSubHandler::default();
io.extend_with(state.to_delegate());
Expand Down
8 changes: 6 additions & 2 deletions rpc/src/author/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ build_rpc_trait! {

/// Unsubscribe from extrinsic watching.
#[rpc(name = "author_unwatchExtrinsic")]
fn unwatch_extrinsic(&self, Self::Metadata, SubscriptionId) -> Result<bool>;
fn unwatch_extrinsic(&self, Option<Self::Metadata>, SubscriptionId) -> Result<bool>;
}

}
Expand Down Expand Up @@ -162,7 +162,11 @@ where
})
}

fn unwatch_extrinsic(&self, _metadata: Self::Metadata, id: SubscriptionId) -> Result<bool> {
fn unwatch_extrinsic(
&self,
_metadata: Option<Self::Metadata>,
id: SubscriptionId,
) -> Result<bool> {
Ok(self.subscriptions.cancel(id))
}
}
16 changes: 10 additions & 6 deletions rpc/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use rpc::futures::{stream, Future, Sink, Stream};
use rpc::Result as RpcResult;
use runtime_primitives::generic::{BlockId, SignedBlock};
use runtime_primitives::traits::{Block as BlockT, Header, NumberFor};
use serde::Serialize;

use subscriptions::Subscriptions;

Expand All @@ -37,7 +38,10 @@ use self::error::Result;

build_rpc_trait! {
/// Substrate blockchain API
pub trait ChainApi<Hash, Header, Number, SignedBlock> {
pub trait ChainApi<Number, Hash> where
Header: Serialize,
SignedBlock: Serialize,
{
type Metadata;

/// Get header of a relay chain block.
Expand Down Expand Up @@ -65,7 +69,7 @@ build_rpc_trait! {

/// Unsubscribe from new head subscription.
#[rpc(name = "chain_unsubscribeNewHead", alias = ["unsubscribe_newHead", ])]
fn unsubscribe_new_head(&self, Self::Metadata, SubscriptionId) -> RpcResult<bool>;
fn unsubscribe_new_head(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
}

#[pubsub(name = "chain_finalisedHead")] {
Expand All @@ -75,7 +79,7 @@ build_rpc_trait! {

/// Unsubscribe from new head subscription.
#[rpc(name = "chain_unsubscribeFinalisedHeads")]
fn unsubscribe_finalised_heads(&self, Self::Metadata, SubscriptionId) -> RpcResult<bool>;
fn unsubscribe_finalised_heads(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
}
}
}
Expand Down Expand Up @@ -145,7 +149,7 @@ where
}
}

impl<B, E, Block, RA> ChainApi<Block::Hash, Block::Header, NumberFor<Block>, SignedBlock<Block>>
impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>>
for Chain<B, E, Block, RA>
where
Block: BlockT<Hash = H256> + 'static,
Expand Down Expand Up @@ -198,7 +202,7 @@ where

fn unsubscribe_new_head(
&self,
_metadata: Self::Metadata,
_metadata: Option<Self::Metadata>,
id: SubscriptionId,
) -> RpcResult<bool> {
Ok(self.subscriptions.cancel(id))
Expand All @@ -222,7 +226,7 @@ where

fn unsubscribe_finalised_heads(
&self,
_metadata: Self::Metadata,
_metadata: Option<Self::Metadata>,
id: SubscriptionId,
) -> RpcResult<bool> {
Ok(self.subscriptions.cancel(id))
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern crate jsonrpc_core as rpc;
extern crate jsonrpc_pubsub;
extern crate parity_codec as codec;
extern crate parking_lot;
extern crate serde;
extern crate serde_json;
extern crate sr_primitives as runtime_primitives;
extern crate sr_version as runtime_version;
Expand All @@ -37,7 +38,6 @@ extern crate error_chain;
extern crate jsonrpc_macros;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;

#[cfg(test)]
Expand Down
15 changes: 9 additions & 6 deletions rpc/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ build_rpc_trait! {

/// Unsubscribe from runtime version subscription
#[rpc(name = "state_unsubscribeRuntimeVersion", alias = ["chain_unsubscribeRuntimeVersion", ])]
fn unsubscribe_runtime_version(&self, Self::Metadata, SubscriptionId) -> RpcResult<bool>;
fn unsubscribe_runtime_version(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
}

#[pubsub(name = "state_storage")] {
Expand All @@ -92,7 +92,7 @@ build_rpc_trait! {

/// Unsubscribe from storage subscription
#[rpc(name = "state_unsubscribeStorage")]
fn unsubscribe_storage(&self, Self::Metadata, SubscriptionId) -> RpcResult<bool>;
fn unsubscribe_storage(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
}
}
}
Expand Down Expand Up @@ -141,8 +141,7 @@ where
let return_data = self
.client
.executor()
.call(&BlockId::Hash(block), &method, &data.0)?
.return_data;
.call(&BlockId::Hash(block), &method, &data.0)?;
Ok(Bytes(return_data))
}

Expand Down Expand Up @@ -316,7 +315,11 @@ where
})
}

fn unsubscribe_storage(&self, _meta: Self::Metadata, id: SubscriptionId) -> RpcResult<bool> {
fn unsubscribe_storage(
&self,
_meta: Option<Self::Metadata>,
id: SubscriptionId,
) -> RpcResult<bool> {
Ok(self.subscriptions.cancel(id))
}

Expand Down Expand Up @@ -375,7 +378,7 @@ where

fn unsubscribe_runtime_version(
&self,
_meta: Self::Metadata,
_meta: Option<Self::Metadata>,
id: SubscriptionId,
) -> RpcResult<bool> {
Ok(self.subscriptions.cancel(id))
Expand Down
19 changes: 19 additions & 0 deletions rpc/src/system/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ pub struct Health {
pub peers: usize,
/// Is the node syncing
pub is_syncing: bool,
/// Should this node have any peers
pub should_have_peers: bool,
}

/// Network Peer information
#[derive(Debug, PartialEq, Serialize)]
pub struct PeerInfo<Hash, Number> {
/// Peer Node Index
pub index: usize,
/// Peer ID
pub peer_id: String,
/// Roles
pub roles: String,
/// Protocol version
pub protocol_version: u32,
/// Peer best block hash
pub best_hash: Hash,
/// Peer best block number
pub best_number: Number,
}

impl fmt::Display for Health {
Expand Down
Loading

0 comments on commit 47221e6

Please sign in to comment.