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
Generated
+2965 -1154
View File
File diff suppressed because it is too large Load Diff
+52 -52
View File
@@ -16,59 +16,59 @@ resolver = "2"
[workspace.dependencies] [workspace.dependencies]
solochain-template-runtime = { path = "./runtime", default-features = false } solochain-template-runtime = { path = "./runtime", default-features = false }
pallet-template = { path = "./pallets/template", default-features = false } pallet-template = { path = "./pallets/template", default-features = false }
clap = { version = "4.5.10" } clap = { version = "4.5.13" }
frame-benchmarking-cli = { version = "43.0.0", default-features = false } frame-benchmarking-cli = { version = "46.0.0", default-features = false }
frame-metadata-hash-extension = { version = "0.6.0", default-features = false } frame-metadata-hash-extension = { version = "0.7.0", default-features = false }
frame-system = { version = "38.0.0", default-features = false } frame-system = { version = "39.1.0", default-features = false }
futures = { version = "0.3.30" } futures = { version = "0.3.31" }
jsonrpsee = { version = "0.24.3" } jsonrpsee = { version = "0.24.3" }
pallet-transaction-payment = { version = "38.0.0", default-features = false } pallet-transaction-payment = { version = "39.0.0", default-features = false }
pallet-transaction-payment-rpc = { version = "41.0.0", default-features = false } pallet-transaction-payment-rpc = { version = "42.0.0", default-features = false }
sc-basic-authorship = { version = "0.45.0", default-features = false } sc-basic-authorship = { version = "0.48.0", default-features = false }
sc-cli = { version = "0.47.0", default-features = false } sc-cli = { version = "0.50.0", default-features = false }
sc-client-api = { version = "37.0.0", default-features = false } sc-client-api = { version = "38.0.0", default-features = false }
sc-consensus = { version = "0.44.0", default-features = false } sc-consensus = { version = "0.47.0", default-features = false }
sc-consensus-aura = { version = "0.45.0", default-features = false } sc-consensus-aura = { version = "0.48.0", default-features = false }
sc-consensus-grandpa = { version = "0.30.0", default-features = false } sc-consensus-grandpa = { version = "0.33.0", default-features = false }
sc-executor = { version = "0.40.1", default-features = false } sc-executor = { version = "0.41.0", default-features = false }
sc-network = { version = "0.45.0", default-features = false } sc-network = { version = "0.48.0", default-features = false }
sc-offchain = { version = "40.0.0", default-features = false } sc-offchain = { version = "43.0.0", default-features = false }
sc-service = { version = "0.46.0", default-features = false } sc-service = { version = "0.49.0", default-features = false }
sc-telemetry = { version = "25.0.0", default-features = false } sc-telemetry = { version = "28.0.0", default-features = false }
sc-transaction-pool = { version = "37.0.0", default-features = false } sc-transaction-pool = { version = "38.0.0", default-features = false }
sc-transaction-pool-api = { version = "37.0.0", default-features = false } sc-transaction-pool-api = { version = "38.0.0", default-features = false }
serde_json = { version = "1.0.127", default-features = false } serde_json = { version = "1.0.132", default-features = false }
sp-api = { version = "34.0.0", default-features = false } sp-api = { version = "35.0.0", default-features = false }
sp-block-builder = { version = "34.0.0", default-features = false } sp-block-builder = { version = "35.0.0", default-features = false }
sp-blockchain = { version = "37.0.1", default-features = false } sp-blockchain = { version = "38.0.0", default-features = false }
sp-consensus-aura = { version = "0.40.0", default-features = false } sp-consensus-aura = { version = "0.41.0", default-features = false }
sp-consensus-grandpa = { version = "21.0.0", default-features = false } sp-consensus-grandpa = { version = "22.0.0", default-features = false }
sp-core = { version = "34.0.0", default-features = false } sp-core = { version = "35.0.0", default-features = false }
sp-inherents = { version = "34.0.0", default-features = false } sp-genesis-builder = { version = "0.16.0", default-features = false }
sp-io = { version = "38.0.0", default-features = false } sp-inherents = { version = "35.0.0", default-features = false }
sp-keyring = { version = "39.0.0", default-features = false } sp-io = { version = "39.0.0", default-features = false }
sp-runtime = { version = "39.0.1", default-features = false } sp-keyring = { version = "40.0.0", default-features = false }
sp-timestamp = { version = "34.0.0", default-features = false } sp-runtime = { version = "40.1.0", default-features = false }
substrate-frame-rpc-system = { version = "39.0.0", default-features = false } sp-timestamp = { version = "35.0.0", default-features = false }
substrate-frame-rpc-system = { version = "42.0.0", default-features = false }
substrate-build-script-utils = { version = "11.0.0", default-features = false } substrate-build-script-utils = { version = "11.0.0", default-features = false }
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" } codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
frame-benchmarking = { version = "38.0.0", default-features = false } frame-benchmarking = { version = "39.0.0", default-features = false }
frame-executive = { version = "38.0.0", default-features = false } frame-executive = { version = "39.0.0", default-features = false }
frame-support = { version = "38.0.0", default-features = false } frame-support = { version = "39.0.0", default-features = false }
frame-system-benchmarking = { version = "38.0.0", default-features = false } frame-system-benchmarking = { version = "39.0.0", default-features = false }
frame-system-rpc-runtime-api = { version = "34.0.0", default-features = false } frame-system-rpc-runtime-api = { version = "35.0.0", default-features = false }
frame-try-runtime = { version = "0.44.0", default-features = false } frame-try-runtime = { version = "0.45.0", default-features = false }
pallet-aura = { version = "37.0.0", default-features = false } pallet-aura = { version = "38.0.0", default-features = false }
pallet-balances = { version = "39.0.0", default-features = false } pallet-balances = { version = "40.0.0", default-features = false }
pallet-grandpa = { version = "38.0.0", default-features = false } pallet-grandpa = { version = "39.0.0", default-features = false }
pallet-sudo = { version = "38.0.0", default-features = false } pallet-sudo = { version = "39.0.0", default-features = false }
pallet-timestamp = { version = "37.0.0", default-features = false } pallet-timestamp = { version = "38.0.0", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { version = "38.0.0", default-features = false } pallet-transaction-payment-rpc-runtime-api = { version = "39.0.0", default-features = false }
scale-info = { version = "2.11.1", default-features = false } scale-info = { version = "2.11.1", default-features = false }
sp-genesis-builder = { version = "0.15.1", default-features = false } sp-offchain = { version = "35.0.0", default-features = false }
sp-offchain = { version = "34.0.0", default-features = false } sp-session = { version = "37.0.0", default-features = false }
sp-session = { version = "36.0.0", default-features = false } sp-storage = { version = "22.0.0", default-features = false }
sp-storage = { version = "21.0.0", default-features = false } sp-transaction-pool = { version = "35.0.0", default-features = false }
sp-transaction-pool = { version = "34.0.0", default-features = false } sp-version = { version = "38.0.0", default-features = false }
sp-version = { version = "37.0.0", default-features = false } substrate-wasm-builder = { version = "25.0.0", default-features = false }
substrate-wasm-builder = { version = "24.0.1", default-features = false }
+10 -2
View File
@@ -23,9 +23,17 @@ packages required to compile this template. Check the
the most common dependencies. Alternatively, you can use one of the [alternative the most common dependencies. Alternatively, you can use one of the [alternative
installation](#alternatives-installations) options. installation](#alternatives-installations) options.
Fetch solochain template code:
```sh
git clone https://github.com/paritytech/polkadot-sdk-solochain-template.git solochain-template
cd solochain-template
```
### Build ### Build
Use the following command to build the node without launching it: 🔨 Use the following command to build the node without launching it:
```sh ```sh
cargo build --release cargo build --release
@@ -177,7 +185,7 @@ template and note the following:
configuration is defined by a code block that begins with `impl configuration is defined by a code block that begins with `impl
$PALLET_NAME::Config for Runtime`. $PALLET_NAME::Config for Runtime`.
- The pallets are composed into a single runtime by way of the - The pallets are composed into a single runtime by way of the
[`construct_runtime!`](https://paritytech.github.io/substrate/master/frame_support/macro.construct_runtime.html) [#[runtime]](https://paritytech.github.io/polkadot-sdk/master/frame_support/attr.runtime.html)
macro, which is part of the [core FRAME pallet macro, which is part of the [core FRAME pallet
library](https://docs.substrate.io/reference/frame-pallets/#system-pallets). library](https://docs.substrate.io/reference/frame-pallets/#system-pallets).
+6 -5
View File
@@ -37,16 +37,18 @@ sc-transaction-pool-api.workspace = true
sc-transaction-pool-api.default-features = true sc-transaction-pool-api.default-features = true
sc-offchain.workspace = true sc-offchain.workspace = true
sc-offchain.default-features = true sc-offchain.default-features = true
sc-consensus.workspace = true
sc-consensus.default-features = true
sc-consensus-aura.workspace = true sc-consensus-aura.workspace = true
sc-consensus-aura.default-features = true sc-consensus-aura.default-features = true
sp-consensus-aura.workspace = true sp-consensus-aura.workspace = true
sp-consensus-aura.default-features = true sp-consensus-aura.default-features = true
sc-consensus.workspace = true
sc-consensus.default-features = true
sc-consensus-grandpa.workspace = true sc-consensus-grandpa.workspace = true
sc-consensus-grandpa.default-features = true sc-consensus-grandpa.default-features = true
sp-consensus-grandpa.workspace = true sp-consensus-grandpa.workspace = true
sp-consensus-grandpa.default-features = true sp-consensus-grandpa.default-features = true
sp-genesis-builder.workspace = true
sp-genesis-builder.default-features = true
sc-client-api.workspace = true sc-client-api.workspace = true
sc-client-api.default-features = true sc-client-api.default-features = true
sc-basic-authorship.workspace = true sc-basic-authorship.workspace = true
@@ -87,13 +89,12 @@ substrate-build-script-utils.default-features = true
[features] [features]
default = ["std"] default = ["std"]
std = [ std = ["solochain-template-runtime/std"]
"solochain-template-runtime/std",
]
# Dependencies that are only required if runtime benchmarking should be build. # Dependencies that are only required if runtime benchmarking should be build.
runtime-benchmarks = [ runtime-benchmarks = [
"frame-benchmarking-cli/runtime-benchmarks", "frame-benchmarking-cli/runtime-benchmarks",
"frame-system/runtime-benchmarks", "frame-system/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"sc-service/runtime-benchmarks", "sc-service/runtime-benchmarks",
"solochain-template-runtime/runtime-benchmarks", "solochain-template-runtime/runtime-benchmarks",
"sp-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks",
+1 -1
View File
@@ -2,4 +2,4 @@
## Release ## Release
Polkadot SDK stable2409 Polkadot SDK Stable 2412
+3 -3
View File
@@ -109,7 +109,7 @@ pub fn create_benchmark_extrinsic(
.checked_next_power_of_two() .checked_next_power_of_two()
.map(|c| c / 2) .map(|c| c / 2)
.unwrap_or(2) as u64; .unwrap_or(2) as u64;
let extra: runtime::SignedExtra = ( let tx_ext: runtime::TxExtension = (
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(), frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(), frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckTxVersion::<runtime::Runtime>::new(), frame_system::CheckTxVersion::<runtime::Runtime>::new(),
@@ -126,7 +126,7 @@ pub fn create_benchmark_extrinsic(
let raw_payload = runtime::SignedPayload::from_raw( let raw_payload = runtime::SignedPayload::from_raw(
call.clone(), call.clone(),
extra.clone(), tx_ext.clone(),
( (
(), (),
runtime::VERSION.spec_version, runtime::VERSION.spec_version,
@@ -145,7 +145,7 @@ pub fn create_benchmark_extrinsic(
call, call,
sp_runtime::AccountId32::from(sender.public()).into(), sp_runtime::AccountId32::from(sender.public()).into(),
runtime::Signature::Sr25519(signature), runtime::Signature::Sr25519(signature),
extra, tx_ext,
) )
} }
+5 -93
View File
@@ -1,39 +1,10 @@
use sc_service::ChainType; use sc_service::ChainType;
use solochain_template_runtime::{AccountId, Signature, WASM_BINARY}; use solochain_template_runtime::WASM_BINARY;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec; pub type ChainSpec = sc_service::GenericChainSpec;
/// Generate a crypto pair from seed. pub fn development_chain_spec() -> Result<ChainSpec, String> {
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}
type AccountPublic = <Signature as Verify>::Signer;
/// Generate an account ID from seed.
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
/// Generate an Aura authority key.
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
}
pub fn development_config() -> Result<ChainSpec, String> {
Ok(ChainSpec::builder( Ok(ChainSpec::builder(
WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?,
None, None,
@@ -41,24 +12,11 @@ pub fn development_config() -> Result<ChainSpec, String> {
.with_name("Development") .with_name("Development")
.with_id("dev") .with_id("dev")
.with_chain_type(ChainType::Development) .with_chain_type(ChainType::Development)
.with_genesis_config_patch(testnet_genesis( .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
// Initial PoA authorities
vec![authority_keys_from_seed("Alice")],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
],
true,
))
.build()) .build())
} }
pub fn local_testnet_config() -> Result<ChainSpec, String> { pub fn local_chain_spec() -> Result<ChainSpec, String> {
Ok(ChainSpec::builder( Ok(ChainSpec::builder(
WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?,
None, None,
@@ -66,52 +24,6 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
.with_name("Local Testnet") .with_name("Local Testnet")
.with_id("local_testnet") .with_id("local_testnet")
.with_chain_type(ChainType::Local) .with_chain_type(ChainType::Local)
.with_genesis_config_patch(testnet_genesis( .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
// Initial PoA authorities
vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
true,
))
.build()) .build())
} }
/// Configure initial storage state for FRAME modules.
fn testnet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
) -> serde_json::Value {
serde_json::json!({
"balances": {
// Configure endowed accounts with initial balance of 1 << 60.
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(),
},
"aura": {
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
},
"grandpa": {
"authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(),
},
"sudo": {
// Assign network admin rights.
"key": Some(root_key),
},
})
}
+4 -3
View File
@@ -37,8 +37,8 @@ impl SubstrateCli for Cli {
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> { fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id { Ok(match id {
"dev" => Box::new(chain_spec::development_config()?), "dev" => Box::new(chain_spec::development_chain_spec()?),
"" | "local" => Box::new(chain_spec::local_testnet_config()?), "" | "local" => Box::new(chain_spec::local_chain_spec()?),
path => path =>
Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
}) })
@@ -144,11 +144,12 @@ pub fn run() -> sc_cli::Result<()> {
let ext_builder = RemarkBuilder::new(client.clone()); let ext_builder = RemarkBuilder::new(client.clone());
cmd.run( cmd.run(
config, config.chain_spec.name().into(),
client, client,
inherent_benchmark_data()?, inherent_benchmark_data()?,
Vec::new(), Vec::new(),
&ext_builder, &ext_builder,
false,
) )
}, },
BenchmarkCmd::Extrinsic(cmd) => { BenchmarkCmd::Extrinsic(cmd) => {
+16 -13
View File
@@ -28,7 +28,7 @@ pub type Service = sc_service::PartialComponents<
FullBackend, FullBackend,
FullSelectChain, FullSelectChain,
sc_consensus::DefaultImportQueue<Block>, sc_consensus::DefaultImportQueue<Block>,
sc_transaction_pool::FullPool<Block, FullClient>, sc_transaction_pool::TransactionPoolHandle<Block, FullClient>,
( (
sc_consensus_grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, FullSelectChain>, sc_consensus_grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, FullSelectChain>,
sc_consensus_grandpa::LinkHalf<Block, FullClient, FullSelectChain>, sc_consensus_grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
@@ -64,12 +64,15 @@ pub fn new_partial(config: &Configuration) -> Result<Service, ServiceError> {
let select_chain = sc_consensus::LongestChain::new(backend.clone()); let select_chain = sc_consensus::LongestChain::new(backend.clone());
let transaction_pool = sc_transaction_pool::BasicPool::new_full( let transaction_pool = Arc::from(
config.transaction_pool.clone(), sc_transaction_pool::Builder::new(
config.role.is_authority().into(), task_manager.spawn_essential_handle(),
config.prometheus_registry(), client.clone(),
task_manager.spawn_essential_handle(), config.role.is_authority().into(),
client.clone(), )
.with_options(config.transaction_pool.clone())
.with_prometheus(config.prometheus_registry())
.build(),
); );
let (grandpa_block_import, grandpa_link) = sc_consensus_grandpa::block_import( let (grandpa_block_import, grandpa_link) = sc_consensus_grandpa::block_import(
@@ -181,9 +184,7 @@ pub fn new_full<
})?; })?;
if config.offchain_worker.enabled { if config.offchain_worker.enabled {
task_manager.spawn_handle().spawn( let offchain_workers =
"offchain-workers-runner",
"offchain-worker",
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions { sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
runtime_api_provider: client.clone(), runtime_api_provider: client.clone(),
is_validator: config.role.is_authority(), is_validator: config.role.is_authority(),
@@ -195,9 +196,11 @@ pub fn new_full<
network_provider: Arc::new(network.clone()), network_provider: Arc::new(network.clone()),
enable_http_requests: true, enable_http_requests: true,
custom_extensions: |_| vec![], custom_extensions: |_| vec![],
}) })?;
.run(client.clone(), task_manager.spawn_handle()) task_manager.spawn_handle().spawn(
.boxed(), "offchain-workers-runner",
"offchain-worker",
offchain_workers.run(client.clone(), task_manager.spawn_handle()).boxed(),
); );
} }
+1 -1
View File
@@ -3,4 +3,4 @@ License: MIT-0
## Release ## Release
Polkadot SDK stable2409 Polkadot SDK Stable 2412
+1 -1
View File
@@ -1,5 +1,5 @@
//! Benchmarking setup for pallet-template //! Benchmarking setup for pallet-template
#![cfg(feature = "runtime-benchmarks")]
use super::*; use super::*;
#[allow(unused)] #[allow(unused)]
+24 -8
View File
@@ -4,14 +4,30 @@ use sp_runtime::BuildStorage;
type Block = frame_system::mocking::MockBlock<Test>; type Block = frame_system::mocking::MockBlock<Test>;
// Configure a mock runtime to test the pallet. #[frame_support::runtime]
frame_support::construct_runtime!( mod runtime {
pub enum Test // The main runtime
{ #[runtime::runtime]
System: frame_system, // Runtime Types to be generated
TemplateModule: pallet_template, #[runtime::derive(
} RuntimeCall,
); RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeFreezeReason,
RuntimeHoldReason,
RuntimeSlashReason,
RuntimeLockId,
RuntimeTask
)]
pub struct Test;
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Test>;
#[runtime::pallet_index(1)]
pub type Template = pallet_template::Pallet<Test>;
}
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] #[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test { impl frame_system::Config for Test {
+2 -5
View File
@@ -7,7 +7,7 @@ fn it_works_for_default_value() {
// Go past genesis block so events get deposited // Go past genesis block so events get deposited
System::set_block_number(1); System::set_block_number(1);
// Dispatch a signed extrinsic. // Dispatch a signed extrinsic.
assert_ok!(TemplateModule::do_something(RuntimeOrigin::signed(1), 42)); assert_ok!(Template::do_something(RuntimeOrigin::signed(1), 42));
// Read pallet storage and assert an expected result. // Read pallet storage and assert an expected result.
assert_eq!(Something::<Test>::get(), Some(42)); assert_eq!(Something::<Test>::get(), Some(42));
// Assert that the correct event was deposited // Assert that the correct event was deposited
@@ -19,9 +19,6 @@ fn it_works_for_default_value() {
fn correct_error_for_none_value() { fn correct_error_for_none_value() {
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
// Ensure the expected error is thrown when no value is present. // Ensure the expected error is thrown when no value is present.
assert_noop!( assert_noop!(Template::cause_error(RuntimeOrigin::signed(1)), Error::<Test>::NoneValue);
TemplateModule::cause_error(RuntimeOrigin::signed(1)),
Error::<Test>::NoneValue
);
}); });
} }
+8 -8
View File
@@ -41,8 +41,8 @@ pub trait WeightInfo {
/// Weights for pallet_template using the Substrate node and recommended hardware. /// Weights for pallet_template using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>); pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: TemplateModule Something (r:0 w:1) /// Storage: Template Something (r:0 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn do_something() -> Weight { fn do_something() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `0` // Measured: `0`
@@ -51,8 +51,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Weight::from_parts(9_000_000, 0) Weight::from_parts(9_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64))
} }
/// Storage: TemplateModule Something (r:1 w:1) /// Storage: Template Something (r:1 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn cause_error() -> Weight { fn cause_error() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `32` // Measured: `32`
@@ -66,8 +66,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// For backwards compatibility and tests // For backwards compatibility and tests
impl WeightInfo for () { impl WeightInfo for () {
/// Storage: TemplateModule Something (r:0 w:1) /// Storage: Template Something (r:0 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn do_something() -> Weight { fn do_something() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `0` // Measured: `0`
@@ -76,8 +76,8 @@ impl WeightInfo for () {
Weight::from_parts(9_000_000, 0) Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64))
} }
/// Storage: TemplateModule Something (r:1 w:1) /// Storage: Template Something (r:1 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) /// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn cause_error() -> Weight { fn cause_error() -> Weight {
// Proof Size summary in bytes: // Proof Size summary in bytes:
// Measured: `32` // Measured: `32`
+7 -7
View File
@@ -20,6 +20,7 @@ scale-info = { features = [
"derive", "derive",
"serde", "serde",
], workspace = true } ], workspace = true }
serde_json = { workspace = true, default-features = false, features = ["alloc"] }
frame-support = { features = ["experimental"], workspace = true } frame-support = { features = ["experimental"], workspace = true }
frame-system.workspace = true frame-system.workspace = true
frame-try-runtime = { optional = true, workspace = true } frame-try-runtime = { optional = true, workspace = true }
@@ -35,6 +36,7 @@ sp-api.workspace = true
sp-block-builder.workspace = true sp-block-builder.workspace = true
sp-consensus-aura = { features = ["serde"], workspace = true } sp-consensus-aura = { features = ["serde"], workspace = true }
sp-consensus-grandpa = { features = ["serde"], workspace = true } sp-consensus-grandpa = { features = ["serde"], workspace = true }
sp-keyring.workspace = true
sp-core = { features = ["serde"], workspace = true } sp-core = { features = ["serde"], workspace = true }
sp-inherents.workspace = true sp-inherents.workspace = true
sp-offchain.workspace = true sp-offchain.workspace = true
@@ -57,18 +59,14 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features =
default = ["std"] default = ["std"]
std = [ std = [
"codec/std", "codec/std",
"scale-info/std", "frame-benchmarking?/std",
"frame-executive/std", "frame-executive/std",
"frame-metadata-hash-extension/std", "frame-metadata-hash-extension/std",
"frame-support/std", "frame-support/std",
"frame-system-benchmarking?/std", "frame-system-benchmarking?/std",
"frame-system-rpc-runtime-api/std", "frame-system-rpc-runtime-api/std",
"frame-system/std", "frame-system/std",
"frame-benchmarking?/std",
"frame-try-runtime?/std", "frame-try-runtime?/std",
"pallet-aura/std", "pallet-aura/std",
"pallet-balances/std", "pallet-balances/std",
"pallet-grandpa/std", "pallet-grandpa/std",
@@ -77,7 +75,8 @@ std = [
"pallet-timestamp/std", "pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std", "pallet-transaction-payment/std",
"scale-info/std",
"serde_json/std",
"sp-api/std", "sp-api/std",
"sp-block-builder/std", "sp-block-builder/std",
"sp-consensus-aura/std", "sp-consensus-aura/std",
@@ -85,13 +84,13 @@ std = [
"sp-core/std", "sp-core/std",
"sp-genesis-builder/std", "sp-genesis-builder/std",
"sp-inherents/std", "sp-inherents/std",
"sp-keyring/std",
"sp-offchain/std", "sp-offchain/std",
"sp-runtime/std", "sp-runtime/std",
"sp-session/std", "sp-session/std",
"sp-storage/std", "sp-storage/std",
"sp-transaction-pool/std", "sp-transaction-pool/std",
"sp-version/std", "sp-version/std",
"substrate-wasm-builder", "substrate-wasm-builder",
] ]
@@ -105,6 +104,7 @@ runtime-benchmarks = [
"pallet-sudo/runtime-benchmarks", "pallet-sudo/runtime-benchmarks",
"pallet-template/runtime-benchmarks", "pallet-template/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"sp-runtime/runtime-benchmarks", "sp-runtime/runtime-benchmarks",
] ]
+1 -1
View File
@@ -2,4 +2,4 @@
## Release ## Release
Polkadot SDK stable2409 Polkadot SDK Stable 2412
+6 -4
View File
@@ -24,7 +24,7 @@
// For more information, please refer to <http://unlicense.org> // For more information, please refer to <http://unlicense.org>
// External crates imports // External crates imports
use alloc::{vec, vec::Vec}; use alloc::vec::Vec;
use frame_support::{ use frame_support::{
genesis_builder_helper::{build_state, get_preset}, genesis_builder_helper::{build_state, get_preset},
weights::Weight, weights::Weight,
@@ -223,6 +223,7 @@ impl_runtime_apis! {
use frame_benchmarking::{baseline, Benchmarking, BenchmarkList}; use frame_benchmarking::{baseline, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait; use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench; use frame_system_benchmarking::Pallet as SystemBench;
use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
use baseline::Pallet as BaselineBench; use baseline::Pallet as BaselineBench;
use super::*; use super::*;
@@ -236,10 +237,11 @@ impl_runtime_apis! {
fn dispatch_benchmark( fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig 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 frame_benchmarking::{baseline, Benchmarking, BenchmarkBatch};
use sp_storage::TrackedStorageKey; use sp_storage::TrackedStorageKey;
use frame_system_benchmarking::Pallet as SystemBench; use frame_system_benchmarking::Pallet as SystemBench;
use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
use baseline::Pallet as BaselineBench; use baseline::Pallet as BaselineBench;
use super::*; use super::*;
@@ -285,11 +287,11 @@ impl_runtime_apis! {
} }
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> { 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> { 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::define_benchmarks!(
[frame_benchmarking, BaselineBench::<Runtime>] [frame_benchmarking, BaselineBench::<Runtime>]
[frame_system, SystemBench::<Runtime>] [frame_system, SystemBench::<Runtime>]
[frame_system_extensions, SystemExtensionsBench::<Runtime>]
[pallet_balances, Balances] [pallet_balances, Balances]
[pallet_timestamp, Timestamp] [pallet_timestamp, Timestamp]
[pallet_sudo, Sudo] [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 FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>; type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = RuntimeHoldReason; type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason;
type DoneSlashHandler = ();
} }
parameter_types! { parameter_types! {
@@ -147,6 +148,7 @@ impl pallet_transaction_payment::Config for Runtime {
type WeightToFee = IdentityFee<Balance>; type WeightToFee = IdentityFee<Balance>;
type LengthToFee = IdentityFee<Balance>; type LengthToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ConstFeeMultiplier<FeeMultiplier>; type FeeMultiplierUpdate = ConstFeeMultiplier<FeeMultiplier>;
type WeightInfo = pallet_transaction_payment::weights::SubstrateWeight<Runtime>;
} }
impl pallet_sudo::Config for 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; extern crate alloc;
use alloc::vec::Vec; use alloc::vec::Vec;
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, generic, impl_opaque_keys,
traits::{BlakeTwo256, IdentifyAccount, Verify}, traits::{BlakeTwo256, IdentifyAccount, Verify},
MultiAddress, MultiSignature, MultiAddress, MultiSignature,
}; };
@@ -25,6 +25,8 @@ pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage; 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 /// 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 /// 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 /// 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 // https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning
#[sp_version::runtime_version] #[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion { pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("solochain-template-runtime"), spec_name: alloc::borrow::Cow::Borrowed("solochain-template-runtime"),
impl_name: create_runtime_str!("solochain-template-runtime"), impl_name: alloc::borrow::Cow::Borrowed("solochain-template-runtime"),
authoring_version: 1, authoring_version: 1,
// The version of the runtime specification. A full node will not attempt to use its native // 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`, // 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, impl_version: 1,
apis: apis::RUNTIME_API_VERSIONS, apis: apis::RUNTIME_API_VERSIONS,
transaction_version: 1, transaction_version: 1,
state_version: 1, system_version: 1,
}; };
mod block_times { mod block_times {
@@ -144,8 +146,8 @@ pub type SignedBlock = generic::SignedBlock<Block>;
/// BlockId type as expected by this runtime. /// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>; pub type BlockId = generic::BlockId<Block>;
/// The SignedExtension to the basic transaction logic. /// The `TransactionExtension` to the basic transaction logic.
pub type SignedExtra = ( pub type TxExtension = (
frame_system::CheckNonZeroSender<Runtime>, frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>, frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>, frame_system::CheckTxVersion<Runtime>,
@@ -159,10 +161,10 @@ pub type SignedExtra = (
/// Unchecked extrinsic type as expected by this runtime. /// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>; generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
/// The payload being signed in transactions. /// 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. /// 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. // Include the custom logic from the pallet-template in the runtime.
#[runtime::pallet_index(7)] #[runtime::pallet_index(7)]
pub type TemplateModule = pallet_template; pub type Template = pallet_template;
} }