Update the solochain template to stable2412 (#18)

This synchronizes the template to the stable2412 branch.

Co-authored-by: iulianbarbu <14218860+iulianbarbu@users.noreply.github.com>
This commit is contained in:
paritytech-polkadotsdk-templatebot[bot]
2025-02-20 15:28:33 +02:00
committed by GitHub
parent 93f30a2356
commit e4c83d4c89
21 changed files with 3240 additions and 1372 deletions
+6 -4
View File
@@ -24,7 +24,7 @@
// For more information, please refer to <http://unlicense.org>
// External crates imports
use alloc::{vec, vec::Vec};
use alloc::vec::Vec;
use frame_support::{
genesis_builder_helper::{build_state, get_preset},
weights::Weight,
@@ -223,6 +223,7 @@ impl_runtime_apis! {
use frame_benchmarking::{baseline, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench;
use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
use baseline::Pallet as BaselineBench;
use super::*;
@@ -236,10 +237,11 @@ impl_runtime_apis! {
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
use frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch};
use sp_storage::TrackedStorageKey;
use frame_system_benchmarking::Pallet as SystemBench;
use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
use baseline::Pallet as BaselineBench;
use super::*;
@@ -285,11 +287,11 @@ impl_runtime_apis! {
}
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
get_preset::<RuntimeGenesisConfig>(id, |_| None)
get_preset::<RuntimeGenesisConfig>(id, crate::genesis_config_presets::get_preset)
}
fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![]
crate::genesis_config_presets::preset_names()
}
}
}
+2 -1
View File
@@ -26,8 +26,9 @@
frame_benchmarking::define_benchmarks!(
[frame_benchmarking, BaselineBench::<Runtime>]
[frame_system, SystemBench::<Runtime>]
[frame_system_extensions, SystemExtensionsBench::<Runtime>]
[pallet_balances, Balances]
[pallet_timestamp, Timestamp]
[pallet_sudo, Sudo]
[pallet_template, TemplateModule]
[pallet_template, Template]
);
+3 -1
View File
@@ -133,7 +133,8 @@ impl pallet_balances::Config for Runtime {
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type DoneSlashHandler = ();
}
parameter_types! {
@@ -147,6 +148,7 @@ impl pallet_transaction_payment::Config for Runtime {
type WeightToFee = IdentityFee<Balance>;
type LengthToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ConstFeeMultiplier<FeeMultiplier>;
type WeightInfo = pallet_transaction_payment::weights::SubstrateWeight<Runtime>;
}
impl pallet_sudo::Config for Runtime {
+112
View File
@@ -0,0 +1,112 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig};
use alloc::{vec, vec::Vec};
use serde_json::Value;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_genesis_builder::{self, PresetId};
use sp_keyring::AccountKeyring;
// Returns the genesis config presets populated with given parameters.
fn testnet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
endowed_accounts: Vec<AccountId>,
root: AccountId,
) -> Value {
let config = RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1u128 << 60))
.collect::<Vec<_>>(),
},
aura: pallet_aura::GenesisConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
},
grandpa: pallet_grandpa::GenesisConfig {
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(),
..Default::default()
},
sudo: SudoConfig { key: Some(root) },
..Default::default()
};
serde_json::to_value(config).expect("Could not build genesis config.")
}
/// Return the development genesis config.
pub fn development_config_genesis() -> Value {
testnet_genesis(
vec![(
sp_keyring::Sr25519Keyring::Alice.public().into(),
sp_keyring::Ed25519Keyring::Alice.public().into(),
)],
vec![
AccountKeyring::Alice.to_account_id(),
AccountKeyring::Bob.to_account_id(),
AccountKeyring::AliceStash.to_account_id(),
AccountKeyring::BobStash.to_account_id(),
],
sp_keyring::AccountKeyring::Alice.to_account_id(),
)
}
/// Return the local genesis config preset.
pub fn local_config_genesis() -> Value {
testnet_genesis(
vec![
(
sp_keyring::Sr25519Keyring::Alice.public().into(),
sp_keyring::Ed25519Keyring::Alice.public().into(),
),
(
sp_keyring::Sr25519Keyring::Bob.public().into(),
sp_keyring::Ed25519Keyring::Bob.public().into(),
),
],
AccountKeyring::iter()
.filter(|v| v != &AccountKeyring::One && v != &AccountKeyring::Two)
.map(|v| v.to_account_id())
.collect::<Vec<_>>(),
AccountKeyring::Alice.to_account_id(),
)
}
/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
let patch = match id.as_ref() {
sp_genesis_builder::DEV_RUNTIME_PRESET => development_config_genesis(),
sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => local_config_genesis(),
_ => return None,
};
Some(
serde_json::to_string(&patch)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}
/// List of supported presets.
pub fn preset_names() -> Vec<PresetId> {
vec![
PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
]
}
+11 -9
View File
@@ -11,7 +11,7 @@ pub mod configs;
extern crate alloc;
use alloc::vec::Vec;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
generic, impl_opaque_keys,
traits::{BlakeTwo256, IdentifyAccount, Verify},
MultiAddress, MultiSignature,
};
@@ -25,6 +25,8 @@ pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
pub mod genesis_config_presets;
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
@@ -59,8 +61,8 @@ impl_opaque_keys! {
// https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("solochain-template-runtime"),
impl_name: create_runtime_str!("solochain-template-runtime"),
spec_name: alloc::borrow::Cow::Borrowed("solochain-template-runtime"),
impl_name: alloc::borrow::Cow::Borrowed("solochain-template-runtime"),
authoring_version: 1,
// The version of the runtime specification. A full node will not attempt to use its native
// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
@@ -71,7 +73,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 1,
apis: apis::RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};
mod block_times {
@@ -144,8 +146,8 @@ pub type SignedBlock = generic::SignedBlock<Block>;
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
/// The `TransactionExtension` to the basic transaction logic.
pub type TxExtension = (
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
@@ -159,10 +161,10 @@ pub type SignedExtra = (
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
pub type SignedPayload = generic::SignedPayload<RuntimeCall, TxExtension>;
/// All migrations of the runtime, aside from the ones declared in the pallets.
///
@@ -220,5 +222,5 @@ mod runtime {
// Include the custom logic from the pallet-template in the runtime.
#[runtime::pallet_index(7)]
pub type TemplateModule = pallet_template;
pub type Template = pallet_template;
}