Skip to content

Commit

Permalink
Sync with Substrate + Release v0.14.0 (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi authored May 11, 2022
1 parent 7c6c301 commit 5f78d73
Show file tree
Hide file tree
Showing 9 changed files with 1,104 additions and 1,268 deletions.
2,294 changes: 1,054 additions & 1,240 deletions Cargo.lock

Large diffs are not rendered by default.

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

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

Expand Down
4 changes: 2 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "contracts-node"
version = "0.13.0"
version = "0.14.0"
authors = ["Parity Technologies <[email protected]>"]
description = "Substrate node configured for smart contracts via `pallet-contracts`."
edition = "2021"
Expand Down Expand Up @@ -40,7 +40,7 @@ frame-system = { git = "https://github.com/paritytech/substrate", package = "fra
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", package = "pallet-transaction-payment" }

# These dependencies are used for the node's RPCs
jsonrpc-core = "18.0.0"
jsonrpsee = { version = "0.12.0", features = ["server"] }
sc-rpc = { git = "https://github.com/paritytech/substrate", package = "sc-rpc" }
sp-api = { git = "https://github.com/paritytech/substrate", package = "sp-api" }
sc-rpc-api = { git = "https://github.com/paritytech/substrate", package = "sc-rpc-api" }
Expand Down
5 changes: 4 additions & 1 deletion node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum Subcommand {
/// Revert the chain to a previous state.
Revert(sc_cli::RevertCmd),

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

Expand All @@ -47,4 +47,7 @@ pub enum Subcommand {
/// Try some command against runtime state. Note: `try-runtime` feature must be enabled.
#[cfg(not(feature = "try-runtime"))]
TryRuntime,

/// Db meta columns information.
ChainInfo(sc_cli::ChainInfoCmd),
}
9 changes: 7 additions & 2 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
service::ExecutorDispatch,
};
use contracts_node_runtime::Block;
use frame_benchmarking_cli::BenchmarkCmd;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
use sc_service::PartialComponents;
use std::sync::Arc;
Expand Down Expand Up @@ -138,7 +138,8 @@ pub fn run() -> sc_cli::Result<()> {

cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder))
},
BenchmarkCmd::Machine(cmd) => cmd.run(&config),
BenchmarkCmd::Machine(cmd) =>
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()),
}
})
},
Expand All @@ -159,6 +160,10 @@ pub fn run() -> sc_cli::Result<()> {
Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \
You can enable it with `--features try-runtime`."
.into()),
Some(Subcommand::ChainInfo(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run::<Block>(&config))
},
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| async move {
Expand Down
27 changes: 15 additions & 12 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
use std::sync::Arc;

use contracts_node_runtime::{opaque::Block, AccountId, Balance, BlockNumber, Hash, Index};
use pallet_contracts_rpc::{Contracts, ContractsApi};
pub use sc_rpc_api::DenyUnsafe;
use jsonrpsee::RpcModule;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};

pub use sc_rpc_api::DenyUnsafe;

/// Full client dependencies.
pub struct FullDeps<C, P> {
/// The client instance to use.
Expand All @@ -26,7 +27,9 @@ pub struct FullDeps<C, P> {
}

/// Instantiate all full RPC extensions.
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> jsonrpc_core::IoHandler<sc_rpc::Metadata>
pub fn create_full<C, P>(
deps: FullDeps<C, P>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
Expand All @@ -37,23 +40,23 @@ where
C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use substrate_frame_rpc_system::{FullSystem, SystemApi};
use pallet_contracts_rpc::{ContractsApiServer, ContractsRpc};
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
use substrate_frame_rpc_system::{SystemApiServer, SystemRpc};

let mut io = jsonrpc_core::IoHandler::default();
let mut module = RpcModule::new(());
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())));
module.merge(SystemRpc::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
module.merge(TransactionPaymentRpc::new(client.clone()).into_rpc())?;

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

// Contracts RPC API extension
io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));
module.merge(ContractsRpc::new(client.clone()).into_rpc())?;

io
Ok(module)
}
7 changes: 3 additions & 4 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn new_partial(

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
&config,
config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
executor,
)?;
Expand Down Expand Up @@ -166,8 +166,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
Box::new(move |deny_unsafe, _| {
let deps =
crate::rpc::FullDeps { client: client.clone(), pool: pool.clone(), deny_unsafe };

Ok(crate::rpc::create_full(deps))
crate::rpc::create_full(deps).map_err(Into::into)
})
};
let prometheus_registry = config.prometheus_registry().cloned();
Expand All @@ -178,7 +177,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
keystore: keystore_container.sync_keystore(),
task_manager: &mut task_manager,
transaction_pool: transaction_pool.clone(),
rpc_extensions_builder,
rpc_builder: rpc_extensions_builder,
backend,
system_rpc_tx,
config,
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "contracts-node-runtime"
version = "0.13.0"
version = "0.14.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
license = "Unlicense"
Expand Down
17 changes: 13 additions & 4 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use frame_support::weights::DispatchClass;
use frame_support::{traits::OnRuntimeUpgrade, weights::DispatchClass};
use frame_system::limits::{BlockLength, BlockWeights};
use pallet_contracts::weights::WeightInfo;
use pallet_contracts::{migration, weights::WeightInfo, DefaultContractAccessWeight};
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
Expand Down Expand Up @@ -127,8 +127,8 @@ const fn deposit(items: u32, bytes: u32) -> Balance {
}

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub const BlockHashCount: BlockNumber = 2400;
pub const Version: RuntimeVersion = VERSION;

// This part is copied from Substrate's `bin/node/runtime/src/lib.rs`.
// The `RuntimeBlockLength` and `RuntimeBlockWeights` exist here because the
Expand Down Expand Up @@ -322,6 +322,14 @@ impl pallet_contracts::Config for Runtime {
type Schedule = Schedule;
type CallStack = [pallet_contracts::Frame<Self>; 31];
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
type ContractAccessWeight = DefaultContractAccessWeight<RuntimeBlockWeights>;
}

pub struct Migrations;
impl OnRuntimeUpgrade for Migrations {
fn on_runtime_upgrade() -> Weight {
migration::migrate::<Runtime>()
}
}

// Create the runtime by composing the FRAME pallets that were previously configured.
Expand Down Expand Up @@ -370,6 +378,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
Migrations,
>;

impl_runtime_apis! {
Expand Down Expand Up @@ -483,7 +492,7 @@ impl_runtime_apis! {

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
(list, storage_info)
}

fn dispatch_benchmark(
Expand Down

0 comments on commit 5f78d73

Please sign in to comment.