Update to the latest Serai Substrate (#125)

* Update to the latest Serai Substrate

* Add Protobuf to build dependencies

Docker shouldn't need updating as this should've been added to the image 
in 
2dbace5b01.

* Get substrate to build

* Correct protoc build step

* Remove the benchmarking code

There's some macro resolution error that isn't apparent. I worked on it 
for about half an hour but...

* Remove unnecessary clone

* Correct runtime-benchmarks flag usage
This commit is contained in:
Luke Parker 2022-09-29 13:33:09 -05:00 committed by GitHub
parent 2c3f36fd3f
commit 482a8ec209
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 588 additions and 515 deletions

View file

@ -15,6 +15,9 @@ inputs:
runs:
using: "composite"
steps:
- name: Install Protobuf
uses: arduino/setup-protoc@v1
- name: Install solc
shell: bash
run: |

961
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@
##### Ubuntu
```
sudo apt-get install -y build-essential cmake clang-11 git curl python3-pip
sudo apt-get install -y build-essential cmake clang-11 git curl python3-pip protobuf-compiler
```
### Install rustup

View file

@ -3,7 +3,6 @@ use std::{marker::Sync, sync::Arc, time::Duration};
use substrate_prometheus_endpoint::Registry;
use sc_consensus_pow as sc_pow;
use sc_client_api::call_executor::ExecutorProvider;
use sc_executor::NativeElseWasmExecutor;
use sc_service::TaskManager;
@ -40,12 +39,11 @@ pub fn import_queue<S: sp_consensus::SelectChain<Block> + 'static>(
) -> Result<sc_pow::PowImportQueue<Block, Db>, sp_consensus::Error> {
let pow_block_import = Box::new(sc_pow::PowBlockImport::new(
client.clone(),
client.clone(),
client,
algorithm::AcceptAny,
0,
select_chain,
|_, _| async { Ok(sp_timestamp::InherentDataProvider::from_system_time()) },
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),
));
sc_pow::import_queue(
@ -97,8 +95,6 @@ pub fn authority<S: sp_consensus::SelectChain<Block> + 'static>(
None,
);
let can_author_with = sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());
let pow_block_import = Box::new(sc_pow::PowBlockImport::new(
client.clone(),
client.clone(),
@ -106,7 +102,6 @@ pub fn authority<S: sp_consensus::SelectChain<Block> + 'static>(
0, // Block to start checking inherents at
select_chain.clone(),
move |_, _| async { Ok(sp_timestamp::InherentDataProvider::from_system_time()) },
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),
));
let (worker, worker_task) = sc_pow::start_mining_worker(
@ -121,7 +116,6 @@ pub fn authority<S: sp_consensus::SelectChain<Block> + 'static>(
move |_, _| async { Ok(sp_timestamp::InherentDataProvider::from_system_time()) },
Duration::from_secs(6),
Duration::from_secs(2),
can_author_with,
);
task_manager.spawn_essential_handle().spawn_blocking("pow", None, worker_task);

View file

@ -31,7 +31,7 @@ frame-system = { git = "https://github.com/serai-dex/substrate" }
pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", default-features = false }
# These dependencies are used for the node template's RPCs
jsonrpsee = { version = "0.14.0", features = ["server"] }
jsonrpsee = { version = "0.15.1", features = ["server"] }
sc-rpc = { git = "https://github.com/serai-dex/substrate" }
sp-api = { git = "https://github.com/serai-dex/substrate" }
sc-rpc-api = { git = "https://github.com/serai-dex/substrate" }
@ -54,4 +54,8 @@ substrate-build-script-utils = { git = "https://github.com/serai-dex/substrate.g
[features]
default = []
runtime-benchmarks = ["serai-runtime/runtime-benchmarks"]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
"serai-runtime/runtime-benchmarks"
]

View file

