Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements in solochain template #5111

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions substrate/frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ frame-system = { workspace = true }
# primitive types used for developing FRAME runtimes.
sp-version = { optional = true, workspace = true }
sp-api = { optional = true, workspace = true }
sp-genesis-builder = { optional = true, workspace = true }
sp-block-builder = { optional = true, workspace = true }
sp-transaction-pool = { optional = true, workspace = true }
sp-offchain = { optional = true, workspace = true }
Expand Down Expand Up @@ -71,6 +72,7 @@ runtime = [
"sp-block-builder",
"sp-consensus-aura",
"sp-consensus-grandpa",
"sp-genesis-builder",
"sp-inherents",
"sp-offchain",
"sp-session",
Expand All @@ -81,6 +83,14 @@ runtime = [
"frame-executive",
"frame-system-rpc-runtime-api",
]
serde = [
"sp-consensus-aura?/serde",
"sp-consensus-grandpa?/serde",

"sp-core/serde",
"sp-runtime/serde",
"sp-version?/serde",
]
std = [
"codec/std",
"frame-benchmarking?/std",
Expand All @@ -98,6 +108,7 @@ std = [
"sp-consensus-aura?/std",
"sp-consensus-grandpa?/std",
"sp-core/std",
"sp-genesis-builder?/std",
"sp-inherents?/std",
"sp-io/std",
"sp-offchain?/std",
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ pub mod runtime {
pub use sp_block_builder::*;
pub use sp_consensus_aura::*;
pub use sp_consensus_grandpa::*;
pub use sp_genesis_builder::{Result as GenesisBuilderResult, *};
pub use sp_offchain::*;
pub use sp_session::runtime_api::*;
pub use sp_transaction_pool::runtime_api::*;
Expand Down Expand Up @@ -383,6 +384,8 @@ pub mod deps {
#[cfg(feature = "runtime")]
pub use sp_consensus_grandpa;
#[cfg(feature = "runtime")]
pub use sp_genesis_builder;
#[cfg(feature = "runtime")]
pub use sp_inherents;
#[cfg(feature = "runtime")]
pub use sp_offchain;
Expand Down
6 changes: 0 additions & 6 deletions templates/minimal/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }

# genesis builder that allows us to interact with runtime genesis config
sp-genesis-builder = { workspace = true }
sp-runtime = { features = ["serde"], workspace = true }

# local pallet templates
pallet-minimal-template = { workspace = true }

Expand All @@ -52,7 +48,5 @@ std = [

"pallet-minimal-template/std",

"sp-genesis-builder/std",
"sp-runtime/std",
"substrate-wasm-builder",
]
10 changes: 5 additions & 5 deletions templates/minimal/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use frame::{
runtime::{
apis::{
self, impl_runtime_apis, ApplyExtrinsicResult, CheckInherentsResult,
ExtrinsicInclusionMode, OpaqueMetadata,
ExtrinsicInclusionMode, GenesisBuilderResult, OpaqueMetadata, PresetId,
},
prelude::*,
},
Expand Down Expand Up @@ -274,16 +274,16 @@ impl_runtime_apis! {
}
}

impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
impl apis::GenesisBuilder<Block> for Runtime {
fn build_state(config: Vec<u8>) -> GenesisBuilderResult {
build_state::<RuntimeGenesisConfig>(config)
}

fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
fn get_preset(id: &Option<PresetId>) -> Option<Vec<u8>> {
get_preset::<RuntimeGenesisConfig>(id, |_| None)
}

fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
fn preset_names() -> Vec<PresetId> {
vec![]
}
}
Expand Down
43 changes: 22 additions & 21 deletions templates/solochain/node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use crate::service::FullClient;

use runtime::{AccountId, Balance, BalancesCall, SystemCall};
use runtime::interface::{
AccountId, Balance, BalancesCall, BlockHashCount, Runtime, RuntimeCall, Signature, SignedExtra,
SignedPayload, SystemCall, UncheckedExtrinsic, VERSION,
};
use sc_cli::Result;
use sc_client_api::BlockBackend;
use solochain_template_runtime as runtime;
Expand Down Expand Up @@ -98,38 +101,36 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
pub fn create_benchmark_extrinsic(
client: &FullClient,
sender: sp_core::sr25519::Pair,
call: runtime::RuntimeCall,
call: RuntimeCall,
nonce: u32,
) -> runtime::UncheckedExtrinsic {
) -> UncheckedExtrinsic {
let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
let best_hash = client.chain_info().best_hash;
let best_block = client.chain_info().best_number;

let period = runtime::BlockHashCount::get()
.checked_next_power_of_two()
.map(|c| c / 2)
.unwrap_or(2) as u64;
let extra: runtime::SignedExtra = (
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
frame_system::CheckGenesis::<runtime::Runtime>::new(),
frame_system::CheckEra::<runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
let period =
BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let extra: SignedExtra = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(sp_runtime::generic::Era::mortal(
period,
best_block.saturated_into(),
)),
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
frame_system::CheckWeight::<runtime::Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
);

let raw_payload = runtime::SignedPayload::from_raw(
let raw_payload = SignedPayload::from_raw(
call.clone(),
extra.clone(),
(
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
VERSION.spec_version,
VERSION.transaction_version,
genesis_hash,
best_hash,
(),
Expand All @@ -139,10 +140,10 @@ pub fn create_benchmark_extrinsic(
);
let signature = raw_payload.using_encoded(|e| sender.sign(e));

runtime::UncheckedExtrinsic::new_signed(
UncheckedExtrinsic::new_signed(
call,
sp_runtime::AccountId32::from(sender.public()).into(),
runtime::Signature::Sr25519(signature),
Signature::Sr25519(signature),
extra,
)
}
Expand Down
5 changes: 4 additions & 1 deletion templates/solochain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use sc_service::ChainType;
use solochain_template_runtime::{AccountId, Signature, WASM_BINARY};
use solochain_template_runtime::{
interface::{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};
Expand Down
6 changes: 3 additions & 3 deletions templates/solochain/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
use sc_cli::SubstrateCli;
use sc_service::PartialComponents;
use solochain_template_runtime::{Block, EXISTENTIAL_DEPOSIT};
use solochain_template_runtime::interface::{Block, OpaqueBlock, EXISTENTIAL_DEPOSIT};
use sp_keyring::Sr25519Keyring;

impl SubstrateCli for Cli {
Expand Down Expand Up @@ -180,8 +180,8 @@ pub fn run() -> sc_cli::Result<()> {
match config.network.network_backend {
sc_network::config::NetworkBackendType::Libp2p => service::new_full::<
sc_network::NetworkWorker<
solochain_template_runtime::opaque::Block,
<solochain_template_runtime::opaque::Block as sp_runtime::traits::Block>::Hash,
OpaqueBlock,
<OpaqueBlock as sp_runtime::traits::Block>::Hash,
>,
>(config)
.map_err(sc_cli::Error::Service),
Expand Down
2 changes: 1 addition & 1 deletion templates/solochain/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::Arc;

use jsonrpsee::RpcModule;
use sc_transaction_pool_api::TransactionPool;
use solochain_template_runtime::{opaque::Block, AccountId, Balance, Nonce};
use solochain_template_runtime::interface::{AccountId, Balance, Nonce, OpaqueBlock as Block};
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
Expand Down
2 changes: 1 addition & 1 deletion templates/solochain/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use sc_consensus_grandpa::SharedVoterState;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use solochain_template_runtime::{self, opaque::Block, RuntimeApi};
use solochain_template_runtime::{self, interface::OpaqueBlock as Block, RuntimeApi};
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use std::{sync::Arc, time::Duration};

Expand Down
Loading
Loading