Skip to content

Commit

Permalink
Update/substrate (paritytech#125)
Browse files Browse the repository at this point in the history
* add NetworkType for polkadot.js

* replace rc3 to rc4

* update XContracts to match rc4 Contracts

* update transaction-payment to rc4

* update runtime and cli crate
  • Loading branch information
atenjin authored Jul 2, 2020
1 parent 87a02ae commit a27bf19
Show file tree
Hide file tree
Showing 42 changed files with 1,350 additions and 1,666 deletions.
554 changes: 352 additions & 202 deletions Cargo.lock

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,32 @@ edition = "2018"

[dependencies]
futures = "0.3.4"
jsonrpc-core = "14.2.0"
log = "0.4.8"
parking_lot = "0.10.0"
structopt = "0.3.8"
log4rs = { version = "0.12", features = ["rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller"] }

# Substrate client
sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-cli = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-client-api = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-consensus-aura = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-executor = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-network = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-rpc = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-service = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-cli = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-client-api = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-consensus-aura = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-executor = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-network = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-rpc = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-service = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }

# Substrate primitives
sp-core = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-inherents = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-core = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-inherents = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }

chainx-primitives = { path = "../primitives" }
chainx-runtime = { path = "../runtime" }
Expand All @@ -41,4 +40,4 @@ chainx-rpc = { path = "../rpc" }
xpallet-protocol = { path = "../xpallets/protocol" }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
41 changes: 27 additions & 14 deletions cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ macro_rules! new_full_start {
($config:expr) => {{
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use std::sync::Arc;
type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;

let mut import_setup = None;
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
Expand Down Expand Up @@ -85,12 +84,25 @@ macro_rules! new_full_start {
Ok(import_queue)
},
)?
.with_rpc_extensions(|builder| -> std::result::Result<RpcExtension, _> {
let deps = chainx_rpc::FullDeps {
client: builder.client().clone(),
pool: builder.pool(),
};
Ok(chainx_rpc::create_full(deps))
.with_rpc_extensions_builder(|builder| {
// let grandpa_link = import_setup
// .as_ref()
// .map(|s| &s.1)
// .expect("GRANDPA LinkHalf is present for full services or set up failed; qed.");
// let shared_authority_set = grandpa_link.shared_authority_set().clone();
// let shared_voter_state = grandpa::SharedVoterState::empty();
//
// rpc_setup = Some((shared_voter_state.clone()));
let client = builder.client().clone();
let pool = builder.pool().clone();
Ok(move |deny_unsafe| {
let deps = chainx_rpc::FullDeps {
client: client.clone(),
pool: pool.clone(),
deny_unsafe,
};
chainx_rpc::create_full(deps)
})
})?;

(builder, import_setup, inherent_data_providers)
Expand All @@ -116,7 +128,7 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
})?
.build()?;
.build_full()?;

if role.is_authority() {
let proposer = sc_basic_authorship::ProposerFactory::new(
Expand Down Expand Up @@ -148,13 +160,15 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr

// the AURA authoring task is considered essential, i.e. if it
// fails we take down the service with it.
service.spawn_essential_task("aura", aura);
service
.spawn_essential_task_handle()
.spawn_blocking("aura", aura);
}

// 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 role.is_authority() {
Some(service.keystore())
Some(service.keystore() as sp_core::traits::BareCryptoStorePtr)
} else {
None
};
Expand Down Expand Up @@ -190,7 +204,7 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr

// the GRANDPA voter task is considered infallible, i.e.
// if it fails we take down the service with it.
service.spawn_essential_task(
service.spawn_essential_task_handle().spawn_blocking(
"grandpa-voter",
sc_finality_grandpa::run_grandpa_voter(grandpa_config)?,
);
Expand All @@ -207,7 +221,6 @@ pub fn new_full(config: Configuration) -> Result<impl AbstractService, ServiceEr

/// Builds a new service for a light client.
pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceError> {
type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
let inherent_data_providers = InherentDataProviders::new();

ServiceBuilder::new_light::<Block, RuntimeApi, Executor>(config)?
Expand Down Expand Up @@ -270,7 +283,7 @@ pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceE
let provider = client as Arc<dyn StorageAndProofProvider<_, _>>;
Ok(Arc::new(GrandpaFinalityProofProvider::new(backend, provider)) as _)
})?
.with_rpc_extensions(|builder| -> Result<RpcExtension, _> {
.with_rpc_extensions(|builder| {
let fetcher = builder
.fetcher()
.ok_or_else(|| "Trying to start node RPC without active fetcher")?;
Expand All @@ -286,5 +299,5 @@ pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceE
};
Ok(chainx_rpc::create_light(light_deps))
})?
.build()
.build_light()
}
6 changes: 6 additions & 0 deletions polkadotjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"Desc": "Text",
"Memo": "Text",
"AddrStr": "Text",
"NetworkType": {
"_enum": [
"Mainnet",
"Testnet"
]
},
"Chain": {
"_enum": [
"ChainX",
Expand Down
12 changes: 6 additions & 6 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ authors = ["ChainX community <https://www.chainx.org>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false }
serde = { version = "1.0.101", optional = true, features = ["derive"] }

# Substrate primitives
sp-application-crypto = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3", default-features = false }
sp-application-crypto = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }

# Substrate pallets
frame-system = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", default-features = false }

# ChainX pallets
xpallet-support = { path = "../xpallets/support", default-features = false }
Expand Down
24 changes: 13 additions & 11 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@ authors = ["ChainX community <https://www.chainx.org>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.3.1", features = ["derive"] }
hex = "0.4"
jsonrpc-core = "14.2.0"
jsonrpc-core-client = "14.2.0"
jsonrpc-derive = "14.2.1"
serde_json = "1.0"

# Substrate client
sc-client-api = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sc-service = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3", features = ["test-helpers"] }
sc-client-api = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sc-service = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4", features = ["test-helpers"] }
sc-rpc-api = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }

# Substrate primitives
sp-api = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-blockchain = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-state-machine = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
sp-api = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-blockchain = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-block-builder = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-state-machine = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }

# Substrate pallets
frame-support = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc3" }
frame-support = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate.git", tag = "v2.0.0-rc4" }

chainx-runtime = { path = "../runtime" }

Expand Down
16 changes: 13 additions & 3 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ use std::fmt;
use std::sync::Arc;

use sc_client_api::{backend::Backend, CallExecutor, StorageProvider};
use sc_rpc_api::DenyUnsafe;
use sc_service::client::Client;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_transaction_pool::TransactionPool;

use chainx_primitives::Block;
use chainx_runtime::{AccountId, Balance, BlockNumber, Index, UncheckedExtrinsic};
use chainx_runtime::{AccountId, Balance, BlockNumber, Hash, Index, UncheckedExtrinsic};

use apis::ChainXApi;
use impls::ChainXRpc;
Expand All @@ -41,6 +43,8 @@ pub struct FullDeps<P, BE, E, RA> {
pub client: Arc<Client<BE, E, Block, RA>>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
}

/// Instantiate all Full RPC extensions.
Expand All @@ -57,6 +61,7 @@ where
+ StorageProvider<Block, BE>
+ 'static,
Client<BE, E, Block, RA>: Send + Sync + 'static,
<Client<BE, E, Block, RA> as ProvideRuntimeApi<Block>>::Api: BlockBuilder<Block>,
<Client<BE, E, Block, RA> as ProvideRuntimeApi<Block>>::Api:
substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
<Client<BE, E, Block, RA> as ProvideRuntimeApi<Block>>::Api:
Expand All @@ -80,11 +85,16 @@ where
use xpallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};

let mut io = jsonrpc_core::IoHandler::default();
let FullDeps { client, pool } = deps;
let FullDeps {
client,
pool,
deny_unsafe,
} = deps;

io.extend_with(SystemApi::to_delegate(FullSystem::new(
client.clone(),
pool,
deny_unsafe,
)));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(
client.clone(),
Expand Down Expand Up @@ -112,7 +122,7 @@ where
fetcher,
} = deps;
let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(SystemApi::<AccountId, Index>::to_delegate(
io.extend_with(SystemApi::<Hash, AccountId, Index>::to_delegate(
LightSystem::new(client, remote_blockchain, fetcher, pool),
));

Expand Down
Loading

0 comments on commit a27bf19

Please sign in to comment.