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

Mangata solo develop #9

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions substrate/frame/authorship/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [
"derive",
] }
log = { version = "0.4.17", default-features = false }
impl-trait-for-tuples = "0.2.2"
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
frame-support = { path = "../support", default-features = false}
Expand Down
11 changes: 11 additions & 0 deletions substrate/frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ where
/// - `signature_check`
///
/// Should only be used for testing ONLY.
/// Might break not tested. Though should work
pub fn try_execute_block(
block: Block,
state_root_check: bool,
Expand Down Expand Up @@ -544,6 +545,16 @@ where
}
}

/// Returns if the runtime was upgraded since the last time the runtime_upgraded function was called.
/// DOES NOT UPDATE
/// ONLY VIEWS
pub fn runtime_upgraded_peek() -> bool {
let last = frame_system::LastRuntimeUpgrade::<System>::get();
let current = <System::Version as frame_support::traits::Get<_>>::get();

last.map(|v| v.was_upgraded(&current)).unwrap_or(true)
}

fn ver_checks(block: &Block, public_key: Vec<u8>) {
// Check that `parent_hash` is correct.
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "ver checks");
Expand Down
19 changes: 9 additions & 10 deletions substrate/utils/frame/benchmarking-cli/src/extrinsic/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sp_runtime::{
transaction_validity::{InvalidTransaction, TransactionValidityError},
Digest, DigestItem, OpaqueExtrinsic,
};
use std::{cell::RefCell, rc::Rc};
use std::{cell::RefCell, rc::Rc, sync::Mutex};
use ver_api::VerApi;

use clap::Args;
Expand Down Expand Up @@ -82,7 +82,7 @@ pub(crate) struct Benchmark<Block, BA, C> {
}

