Skip to content

Commit

Permalink
Sync with Substrate (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi authored Aug 9, 2022
1 parent 8bb970a commit 10f07a8
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 200 deletions.
333 changes: 160 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ configured to include Substrate's [`pallet-contracts`](https://github.com/parity

This repository is tracking Substrate's `master`.
The last time it was synchronized with Substrate was up to
[16bae92](https://github.com/paritytech/substrate/tree/16bae92b3f257f9c15525ae3d0a23d036bd59715).
[74a6370](https://github.com/paritytech/substrate/tree/74a6370e805ebaf88b7939e496818531f762cadf).

_This repository contains a couple of modifications that make it unsuitable
for a production deployment, but a great fit for development and testing:_
Expand Down Expand Up @@ -56,7 +56,7 @@ as the `Cargo.lock` in those repositories ‒ ensuring that the last
known-to-work version of the dependencies are used.

The latest confirmed working Substrate commit which will then be used is
[b0777b4](https://github.com/paritytech/substrate/tree/b0777b4c7f7d8d3c635319d0153953d0a22aa58e).
[74a6370](https://github.com/paritytech/substrate/tree/74a6370e805ebaf88b7939e496818531f762cadf).

## Usage

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.17.0"
version = "0.18.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
jsonrpsee = { version = "0.14.0", features = ["server"] }
jsonrpsee = { version = "0.15.1", 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
66 changes: 59 additions & 7 deletions node/src/command_helper.rs → node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Contains code to setup the command invocations in [`super::command`] which would
//! otherwise bloat that module.
//! Setup code for [`super::command`] which would otherwise bloat that module.
//!
//! Should only be used for benchmarking as it may break in other contexts.
use crate::service::FullClient;

use contracts_node_runtime as runtime;
use runtime::SystemCall;
use runtime::{AccountId, Balance, BalancesCall, SystemCall};
use sc_cli::Result;
use sc_client_api::BlockBackend;
use sp_core::{Encode, Pair};
Expand All @@ -35,19 +36,27 @@ use std::{sync::Arc, time::Duration};
/// Generates extrinsics for the `benchmark overhead` command.
///
/// Note: Should only be used for benchmarking.
pub struct BenchmarkExtrinsicBuilder {
pub struct RemarkBuilder {
client: Arc<FullClient>,
}

impl BenchmarkExtrinsicBuilder {
impl RemarkBuilder {
/// Creates a new [`Self`] from the given client.
pub fn new(client: Arc<FullClient>) -> Self {
Self { client }
}
}

impl frame_benchmarking_cli::ExtrinsicBuilder for BenchmarkExtrinsicBuilder {
fn remark(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder {
fn pallet(&self) -> &str {
"system"
}

fn extrinsic(&self) -> &str {
"remark"
}

fn build(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
let acc = Sr25519Keyring::Bob.pair();
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
self.client.as_ref(),
Expand All @@ -61,6 +70,49 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for BenchmarkExtrinsicBuilder {
}
}

/// Generates `Balances::TransferKeepAlive` extrinsics for the benchmarks.
///
/// Note: Should only be used for benchmarking.
pub struct TransferKeepAliveBuilder {
client: Arc<FullClient>,
dest: AccountId,
value: Balance,
}

impl TransferKeepAliveBuilder {
/// Creates a new [`Self`] from the given client.
pub fn new(client: Arc<FullClient>, dest: AccountId, value: Balance) -> Self {
Self { client, dest, value }
}
}

impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
fn pallet(&self) -> &str {
"balances"
}

fn extrinsic(&self) -> &str {
"transfer_keep_alive"
}

fn build(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
let acc = Sr25519Keyring::Bob.pair();
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
self.client.as_ref(),
acc,
BalancesCall::transfer_keep_alive {
dest: self.dest.clone().into(),
value: self.value.into(),
}
.into(),
nonce,
)
.into();

Ok(extrinsic)
}
}

/// Create a transaction using the given `call`.
///
/// Note: Should only be used for benchmarking.
Expand Down
26 changes: 20 additions & 6 deletions node/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::{
benchmarking::{inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder},
chain_spec,
cli::{Cli, Subcommand},
command_helper::{inherent_benchmark_data, BenchmarkExtrinsicBuilder},
service,
service::ExecutorDispatch,
};
use contracts_node_runtime::Block;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use contracts_node_runtime::{Block, EXISTENTIAL_DEPOSIT};
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
use sc_service::PartialComponents;
use std::sync::Arc;
use sp_keyring::Sr25519Keyring;

impl SubstrateCli for Cli {
fn impl_name() -> String {
Expand Down Expand Up @@ -134,9 +134,23 @@ pub fn run() -> sc_cli::Result<()> {
},
BenchmarkCmd::Overhead(cmd) => {
let PartialComponents { client, .. } = service::new_partial(&config)?;
let ext_builder = BenchmarkExtrinsicBuilder::new(client.clone());
let ext_builder = RemarkBuilder::new(client.clone());

cmd.run(config, client, inherent_benchmark_data()?, Arc::new(ext_builder))
cmd.run(config, client, inherent_benchmark_data()?, &ext_builder)
},
BenchmarkCmd::Extrinsic(cmd) => {
let PartialComponents { client, .. } = service::new_partial(&config)?;
// Register the *Remark* and *TKA* builders.
let ext_factory = ExtrinsicFactory(vec![
Box::new(RemarkBuilder::new(client.clone())),
Box::new(TransferKeepAliveBuilder::new(
client.clone(),
Sr25519Keyring::Alice.to_account_id(),
EXISTENTIAL_DEPOSIT,
)),
]);

cmd.run(client, inherent_benchmark_data()?, &ext_factory)
},
BenchmarkCmd::Machine(cmd) =>
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()),
Expand Down
2 changes: 1 addition & 1 deletion node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
mod chain_spec;
#[macro_use]
mod service;
mod benchmarking;
mod cli;
mod command;
mod command_helper;
mod rpc;

fn main() -> sc_cli::Result<()> {
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.17.0"
version = "0.18.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
license = "Unlicense"
Expand Down
16 changes: 8 additions & 8 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sp_version::RuntimeVersion;
// A few exports that help ease life for downstream crates.
pub use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU32, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo},
traits::{ConstU128, ConstU32, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
IdentityFee, Weight,
Expand Down Expand Up @@ -79,8 +79,8 @@ pub mod opaque {
pub struct SessionKeys {}
}
}
// To learn more about runtime versioning and what each of the following value means:
// https://docs.substrate.io/v3/runtime/upgrades#runtime-versioning
// To learn more about runtime versioning, see:
// https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("substrate-contracts-node"),
Expand Down Expand Up @@ -120,7 +120,7 @@ const CONTRACTS_DEBUG_OUTPUT: bool = true;
// Unit = the base number of indivisible units for balances
const UNIT: Balance = 1_000_000_000_000;
const MILLIUNIT: Balance = 1_000_000_000;
const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;

const fn deposit(items: u32, bytes: u32) -> Balance {
(items as Balance * UNIT + (bytes as Balance) * (5 * MILLIUNIT / 100)) / 10
Expand Down Expand Up @@ -238,7 +238,6 @@ impl pallet_timestamp::Config for Runtime {
}

parameter_types! {
pub const ExistentialDeposit: u128 = EXISTENTIAL_DEPOSIT;
pub const MaxLocks: u32 = 50;
}

Expand All @@ -251,7 +250,7 @@ impl pallet_balances::Config for Runtime {
/// The ubiquitous event type.
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type ExistentialDeposit = ConstU128<EXISTENTIAL_DEPOSIT>;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}
Expand Down Expand Up @@ -329,10 +328,11 @@ impl OnRuntimeUpgrade for Migrations {

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
pub struct Runtime
where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system,
RandomnessCollectiveFlip: pallet_randomness_collective_flip,
Expand Down

0 comments on commit 10f07a8

Please sign in to comment.