Skip to content

Commit 1a7fe78

Browse files
authored
Synchronize with Substrate + Release 0.13.0 (#53)
* Synchronize with Substrate * Bump version * Update `Cargo.lock`
1 parent ec3ff2d commit 1a7fe78

File tree

8 files changed

+169
-7
lines changed

8 files changed

+169
-7
lines changed

Cargo.lock

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

node/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "contracts-node"
3-
version = "0.12.0"
3+
version = "0.13.0"
44
authors = ["Parity Technologies <[email protected]>"]
55
description = "Substrate node configured for smart contracts via `pallet-contracts`."
66
edition = "2021"
@@ -26,7 +26,6 @@ sc-executor = { git = "https://github.com/paritytech/substrate", package = "sc-e
2626
sc-service = { git = "https://github.com/paritytech/substrate", package = "sc-service", features = ["wasmtime"] }
2727
sc-telemetry = { git = "https://github.com/paritytech/substrate", package = "sc-telemetry" }
2828
sc-keystore = { git = "https://github.com/paritytech/substrate", package = "sc-keystore" }
29-
sp-inherents = { git = "https://github.com/paritytech/substrate", package = "sp-inherents" }
3029
sc-transaction-pool = { git = "https://github.com/paritytech/substrate", package = "sc-transaction-pool" }
3130
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", package = "sc-transaction-pool-api" }
3231
sp-consensus = { git = "https://github.com/paritytech/substrate", package = "sp-consensus" }
@@ -35,6 +34,10 @@ sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", pa
3534
sc-client-api = { git = "https://github.com/paritytech/substrate", package = "sc-client-api" }
3635
sp-runtime = { git = "https://github.com/paritytech/substrate", package = "sp-runtime" }
3736
sp-timestamp = { git = "https://github.com/paritytech/substrate", package = "sp-timestamp" }
37+
sp-inherents = { git = "https://github.com/paritytech/substrate", package = "sp-inherents" }
38+
sp-keyring = { git = "https://github.com/paritytech/substrate", package = "sp-keyring" }
39+
frame-system = { git = "https://github.com/paritytech/substrate", package = "frame-system" }
40+
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", package = "pallet-transaction-payment" }
3841

3942
# These dependencies are used for the node's RPCs
4043
jsonrpc-core = "18.0.0"
@@ -52,6 +55,7 @@ pallet-contracts-rpc = { git = "https://github.com/paritytech/substrate", packag
5255
frame-benchmarking = { git = "https://github.com/paritytech/substrate", package = "frame-benchmarking" }
5356
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", package = "frame-benchmarking-cli" }
5457

58+
# Local Dependencies
5559
contracts-node-runtime = { path = "../runtime" }
5660

5761
# CLI-specific dependencies

node/src/command.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use crate::{
22
chain_spec,
33
cli::{Cli, Subcommand},
4+
command_helper::{inherent_benchmark_data, BenchmarkExtrinsicBuilder},
45
service,
56
service::ExecutorDispatch,
67
};
78
use contracts_node_runtime::Block;
89
use frame_benchmarking_cli::BenchmarkCmd;
910
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
1011
use sc_service::PartialComponents;
12+
use std::sync::Arc;
1113

1214
impl SubstrateCli for Cli {
1315
fn impl_name() -> String {
@@ -119,7 +121,24 @@ pub fn run() -> sc_cli::Result<()> {
119121

120122
cmd.run::<Block, ExecutorDispatch>(config)
121123
},
122-
_ => Ok(()),
124+
BenchmarkCmd::Block(cmd) => {
125+
let PartialComponents { client, .. } = service::new_partial(&config)?;
126+
cmd.run(client)
127+
},
128+
BenchmarkCmd::Storage(cmd) => {
129+
let PartialComponents { client, backend, .. } =
130+
service::new_partial(&config)?;
131+
let db = backend.expose_db();
132+
let storage = backend.expose_storage();
133+
cmd.run(config, client, db, storage)
134+
},
135+
BenchmarkCmd::Overhead(cmd) => {
136+
let PartialComponents { client, .. } = service::new_partial(&config)?;
137+
let ext_builder = BenchmarkExtrinsicBuilder::new(client.clone());
138+
139+
cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder))
140+
},
141+
BenchmarkCmd::Machine(cmd) => cmd.run(&config),
123142
}
124143
})
125144
},

