Skip to content

Commit

Permalink
fix: benachmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
nakul1010 committed Sep 5, 2023
1 parent 775672e commit fde2626
Show file tree
Hide file tree
Showing 17 changed files with 664 additions and 653 deletions.
631 changes: 316 additions & 315 deletions Cargo.lock

Large diffs are not rendered by default.

473 changes: 237 additions & 236 deletions Cargo.toml

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions crates/bitcoin/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ impl TryFormat for CompactUint {
fn try_format<W: Writer>(&self, w: &mut W) -> Result<(), Error> {
if self.value < 0xfd {
(self.value as u8).try_format(w)?;
} else if self.value < u16::max_value() as u64 {
} else if self.value < u16::MAX as u64 {
0xfd_u8.try_format(w)?;
(self.value as u16).try_format(w)?;
} else if self.value < u32::max_value() as u64 {
} else if self.value < u32::MAX as u64 {
0xfe_u8.try_format(w)?;
(self.value as u32).try_format(w)?;
} else {
Expand Down Expand Up @@ -136,7 +136,7 @@ where
impl TryFormat for TransactionInput {
fn try_format<W: Writer>(&self, w: &mut W) -> Result<(), Error> {
let (previous_hash, previous_index) = match self.source {
TransactionInputSource::Coinbase(_) => (H256Le::zero(), u32::max_value()),
TransactionInputSource::Coinbase(_) => (H256Le::zero(), u32::MAX),
TransactionInputSource::FromOutput(hash, index) => (hash, index),
};
previous_hash.try_format(w)?;
Expand Down Expand Up @@ -304,7 +304,7 @@ mod tests {
assert_eq!(try_format(256u16), [0, 1]);
assert_eq!(try_format(0xffffu32 + 1), [0, 0, 1, 0]);
assert_eq!(try_format(0xffffffu32 + 1), [0, 0, 0, 1]);
assert_eq!(try_format(u64::max_value()), [0xff].repeat(8));
assert_eq!(try_format(u64::MAX), [0xff].repeat(8));
}

#[test]
Expand All @@ -313,9 +313,7 @@ mod tests {
assert_eq!(try_format(CompactUint { value: 0xff }), [0xfd, 0xff, 0]);
let u32_cuint = CompactUint { value: 0xffff + 1 };
assert_eq!(try_format(u32_cuint), [0xfe, 0, 0, 1, 0]);
let u64_cuint = CompactUint {
value: u64::max_value(),
};
let u64_cuint = CompactUint { value: u64::MAX };
assert_eq!(try_format(u64_cuint), [0xff].repeat(9));
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bitcoin/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn parse_transaction_input(raw_input: &[u8], version: i32) -> Result<(Transactio

// fail if transaction is coinbase and previous index is not 0xffffffff
// previous_hash
if is_coinbase && previous_index != u32::max_value() {
if is_coinbase && previous_index != u32::MAX {
return Err(Error::MalformedTransaction);
}

Expand Down Expand Up @@ -559,7 +559,7 @@ pub(crate) mod tests {
let previous_hash = H256Le::from_hex_le("7b1eabe0209b1fe794124575ef807057c77ada2138ae4fa8d6c4de0398a14f3f");

assert!(matches!(input.source, TransactionInputSource::FromOutput(hash, 0) if hash == previous_hash));
assert_eq!(input.sequence, u32::max_value());
assert_eq!(input.sequence, u32::MAX);
assert_eq!(input.script.len(), 73);
}

Expand Down
7 changes: 1 addition & 6 deletions crates/bitcoin/src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ pub const TARGET_TIMESPAN_DIVISOR: u64 = 4;

/// Unrounded Maximum Target
/// 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
pub const UNROUNDED_MAX_TARGET: U256 = U256([
<u64>::max_value(),
<u64>::max_value(),
<u64>::max_value(),
0x0000_0000_ffff_ffffu64,
]);
pub const UNROUNDED_MAX_TARGET: U256 = U256([<u64>::MAX, <u64>::MAX, <u64>::MAX, 0x0000_0000_ffff_ffffu64]);

// https://github.com/bitcoin/bitcoin/blob/89b910711c004c21b7d67baa888073742f7f94f0/src/pow.cpp#L49-L72
pub fn calculate_next_work_required(
Expand Down
2 changes: 1 addition & 1 deletion crates/bitcoin/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ fn generate_coinbase_transaction(
input_builder
.with_source(TransactionInputSource::Coinbase(Some(height)))
.add_witness(&[0; 32])
.with_sequence(u32::max_value());
.with_sequence(u32::MAX);
if let Some(script) = input_script {
input_builder.with_script(&script);
}
Expand Down
7 changes: 1 addition & 6 deletions crates/btc-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,7 @@ pub const ACCEPTED_MAX_TRANSACTION_OUTPUTS: usize = 3;

/// Unrounded Maximum Target
/// 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
pub const UNROUNDED_MAX_TARGET: U256 = U256([
<u64>::max_value(),
<u64>::max_value(),
<u64>::max_value(),
0x0000_0000_ffff_ffffu64,
]);
pub const UNROUNDED_MAX_TARGET: U256 = U256([<u64>::MAX, <u64>::MAX, <u64>::MAX, 0x0000_0000_ffff_ffffu64]);

/// Main chain id
pub const MAIN_CHAIN_ID: u32 = 0;
Expand Down
2 changes: 1 addition & 1 deletion crates/escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ impl<T: Config> Pallet<T> {
Self::checkpoint(who, old_locked, Default::default());

T::Currency::remove_lock(LOCK_ID, &who);
let _ = <UserPointHistory<T>>::clear_prefix(who, u32::max_value(), None);
let _ = <UserPointHistory<T>>::clear_prefix(who, u32::MAX, None);

Self::deposit_event(Event::<T>::Withdraw {
who: who.clone(),
Expand Down
1 change: 1 addition & 0 deletions parachain/runtime/interlay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ runtime-benchmarks = [
"pallet-society/runtime-benchmarks",

"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",

"pallet-xcm/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
Expand Down
14 changes: 11 additions & 3 deletions parachain/runtime/interlay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ mod benches {

// Other
[cumulus_pallet_xcmp_queue, XcmpQueue]
// [frame_system, frame_system_benchmarking::Pallet::<Runtime>]
[frame_system, frame_system_benchmarking::Pallet::<Runtime>]
[orml_asset_registry, runtime_common::benchmarking::orml_asset_registry::Pallet::<Runtime>]
[orml_tokens, runtime_common::benchmarking::orml_tokens::Pallet::<Runtime>]
[orml_vesting, runtime_common::benchmarking::orml_vesting::Pallet::<Runtime>]
Expand Down Expand Up @@ -1738,8 +1738,16 @@ impl_runtime_apis! {
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
impl frame_system_benchmarking::Config for Runtime {}
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey, BenchmarkError};
impl frame_system_benchmarking::Config for Runtime {
fn setup_set_code_requirements(code: &sp_std::vec::Vec<u8>) -> Result<(), BenchmarkError> {
ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
Ok(())
}
fn verify_set_code() {
System::assert_last_event(cumulus_pallet_parachain_system::Event::<Runtime>::ValidationFunctionStored.into());
}
}
impl runtime_common::benchmarking::orml_tokens::Config for Runtime {}
impl runtime_common::benchmarking::orml_vesting::Config for Runtime {}
impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {}
Expand Down
1 change: 1 addition & 0 deletions parachain/runtime/kintsugi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ runtime-benchmarks = [
"pallet-society/runtime-benchmarks",

"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",

"pallet-xcm/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
Expand Down
15 changes: 11 additions & 4 deletions parachain/runtime/kintsugi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use frame_system::{
use loans::{OnSlashHook, PostDeposit, PostTransfer, PreDeposit, PreTransfer};
use orml_asset_registry::SequentialId;
use orml_traits::{currency::MutationHooks, parameter_type_with_key};
use pallet_contracts_primitives::ContractResult;
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use sp_api::impl_runtime_apis;
use sp_core::{OpaqueMetadata, H256};
Expand Down Expand Up @@ -1445,7 +1444,7 @@ mod benches {

// Other
[cumulus_pallet_xcmp_queue, XcmpQueue]
// [frame_system, frame_system_benchmarking::Pallet::<Runtime>]
[frame_system, frame_system_benchmarking::Pallet::<Runtime>]
[orml_asset_registry, runtime_common::benchmarking::orml_asset_registry::Pallet::<Runtime>]
[orml_tokens, runtime_common::benchmarking::orml_tokens::Pallet::<Runtime>]
[orml_vesting, runtime_common::benchmarking::orml_vesting::Pallet::<Runtime>]
Expand Down Expand Up @@ -1609,8 +1608,16 @@ impl_runtime_apis! {
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
impl frame_system_benchmarking::Config for Runtime {}
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey, BenchmarkError};
impl frame_system_benchmarking::Config for Runtime {
fn setup_set_code_requirements(code: &sp_std::vec::Vec<u8>) -> Result<(), BenchmarkError> {
ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
Ok(())
}
fn verify_set_code() {
System::assert_last_event(cumulus_pallet_parachain_system::Event::<Runtime>::ValidationFunctionStored.into());
}
}
impl runtime_common::benchmarking::orml_tokens::Config for Runtime {}
impl runtime_common::benchmarking::orml_vesting::Config for Runtime {}
impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {}
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtime/kintsugi/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ parameter_types! {
}

/// Means for transacting assets on this chain.
type LocationToAccountId = (
pub type LocationToAccountId = (
// The parent (Relay-chain) origin converts to the default `AccountId`.
ParentIsPreset<AccountId>,
// Sibling parachain origins convert to AccountId via the `ParaId::into`.
Expand Down
Loading

0 comments on commit fde2626

Please sign in to comment.