Skip to content

Commit 47221e6

Browse files
author
Aton
authored
update substrate (paritytech#195)
update substrate for ce83a74
1 parent f60266d commit 47221e6

File tree

27 files changed

+774
-655
lines changed

27 files changed

+774
-655
lines changed

Cargo.lock

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

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ slog = "^2"
1414
substrate-cli = { git = "https://github.com/chainpool/substrate" }
1515
substrate-client = { git = "https://github.com/chainpool/substrate" }
1616
substrate-primitives = { git = "https://github.com/chainpool/substrate" }
17+
substrate-basic-authorship = { git = "https://github.com/chainpool/substrate" }
1718
substrate-service = { git = "https://github.com/chainpool/substrate" }
1819
substrate-transaction-pool = { git = "https://github.com/chainpool/substrate" }
1920
substrate-network = { git = "https://github.com/chainpool/substrate" }

cli/src/genesis_config.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ extern crate substrate_keyring;
88
extern crate substrate_primitives;
99

1010
use self::base58::FromBase58;
11-
use chainx_runtime::GrandpaConfig;
1211
use chainx_runtime::xassets;
12+
use chainx_runtime::GrandpaConfig;
1313

1414
use chainx_runtime::{
1515
xassets::{Asset, Chain, ChainT},
@@ -18,7 +18,7 @@ use chainx_runtime::{
1818
use chainx_runtime::{
1919
BalancesConfig, ConsensusConfig, GenesisConfig, Params, Perbill, Permill, SessionConfig,
2020
TimestampConfig, XAccountsConfig, XAssetsConfig, XBridgeOfBTCConfig, XFeeManagerConfig,
21-
XSpotConfig, XStakingConfig, XSystemConfig,
21+
XSpotConfig, XStakingConfig, XSystemConfig,
2222
};
2323

2424
use ed25519;
@@ -75,7 +75,10 @@ pub fn testnet_genesis(genesis_spec: GenesisSpec) -> GenesisConfig {
7575
transfer_fee: 0,
7676
creation_fee: 0,
7777
reclaim_rebate: 0,
78-
balances: vec![(Keyring::Alice.to_raw_public().into(), 1_000_000_000),(Keyring::Bob.to_raw_public().into(), 1_000_000_000)],
78+
balances: vec![
79+
(Keyring::Alice.to_raw_public().into(), 1_000_000_000),
80+
(Keyring::Bob.to_raw_public().into(), 1_000_000_000),
81+
],
7982
};
8083
//let balances_config_copy = BalancesConfigCopy::create_from_src(&balances_config).src();
8184

cli/src/lib.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,15 @@ where
121121
let (spec, mut config) =
122122
cli::parse_matches::<service::Factory, _>(load_spec, version, "chainx-node", &matches)?;
123123

124-
if cfg!(feature = "msgbus-redis") == false {
125-
if matches.is_present("grandpa_authority_only") {
126-
config.custom.grandpa_authority = true;
127-
config.custom.grandpa_authority_only = true;
128-
// Authority Setup is only called if validator is set as true
129-
config.roles = ServiceRoles::AUTHORITY;
130-
} else if matches.is_present("grandpa_authority") {
131-
config.custom.grandpa_authority = true;
132-
// Authority Setup is only called if validator is set as true
133-
config.roles = ServiceRoles::AUTHORITY;
134-
}
135-
}
124+
// if cfg!(feature = "msgbus-redis") == false {
125+
// if matches.is_present("grandpa_authority_only") {
126+
// // Authority Setup is only called if validator is set as true
127+
// config.roles = ServiceRoles::AUTHORITY;
128+
// } else if matches.is_present("grandpa_authority") {
129+
// // Authority Setup is only called if validator is set as true
130+
// config.roles = ServiceRoles::AUTHORITY;
131+
// }
132+
// }
136133
match cli::execute_default::<service::Factory, _>(spec, exit, &matches, &config)? {
137134
cli::Action::ExecutedInternally => (),
138135
cli::Action::RunService(exit) => {

cli/src/service.rs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ construct_simple_protocol! {
4040

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

89-
let mut producer = None;
90-
91-
let local_key = if let Some(key) = key {
92-
if !service.config.custom.grandpa_authority_only {
83+
if let Some(ref key) = local_key {
9384
info!("Using authority key {}", key.public());
94-
let proposer = Arc::new(substrate_service::ProposerFactory {
85+
let proposer = Arc::new(substrate_basic_authorship::ProposerFactory {
9586
client: service.client(),
9687
transaction_pool: service.transaction_pool(),
9788
});
@@ -104,36 +95,22 @@ construct_service_factory! {
10495
block_import.clone(),
10596
proposer,
10697
service.network(),
98+
service.on_exit(),
10799
));
108100

109-
producer = Some(key.clone());
110-
}
111-
112-
if service.config.custom.grandpa_authority {
113101
info!("Running Grandpa session as Authority {}", key.public());
114-
Some(key)
115-
} else {
116-
None
117102
}
118-
} else {
119-
None
120-
};
121103

122-
if let Some(ref k) = producer {
123-
set_blockproducer(k.public().0.into());
124-
}
125-
126-
let voter = grandpa::run_grandpa(
104+
executor.spawn(grandpa::run_grandpa(
127105
grandpa::Config {
128106
local_key,
129107
gossip_duration: Duration::new(4, 0), // FIXME: make this available through chainspec?
130108
name: Some(service.config.name.clone())
131109
},
132110
link_half,
133111
grandpa::NetworkBridge::new(service.network()),
134-
)?;
135-
136-
executor.spawn(voter);
112+
service.on_exit(),
113+
)?);
137114

138115
Ok(service)
139116
}

primitives/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ serde_derive = { version = "1.0", optional = true }
99
parity-codec = { version = "2.0", default-features = false }
1010
parity-codec-derive = { version = "2.0", default-features = false }
1111
substrate-primitives = { git = "https://github.com/chainpool/substrate", default_features = false }
12-
sr-std = { git = "https://github.com/chainpool/substrate/", default_features = false }
12+
sr-std = { git = "https://github.com/chainpool/substrate", default_features = false }
1313
sr-primitives = { git = "https://github.com/chainpool/substrate", default_features = false }
1414

1515
[dev-dependencies]

primitives/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub type CandidateSignature = ::runtime_primitives::Ed25519Signature;
5454

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

5959
/// A hash of some data used by the relay chain.
6060
pub type Hash = primitives::H256;

rpc-servers/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,16 @@ pub fn rpc_handler<Block: BlockT, ExHash, S, C, A, Y>(
5252
where
5353
Block: BlockT + 'static,
5454
ExHash: Send + Sync + 'static + sr_primitives::Serialize + sr_primitives::DeserializeOwned,
55-
SignedBlock<Block>: serde::Serialize + sr_primitives::DeserializeOwned,
5655
S: apis::state::StateApi<Block::Hash, Metadata = Metadata>,
5756
C: apis::chain::ChainApi<
57+
NumberFor<Block>,
5858
Block::Hash,
5959
Block::Header,
60-
NumberFor<Block>,
6160
SignedBlock<Block>,
6261
Metadata = Metadata,
6362
>,
6463
A: apis::author::AuthorApi<ExHash, Block::Hash, Metadata = Metadata>,
65-
Y: apis::system::SystemApi,
64+
Y: apis::system::SystemApi<Block::Hash, NumberFor<Block>>,
6665
{
6766
let mut io = pubsub::PubSubHandler::default();
6867
io.extend_with(state.to_delegate());

rpc/src/author/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ build_rpc_trait! {
5757

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

6363
}
@@ -162,7 +162,11 @@ where
162162
})
163163
}
164164

165-
fn unwatch_extrinsic(&self, _metadata: Self::Metadata, id: SubscriptionId) -> Result<bool> {
165+
fn unwatch_extrinsic(
166+
&self,
167+
_metadata: Option<Self::Metadata>,
168+
id: SubscriptionId,
169+
) -> Result<bool> {
166170
Ok(self.subscriptions.cancel(id))
167171
}
168172
}

rpc/src/chain/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rpc::futures::{stream, Future, Sink, Stream};
2626
use rpc::Result as RpcResult;
2727
use runtime_primitives::generic::{BlockId, SignedBlock};
2828
use runtime_primitives::traits::{Block as BlockT, Header, NumberFor};
29+
use serde::Serialize;
2930

3031
use subscriptions::Subscriptions;
3132

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

3839
build_rpc_trait! {
3940
/// Substrate blockchain API
40-
pub trait ChainApi<Hash, Header, Number, SignedBlock> {
41+
pub trait ChainApi<Number, Hash> where
42+
Header: Serialize,
43+
SignedBlock: Serialize,
44+
{
4145
type Metadata;
4246

4347
/// Get header of a relay chain block.
@@ -65,7 +69,7 @@ build_rpc_trait! {
6569

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

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

7680
/// Unsubscribe from new head subscription.
7781
#[rpc(name = "chain_unsubscribeFinalisedHeads")]
78-
fn unsubscribe_finalised_heads(&self, Self::Metadata, SubscriptionId) -> RpcResult<bool>;
82+
fn unsubscribe_finalised_heads(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
7983
}
8084
}
8185
}
@@ -145,7 +149,7 @@ where
145149
}
146150
}
147151

148-
impl<B, E, Block, RA> ChainApi<Block::Hash, Block::Header, NumberFor<Block>, SignedBlock<Block>>
152+
impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>>
149153
for Chain<B, E, Block, RA>
150154
where
151155
Block: BlockT<Hash = H256> + 'static,
@@ -198,7 +202,7 @@ where
198202

199203
fn unsubscribe_new_head(
200204
&self,
201-
_metadata: Self::Metadata,
205+
_metadata: Option<Self::Metadata>,
202206
id: SubscriptionId,
203207
) -> RpcResult<bool> {
204208
Ok(self.subscriptions.cancel(id))
@@ -222,7 +226,7 @@ where
222226

223227
fn unsubscribe_finalised_heads(
224228
&self,
225-
_metadata: Self::Metadata,
229+
_metadata: Option<Self::Metadata>,
226230
id: SubscriptionId,
227231
) -> RpcResult<bool> {
228232
Ok(self.subscriptions.cancel(id))

rpc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern crate jsonrpc_core as rpc;
2222
extern crate jsonrpc_pubsub;
2323
extern crate parity_codec as codec;
2424
extern crate parking_lot;
25+
extern crate serde;
2526
extern crate serde_json;
2627
extern crate sr_primitives as runtime_primitives;
2728
extern crate sr_version as runtime_version;
@@ -37,7 +38,6 @@ extern crate error_chain;
3738
extern crate jsonrpc_macros;
3839
#[macro_use]
3940
extern crate log;
40-
#[macro_use]
4141
extern crate serde_derive;
4242

4343
#[cfg(test)]

rpc/src/state/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ build_rpc_trait! {
8282

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

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

9393
/// Unsubscribe from storage subscription
9494
#[rpc(name = "state_unsubscribeStorage")]
95-
fn unsubscribe_storage(&self, Self::Metadata, SubscriptionId) -> RpcResult<bool>;
95+
fn unsubscribe_storage(&self, Option<Self::Metadata>, SubscriptionId) -> RpcResult<bool>;
9696
}
9797
}
9898
}
@@ -141,8 +141,7 @@ where
141141
let return_data = self
142142
.client
143143
.executor()
144-
.call(&BlockId::Hash(block), &method, &data.0)?
145-
.return_data;
144+
.call(&BlockId::Hash(block), &method, &data.0)?;
146145
Ok(Bytes(return_data))
147146
}
148147

@@ -316,7 +315,11 @@ where
316315
})
317316
}
318317

319-
fn unsubscribe_storage(&self, _meta: Self::Metadata, id: SubscriptionId) -> RpcResult<bool> {
318+
fn unsubscribe_storage(
319+
&self,
320+
_meta: Option<Self::Metadata>,
321+
id: SubscriptionId,
322+
) -> RpcResult<bool> {
320323
Ok(self.subscriptions.cancel(id))
321324
}
322325

@@ -375,7 +378,7 @@ where
375378

376379
fn unsubscribe_runtime_version(
377380
&self,
378-
_meta: Self::Metadata,
381+
_meta: Option<Self::Metadata>,
379382
id: SubscriptionId,
380383
) -> RpcResult<bool> {
381384
Ok(self.subscriptions.cancel(id))

rpc/src/system/helpers.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ pub struct Health {
4343
pub peers: usize,
4444
/// Is the node syncing
4545
pub is_syncing: bool,
46+
/// Should this node have any peers
47+
pub should_have_peers: bool,
48+
}
49+
50+
/// Network Peer information
51+
#[derive(Debug, PartialEq, Serialize)]
52+
pub struct PeerInfo<Hash, Number> {
53+
/// Peer Node Index
54+
pub index: usize,
55+
/// Peer ID
56+
pub peer_id: String,
57+
/// Roles
58+
pub roles: String,
59+
/// Protocol version
60+
pub protocol_version: u32,
61+
/// Peer best block hash
62+
pub best_hash: Hash,
63+
/// Peer best block number
64+
pub best_number: Number,
4665
}
4766

4867
impl fmt::Display for Health {

0 commit comments

Comments
 (0)