From b651ab36d27d14ab1c61c798722eb9a2cc8c370d Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Wed, 27 Sep 2023 10:29:40 +0530 Subject: [PATCH] fix: changed approach, remove looping --- crates/btc-relay/src/benchmarking.rs | 95 ++- crates/btc-relay/src/default_weights.rs | 669 +++++++++++------- crates/btc-relay/src/lib.rs | 246 +++---- crates/btc-relay/src/migration.rs | 25 + crates/btc-relay/src/tests.rs | 179 +++-- .../runtime/interlay/src/weights/btc_relay.rs | 344 +++++---- .../runtime/kintsugi/src/weights/btc_relay.rs | 348 +++++---- .../runtime-tests/src/parachain/btc_relay.rs | 3 - 8 files changed, 1166 insertions(+), 743 deletions(-) create mode 100644 crates/btc-relay/src/migration.rs diff --git a/crates/btc-relay/src/benchmarking.rs b/crates/btc-relay/src/benchmarking.rs index 087b2b994a..88a00449f9 100644 --- a/crates/btc-relay/src/benchmarking.rs +++ b/crates/btc-relay/src/benchmarking.rs @@ -62,6 +62,46 @@ pub mod benchmarks { _(RawOrigin::Signed(caller), block.header, height); } + #[benchmark] + pub fn set_chainwork_for_block() { + let caller: T::AccountId = whitelisted_caller(); + + let init_block = initialize_relay::(caller.clone()); + let init_block_hash = init_block.header.hash; + + migration::v1::migrate_from_v0_to_v1::(); + + let block = add_new_block_to_relay::(caller.clone(), init_block_hash, 0); + + #[extrinsic_call] + _(RawOrigin::Signed(caller), block.header.hash); + + // make sure chain work is stored + assert_eq!(BtcRelay::::contains_chainwork(block.header.hash), true); + } + + #[benchmark] + pub fn store_block_header_when_adding_chainwork() { + let caller: T::AccountId = whitelisted_caller(); + + let init_block = initialize_relay::(caller.clone()); + let init_block_hash = init_block.header.hash; + + migration::v1::migrate_from_v0_to_v1::(); + + let block = new_block::(init_block_hash, 0); + + #[extrinsic_call] + store_block_header(RawOrigin::Signed(caller), block.header, u32::MAX); + + // make sure block is stored + let rich_header = BtcRelay::::get_block_header_from_hash(block.header.hash).unwrap(); + assert_eq!(rich_header.chain_id, MAIN_CHAIN_ID); + + // make sure chain work is stored + assert_eq!(BtcRelay::::contains_chainwork(block.header.hash), true); + } + #[benchmark] pub fn store_block_header() { let caller: T::AccountId = whitelisted_caller(); @@ -140,11 +180,8 @@ pub mod benchmarks { } } - BtcRelay::::insert_block_hash(0, DIFFICULTY_ADJUSTMENT_INTERVAL, init_block_hash); - // new fork up to block before swapping the main chain - for chain_id in 1..(BestBlockHeight::::get() + SECURE_BITCOIN_CONFIRMATIONS) { - BtcRelay::::insert_block_hash(chain_id, DIFFICULTY_ADJUSTMENT_INTERVAL, init_block_hash); + for _ in 1..(BestBlockHeight::::get() + SECURE_BITCOIN_CONFIRMATIONS) { let block = add_new_block_to_relay::(caller.clone(), init_block_hash, f as usize); init_block_hash = block.header.hash; } @@ -169,5 +206,55 @@ pub mod benchmarks { assert_eq!(rich_header.chain_id, MAIN_CHAIN_ID); } + #[benchmark] + pub fn store_block_header_reorganize_chains_based_on_chainwork(f: Linear<3, 6>) { + let caller: T::AccountId = whitelisted_caller(); + StableBitcoinConfirmations::::put(SECURE_BITCOIN_CONFIRMATIONS); + + let init_block = initialize_relay::(caller.clone()); + let mut init_block_hash = init_block.header.hash; + + migration::v1::migrate_from_v0_to_v1::(); + + for i in 1..f { + let mut block_hash = init_block_hash; + for _ in 0..SECURE_BITCOIN_CONFIRMATIONS { + let block = add_new_block_to_relay::(caller.clone(), block_hash, i as usize); + block_hash = block.header.hash; + } + } + + // new fork up to block before swapping the main chain + for _ in 1..(BestBlockHeight::::get() + SECURE_BITCOIN_CONFIRMATIONS) { + let block = add_new_block_to_relay::(caller.clone(), init_block_hash, f as usize); + init_block_hash = block.header.hash; + } + + let prev_best_block_height = BestBlockHeight::::get(); + assert_eq!(prev_best_block_height, SECURE_BITCOIN_CONFIRMATIONS); + assert_eq!(ChainsIndex::::iter().collect::>().len(), f as usize); + + let mut last_entered_block = BtcRelay::::get_block_header_from_hash(init_block_hash).unwrap(); + last_entered_block.block_header.target = U256::max_value(); + BlockHeaders::::insert(last_entered_block.block_header.hash, last_entered_block); + + // we can benchmark the worst-case complexity for swapping + // since we know how many blocks are required + let mut block = new_block::(init_block_hash, f as usize); + block.header.target = U256::max_value(); + block.header.update_hash().unwrap(); + + #[extrinsic_call] + store_block_header(RawOrigin::Signed(caller), block.header, u32::MAX); + + // make sure reorg occurred + assert_eq!( + BestBlockHeight::::get(), + prev_best_block_height + SECURE_BITCOIN_CONFIRMATIONS + ); + let rich_header = BtcRelay::::get_block_header_from_hash(block.header.hash).unwrap(); + assert_eq!(rich_header.chain_id, MAIN_CHAIN_ID); + } + impl_benchmark_test_suite!(BtcRelay, crate::mock::ExtBuilder::build(), crate::mock::Test); } diff --git a/crates/btc-relay/src/default_weights.rs b/crates/btc-relay/src/default_weights.rs index 648c215b05..97d5b3b167 100644 --- a/crates/btc-relay/src/default_weights.rs +++ b/crates/btc-relay/src/default_weights.rs @@ -42,311 +42,452 @@ pub trait WeightInfo { fn store_block_header_new_fork_sorted(f: u32, ) -> Weight; fn store_block_header_new_fork_unsorted(f: u32, ) -> Weight; fn store_block_header_reorganize_chains(f: u32, ) -> Weight; + fn set_chainwork_for_block() -> Weight; + fn store_block_header_when_adding_chainwork () -> Weight; + fn store_block_header_reorganize_chains_based_on_chainwork(f: u32, ) -> Weight; } /// Weights for btc_relay using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: BTCRelay BestBlock (r:1 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:1 w:1) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: BTCRelay StartBlockHeight (r:0 w:1) - /// Proof: BTCRelay StartBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:0 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:0 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - fn initialize() -> Weight { + + + /// Storage: `BTCRelay::BestBlock` (r:1 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:1 w:1) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::StartBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::StartBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:0 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:0 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + fn initialize () -> Weight { // Proof Size summary in bytes: - // Measured: `1451` - // Estimated: `4520` - // Minimum execution time: 57_676_000 picoseconds. - Weight::from_parts(58_347_000, 4520) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Measured: `403` + // Estimated: `3545` + // Minimum execution time: 44_000_000 picoseconds. + Weight::from_parts(44_000_000, 3545) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:0) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:1 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:1 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:0 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn store_block_header() -> Weight { + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:0) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + fn set_chainwork_for_block () -> Weight { + // Proof Size summary in bytes: + // Measured: `1049` + // Estimated: `6340` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(27_000_000, 6340) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:1 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:1 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn store_block_header_when_adding_chainwork () -> Weight { + // Proof Size summary in bytes: + // Measured: `979` + // Estimated: `6340` + // Minimum execution time: 52_000_000 picoseconds. + Weight::from_parts(52_000_000, 6340) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:1 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:1 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn store_block_header () -> Weight { // Proof Size summary in bytes: - // Measured: `1953` - // Estimated: `11898` - // Minimum execution time: 65_610_000 picoseconds. - Weight::from_parts(66_748_000, 11898) - .saturating_add(T::DbWeight::get().reads(7_u64)) + // Measured: `874` + // Estimated: `6340` + // Minimum execution time: 47_000_000 picoseconds. + Weight::from_parts(47_000_000, 6340) + .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:6 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:7 w:1) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:1 w:0) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:6 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:7 w:1) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:1 w:0) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) /// The range of component `f` is `[1, 6]`. - fn store_block_header_new_fork_sorted(f: u32, ) -> Weight { + fn store_block_header_new_fork_sorted (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1894 + f * (92 ±0)` - // Estimated: `9870 + f * (5006 ±0)` - // Minimum execution time: 81_320_000 picoseconds. - Weight::from_parts(83_847_120, 9870) - // Standard Error: 384_640 - .saturating_add(Weight::from_parts(11_883_224, 0).saturating_mul(f.into())) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(f.into()))) + // Measured: `796 + f * (110 ±0)` + // Estimated: `18483` + // Minimum execution time: 71_000_000 picoseconds. + Weight::from_parts(93_000_000, 18483) + .saturating_add(T::DbWeight::get().reads(20_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) - .saturating_add(Weight::from_parts(0, 5006).saturating_mul(f.into())) } - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:2 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:7 w:6) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:1 w:0) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:2 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:7 w:6) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:1 w:0) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) /// The range of component `f` is `[1, 6]`. - fn store_block_header_new_fork_unsorted(f: u32, ) -> Weight { + fn store_block_header_new_fork_unsorted (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1973 + f * (98 ±0)` - // Estimated: `12911 + f * (2987 ±22)` - // Minimum execution time: 84_731_000 picoseconds. - Weight::from_parts(116_733_612, 12911) - // Standard Error: 720_816 - .saturating_add(Weight::from_parts(5_329_595, 0).saturating_mul(f.into())) - .saturating_add(T::DbWeight::get().reads(8_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(f.into()))) - .saturating_add(T::DbWeight::get().writes(4_u64)) - .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(f.into()))) - .saturating_add(Weight::from_parts(0, 2987).saturating_mul(f.into())) + // Measured: `832 + f * (108 ±0)` + // Estimated: `18483` + // Minimum execution time: 54_000_000 picoseconds. + Weight::from_parts(94_000_000, 18483) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:0) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:20 w:18) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:3 w:2) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:13 w:24) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:6 w:0) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: BTCRelay StableBitcoinConfirmations (r:1 w:0) - /// Proof: BTCRelay StableBitcoinConfirmations (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:0 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:20 w:18) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:3 w:2) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:13 w:24) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:3 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:6 w:0) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::StableBitcoinConfirmations` (r:1 w:0) + /// Proof: `BTCRelay::StableBitcoinConfirmations` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// The range of component `f` is `[3, 6]`. - fn store_block_header_reorganize_chains(f: u32, ) -> Weight { + fn store_block_header_reorganize_chains (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `6534 + f * (199 ±0)` - // Estimated: `101752 + f * (1305 ±32)` - // Minimum execution time: 363_791_000 picoseconds. - Weight::from_parts(341_578_042, 101752) - // Standard Error: 162_430 - .saturating_add(Weight::from_parts(9_039_414, 0).saturating_mul(f.into())) - .saturating_add(T::DbWeight::get().reads(42_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(f.into()))) + // Measured: `4754 + f * (235 ±0)` + // Estimated: `54490` + // Minimum execution time: 322_000_000 picoseconds. + Weight::from_parts(345_000_000, 54490) + .saturating_add(T::DbWeight::get().reads(49_u64)) .saturating_add(T::DbWeight::get().writes(46_u64)) - .saturating_add(Weight::from_parts(0, 1305).saturating_mul(f.into())) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:20 w:18) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:3 w:2) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:13 w:24) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:2 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:6 w:0) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// The range of component `f` is `[3, 6]`. + fn store_block_header_reorganize_chains_based_on_chainwork (_f: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `5196 + f * (298 ±0)` + // Estimated: `54490` + // Minimum execution time: 328_000_000 picoseconds. + Weight::from_parts(358_000_000, 54490) + .saturating_add(T::DbWeight::get().reads(47_u64)) + .saturating_add(T::DbWeight::get().writes(47_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - /// Storage: BTCRelay BestBlock (r:1 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:1 w:1) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: BTCRelay StartBlockHeight (r:0 w:1) - /// Proof: BTCRelay StartBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:0 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:0 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - fn initialize() -> Weight { + + + /// Storage: `BTCRelay::BestBlock` (r:1 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:1 w:1) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::StartBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::StartBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:0 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:0 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + fn initialize () -> Weight { // Proof Size summary in bytes: - // Measured: `1451` - // Estimated: `4520` - // Minimum execution time: 57_676_000 picoseconds. - Weight::from_parts(58_347_000, 4520) - .saturating_add(RocksDbWeight::get().reads(5_u64)) + // Measured: `403` + // Estimated: `3545` + // Minimum execution time: 44_000_000 picoseconds. + Weight::from_parts(44_000_000, 3545) + .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(8_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:0) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:1 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:1 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:0 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - fn store_block_header() -> Weight { + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:0) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + fn set_chainwork_for_block () -> Weight { + // Proof Size summary in bytes: + // Measured: `1049` + // Estimated: `6340` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(27_000_000, 6340) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:1 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:1 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn store_block_header_when_adding_chainwork () -> Weight { + // Proof Size summary in bytes: + // Measured: `979` + // Estimated: `6340` + // Minimum execution time: 52_000_000 picoseconds. + Weight::from_parts(52_000_000, 6340) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:1 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:1 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn store_block_header () -> Weight { // Proof Size summary in bytes: - // Measured: `1953` - // Estimated: `11898` - // Minimum execution time: 65_610_000 picoseconds. - Weight::from_parts(66_748_000, 11898) - .saturating_add(RocksDbWeight::get().reads(7_u64)) + // Measured: `874` + // Estimated: `6340` + // Minimum execution time: 47_000_000 picoseconds. + Weight::from_parts(47_000_000, 6340) + .saturating_add(RocksDbWeight::get().reads(8_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:6 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:7 w:1) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:1 w:0) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:6 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:7 w:1) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:1 w:0) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) /// The range of component `f` is `[1, 6]`. - fn store_block_header_new_fork_sorted(f: u32, ) -> Weight { + fn store_block_header_new_fork_sorted (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1894 + f * (92 ±0)` - // Estimated: `9870 + f * (5006 ±0)` - // Minimum execution time: 81_320_000 picoseconds. - Weight::from_parts(83_847_120, 9870) - // Standard Error: 384_640 - .saturating_add(Weight::from_parts(11_883_224, 0).saturating_mul(f.into())) - .saturating_add(RocksDbWeight::get().reads(7_u64)) - .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(f.into()))) + // Measured: `796 + f * (110 ±0)` + // Estimated: `18483` + // Minimum execution time: 71_000_000 picoseconds. + Weight::from_parts(93_000_000, 18483) + .saturating_add(RocksDbWeight::get().reads(20_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) - .saturating_add(Weight::from_parts(0, 5006).saturating_mul(f.into())) } - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:2 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:7 w:6) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:1 w:0) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:2 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:7 w:6) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:1 w:0) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) /// The range of component `f` is `[1, 6]`. - fn store_block_header_new_fork_unsorted(f: u32, ) -> Weight { + fn store_block_header_new_fork_unsorted (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1973 + f * (98 ±0)` - // Estimated: `12911 + f * (2987 ±22)` - // Minimum execution time: 84_731_000 picoseconds. - Weight::from_parts(116_733_612, 12911) - // Standard Error: 720_816 - .saturating_add(Weight::from_parts(5_329_595, 0).saturating_mul(f.into())) - .saturating_add(RocksDbWeight::get().reads(8_u64)) - .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(f.into()))) - .saturating_add(RocksDbWeight::get().writes(4_u64)) - .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(f.into()))) - .saturating_add(Weight::from_parts(0, 2987).saturating_mul(f.into())) + // Measured: `832 + f * (108 ±0)` + // Estimated: `18483` + // Minimum execution time: 54_000_000 picoseconds. + Weight::from_parts(94_000_000, 18483) + .saturating_add(RocksDbWeight::get().reads(16_u64)) + .saturating_add(RocksDbWeight::get().writes(10_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:0) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:20 w:18) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:3 w:2) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:13 w:24) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:6 w:0) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: BTCRelay StableBitcoinConfirmations (r:1 w:0) - /// Proof: BTCRelay StableBitcoinConfirmations (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:0 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:20 w:18) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:3 w:2) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:13 w:24) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:3 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:6 w:0) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::StableBitcoinConfirmations` (r:1 w:0) + /// Proof: `BTCRelay::StableBitcoinConfirmations` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// The range of component `f` is `[3, 6]`. - fn store_block_header_reorganize_chains(f: u32, ) -> Weight { + fn store_block_header_reorganize_chains (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `6534 + f * (199 ±0)` - // Estimated: `101752 + f * (1305 ±32)` - // Minimum execution time: 363_791_000 picoseconds. - Weight::from_parts(341_578_042, 101752) - // Standard Error: 162_430 - .saturating_add(Weight::from_parts(9_039_414, 0).saturating_mul(f.into())) - .saturating_add(RocksDbWeight::get().reads(42_u64)) - .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(f.into()))) + // Measured: `4754 + f * (235 ±0)` + // Estimated: `54490` + // Minimum execution time: 322_000_000 picoseconds. + Weight::from_parts(345_000_000, 54490) + .saturating_add(RocksDbWeight::get().reads(49_u64)) .saturating_add(RocksDbWeight::get().writes(46_u64)) - .saturating_add(Weight::from_parts(0, 1305).saturating_mul(f.into())) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:20 w:18) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:3 w:2) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:13 w:24) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:2 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:6 w:0) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// The range of component `f` is `[3, 6]`. + fn store_block_header_reorganize_chains_based_on_chainwork (_f: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `5196 + f * (298 ±0)` + // Estimated: `54490` + // Minimum execution time: 328_000_000 picoseconds. + Weight::from_parts(358_000_000, 54490) + .saturating_add(RocksDbWeight::get().reads(47_u64)) + .saturating_add(RocksDbWeight::get().writes(47_u64)) } } diff --git a/crates/btc-relay/src/lib.rs b/crates/btc-relay/src/lib.rs index 7b84b350b0..71b9731196 100644 --- a/crates/btc-relay/src/lib.rs +++ b/crates/btc-relay/src/lib.rs @@ -48,6 +48,8 @@ mod mock; #[cfg(test)] extern crate mocktopus; +pub mod migration; + #[cfg(test)] use mocktopus::macros::mockable; @@ -65,7 +67,6 @@ use frame_support::{ transactional, }; use frame_system::{ensure_signed, pallet_prelude::BlockNumberFor}; -use sp_arithmetic::traits::Saturating; use sp_core::{H256, U256}; use sp_runtime::traits::{CheckedAdd, CheckedDiv, CheckedSub, One}; use sp_std::{ @@ -87,6 +88,7 @@ pub mod pallet { use frame_system::pallet_prelude::*; #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] @@ -103,8 +105,15 @@ pub mod pallet { type ParachainBlocksPerBitcoinBlock: Get>; } + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); + #[pallet::hooks] - impl Hooks> for Pallet {} + impl Hooks> for Pallet { + fn on_runtime_upgrade() -> Weight { + migration::v1::migrate_from_v0_to_v1::() + } + } #[pallet::call] impl Pallet { @@ -153,6 +162,8 @@ pub mod pallet { .max(::WeightInfo::store_block_header_new_fork_sorted(f)) .max(::WeightInfo::store_block_header_new_fork_unsorted(f)) .max(::WeightInfo::store_block_header_reorganize_chains(f)) + .max(::WeightInfo::store_block_header_reorganize_chains_based_on_chainwork(f)) + .max(::WeightInfo::store_block_header_when_adding_chainwork()) }, DispatchClass::Operational ))] @@ -180,6 +191,29 @@ pub mod pallet { // don't take tx fees on success Ok(Pays::No.into()) } + + /// Stores a chainwork for block header + #[pallet::call_index(2)] + #[pallet::weight(( + ::WeightInfo::set_chainwork_for_block(), + DispatchClass::Operational + ))] + #[transactional] + pub fn set_chainwork_for_block(origin: OriginFor, block_hash: H256Le) -> DispatchResultWithPostInfo { + let _relayer = ensure_signed(origin)?; + let block_header = Self::get_block_header_from_hash(block_hash)?.block_header; + + // ensure previous block contains chainwork + ensure!( + Self::contains_chainwork(block_header.hash_prev_block), + Error::::ChainWorkDoesNotExist + ); + + Self::_set_chainwork_for_block(&block_header)?; + + // don't take tx fees on success + Ok(Pays::No.into()) + } } #[pallet::event] @@ -319,12 +353,16 @@ pub mod pallet { BoundExceeded, /// Coinbase tx must be the first transaction in the block InvalidCoinbasePosition, + /// The Chain Work for the block doesn't exist + ChainWorkDoesNotExist, + /// Checked Division failed + DivisionError, } /// Store ChainWork /// mapping block hash -> chain work #[pallet::storage] - pub(super) type ChainWork = StorageMap<_, Blake2_128Concat, H256Le, u32, OptionQuery>; + pub(super) type ChainWork = StorageMap<_, Blake2_128Concat, H256Le, U256, OptionQuery>; /// Store Bitcoin block headers #[pallet::storage] @@ -404,8 +442,6 @@ pub mod pallet { StableParachainConfirmations::::put(self.parachain_confirmations); DisableDifficultyCheck::::put(self.disable_difficulty_check); DisableInclusionCheck::::put(self.disable_inclusion_check); - // ToDo: insert genesis block hash and block work as zero - ChainWork::::insert(H256Le::zero(), 0); } } } @@ -428,6 +464,8 @@ pub const UNROUNDED_MAX_TARGET: U256 = U256([::MAX, ::MAX, ::MAX, /// Main chain id pub const MAIN_CHAIN_ID: u32 = 0; +pub const ONE: U256 = U256::one(); + #[cfg_attr(test, mockable)] impl Pallet { pub fn _initialize(relayer: T::AccountId, basic_block_header: BlockHeader, block_height: u32) -> DispatchResult { @@ -775,12 +813,12 @@ impl Pallet { ChainCounter::::get() } - fn get_block_chainwork(block_hash: H256Le) -> Option { - ChainWork::::get(block_hash) - } - - fn set_block_chainwork(block_hash: H256Le, chain_work: u32) { - ChainWork::::insert(block_hash, chain_work) + pub fn contains_chainwork(block_hash: H256Le) -> bool { + if let None = ChainWork::::get(block_hash) { + false + } else { + true + } } /// Get a block hash from a blockchain @@ -796,33 +834,6 @@ impl Pallet { Ok(ChainsHashes::::get(chain_id, block_height)) } - fn get_block_hash_from_forks(chain_id: u32, block_height: u32) -> Result { - // Get the blockchain associated with the given chain_id. - let chain = Self::get_block_chain_from_id(chain_id)?; - - // If the requested block height is before the chain's start height, - // recursively fetch the block hash from the previous chain. - if block_height < chain.start_height { - // Get the hash of the block at the start height of the current chain. - let start_height_hash = Self::get_block_hash(chain_id, chain.start_height)?; - - // Get the previous block's header from its hash. - let prev_hash = Self::get_block_header_from_hash(start_height_hash)? - .block_header - .hash_prev_block; - - // Get the chain_id of the previous chain. - let prev_chain_id = Self::get_block_header_from_hash(prev_hash)?.chain_id; - - // Recursively call the function for the previous chain and requested block height. - Self::get_block_hash_from_forks(prev_chain_id, block_height) - } else { - // If the requested block height is within the current chain's range, - // directly fetch the block hash from the current chain. - Self::get_block_hash(chain_id, block_height) - } - } - /// Get a block header from its hash pub fn get_block_header_from_hash(block_hash: H256Le) -> Result>, DispatchError> { BlockHeaders::::try_get(block_hash).or(Err(Error::::BlockNotFound.into())) @@ -904,6 +915,11 @@ impl Pallet { Self::store_rich_header(basic_block_header.clone(), block_height, blockchain.chain_id); + // Add chainwork for block if prev block contains chainwork + if Self::contains_chainwork(basic_block_header.hash_prev_block) { + Self::_set_chainwork_for_block(basic_block_header)?; + } + Ok(blockchain.chain_id) } @@ -946,6 +962,11 @@ impl Pallet { Self::store_rich_header(basic_block_header.clone(), block_height, blockchain.chain_id); + // Add chainwork for block if prev block contains chainwork + if Self::contains_chainwork(basic_block_header.hash_prev_block) { + Self::_set_chainwork_for_block(basic_block_header)?; + } + Ok(blockchain) } @@ -1224,17 +1245,8 @@ impl Pallet { // and the current height is more than the // STABLE_TRANSACTION_CONFIRMATIONS ahead // we are swapping the main chain - let current_chain_id = Self::get_chain_id_from_position(current_position)?; - let current_fork_work = Self::get_chainwork(Self::get_block_chain_from_id(current_chain_id)?)?; - - let prev_chain_id = Self::get_chain_id_from_position(prev_position)?; - let prev_fork_work = Self::get_chainwork(Self::get_block_chain_from_id(prev_chain_id)?)?; // update: ensure_no_ongoing_fork - if prev_height.saturating_add(Self::get_stable_transaction_confirmations()) <= current_height - && - // We should only reorg when the fork has more or equal work than the current main chain - current_fork_work >= prev_fork_work - { + if Self::is_reorg_required(prev_blockchain_id, current_position, prev_height, current_height)? { // Swap the mainchain. As an optimization, this function returns the // new best block hash and its height let (new_chain_tip_hash, new_chain_tip_height) = Self::swap_main_blockchain(&fork)?; @@ -1271,113 +1283,55 @@ impl Pallet { Ok(()) } - /// The target value represents the mining difficulty required to mine a block with the specified hash. - /// - /// # Parameters - /// - /// * `block_hash`: A 256-bit block hash. - /// - /// # Returns - /// - /// * `Result`: A `Result` containing the retrieved target value as a `u32` if successful, or a - /// `DispatchError` if an error occurs during the retrieval. - fn get_target(block_hash: H256Le) -> Result { - let block_header = Self::get_block_header_from_hash(block_hash)?; - // Fixme: Should this be kept as a U256 type and other u32 type can be converted to U256? - // Currently taking low_u32/as_u32 loses precision - Ok(block_header.block_header.target.low_u32()) - } - - /// Calculates the chainwork of a block header at a given height based on the provided block hash. - /// Reference: https://github.com/spesmilo/electrum/blob/cee22abcb5544c5a6fa7f8a8108ccda9c32c2e29/electrum/blockchain.py#L582-L588 - /// - /// # Arguments - /// - /// * `block_hash`: A 256-bit block hash. - /// - /// # Returns - /// - /// * `Result`: A `Result` containing the calculated chainwork as a `u32` if successful, or a - /// `DispatchError` if an error occurs during target retrieval. - fn chainwork_of_header_at_height(block_hash: H256Le) -> Result { - let target = Self::get_target(block_hash)?; - let work = (2_u32.saturating_pow(256).saturating_sub(target).saturating_less_one()) - .saturating_div(target.saturating_plus_one()) - .saturating_plus_one(); - Ok(work) - } - - /// The chainwork is a measure of the total computational work done by the chain up to a certain point. - /// Reference: https://github.com/spesmilo/electrum/blob/cee22abcb5544c5a6fa7f8a8108ccda9c32c2e29/electrum/blockchain.py#L589-L614 - /// - /// # Parameters - /// - /// * `chain`: new blockchain element - /// - /// # Returns - /// - /// * `Result`: A `Result` containing the calculated cumulative chainwork as a `u32` if - /// successful, or a `DispatchError` if an error occurs during the calculation. - fn get_chainwork(chain: BlockChain) -> Result { - // Calculate the height of the last retarget point. - let last_retarget = chain - .max_height - .saturating_div(DIFFICULTY_ADJUSTMENT_INTERVAL) - .saturating_mul(DIFFICULTY_ADJUSTMENT_INTERVAL) - .saturating_less_one(); - - let mut cached_height = last_retarget; - - // Iterate backward to find the last block with known chainwork. - while Self::get_block_chainwork(Self::get_block_hash_from_forks(chain.chain_id, cached_height)?).is_none() { - if cached_height == 0 { - break; + fn is_reorg_required( + prev_blockchain_id: u32, + current_position: u32, + prev_height: u32, + current_height: u32, + ) -> Result { + let previous_block_hash = Self::get_block_hash(prev_blockchain_id, prev_height)?; + let current_chain_id = Self::get_chain_id_from_position(current_position)?; + let current_block_hash = Self::get_block_hash(current_chain_id, current_height)?; + + match ( + ChainWork::::get(previous_block_hash), + ChainWork::::get(current_block_hash), + ) { + // if both block have chain work use chain work to determine reorg + (Some(previous_block_chain_work), Some(current_block_chain_work)) => { + Ok(previous_block_chain_work > current_block_chain_work) } - cached_height = cached_height.saturating_sub(DIFFICULTY_ADJUSTMENT_INTERVAL) + // otherwise use longest chain to determine reorg + _ => Ok(prev_height.saturating_add(Self::get_stable_transaction_confirmations()) <= current_height), } + } - // Get the chainwork of the last known block. - let cache_chain_work = - Self::get_block_chainwork(Self::get_block_hash_from_forks(chain.chain_id, cached_height)?); - - let mut running_total = if let Some(chain_work) = cache_chain_work { - chain_work - } else { - // Genesis chain work should be 0. - 0_u32 - }; - - // Loop to calculate chainwork for blocks between 'cached_height' and 'last_retarget' (0 to 2015). - while cached_height < last_retarget { - cached_height = cached_height.saturating_add(DIFFICULTY_ADJUSTMENT_INTERVAL); - - let cached_block_hash = Self::get_block_hash_from_forks(chain.chain_id, cached_height)?; - - // Calculate the chainwork for a single header at the current height. - let work_in_single_header = Self::chainwork_of_header_at_height(cached_block_hash)?; - - // Calculate the chainwork for a chunk of blocks (DIFFICULTY_ADJUSTMENT_INTERVAL) at the current height. - let work_in_chunk = DIFFICULTY_ADJUSTMENT_INTERVAL.saturating_mul(work_in_single_header); + pub fn calculate_chainwork(prev_block_hash: H256Le) -> Result { + // Retrieve the previous block's header + let prev_block_header = Self::get_block_header_from_hash(prev_block_hash)?; - // Update the running total chainwork. - running_total = running_total.saturating_add(work_in_chunk); + // Calculate the chainwork + let chainwork = U256::max_value() + .saturating_sub(prev_block_header.block_header.target) + .saturating_sub(ONE); - // Store the calculated chainwork for the block. - Self::set_block_chainwork(cached_block_hash, running_total); + // Check if division is possible, and perform the division if so + if let Some(chainwork_done) = chainwork.checked_div(prev_block_header.block_header.target.saturating_add(ONE)) { + Ok(chainwork_done.saturating_add(ONE)) + } else { + // Handle division error + Err(Error::::DivisionError.into()) } + } - // Move to the next height. - cached_height = cached_height.saturating_add(DIFFICULTY_ADJUSTMENT_INTERVAL); - - // Calculate the chainwork for the last partial chunk of blocks. - let work_in_single_header = - Self::chainwork_of_header_at_height(Self::get_block_hash_from_forks(chain.chain_id, cached_height)?)?; + fn _set_chainwork_for_block(block_header: &BlockHeader) -> Result<(), DispatchError> { + //calculate chain work for current block + let chain_work = Self::calculate_chainwork(block_header.hash_prev_block)?; - let work_in_last_partial_chunk = ((chain.max_height % DIFFICULTY_ADJUSTMENT_INTERVAL).saturating_plus_one()) - .saturating_mul(work_in_single_header); + //set chain work for the block + ChainWork::::insert(block_header.hash, chain_work); - // Return the total chainwork, which is the running total plus the chain work of the last partial chunk. - Ok(running_total.saturating_add(work_in_last_partial_chunk)) + Ok(()) } /// Insert a new fork into the Chains mapping sorted by its max height diff --git a/crates/btc-relay/src/migration.rs b/crates/btc-relay/src/migration.rs new file mode 100644 index 0000000000..226542bb91 --- /dev/null +++ b/crates/btc-relay/src/migration.rs @@ -0,0 +1,25 @@ +use super::*; +use frame_support::pallet_prelude::Weight; + +pub mod v1 { + use super::*; + use frame_support::{dispatch::GetStorageVersion, traits::StorageVersion}; + pub fn migrate_from_v0_to_v1() -> Weight { + let weight = T::DbWeight::get().reads(1); + let current_storage_version = Pallet::::current_storage_version(); + let _expected_storage_version = StorageVersion::new(0); + if matches!(current_storage_version, _expected_storage_version) { + // Fixme: insert latest btc block as well as the calculated chain work. But for testnet the + // block header should be different. + ChainWork::::insert( + H256Le::from_bytes_le(&[ + 177, 89, 206, 70, 83, 47, 12, 29, 30, 21, 192, 96, 38, 114, 155, 10, 5, 77, 59, 247, 14, 99, 150, + 79, 228, 250, 72, 71, 124, 92, 197, 19, + ]), + U256::zero(), + ); + } + StorageVersion::new(1).put::>(); + weight + } +} diff --git a/crates/btc-relay/src/tests.rs b/crates/btc-relay/src/tests.rs index a360bd4db6..745fb13d11 100644 --- a/crates/btc-relay/src/tests.rs +++ b/crates/btc-relay/src/tests.rs @@ -241,13 +241,143 @@ fn store_block_header_on_fork_succeeds() { }) } +mod chainwork { + use super::*; + use frame_support::assert_ok; + use mocktopus::mocking::MockResult; + // use scale_info::TypeDefPrimitive::U256; + use crate::{ + migration::v1::migrate_from_v0_to_v1, + mock::run_test, + pallet::{ChainWork, ChainsHashes, ChainsIndex}, + tests::{sample_block_header, sample_parsed_genesis_header, store_block_header_tests::from_prev}, + ONE, + }; + use bitcoin::types::H256Le; + + #[test] + fn calculate_chainwork_when_previous_block_has_max_target() { + run_test(|| { + let mut sample_header = sample_parsed_genesis_header(0, 0); + sample_header.block_header.target = U256::max_value(); + BTCRelay::get_block_header_from_hash.mock_safe(move |_| MockResult::Return(Ok(sample_header))); + + let chainwork = BTCRelay::calculate_chainwork(sample_header.block_header.hash).unwrap(); + assert_eq!(chainwork, U256::one()); + }); + } + + #[test] + fn calculate_chainwork_when_previous_block_has_min_target() { + run_test(|| { + let mut sample_header = sample_parsed_genesis_header(0, 0); + sample_header.block_header.target = U256::zero(); + BTCRelay::get_block_header_from_hash.mock_safe(move |_| MockResult::Return(Ok(sample_header))); + + let chainwork = BTCRelay::calculate_chainwork(sample_header.block_header.hash).unwrap(); + assert_eq!(chainwork, U256::from(U256::max_value()).saturating_add(ONE)); + }); + } + + // Test Scenario: + // Step 1: Start storing block headers with `store_block_header` + // Step 2: Perform Migration + // Step 3: Relayer Calls Set chain work for previous blocks `set_chainwork_for_block` + // Step 4: Add new blocks; they should contain chain work + // Step 5: Check if ReOrgs now depends on chain work + // Step 6: Perform a reorg based on chainwork + #[test] + fn switch_reorging_method_from_longest_fork_to_most_work() { + run_test(|| { + // Step 1: Start storing block headers with `store_block_header` + BTCRelay::verify_block_header.mock_safe(|_, _, _| MockResult::Return(Ok(()))); + + let mut genesis_block = sample_block_header(); + genesis_block.nonce = 11; + genesis_block.hash = H256Le::from_bytes_le(&[ + 177, 89, 206, 70, 83, 47, 12, 29, 30, 21, 192, 96, 38, 114, 155, 10, 5, 77, 59, 247, 14, 99, 150, 79, + 228, 250, 72, 71, 124, 92, 197, 19, + ]); + + let block_height = 0; + assert_ok!(BTCRelay::_initialize(3, genesis_block, block_height)); + + let mut blocks = vec![genesis_block]; + + let mut prev_hash = genesis_block.hash; + + // Extend chain height from 1 to height 6 + for _ in 1..7 { + let current_block = from_prev(12, prev_hash); + blocks.push(current_block); + prev_hash = current_block.hash; + assert_ok!(BTCRelay::_store_block_header(&3, current_block)); + } + + // Step 2: Perform Migration + let chains = ChainWork::::iter().collect::>(); + assert_eq!(chains.len(), 0); + + migrate_from_v0_to_v1::(); + assert!(ChainWork::::get(genesis_block.hash).is_some()); + + // Step 3: Relayer Calls Set chain work for previous blocks `set_chainwork_for_block` + for index in 1..7 { + assert_ok!(BTCRelay::set_chainwork_for_block( + RuntimeOrigin::signed(3), + blocks[index].hash + )); + } + + // Step 4: Add new blocks; they should contain chain work + prev_hash = blocks[5].hash; + // Extend chain from height 7 to height 14 with changed nonce + for _ in 7..15 { + let current_block = from_prev(31 + 12, prev_hash); + blocks.push(current_block); + prev_hash = current_block.hash; + assert_ok!(BTCRelay::_store_block_header(&3, current_block)); + } + + // Step 5: Check if ReOrgs now depend on most work + + // The best block height remains 6 even though the fork max height is 13; this is because + // the fork chain has equal work to that of the main chain. + assert_eq!(BTCRelay::get_best_block_height(), 6); + assert_eq!(ChainsIndex::::get(0).unwrap().max_height, 6); + assert_eq!(ChainsIndex::::get(1).unwrap().max_height, 13); + let main_chain_best_block_hash = ChainsHashes::::get(0, 6); + let fork_chain_max_ht_hash = ChainsHashes::::get(1, 13); + assert_eq!( + ChainWork::::get(main_chain_best_block_hash), + ChainWork::::get(fork_chain_max_ht_hash) + ); + + // Step 6: Perform a reorg based on chainwork + let mut block_14 = from_prev(31 + 12, prev_hash); + // update target so that the next block chain work calculation is more that the best block. + block_14.target = U256::max_value(); + prev_hash = block_14.hash; + assert_ok!(BTCRelay::_store_block_header(&3, block_14)); + + let block_15 = from_prev(31 + 12, prev_hash); + assert_ok!(BTCRelay::_store_block_header(&3, block_15)); + + // The fork chain now becomes the best chain + assert_eq!(BTCRelay::get_best_block_height(), 15); + assert_eq!(ChainsIndex::::get(0).unwrap().max_height, 15); + assert_eq!(ChainsIndex::::get(1).unwrap().max_height, 6); + }); + } +} + mod store_block_header_tests { use std::iter::successors; use crate::MAIN_CHAIN_ID; use super::*; - fn from_prev(nonce: u32, prev: H256Le) -> BlockHeader { + pub fn from_prev(nonce: u32, prev: H256Le) -> BlockHeader { let mut ret = BlockHeader { nonce, hash_prev_block: prev, @@ -370,13 +500,6 @@ mod store_block_header_tests { let mut blocks = vec![a2]; - BTCRelay::get_target.mock_safe(|_| MockResult::Return(Ok(0_u32))); - BTCRelay::get_block_hash_from_forks.mock_safe(move |chain_id, height| { - assert!(matches!(chain_id, 0 | 1)); - assert!(matches!(height, 0 | DIFFICULTY_ADJUSTMENT_INTERVAL)); - MockResult::Return(Ok(H256Le::zero())) - }); - // create a new fork, and make it overtake the main chain let mut prev = genesis.hash; for i in 0..10 { @@ -429,13 +552,6 @@ mod store_block_header_tests { let mut genesis = sample_block_header(); genesis.update_hash().unwrap(); - BTCRelay::get_target.mock_safe(|_| MockResult::Return(Ok(0_u32))); - BTCRelay::get_block_hash_from_forks.mock_safe(move |chain_id, height| { - assert!(matches!(chain_id, 0 | 1 | 2)); - assert!(matches!(height, 0 | DIFFICULTY_ADJUSTMENT_INTERVAL)); - MockResult::Return(Ok(H256Le::zero())) - }); - // create the following tree shape: // f1 --> temp_fork_1 // \-> f2 --> temp_fork_2 @@ -568,13 +684,6 @@ mod store_block_header_tests { // "030000005fbd386a5032a0aa1c428416d2d0a9e62b3f31021bb695000000000000000000c46349cf6bddc4451f5df490ad53a83a58018e519579755800845fd4b0e39e79f46197558e41161884eabd86", ].into_iter().map(parse_from_hex).collect(); - BTCRelay::get_target.mock_safe(|_| MockResult::Return(Ok(0_u32))); - BTCRelay::get_block_hash_from_forks.mock_safe(move |chain_id, height| { - assert!(matches!(chain_id, 0 | 1)); - assert!(matches!(height, 0 | DIFFICULTY_ADJUSTMENT_INTERVAL)); - MockResult::Return(Ok(H256Le::zero())) - }); - for (idx, block) in reorg_blocks.iter().take(11).enumerate() { store_header_and_check_invariants(block); @@ -709,19 +818,7 @@ fn check_and_do_reorg_new_fork_is_main_chain() { BTCRelay::swap_main_blockchain.mock_safe(move |_| MockResult::Return(Ok((best_block_hash, fork_block_height)))); - BTCRelay::swap_main_blockchain.mock_safe(move |_| MockResult::Return(Ok((best_block_hash, fork_block_height)))); - - BTCRelay::get_chainwork.mock_safe(move |chain| { - if chain.chain_id == fork_chain_id { - assert_eq!(chain.start_height, main_start_height); - assert_eq!(chain.max_height, fork_block_height); - MockResult::Return(Ok(fork_chain_id)) - } else { - assert_eq!(chain.start_height, main_start_height); - assert_eq!(chain.max_height, main_block_height); - MockResult::Return(Ok(main_chain_id)) - } - }); + BTCRelay::get_block_hash.mock_safe(move |_, _| MockResult::Return(Ok(H256Le::zero()))); assert_ok!(BTCRelay::reorganize_chains(&fork)); // assert that the new main chain is set @@ -765,17 +862,7 @@ fn check_and_do_reorg_new_fork_below_stable_transaction_confirmations() { BTCRelay::swap_main_blockchain.mock_safe(move |_| MockResult::Return(Ok((best_block_hash, fork_block_height)))); - BTCRelay::get_chainwork.mock_safe(move |chain| { - if chain.chain_id == fork_chain_id { - assert_eq!(chain.start_height, main_start_height); - assert_eq!(chain.max_height, fork_block_height); - MockResult::Return(Ok(fork_chain_id)) - } else { - assert_eq!(chain.start_height, main_start_height); - assert_eq!(chain.max_height, main_block_height); - MockResult::Return(Ok(main_chain_id)) - } - }); + BTCRelay::get_block_hash.mock_safe(move |_, _| MockResult::Return(Ok(H256Le::zero()))); assert_ok!(BTCRelay::reorganize_chains(&fork)); // assert that the fork has not overtaken the main chain diff --git a/parachain/runtime/interlay/src/weights/btc_relay.rs b/parachain/runtime/interlay/src/weights/btc_relay.rs index 0958e8c733..9d435dc726 100644 --- a/parachain/runtime/interlay/src/weights/btc_relay.rs +++ b/parachain/runtime/interlay/src/weights/btc_relay.rs @@ -2,31 +2,30 @@ //! Autogenerated weights for btc_relay //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-08-07, STEPS: `50`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-09-27, STEPS: `2`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `interlay-rust-runner-2mz2v-jrrg4`, CPU: `AMD EPYC 7502P 32-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("interlay-dev"), DB CACHE: 1024 +//! HOSTNAME: `Nakuls-MacBook-Pro.local`, CPU: `` +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("interlay-dev"), DB CACHE: 1024 // Executed Command: -// target/release/interbtc-parachain +// ./target/release/interbtc-parachain // benchmark // pallet // --pallet -// * +// btc-relay // --extrinsic // * -// --chain -// interlay-dev -// --execution=wasm // --wasm-execution=compiled // --steps -// 50 +// 2 // --repeat -// 10 -// --output -// parachain/runtime/interlay/src/weights/ +// 1 // --template // .deploy/runtime-weight-template.hbs +// --chain +// interlay-dev +// --output +// interlay_bench.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -40,153 +39,220 @@ pub struct WeightInfo(PhantomData); impl btc_relay::WeightInfo for WeightInfo { - /// Storage: BTCRelay BestBlock (r:1 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:1 w:1) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: BTCRelay StartBlockHeight (r:0 w:1) - /// Proof: BTCRelay StartBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:0 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:0 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) + /// Storage: `BTCRelay::BestBlock` (r:1 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:1 w:1) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::StartBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::StartBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:0 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:0 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) fn initialize () -> Weight { // Proof Size summary in bytes: // Measured: `403` - // Estimated: `3489` - // Minimum execution time: 71_783_000 picoseconds. - Weight::from_parts(74_009_000, 3489) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Estimated: `3545` + // Minimum execution time: 44_000_000 picoseconds. + Weight::from_parts(44_000_000, 3545) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:0) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:1 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:1 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:0 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:0) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + fn set_chainwork_for_block () -> Weight { + // Proof Size summary in bytes: + // Measured: `1049` + // Estimated: `6340` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(27_000_000, 6340) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:1 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:1 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn store_block_header_when_adding_chainwork () -> Weight { + // Proof Size summary in bytes: + // Measured: `979` + // Estimated: `6340` + // Minimum execution time: 52_000_000 picoseconds. + Weight::from_parts(52_000_000, 6340) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:1 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:1 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn store_block_header () -> Weight { // Proof Size summary in bytes: // Measured: `874` // Estimated: `6340` - // Minimum execution time: 88_808_000 picoseconds. - Weight::from_parts(90_482_000, 6340) - .saturating_add(T::DbWeight::get().reads(7_u64)) + // Minimum execution time: 47_000_000 picoseconds. + Weight::from_parts(47_000_000, 6340) + .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:6 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:7 w:1) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:1 w:0) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:6 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:7 w:1) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:1 w:0) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) /// The range of component `f` is `[1, 6]`. - fn store_block_header_new_fork_sorted (f: u32, ) -> Weight { + fn store_block_header_new_fork_sorted (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `806 + f * (101 ±0)` - // Estimated: `6340 + f * (2507 ±0)` - // Minimum execution time: 101_073_000 picoseconds. - Weight::from_parts(95_176_412, 6340) - // Standard Error: 452_083 - .saturating_add(Weight::from_parts(11_888_980, 0).saturating_mul(f.into())) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(f.into()))) + // Measured: `796 + f * (110 ±0)` + // Estimated: `18483` + // Minimum execution time: 71_000_000 picoseconds. + Weight::from_parts(93_000_000, 18483) + .saturating_add(T::DbWeight::get().reads(20_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) - .saturating_add(Weight::from_parts(0, 2507).saturating_mul(f.into())) } - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:2 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:7 w:6) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:1 w:0) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:2 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:7 w:6) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:1 w:0) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) /// The range of component `f` is `[1, 6]`. - fn store_block_header_new_fork_unsorted (f: u32, ) -> Weight { + fn store_block_header_new_fork_unsorted (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `842 + f * (99 ±0)` - // Estimated: `6340 + f * (2499 ±0)` - // Minimum execution time: 97_675_000 picoseconds. - Weight::from_parts(89_104_041, 6340) - // Standard Error: 196_333 - .saturating_add(Weight::from_parts(14_328_939, 0).saturating_mul(f.into())) - .saturating_add(T::DbWeight::get().reads(8_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(f.into()))) - .saturating_add(T::DbWeight::get().writes(4_u64)) - .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(f.into()))) - .saturating_add(Weight::from_parts(0, 2499).saturating_mul(f.into())) + // Measured: `832 + f * (108 ±0)` + // Estimated: `18483` + // Minimum execution time: 54_000_000 picoseconds. + Weight::from_parts(94_000_000, 18483) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:0) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:20 w:18) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:3 w:2) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:13 w:24) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:6 w:0) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: BTCRelay StableBitcoinConfirmations (r:1 w:0) - /// Proof: BTCRelay StableBitcoinConfirmations (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:0 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:20 w:18) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:3 w:2) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:13 w:24) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:3 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:6 w:0) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::StableBitcoinConfirmations` (r:1 w:0) + /// Proof: `BTCRelay::StableBitcoinConfirmations` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// The range of component `f` is `[3, 6]`. - fn store_block_header_reorganize_chains (f: u32, ) -> Weight { + fn store_block_header_reorganize_chains (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `4741 + f * (240 ±0)` - // Estimated: `54490 + f * (1340 ±45)` - // Minimum execution time: 506_604_000 picoseconds. - Weight::from_parts(465_095_071, 54490) - // Standard Error: 430_820 - .saturating_add(Weight::from_parts(18_597_675, 0).saturating_mul(f.into())) - .saturating_add(T::DbWeight::get().reads(42_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(f.into()))) + // Measured: `4754 + f * (235 ±0)` + // Estimated: `54490` + // Minimum execution time: 322_000_000 picoseconds. + Weight::from_parts(345_000_000, 54490) + .saturating_add(T::DbWeight::get().reads(49_u64)) .saturating_add(T::DbWeight::get().writes(46_u64)) - .saturating_add(Weight::from_parts(0, 1340).saturating_mul(f.into())) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:20 w:18) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:3 w:2) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:13 w:24) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:2 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:6 w:0) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// The range of component `f` is `[3, 6]`. + fn store_block_header_reorganize_chains_based_on_chainwork (_f: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `5196 + f * (298 ±0)` + // Estimated: `54490` + // Minimum execution time: 328_000_000 picoseconds. + Weight::from_parts(358_000_000, 54490) + .saturating_add(T::DbWeight::get().reads(47_u64)) + .saturating_add(T::DbWeight::get().writes(47_u64)) } } \ No newline at end of file diff --git a/parachain/runtime/kintsugi/src/weights/btc_relay.rs b/parachain/runtime/kintsugi/src/weights/btc_relay.rs index 4a89ccbe56..5ebbc61aed 100644 --- a/parachain/runtime/kintsugi/src/weights/btc_relay.rs +++ b/parachain/runtime/kintsugi/src/weights/btc_relay.rs @@ -2,31 +2,30 @@ //! Autogenerated weights for btc_relay //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-08-07, STEPS: `50`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-09-27, STEPS: `2`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `interlay-rust-runner-2mz2v-kcxvd`, CPU: `AMD EPYC 7502P 32-Core Processor` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kintsugi-dev"), DB CACHE: 1024 +//! HOSTNAME: `Nakuls-MacBook-Pro.local`, CPU: `` +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("kintsugi-dev"), DB CACHE: 1024 // Executed Command: -// target/release/interbtc-parachain +// ./target/release/interbtc-parachain // benchmark // pallet // --pallet -// * +// btc-relay // --extrinsic // * -// --chain -// kintsugi-dev -// --execution=wasm // --wasm-execution=compiled // --steps -// 50 +// 2 // --repeat -// 10 -// --output -// parachain/runtime/kintsugi/src/weights/ +// 1 // --template // .deploy/runtime-weight-template.hbs +// --chain +// kintsugi-dev +// --output +// kintsugi_bench.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -40,153 +39,220 @@ pub struct WeightInfo(PhantomData); impl btc_relay::WeightInfo for WeightInfo { - /// Storage: BTCRelay BestBlock (r:1 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:1 w:1) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: BTCRelay StartBlockHeight (r:0 w:1) - /// Proof: BTCRelay StartBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:0 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:0 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) + /// Storage: `BTCRelay::BestBlock` (r:1 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:1 w:1) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::StartBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::StartBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:0 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:0 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) fn initialize () -> Weight { // Proof Size summary in bytes: - // Measured: `403` - // Estimated: `3489` - // Minimum execution time: 66_834_000 picoseconds. - Weight::from_parts(67_535_000, 3489) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Measured: `423` + // Estimated: `3545` + // Minimum execution time: 40_000_000 picoseconds. + Weight::from_parts(40_000_000, 3545) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(8_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:0) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:1 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:1 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:0 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:0) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + fn set_chainwork_for_block () -> Weight { + // Proof Size summary in bytes: + // Measured: `1049` + // Estimated: `6340` + // Minimum execution time: 22_000_000 picoseconds. + Weight::from_parts(22_000_000, 6340) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:1 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:1 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn store_block_header_when_adding_chainwork () -> Weight { + // Proof Size summary in bytes: + // Measured: `999` + // Estimated: `6340` + // Minimum execution time: 48_000_000 picoseconds. + Weight::from_parts(48_000_000, 6340) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:1 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:1 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn store_block_header () -> Weight { // Proof Size summary in bytes: - // Measured: `874` + // Measured: `894` // Estimated: `6340` - // Minimum execution time: 82_235_000 picoseconds. - Weight::from_parts(83_036_000, 6340) - .saturating_add(T::DbWeight::get().reads(7_u64)) + // Minimum execution time: 44_000_000 picoseconds. + Weight::from_parts(44_000_000, 6340) + .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:6 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:7 w:1) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:1 w:0) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:6 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:7 w:1) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:1 w:0) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) /// The range of component `f` is `[1, 6]`. - fn store_block_header_new_fork_sorted (f: u32, ) -> Weight { + fn store_block_header_new_fork_sorted (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `806 + f * (101 ±0)` - // Estimated: `6340 + f * (2507 ±0)` - // Minimum execution time: 93_938_000 picoseconds. - Weight::from_parts(85_636_123, 6340) - // Standard Error: 86_395 - .saturating_add(Weight::from_parts(10_763_758, 0).saturating_mul(f.into())) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(f.into()))) + // Measured: `816 + f * (110 ±0)` + // Estimated: `18483` + // Minimum execution time: 50_000_000 picoseconds. + Weight::from_parts(81_000_000, 18483) + .saturating_add(T::DbWeight::get().reads(20_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) - .saturating_add(Weight::from_parts(0, 2507).saturating_mul(f.into())) } - /// Storage: BTCRelay ChainCounter (r:1 w:1) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:2 w:1) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:2 w:1) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:7 w:6) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:1 w:0) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:0 w:1) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:1) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:2 w:1) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:2 w:1) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:7 w:6) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:1 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:1 w:0) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:0 w:1) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) /// The range of component `f` is `[1, 6]`. - fn store_block_header_new_fork_unsorted (f: u32, ) -> Weight { + fn store_block_header_new_fork_unsorted (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `842 + f * (99 ±0)` - // Estimated: `6340 + f * (2499 ±31)` - // Minimum execution time: 95_491_000 picoseconds. - Weight::from_parts(87_545_230, 6340) - // Standard Error: 88_777 - .saturating_add(Weight::from_parts(13_033_203, 0).saturating_mul(f.into())) - .saturating_add(T::DbWeight::get().reads(8_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(f.into()))) - .saturating_add(T::DbWeight::get().writes(4_u64)) - .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(f.into()))) - .saturating_add(Weight::from_parts(0, 2499).saturating_mul(f.into())) + // Measured: `852 + f * (108 ±0)` + // Estimated: `18483` + // Minimum execution time: 58_000_000 picoseconds. + Weight::from_parts(90_000_000, 18483) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) } - /// Storage: BTCRelay ChainCounter (r:1 w:0) - /// Proof: BTCRelay ChainCounter (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BlockHeaders (r:20 w:18) - /// Proof: BTCRelay BlockHeaders (max_values: None, max_size: Some(200), added: 2675, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsIndex (r:3 w:2) - /// Proof: BTCRelay ChainsIndex (max_values: None, max_size: Some(32), added: 2507, mode: MaxEncodedLen) - /// Storage: BTCRelay DisableDifficultyCheck (r:1 w:0) - /// Proof: BTCRelay DisableDifficultyCheck (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) - /// Storage: BTCRelay ChainsHashes (r:13 w:24) - /// Proof: BTCRelay ChainsHashes (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen) - /// Storage: Security ActiveBlockCount (r:1 w:0) - /// Proof: Security ActiveBlockCount (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay Chains (r:6 w:0) - /// Proof: BTCRelay Chains (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) - /// Storage: BTCRelay StableBitcoinConfirmations (r:1 w:0) - /// Proof: BTCRelay StableBitcoinConfirmations (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlock (r:0 w:1) - /// Proof: BTCRelay BestBlock (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - /// Storage: BTCRelay BestBlockHeight (r:0 w:1) - /// Proof: BTCRelay BestBlockHeight (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:20 w:18) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:3 w:2) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:13 w:24) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:3 w:0) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:6 w:0) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::StableBitcoinConfirmations` (r:1 w:0) + /// Proof: `BTCRelay::StableBitcoinConfirmations` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// The range of component `f` is `[3, 6]`. - fn store_block_header_reorganize_chains (f: u32, ) -> Weight { + fn store_block_header_reorganize_chains (_f: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `4741 + f * (240 ±0)` - // Estimated: `54490 + f * (1340 ±45)` - // Minimum execution time: 513_248_000 picoseconds. - Weight::from_parts(504_054_659, 54490) - // Standard Error: 322_620 - .saturating_add(Weight::from_parts(7_203_738, 0).saturating_mul(f.into())) - .saturating_add(T::DbWeight::get().reads(42_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(f.into()))) + // Measured: `4774 + f * (235 ±0)` + // Estimated: `54490` + // Minimum execution time: 311_000_000 picoseconds. + Weight::from_parts(323_000_000, 54490) + .saturating_add(T::DbWeight::get().reads(49_u64)) .saturating_add(T::DbWeight::get().writes(46_u64)) - .saturating_add(Weight::from_parts(0, 1340).saturating_mul(f.into())) + } + /// Storage: `BTCRelay::ChainCounter` (r:1 w:0) + /// Proof: `BTCRelay::ChainCounter` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BlockHeaders` (r:20 w:18) + /// Proof: `BTCRelay::BlockHeaders` (`max_values`: None, `max_size`: Some(200), added: 2675, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsIndex` (r:3 w:2) + /// Proof: `BTCRelay::ChainsIndex` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::DisableDifficultyCheck` (r:1 w:0) + /// Proof: `BTCRelay::DisableDifficultyCheck` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainsHashes` (r:13 w:24) + /// Proof: `BTCRelay::ChainsHashes` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: `Security::ActiveBlockCount` (r:1 w:0) + /// Proof: `Security::ActiveBlockCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::ChainWork` (r:2 w:1) + /// Proof: `BTCRelay::ChainWork` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::Chains` (r:6 w:0) + /// Proof: `BTCRelay::Chains` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlock` (r:0 w:1) + /// Proof: `BTCRelay::BestBlock` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `BTCRelay::BestBlockHeight` (r:0 w:1) + /// Proof: `BTCRelay::BestBlockHeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// The range of component `f` is `[3, 6]`. + fn store_block_header_reorganize_chains_based_on_chainwork (_f: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `5216 + f * (298 ±0)` + // Estimated: `54490` + // Minimum execution time: 297_000_000 picoseconds. + Weight::from_parts(329_000_000, 54490) + .saturating_add(T::DbWeight::get().reads(47_u64)) + .saturating_add(T::DbWeight::get().writes(47_u64)) } } \ No newline at end of file diff --git a/parachain/runtime/runtime-tests/src/parachain/btc_relay.rs b/parachain/runtime/runtime-tests/src/parachain/btc_relay.rs index 0be7dc4253..6e45432129 100644 --- a/parachain/runtime/runtime-tests/src/parachain/btc_relay.rs +++ b/parachain/runtime/runtime-tests/src/parachain/btc_relay.rs @@ -165,9 +165,6 @@ fn integration_test_submit_fork_headers() { assert_store_main_chain_header_event(index as u32, header.hash, account_of(ALICE)); } - BTCRelayPallet::insert_block_hash(0, DIFFICULTY_ADJUSTMENT_INTERVAL, genesis_header.hash); - BTCRelayPallet::insert_block_hash(FORK_ID, DIFFICULTY_ADJUSTMENT_INTERVAL, test_data[1].hash); - // submit future main chain without genesis for (index, header) in test_data.iter().enumerate().skip(1 + NUM_FORK_HEADERS as usize) { SecurityPallet::set_active_block_number(index as u32);