@ -94,6 +94,12 @@ pub fn run() -> sc_cli::Result<()> {
BenchmarkCmd::Block(cmd) => cmd.run(service::new_partial(&config)?.client),
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Storage(_) => {
Err("Storage benchmarking can be enabled with `--features runtime-benchmarks`.".into())
}
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => {
let PartialComponents { client, backend, .. } = service::new_partial(&config)?;
cmd.run(config, client, backend.expose_db(), backend.expose_storage())
@ -101,7 +107,13 @@ pub fn run() -> sc_cli::Result<()> {
BenchmarkCmd::Overhead(cmd) => {
let client = service::new_partial(&config)?.client;
cmd.run(config, client.clone(), inherent_benchmark_data()?, &RemarkBuilder::new(client))
cmd.run(
config,
client.clone(),
inherent_benchmark_data()?,
vec![],
&RemarkBuilder::new(client),
)
}
BenchmarkCmd::Extrinsic(cmd) => {
@ -109,6 +121,7 @@ pub fn run() -> sc_cli::Result<()> {
cmd.run(
client.clone(),
inherent_benchmark_data()?,
vec![],
&ExtrinsicFactory(vec![Box::new(RemarkBuilder::new(client))]),
)
}

View file

@ -45,7 +45,7 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder {
pub fn create_benchmark_extrinsic(
client: &FullClient,
sender: sp_core::sr25519::Pair,
call: runtime::Call,
call: runtime::RuntimeCall,
nonce: u32,
) -> runtime::UncheckedExtrinsic {
let extra = (

View file

@ -96,7 +96,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
transaction_pool,
} = new_partial(&config)?;
let (network, system_rpc_tx, network_starter) =
let (network, system_rpc_tx, tx_handler_controller, network_starter) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
@ -142,6 +142,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
rpc_builder: rpc_extensions_builder,
backend,
system_rpc_tx,
tx_handler_controller,
config,
telemetry: telemetry.as_mut(),
})?;

View file

@ -17,11 +17,12 @@ use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use frame_support::{
traits::{OnRuntimeUpgrade, ConstU8, ConstU32, ConstU64},
traits::{ConstU8, ConstU32, ConstU64},
weights::{
constants::{RocksDbWeight, ExtrinsicBaseWeight, BlockExecutionWeight, WEIGHT_PER_SECOND},
IdentityFee, Weight, DispatchClass,
IdentityFee, Weight,
},
dispatch::DispatchClass,
parameter_types, construct_runtime,
};
pub use frame_system::Call as SystemCall;
@ -29,7 +30,7 @@ pub use frame_system::Call as SystemCall;
pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall;
use pallet_transaction_payment::CurrencyAdapter;
use pallet_contracts::{migration, DefaultContractAccessWeight};
use pallet_contracts::DefaultContractAccessWeight;
/// An index to a block.
pub type BlockNumber = u32;
@ -96,7 +97,7 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// We allow for 2 seconds of compute with a 6 second average block time.
const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_ref_time(2 * WEIGHT_PER_SECOND.ref_time());
// Prints debug output of the `contracts` pallet to stdout if the node is
// started with `-lruntime::contracts=debug`.
@ -156,15 +157,15 @@ impl frame_system::Config for Runtime {
type BlockWeights = BlockWeights;
type BlockLength = BlockLength;
type AccountId = AccountId;
type Call = Call;
type RuntimeCall = RuntimeCall;
type Lookup = AccountIdLookup<AccountId, ()>;
type Index = Index;
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hashing = BlakeTwo256;
type Header = Header;
type Event = Event;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = RocksDbWeight;
type Version = Version;
@ -195,7 +196,7 @@ impl pallet_balances::Config for Runtime {
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type Balance = Balance;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ConstU64<500>;
type AccountStore = System;
@ -203,7 +204,7 @@ impl pallet_balances::Config for Runtime {
}
impl pallet_transaction_payment::Config for Runtime {
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = IdentityFee<Balance>;
@ -215,8 +216,8 @@ impl pallet_contracts::Config for Runtime {
type Time = Timestamp;
type Randomness = RandomnessCollectiveFlip;
type Currency = Balances;
type Event = Event;
type Call = Call;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
/// The safest default is to allow no calls at all.
///
@ -238,17 +239,9 @@ impl pallet_contracts::Config for Runtime {
type ContractAccessWeight = DefaultContractAccessWeight<BlockWeights>;
type MaxCodeLen = ConstU32<{ 128 * 1024 }>;
type RelaxedMaxCodeLen = ConstU32<{ 256 * 1024 }>;
type MaxStorageKeyLen = ConstU32<128>;
}
pub struct Migrations;
impl OnRuntimeUpgrade for Migrations {
fn on_runtime_upgrade() -> Weight {
migration::migrate::<Runtime>()
}
}
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
@ -262,8 +255,9 @@ pub type SignedExtra = (
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
);
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
pub type Executive = frame_executive::Executive<
Runtime,
Block,
@ -410,7 +404,7 @@ sp_api::impl_runtime_apis! {
origin,
dest,
value,
gas_limit,
Weight::from_ref_time(gas_limit),
storage_deposit_limit,
input_data,
CONTRACTS_DEBUG_OUTPUT
@ -429,7 +423,7 @@ sp_api::impl_runtime_apis! {
Contracts::bare_instantiate(
origin,
value,
gas_limit,
Weight::from_ref_time(gas_limit),
storage_deposit_limit,
code,
data,
@ -453,65 +447,4 @@ sp_api::impl_runtime_apis! {
Contracts::get_storage(address, key)
}
}
#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{baseline, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;
let mut list = Vec::<BenchmarkList>::new();
list_benchmarks!(list, extra);
let storage_info = AllPalletsWithSystem::storage_info();
(list, storage_info)
}
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch, TrackedStorageKey};
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;
impl frame_system_benchmarking::Config for Runtime {}
impl baseline::Config for Runtime {}
let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!(
"26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac"
).to_vec().into(),
// Total Issuance
hex_literal::hex!(
"c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80"
).to_vec().into(),
// Execution Phase
hex_literal::hex!(
"26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a"
).to_vec().into(),
// Event Count
hex_literal::hex!(
"26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850"
).to_vec().into(),
// System Events
hex_literal::hex!(
"26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"
).to_vec().into(),
];
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
add_benchmarks!(params, batches);
Ok(batches)
}
}
}