pub(crate) struct BenchmarkVer<Block, BA, C> {
client: Rc<RefCell<C>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why exactly these changes are needed? im pretty sure it works just fine at the moment ? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works just fine... But the rest of the relevant codebase uses Arc so I thought I'd switch to it entirely

client: Arc<Mutex<C>>,
params: BenchmarkParams,
inherent_data: (sp_inherents::InherentData, sp_inherents::InherentData),
_p: PhantomData<(Block, BA)>,
Expand Down Expand Up @@ -234,7 +234,7 @@ where
{
/// Create a new [`Self`] from the arguments.
pub fn new(
client: Rc<RefCell<C>>,
client: Arc<Mutex<C>>,
params: BenchmarkParams,
inherent_data: (sp_inherents::InherentData, sp_inherents::InherentData),
) -> Self {
Expand Down Expand Up @@ -294,9 +294,9 @@ where
StateAction::ApplyChanges(sc_consensus::StorageChanges::Changes(block.storage_changes));
params.fork_choice = Some(ForkChoiceStrategy::LongestChain);

futures::executor::block_on(self.client.borrow_mut().import_block(params))
futures::executor::block_on(self.client.lock().unwrap().import_block(params))
.expect("importing a block doesn't fail");
info!("best number: {} ", self.client.borrow().info().best_number);
info!("best number: {} ", self.client.lock().unwrap().info().best_number);
}

/// Builds a block that enqueues maximum possible amount of extrinsics
Expand All @@ -310,7 +310,7 @@ where
.map(|nonce| ext_builder.build(nonce).expect("remark txs creation should not fail"))
.collect::<Vec<_>>();

let client = self.client.borrow();
let client = self.client.lock().unwrap();
let mut builder = client.new_block(digest)?;

info!("creating inherents");
Expand Down Expand Up @@ -372,7 +372,7 @@ where
.collect::<Vec<_>>();

let digest = self.create_digest(3_u64);
let client = self.client.borrow();
let client = self.client.lock().unwrap();
let mut builder = client.new_block(digest)?;
let (seed, inherents) = builder.create_inherents(self.inherent_data.1.clone()).unwrap();
info!("pushing inherents");
Expand Down Expand Up @@ -404,8 +404,7 @@ where

info!("Running {} warmups...", self.params.warmup);
for _ in 0..self.params.warmup {
self.client
.borrow()
self.client.lock().unwrap()
.runtime_api()
.execute_block(parent, block.clone())
.map_err(|e| Error::Client(RuntimeApiError(e)))?;
Expand All @@ -416,7 +415,7 @@ where
// Execute a block multiple times and record each execution time.
for _ in 0..self.params.repeat {
let block = block.clone();
let client = self.client.borrow();
let client = self.client.lock().unwrap();
let runtime_api = client.runtime_api();
let start = Instant::now();

Expand Down
57 changes: 56 additions & 1 deletion substrate/utils/frame/benchmarking-cli/src/extrinsic/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
use sc_client_api::Backend as ClientBackend;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_runtime::{traits::Block as BlockT, DigestItem, OpaqueExtrinsic};
use sc_block_builder_ver::{
validate_transaction, BlockBuilderApi as BlockBuilderApiVer,
BlockBuilderProvider as BlockBuilderProviderVer,
};
use ver_api::VerApi;
use crate::extrinsic::bench::BenchmarkVer;
use sc_consensus::BlockImport;

use clap::{Args, Parser};
use log::info;
use serde::Serialize;
use std::{fmt::Debug, sync::Arc};
use std::{fmt::Debug, sync::Arc, sync::Mutex};

use super::{
bench::{Benchmark, BenchmarkParams},
Expand Down Expand Up @@ -129,6 +136,54 @@ impl ExtrinsicCmd {

Ok(())
}

pub fn run_ver<Block, BA, C>(
&self,
client: Arc<Mutex<C>>,
inherent_data: (sp_inherents::InherentData, sp_inherents::InherentData),
digest_items: Vec<DigestItem>,
ext_factory: &ExtrinsicFactory,
) -> Result<()>
where
Block: BlockT<Extrinsic = OpaqueExtrinsic>,
BA: ClientBackend<Block>,
C: BlockBuilderProviderVer<BA, Block, C>
+ ProvideRuntimeApi<Block>
+ sp_blockchain::HeaderBackend<Block>
+ BlockImport<Block>,
C::Api: ApiExt<Block> + BlockBuilderApiVer<Block> + VerApi<Block>,
{
// Short circuit if --list was specified.
if self.params.list {
let list: Vec<String> = ext_factory.0.iter().map(|b| b.name()).collect();
info!(
"Listing available extrinsics ({}):\npallet, extrinsic\n{}",
list.len(),
list.join("\n")
);
return Ok(())
}

let pallet = self.params.pallet.clone().unwrap_or_default();
let extrinsic = self.params.extrinsic.clone().unwrap_or_default();
let ext_builder = match ext_factory.try_get(&pallet, &extrinsic) {
Some(ext_builder) => ext_builder,
None =>
return Err("Unknown pallet or extrinsic. Use --list for a complete list.".into()),
};

let mut bench = BenchmarkVer::new(client, self.params.bench.clone(), inherent_data);
let count = bench.prepare_benchmark(ext_builder)?;
let stats = bench.bench_extrinsic(ext_builder, count)?;
info!(
"Executing a {}::{} extrinsic takes[ns]:\n{:?}",
ext_builder.pallet(),
ext_builder.extrinsic(),
stats
);

Ok(())
}
}

// Boilerplate
Expand Down
4 changes: 2 additions & 2 deletions substrate/utils/frame/benchmarking-cli/src/overhead/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sc_consensus::BlockImport;
use sc_service::Configuration;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_runtime::{traits::Block as BlockT, DigestItem, OpaqueExtrinsic};
use std::{cell::RefCell, rc::Rc};
use std::{cell::RefCell, rc::Rc, sync::Mutex};
use ver_api::VerApi;

use clap::{Args, Parser};
Expand Down Expand Up @@ -145,7 +145,7 @@ impl OverheadCmd {
pub fn run_ver<Block, BA, C>(
&self,
cfg: Configuration,
client: Rc<RefCell<C>>,
client: Arc<Mutex<C>>,
inherent_data: (sp_inherents::InherentData, sp_inherents::InherentData),
ext_builder: &dyn ExtrinsicBuilder,
) -> Result<()>
Expand Down
Loading