node/src/command_helper.rs

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2022 Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5+
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
19+
//! Contains code to setup the command invocations in [`super::command`] which would
20+
//! otherwise bloat that module.
21+
22+
use crate::service::FullClient;
23+
24+
use contracts_node_runtime as runtime;
25+
use runtime::SystemCall;
26+
use sc_cli::Result;
27+
use sc_client_api::BlockBackend;
28+
use sp_core::{Encode, Pair};
29+
use sp_inherents::{InherentData, InherentDataProvider};
30+
use sp_keyring::Sr25519Keyring;
31+
use sp_runtime::{OpaqueExtrinsic, SaturatedConversion};
32+
33+
use std::{sync::Arc, time::Duration};
34+
35+
/// Generates extrinsics for the `benchmark overhead` command.
36+
///
37+
/// Note: Should only be used for benchmarking.
38+
pub struct BenchmarkExtrinsicBuilder {
39+
client: Arc<FullClient>,
40+
}
41+
42+
impl BenchmarkExtrinsicBuilder {
43+
/// Creates a new [`Self`] from the given client.
44+
pub fn new(client: Arc<FullClient>) -> Self {
45+
Self { client }
46+
}
47+
}
48+
49+
impl frame_benchmarking_cli::ExtrinsicBuilder for BenchmarkExtrinsicBuilder {
50+
fn remark(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
51+
let acc = Sr25519Keyring::Bob.pair();
52+
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
53+
self.client.as_ref(),
54+
acc,
55+
SystemCall::remark { remark: vec![] }.into(),
56+
nonce,
57+
)
58+
.into();
59+
60+
Ok(extrinsic)
61+
}
62+
}
63+
64+
/// Create a transaction using the given `call`.
65+
///
66+
/// Note: Should only be used for benchmarking.
67+
pub fn create_benchmark_extrinsic(
68+
client: &FullClient,
69+
sender: sp_core::sr25519::Pair,
70+
call: runtime::Call,
71+
nonce: u32,
72+
) -> runtime::UncheckedExtrinsic {
73+
let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
74+
let best_hash = client.chain_info().best_hash;
75+
let best_block = client.chain_info().best_number;
76+
77+
let period = runtime::BlockHashCount::get()
78+
.checked_next_power_of_two()
79+
.map(|c| c / 2)
80+
.unwrap_or(2) as u64;
81+
let extra: runtime::SignedExtra = (
82+
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
83+
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
84+
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
85+
frame_system::CheckGenesis::<runtime::Runtime>::new(),
86+
frame_system::CheckEra::<runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
87+
period,
88+
best_block.saturated_into(),
89+
)),
90+
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
91+
frame_system::CheckWeight::<runtime::Runtime>::new(),
92+
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
93+
);
94+
95+
let raw_payload = runtime::SignedPayload::from_raw(
96+
call.clone(),
97+
extra.clone(),
98+
(
99+
(),
100+
runtime::VERSION.spec_version,
101+
runtime::VERSION.transaction_version,
102+
genesis_hash,
103+
best_hash,
104+
(),
105+
(),
106+
(),
107+
),
108+
);
109+
let signature = raw_payload.using_encoded(|e| sender.sign(e));
110+
111+
runtime::UncheckedExtrinsic::new_signed(
112+
call.clone(),
113+
sp_runtime::AccountId32::from(sender.public()).into(),
114+
runtime::Signature::Sr25519(signature.clone()),
115+
extra.clone(),
116+
)
117+
}
118+
119+
/// Generates inherent data for the `benchmark overhead` command.
120+
///
121+
/// Note: Should only be used for benchmarking.
122+
pub fn inherent_benchmark_data() -> Result<InherentData> {
123+
let mut inherent_data = InherentData::new();
124+
let d = Duration::from_millis(0);
125+
let timestamp = sp_timestamp::InherentDataProvider::new(d.into());
126+
127+
timestamp
128+
.provide_inherent_data(&mut inherent_data)
129+
.map_err(|e| format!("creating inherent data: {:?}", e))?;
130+
Ok(inherent_data)
131+
}

node/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod chain_spec;
66
mod service;
77
mod cli;
88
mod command;
9+
mod command_helper;
910
mod rpc;
1011

1112
fn main() -> sc_cli::Result<()> {

node/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
2727
}
2828
}
2929

30-
type FullClient =
30+
pub(crate) type FullClient =
3131
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
3232
type FullBackend = sc_service::TFullBackend<Block>;
3333
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

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.12.0"
3+
version = "0.13.0"
44
authors = ["Parity Technologies <[email protected]>"]
55
edition = "2021"
66
license = "Unlicense"

runtime/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub use frame_support::{
3232
},
3333
StorageValue,
3434
};
35+
pub use frame_system::Call as SystemCall;
3536
pub use pallet_balances::Call as BalancesCall;
3637
pub use pallet_timestamp::Call as TimestampCall;
3738
use pallet_transaction_payment::CurrencyAdapter;
@@ -349,6 +350,7 @@ pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
349350
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
350351
/// The SignedExtension to the basic transaction logic.
351352
pub type SignedExtra = (
353+
frame_system::CheckNonZeroSender<Runtime>,
352354
frame_system::CheckSpecVersion<Runtime>,
353355
frame_system::CheckTxVersion<Runtime>,
354356
frame_system::CheckGenesis<Runtime>,
@@ -357,6 +359,8 @@ pub type SignedExtra = (
357359
frame_system::CheckWeight<Runtime>,
358360
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
359361
);
362+
/// The payload being signed in transactions.
363+
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
360364
/// Unchecked extrinsic type as expected by this runtime.
361365
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
362366
/// Executive: handles dispatch to the various modules.

0 commit comments

Comments
 (0)