Skip to content

Commit 5f78d73

Browse files
authored
Sync with Substrate + Release v0.14.0 (#58)
1 parent 7c6c301 commit 5f78d73

File tree

9 files changed

+1104
-1268
lines changed

9 files changed

+1104
-1268
lines changed

Cargo.lock

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

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ production deployment, but a great fit for development and testing:_
1515
[#42](https://github.com/paritytech/substrate-contracts-node/pull/42).
1616
Hereby blocks are authored immediately at every transaction, so there
1717
is none of the typical six seconds block time associated with `grandpa` or `aura`.
18-
* If no CLI arguments are passed the node is started in development mode
19-
by default.
18+
* _If no CLI arguments are passed the node is started in development mode
19+
by default._
20+
* _With each start of the node process the chain starts from genesis ‒ so no
21+
chain state is retained, all contracts will be lost! If you want to retain
22+
chain state you have to supply a `--base-path`._
2023

2124
If you are looking for a node suitable for production see these configurations:
2225

node/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "contracts-node"
3-
version = "0.13.0"
3+
version = "0.14.0"
44
authors = ["Parity Technologies <[email protected]>"]
55
description = "Substrate node configured for smart contracts via `pallet-contracts`."
66
edition = "2021"
@@ -40,7 +40,7 @@ frame-system = { git = "https://github.com/paritytech/substrate", package = "fra
4040
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", package = "pallet-transaction-payment" }
4141

4242
# These dependencies are used for the node's RPCs
43-
jsonrpc-core = "18.0.0"
43+
jsonrpsee = { version = "0.12.0", features = ["server"] }
4444
sc-rpc = { git = "https://github.com/paritytech/substrate", package = "sc-rpc" }
4545
sp-api = { git = "https://github.com/paritytech/substrate", package = "sp-api" }
4646
sc-rpc-api = { git = "https://github.com/paritytech/substrate", package = "sc-rpc-api" }

node/src/cli.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub enum Subcommand {
3636
/// Revert the chain to a previous state.
3737
Revert(sc_cli::RevertCmd),
3838

39-
/// The custom benchmark subcommand benchmarking runtime pallets.
39+
/// Sub-commands concerned with benchmarking.
4040
#[clap(subcommand)]
4141
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
4242

@@ -47,4 +47,7 @@ pub enum Subcommand {
4747
/// Try some command against runtime state. Note: `try-runtime` feature must be enabled.
4848
#[cfg(not(feature = "try-runtime"))]
4949
TryRuntime,
50+
51+
/// Db meta columns information.
52+
ChainInfo(sc_cli::ChainInfoCmd),
5053
}

node/src/command.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
service::ExecutorDispatch,
77
};
88
use contracts_node_runtime::Block;
9-
use frame_benchmarking_cli::BenchmarkCmd;
9+
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
1010
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
1111
use sc_service::PartialComponents;
1212
use std::sync::Arc;
@@ -138,7 +138,8 @@ pub fn run() -> sc_cli::Result<()> {
138138

139139
cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder))
140140
},
141-
BenchmarkCmd::Machine(cmd) => cmd.run(&config),
141+
BenchmarkCmd::Machine(cmd) =>
142+
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()),
142143
}
143144
})
144145
},
@@ -159,6 +160,10 @@ pub fn run() -> sc_cli::Result<()> {
159160
Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \
160161
You can enable it with `--features try-runtime`."
161162
.into()),
163+
Some(Subcommand::ChainInfo(cmd)) => {
164+
let runner = cli.create_runner(cmd)?;
165+
runner.sync_run(|config| cmd.run::<Block>(&config))
166+
},
162167
None => {
163168
let runner = cli.create_runner(&cli.run)?;
164169
runner.run_node_until_exit(|config| async move {

node/src/rpc.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
use std::sync::Arc;
99

1010
use contracts_node_runtime::{opaque::Block, AccountId, Balance, BlockNumber, Hash, Index};
11-
use pallet_contracts_rpc::{Contracts, ContractsApi};
12-
pub use sc_rpc_api::DenyUnsafe;
11+
use jsonrpsee::RpcModule;
1312
use sc_transaction_pool_api::TransactionPool;
1413
use sp_api::ProvideRuntimeApi;
1514
use sp_block_builder::BlockBuilder;
1615
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
1716

17+
pub use sc_rpc_api::DenyUnsafe;
18+
1819
/// Full client dependencies.
1920
pub struct FullDeps<C, P> {
2021
/// The client instance to use.
@@ -26,7 +27,9 @@ pub struct FullDeps<C, P> {
2627
}
2728

2829
/// Instantiate all full RPC extensions.
29-
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> jsonrpc_core::IoHandler<sc_rpc::Metadata>
30+
pub fn create_full<C, P>(
31+
deps: FullDeps<C, P>,
32+
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
3033
where
3134
C: ProvideRuntimeApi<Block>,
3235
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
@@ -37,23 +40,23 @@ where
3740
C::Api: BlockBuilder<Block>,
3841
P: TransactionPool + 'static,
3942
{
40-
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
41-
use substrate_frame_rpc_system::{FullSystem, SystemApi};
43+
use pallet_contracts_rpc::{ContractsApiServer, ContractsRpc};
44+
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
45+
use substrate_frame_rpc_system::{SystemApiServer, SystemRpc};
4246

43-
let mut io = jsonrpc_core::IoHandler::default();
47+
let mut module = RpcModule::new(());
4448
let FullDeps { client, pool, deny_unsafe } = deps;
4549

46-
io.extend_with(SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe)));
47-
48-
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));
50+
module.merge(SystemRpc::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
51+
module.merge(TransactionPaymentRpc::new(client.clone()).into_rpc())?;
4952

5053
// Extend this RPC with a custom API by using the following syntax.
5154
// `YourRpcStruct` should have a reference to a client, which is needed
5255
// to call into the runtime.
53-
// `io.extend_with(YourRpcTrait::to_delegate(YourRpcStruct::new(ReferenceToClient, ...)));`
56+
// `module.merge(YourRpcTrait::into_rpc(YourRpcStruct::new(ReferenceToClient, ...)))?;`
5457

5558
// Contracts RPC API extension
56-
io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));
59+
module.merge(ContractsRpc::new(client.clone()).into_rpc())?;
5760

58-
io
61+
Ok(module)
5962
}

