mirror of
https://github.com/pezkuwichain/pez-solochain-template.git
synced 2026-04-21 23:47:59 +00:00
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:
committed by
GitHub
parent
93f30a2356
commit
e4c83d4c89
Generated
+2965
-1154
File diff suppressed because it is too large
Load Diff
+52
-52
@@ -16,59 +16,59 @@ resolver = "2"
|
||||
[workspace.dependencies]
|
||||
solochain-template-runtime = { path = "./runtime", default-features = false }
|
||||
pallet-template = { path = "./pallets/template", default-features = false }
|
||||
clap = { version = "4.5.10" }
|
||||
frame-benchmarking-cli = { version = "43.0.0", default-features = false }
|
||||
frame-metadata-hash-extension = { version = "0.6.0", default-features = false }
|
||||
frame-system = { version = "38.0.0", default-features = false }
|
||||
futures = { version = "0.3.30" }
|
||||
clap = { version = "4.5.13" }
|
||||
frame-benchmarking-cli = { version = "46.0.0", default-features = false }
|
||||
frame-metadata-hash-extension = { version = "0.7.0", default-features = false }
|
||||
frame-system = { version = "39.1.0", default-features = false }
|
||||
futures = { version = "0.3.31" }
|
||||
jsonrpsee = { version = "0.24.3" }
|
||||
pallet-transaction-payment = { version = "38.0.0", default-features = false }
|
||||
pallet-transaction-payment-rpc = { version = "41.0.0", default-features = false }
|
||||
sc-basic-authorship = { version = "0.45.0", default-features = false }
|
||||
sc-cli = { version = "0.47.0", default-features = false }
|
||||
sc-client-api = { version = "37.0.0", default-features = false }
|
||||
sc-consensus = { version = "0.44.0", default-features = false }
|
||||
sc-consensus-aura = { version = "0.45.0", default-features = false }
|
||||
sc-consensus-grandpa = { version = "0.30.0", default-features = false }
|
||||
sc-executor = { version = "0.40.1", default-features = false }
|
||||
sc-network = { version = "0.45.0", default-features = false }
|
||||
sc-offchain = { version = "40.0.0", default-features = false }
|
||||
sc-service = { version = "0.46.0", default-features = false }
|
||||
sc-telemetry = { version = "25.0.0", default-features = false }
|
||||
sc-transaction-pool = { version = "37.0.0", default-features = false }
|
||||
sc-transaction-pool-api = { version = "37.0.0", default-features = false }
|
||||
serde_json = { version = "1.0.127", default-features = false }
|
||||
sp-api = { version = "34.0.0", default-features = false }
|
||||
sp-block-builder = { version = "34.0.0", default-features = false }
|
||||
sp-blockchain = { version = "37.0.1", default-features = false }
|
||||
sp-consensus-aura = { version = "0.40.0", default-features = false }
|
||||
sp-consensus-grandpa = { version = "21.0.0", default-features = false }
|
||||
sp-core = { version = "34.0.0", default-features = false }
|
||||
sp-inherents = { version = "34.0.0", default-features = false }
|
||||
sp-io = { version = "38.0.0", default-features = false }
|
||||
sp-keyring = { version = "39.0.0", default-features = false }
|
||||
sp-runtime = { version = "39.0.1", default-features = false }
|
||||
sp-timestamp = { version = "34.0.0", default-features = false }
|
||||
substrate-frame-rpc-system = { version = "39.0.0", default-features = false }
|
||||
pallet-transaction-payment = { version = "39.0.0", default-features = false }
|
||||
pallet-transaction-payment-rpc = { version = "42.0.0", default-features = false }
|
||||
sc-basic-authorship = { version = "0.48.0", default-features = false }
|
||||
sc-cli = { version = "0.50.0", default-features = false }
|
||||
sc-client-api = { version = "38.0.0", default-features = false }
|
||||
sc-consensus = { version = "0.47.0", default-features = false }
|
||||
sc-consensus-aura = { version = "0.48.0", default-features = false }
|
||||
sc-consensus-grandpa = { version = "0.33.0", default-features = false }
|
||||
sc-executor = { version = "0.41.0", default-features = false }
|
||||
sc-network = { version = "0.48.0", default-features = false }
|
||||
sc-offchain = { version = "43.0.0", default-features = false }
|
||||
sc-service = { version = "0.49.0", default-features = false }
|
||||
sc-telemetry = { version = "28.0.0", default-features = false }
|
||||
sc-transaction-pool = { version = "38.0.0", default-features = false }
|
||||
sc-transaction-pool-api = { version = "38.0.0", default-features = false }
|
||||
serde_json = { version = "1.0.132", default-features = false }
|
||||
sp-api = { version = "35.0.0", default-features = false }
|
||||
sp-block-builder = { version = "35.0.0", default-features = false }
|
||||
sp-blockchain = { version = "38.0.0", default-features = false }
|
||||
sp-consensus-aura = { version = "0.41.0", default-features = false }
|
||||
sp-consensus-grandpa = { version = "22.0.0", default-features = false }
|
||||
sp-core = { version = "35.0.0", default-features = false }
|
||||
sp-genesis-builder = { version = "0.16.0", default-features = false }
|
||||
sp-inherents = { version = "35.0.0", default-features = false }
|
||||
sp-io = { version = "39.0.0", default-features = false }
|
||||
sp-keyring = { version = "40.0.0", default-features = false }
|
||||
sp-runtime = { version = "40.1.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 }
|
||||
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
||||
frame-benchmarking = { version = "38.0.0", default-features = false }
|
||||
frame-executive = { version = "38.0.0", default-features = false }
|
||||
frame-support = { version = "38.0.0", default-features = false }
|
||||
frame-system-benchmarking = { version = "38.0.0", default-features = false }
|
||||
frame-system-rpc-runtime-api = { version = "34.0.0", default-features = false }
|
||||
frame-try-runtime = { version = "0.44.0", default-features = false }
|
||||
pallet-aura = { version = "37.0.0", default-features = false }
|
||||
pallet-balances = { version = "39.0.0", default-features = false }
|
||||
pallet-grandpa = { version = "38.0.0", default-features = false }
|
||||
pallet-sudo = { version = "38.0.0", default-features = false }
|
||||
pallet-timestamp = { version = "37.0.0", default-features = false }
|
||||
pallet-transaction-payment-rpc-runtime-api = { version = "38.0.0", default-features = false }
|
||||
frame-benchmarking = { version = "39.0.0", default-features = false }
|
||||
frame-executive = { version = "39.0.0", default-features = false }
|
||||
frame-support = { version = "39.0.0", default-features = false }
|
||||
frame-system-benchmarking = { version = "39.0.0", default-features = false }
|
||||
frame-system-rpc-runtime-api = { version = "35.0.0", default-features = false }
|
||||
frame-try-runtime = { version = "0.45.0", default-features = false }
|
||||
pallet-aura = { version = "38.0.0", default-features = false }
|
||||
pallet-balances = { version = "40.0.0", default-features = false }
|
||||
pallet-grandpa = { version = "39.0.0", default-features = false }
|
||||
pallet-sudo = { version = "39.0.0", default-features = false }
|
||||
pallet-timestamp = { 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 }
|
||||
sp-genesis-builder = { version = "0.15.1", default-features = false }
|
||||
sp-offchain = { version = "34.0.0", default-features = false }
|
||||
sp-session = { version = "36.0.0", default-features = false }
|
||||
sp-storage = { version = "21.0.0", default-features = false }
|
||||
sp-transaction-pool = { version = "34.0.0", default-features = false }
|
||||
sp-version = { version = "37.0.0", default-features = false }
|
||||
substrate-wasm-builder = { version = "24.0.1", default-features = false }
|
||||
sp-offchain = { version = "35.0.0", default-features = false }
|
||||
sp-session = { version = "37.0.0", default-features = false }
|
||||
sp-storage = { version = "22.0.0", default-features = false }
|
||||
sp-transaction-pool = { version = "35.0.0", default-features = false }
|
||||
sp-version = { version = "38.0.0", default-features = false }
|
||||
substrate-wasm-builder = { version = "25.0.0", default-features = false }
|
||||
|
||||
@@ -23,9 +23,17 @@ packages required to compile this template. Check the
|
||||
the most common dependencies. Alternatively, you can use one of the [alternative
|
||||
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
|
||||
|
||||
Use the following command to build the node without launching it:
|
||||
🔨 Use the following command to build the node without launching it:
|
||||
|
||||
```sh
|
||||
cargo build --release
|
||||
@@ -177,7 +185,7 @@ template and note the following:
|
||||
configuration is defined by a code block that begins with `impl
|
||||
$PALLET_NAME::Config for Runtime`.
|
||||
- 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
|
||||
library](https://docs.substrate.io/reference/frame-pallets/#system-pallets).
|
||||
|
||||
|
||||
+6
-5
@@ -37,16 +37,18 @@ sc-transaction-pool-api.workspace = true
|
||||
sc-transaction-pool-api.default-features = true
|
||||
sc-offchain.workspace = true
|
||||
sc-offchain.default-features = true
|
||||
sc-consensus.workspace = true
|
||||
sc-consensus.default-features = true
|
||||
sc-consensus-aura.workspace = true
|
||||
sc-consensus-aura.default-features = true
|
||||
sp-consensus-aura.workspace = true
|
||||
sp-consensus-aura.default-features = true
|
||||
sc-consensus.workspace = true
|
||||
sc-consensus.default-features = true
|
||||
sc-consensus-grandpa.workspace = true
|
||||
sc-consensus-grandpa.default-features = true
|
||||
sp-consensus-grandpa.workspace = 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.default-features = true
|
||||
sc-basic-authorship.workspace = true
|
||||
@@ -87,13 +89,12 @@ substrate-build-script-utils.default-features = true
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"solochain-template-runtime/std",
|
||||
]
|
||||
std = ["solochain-template-runtime/std"]
|
||||
# Dependencies that are only required if runtime benchmarking should be build.
|
||||
runtime-benchmarks = [
|
||||
"frame-benchmarking-cli/runtime-benchmarks",
|
||||
"frame-system/runtime-benchmarks",
|
||||
"pallet-transaction-payment/runtime-benchmarks",
|
||||
"sc-service/runtime-benchmarks",
|
||||
"solochain-template-runtime/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
|
||||
## Release
|
||||
|
||||
Polkadot SDK stable2409
|
||||
Polkadot SDK Stable 2412
|
||||
|
||||
@@ -109,7 +109,7 @@ pub fn create_benchmark_extrinsic(
|
||||
.checked_next_power_of_two()
|
||||
.map(|c| c / 2)
|
||||
.unwrap_or(2) as u64;
|
||||
let extra: runtime::SignedExtra = (
|
||||
let tx_ext: runtime::TxExtension = (
|
||||
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
|
||||
frame_system::CheckSpecVersion::<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(
|
||||
call.clone(),
|
||||
extra.clone(),
|
||||
tx_ext.clone(),
|
||||
(
|
||||
(),
|
||||
runtime::VERSION.spec_version,
|
||||
@@ -145,7 +145,7 @@ pub fn create_benchmark_extrinsic(
|
||||
call,
|
||||
sp_runtime::AccountId32::from(sender.public()).into(),
|
||||
runtime::Signature::Sr25519(signature),
|
||||
extra,
|
||||
tx_ext,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+5
-93
@@ -1,39 +1,10 @@
|
||||
use sc_service::ChainType;
|
||||
use solochain_template_runtime::{AccountId, Signature, 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/";
|
||||
use solochain_template_runtime::WASM_BINARY;
|
||||
|
||||
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
|
||||
pub type ChainSpec = sc_service::GenericChainSpec;
|
||||
|
||||
/// Generate a crypto pair from seed.
|
||||
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> {
|
||||
pub fn development_chain_spec() -> Result<ChainSpec, String> {
|
||||
Ok(ChainSpec::builder(
|
||||
WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?,
|
||||
None,
|
||||
@@ -41,24 +12,11 @@ pub fn development_config() -> Result<ChainSpec, String> {
|
||||
.with_name("Development")
|
||||
.with_id("dev")
|
||||
.with_chain_type(ChainType::Development)
|
||||
.with_genesis_config_patch(testnet_genesis(
|
||||
// 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,
|
||||
))
|
||||
.with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET)
|
||||
.build())
|
||||
}
|
||||
|
||||
pub fn local_testnet_config() -> Result<ChainSpec, String> {
|
||||
pub fn local_chain_spec() -> Result<ChainSpec, String> {
|
||||
Ok(ChainSpec::builder(
|
||||
WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?,
|
||||
None,
|
||||
@@ -66,52 +24,6 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
|
||||
.with_name("Local Testnet")
|
||||
.with_id("local_testnet")
|
||||
.with_chain_type(ChainType::Local)
|
||||
.with_genesis_config_patch(testnet_genesis(
|
||||
// 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,
|
||||
))
|
||||
.with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET)
|
||||
.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
@@ -37,8 +37,8 @@ impl SubstrateCli for Cli {
|
||||
|
||||
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
Ok(match id {
|
||||
"dev" => Box::new(chain_spec::development_config()?),
|
||||
"" | "local" => Box::new(chain_spec::local_testnet_config()?),
|
||||
"dev" => Box::new(chain_spec::development_chain_spec()?),
|
||||
"" | "local" => Box::new(chain_spec::local_chain_spec()?),
|
||||
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());
|
||||
|
||||
cmd.run(
|
||||
config,
|
||||
config.chain_spec.name().into(),
|
||||
client,
|
||||
inherent_benchmark_data()?,
|
||||
Vec::new(),
|
||||
&ext_builder,
|
||||
false,
|
||||
)
|
||||
},
|
||||
BenchmarkCmd::Extrinsic(cmd) => {
|
||||
|
||||
+16
-13
@@ -28,7 +28,7 @@ pub type Service = sc_service::PartialComponents<
|
||||
FullBackend,
|
||||
FullSelectChain,
|
||||
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::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 transaction_pool = sc_transaction_pool::BasicPool::new_full(
|
||||
config.transaction_pool.clone(),
|
||||
config.role.is_authority().into(),
|
||||
config.prometheus_registry(),
|
||||
task_manager.spawn_essential_handle(),
|
||||
client.clone(),
|
||||
let transaction_pool = Arc::from(
|
||||
sc_transaction_pool::Builder::new(
|
||||
task_manager.spawn_essential_handle(),
|
||||
client.clone(),
|
||||
config.role.is_authority().into(),
|
||||
)
|
||||
.with_options(config.transaction_pool.clone())
|
||||
.with_prometheus(config.prometheus_registry())
|
||||
.build(),
|
||||
);
|
||||
|
||||
let (grandpa_block_import, grandpa_link) = sc_consensus_grandpa::block_import(
|
||||
@@ -181,9 +184,7 @@ pub fn new_full<
|
||||
})?;
|
||||
|
||||
if config.offchain_worker.enabled {
|
||||
task_manager.spawn_handle().spawn(
|
||||
"offchain-workers-runner",
|
||||
"offchain-worker",
|
||||
let offchain_workers =
|
||||
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
|
||||
runtime_api_provider: client.clone(),
|
||||
is_validator: config.role.is_authority(),
|
||||
@@ -195,9 +196,11 @@ pub fn new_full<
|
||||
network_provider: Arc::new(network.clone()),
|
||||
enable_http_requests: true,
|
||||
custom_extensions: |_| vec![],
|
||||
})
|
||||
.run(client.clone(), task_manager.spawn_handle())
|
||||
.boxed(),
|
||||
})?;
|
||||
task_manager.spawn_handle().spawn(
|
||||
"offchain-workers-runner",
|
||||
"offchain-worker",
|
||||
offchain_workers.run(client.clone(), task_manager.spawn_handle()).boxed(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,4 +3,4 @@ License: MIT-0
|
||||
|
||||
## Release
|
||||
|
||||
Polkadot SDK stable2409
|
||||
Polkadot SDK Stable 2412
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Benchmarking setup for pallet-template
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
|
||||
#[allow(unused)]
|
||||
|
||||
@@ -4,14 +4,30 @@ use sp_runtime::BuildStorage;
|
||||
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
|
||||
// Configure a mock runtime to test the pallet.
|
||||
frame_support::construct_runtime!(
|
||||
pub enum Test
|
||||
{
|
||||
System: frame_system,
|
||||
TemplateModule: pallet_template,
|
||||
}
|
||||
);
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
// The main runtime
|
||||
#[runtime::runtime]
|
||||
// Runtime Types to be generated
|
||||
#[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)]
|
||||
impl frame_system::Config for Test {
|
||||
|
||||
@@ -7,7 +7,7 @@ fn it_works_for_default_value() {
|
||||
// Go past genesis block so events get deposited
|
||||
System::set_block_number(1);
|
||||
// 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.
|
||||
assert_eq!(Something::<Test>::get(), Some(42));
|
||||
// Assert that the correct event was deposited
|
||||
@@ -19,9 +19,6 @@ fn it_works_for_default_value() {
|
||||
fn correct_error_for_none_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Ensure the expected error is thrown when no value is present.
|
||||
assert_noop!(
|
||||
TemplateModule::cause_error(RuntimeOrigin::signed(1)),
|
||||
Error::<Test>::NoneValue
|
||||
);
|
||||
assert_noop!(Template::cause_error(RuntimeOrigin::signed(1)), Error::<Test>::NoneValue);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ pub trait WeightInfo {
|
||||
/// Weights for pallet_template using the Substrate node and recommended hardware.
|
||||
pub struct SubstrateWeight<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
/// Storage: TemplateModule Something (r:0 w:1)
|
||||
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
/// Storage: Template Something (r:0 w:1)
|
||||
/// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
fn do_something() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
@@ -51,8 +51,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
Weight::from_parts(9_000_000, 0)
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: TemplateModule Something (r:1 w:1)
|
||||
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
/// Storage: Template Something (r:1 w:1)
|
||||
/// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
fn cause_error() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `32`
|
||||
@@ -66,8 +66,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
|
||||
// For backwards compatibility and tests
|
||||
impl WeightInfo for () {
|
||||
/// Storage: TemplateModule Something (r:0 w:1)
|
||||
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
/// Storage: Template Something (r:0 w:1)
|
||||
/// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
fn do_something() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
@@ -76,8 +76,8 @@ impl WeightInfo for () {
|
||||
Weight::from_parts(9_000_000, 0)
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: TemplateModule Something (r:1 w:1)
|
||||
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
/// Storage: Template Something (r:1 w:1)
|
||||
/// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
|
||||
fn cause_error() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `32`
|
||||
|
||||
+7
-7
@@ -20,6 +20,7 @@ scale-info = { features = [
|
||||
"derive",
|
||||
"serde",
|
||||
], workspace = true }
|
||||
serde_json = { workspace = true, default-features = false, features = ["alloc"] }
|
||||
frame-support = { features = ["experimental"], workspace = true }
|
||||
frame-system.workspace = true
|
||||
frame-try-runtime = { optional = true, workspace = true }
|
||||
@@ -35,6 +36,7 @@ sp-api.workspace = true
|
||||
sp-block-builder.workspace = true
|
||||
sp-consensus-aura = { features = ["serde"], workspace = true }
|
||||
sp-consensus-grandpa = { features = ["serde"], workspace = true }
|
||||
sp-keyring.workspace = true
|
||||
sp-core = { features = ["serde"], workspace = true }
|
||||
sp-inherents.workspace = true
|
||||
sp-offchain.workspace = true
|
||||
@@ -57,18 +59,14 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features =
|
||||
default = ["std"]
|
||||
std = [
|
||||
"codec/std",
|
||||
"scale-info/std",
|
||||
|
||||
"frame-benchmarking?/std",
|
||||
"frame-executive/std",
|
||||
"frame-metadata-hash-extension/std",
|
||||
"frame-support/std",
|
||||
"frame-system-benchmarking?/std",
|
||||
"frame-system-rpc-runtime-api/std",
|
||||
"frame-system/std",
|
||||
|
||||
"frame-benchmarking?/std",
|
||||
"frame-try-runtime?/std",
|
||||
|
||||
"pallet-aura/std",
|
||||
"pallet-balances/std",
|
||||
"pallet-grandpa/std",
|
||||
@@ -77,7 +75,8 @@ std = [
|
||||
"pallet-timestamp/std",
|
||||
"pallet-transaction-payment-rpc-runtime-api/std",
|
||||
"pallet-transaction-payment/std",
|
||||
|
||||
"scale-info/std",
|
||||
"serde_json/std",
|
||||
"sp-api/std",
|
||||
"sp-block-builder/std",
|
||||
"sp-consensus-aura/std",
|
||||
@@ -85,13 +84,13 @@ std = [
|
||||
"sp-core/std",
|
||||
"sp-genesis-builder/std",
|
||||
"sp-inherents/std",
|
||||
"sp-keyring/std",
|
||||
"sp-offchain/std",
|
||||
"sp-runtime/std",
|
||||
"sp-session/std",
|
||||
"sp-storage/std",
|
||||
"sp-transaction-pool/std",
|
||||
"sp-version/std",
|
||||
|
||||
"substrate-wasm-builder",
|
||||
]
|
||||
|
||||
@@ -105,6 +104,7 @@ runtime-benchmarks = [
|
||||
"pallet-sudo/runtime-benchmarks",
|
||||
"pallet-template/runtime-benchmarks",
|
||||
"pallet-timestamp/runtime-benchmarks",
|
||||
"pallet-transaction-payment/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
]
|
||||
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
|
||||
## Release
|
||||
|
||||
Polkadot SDK stable2409
|
||||
Polkadot SDK Stable 2412
|
||||
|
||||
+6
-4
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user