node/src/service.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn new_partial(
6969

7070
let (client, backend, keystore_container, task_manager) =
7171
sc_service::new_full_parts::<Block, RuntimeApi, _>(
72-
&config,
72+
config,
7373
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
7474
executor,
7575
)?;
@@ -166,8 +166,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
166166
Box::new(move |deny_unsafe, _| {
167167
let deps =
168168
crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe };
169-
170-
Ok(crate::rpc::create_full(deps))
169+
crate::rpc::create_full(deps).map_err(Into::into)
171170
})
172171
};
173172
let prometheus_registry = config.prometheus_registry().cloned();
@@ -178,7 +177,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
178177
keystore: keystore_container.sync_keystore(),
179178
task_manager: &mut task_manager,
180179
transaction_pool: transaction_pool.clone(),
181-
rpc_extensions_builder,
180+
rpc_builder: rpc_extensions_builder,
182181
backend,
183182
system_rpc_tx,
184183
config,

runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "contracts-node-runtime"
3-
version = "0.13.0"
3+
version = "0.14.0"
44
authors = ["Parity Technologies <[email protected]>"]
55
edition = "2021"
66
license = "Unlicense"

runtime/src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#[cfg(feature = "std")]
77
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
88

9-
use frame_support::weights::DispatchClass;
9+
use frame_support::{traits::OnRuntimeUpgrade, weights::DispatchClass};
1010
use frame_system::limits::{BlockLength, BlockWeights};
11-
use pallet_contracts::weights::WeightInfo;
11+
use pallet_contracts::{migration, weights::WeightInfo, DefaultContractAccessWeight};
1212
use sp_api::impl_runtime_apis;
1313
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
1414
use sp_runtime::{
@@ -127,8 +127,8 @@ const fn deposit(items: u32, bytes: u32) -> Balance {
127127
}
128128

129129
parameter_types! {
130-
pub const Version: RuntimeVersion = VERSION;
131130
pub const BlockHashCount: BlockNumber = 2400;
131+
pub const Version: RuntimeVersion = VERSION;
132132

133133
// This part is copied from Substrate's `bin/node/runtime/src/lib.rs`.
134134
// The `RuntimeBlockLength` and `RuntimeBlockWeights` exist here because the
@@ -322,6 +322,14 @@ impl pallet_contracts::Config for Runtime {
322322
type Schedule = Schedule;
323323
type CallStack = [pallet_contracts::Frame<Self>; 31];
324324
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
325+
type ContractAccessWeight = DefaultContractAccessWeight<RuntimeBlockWeights>;
326+
}
327+
328+
pub struct Migrations;
329+
impl OnRuntimeUpgrade for Migrations {
330+
fn on_runtime_upgrade() -> Weight {
331+
migration::migrate::<Runtime>()
332+
}
325333
}
326334

327335
// Create the runtime by composing the FRAME pallets that were previously configured.
@@ -370,6 +378,7 @@ pub type Executive = frame_executive::Executive<
370378
frame_system::ChainContext<Runtime>,
371379
Runtime,
372380
AllPalletsWithSystem,
381+
Migrations,
373382
>;
374383

375384
impl_runtime_apis! {
@@ -483,7 +492,7 @@ impl_runtime_apis! {
483492

484493
let storage_info = AllPalletsWithSystem::storage_info();
485494

486-
return (list, storage_info)
495+
(list, storage_info)
487496
}
488497

489498
fn dispatch_benchmark(

0 commit comments

Comments
 (0)