mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-12 12:15:40 +00:00
Update bridges subtree (#1392)
* Move the bridges subtree under root * Squashed 'bridges/' changes from 277f0d5496..e50398d1c5 e50398d1c5 bridges subtree fixes (#2528) 99af07522d Markdown linter (#1309) (#2526) 733ff0fe7a `polkadot-staging` branch: Use polkadot-sdk dependencies (#2524) e8a59f141e Fix benchmark with new XCM::V3 `MAX_INSTRUCTIONS_TO_DECODE` (#2514) 62b185de15 Backport `polkadot-sdk` changes to `polkadot-staging` (#2518) d9658f4d5b Fix equivocation detection containers startup (#2516) (#2517) d65db28a8f Backport: building images from locally built binaries (#2513) 5fdbaf45f6 Start the equivocation detection loop from the complex relayer (#2507) (#2512) 7fbb67de46 Backport: Implement basic equivocations detection loop (#2375) cb7efe245c Manually update deps in polkadot staging (#2371) d17981fc33 #2351 to polkadot-staging (#2359) git-subtree-dir: bridges git-subtree-split: e50398d1c594e4e96df70b0bd376e565d17e8558 * Reapply diener workspacify * Fix Cargo.toml * Fix test * Adjustments
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Weight-related utilities.
|
||||
|
||||
use crate::weights::{BridgeWeight, WeightInfo};
|
||||
|
||||
use bp_runtime::Size;
|
||||
use frame_support::weights::{RuntimeDbWeight, Weight};
|
||||
|
||||
/// Size of the regular parachain head.
|
||||
///
|
||||
/// It's not that we are expecting all parachain heads to share the same size or that we would
|
||||
/// reject all heads that have larger/lesser size. It is about head size that we use in benchmarks.
|
||||
/// Relayer would need to pay additional fee for extra bytes.
|
||||
///
|
||||
/// 384 is a bit larger (1.3 times) than the size of the randomly chosen Polkadot block.
|
||||
pub const DEFAULT_PARACHAIN_HEAD_SIZE: u32 = 384;
|
||||
|
||||
/// Number of extra bytes (excluding size of storage value itself) of storage proof, built at
|
||||
/// the Rialto chain.
|
||||
pub const EXTRA_STORAGE_PROOF_SIZE: u32 = 1024;
|
||||
|
||||
/// Extended weight info.
|
||||
pub trait WeightInfoExt: WeightInfo {
|
||||
/// Storage proof overhead, that is included in every storage proof.
|
||||
///
|
||||
/// The relayer would pay some extra fee for additional proof bytes, since they mean
|
||||
/// more hashing operations.
|
||||
fn expected_extra_storage_proof_size() -> u32;
|
||||
|
||||
/// Weight of the parachain heads delivery extrinsic.
|
||||
fn submit_parachain_heads_weight(
|
||||
db_weight: RuntimeDbWeight,
|
||||
proof: &impl Size,
|
||||
parachains_count: u32,
|
||||
) -> Weight {
|
||||
// weight of the `submit_parachain_heads` with exactly `parachains_count` parachain
|
||||
// heads of the default size (`DEFAULT_PARACHAIN_HEAD_SIZE`)
|
||||
let base_weight = Self::submit_parachain_heads_with_n_parachains(parachains_count);
|
||||
|
||||
// overhead because of extra storage proof bytes
|
||||
let expected_proof_size = parachains_count
|
||||
.saturating_mul(DEFAULT_PARACHAIN_HEAD_SIZE)
|
||||
.saturating_add(Self::expected_extra_storage_proof_size());
|
||||
let actual_proof_size = proof.size();
|
||||
let proof_size_overhead = Self::storage_proof_size_overhead(
|
||||
actual_proof_size.saturating_sub(expected_proof_size),
|
||||
);
|
||||
|
||||
// potential pruning weight (refunded if hasn't happened)
|
||||
let pruning_weight =
|
||||
Self::parachain_head_pruning_weight(db_weight).saturating_mul(parachains_count as u64);
|
||||
|
||||
base_weight.saturating_add(proof_size_overhead).saturating_add(pruning_weight)
|
||||
}
|
||||
|
||||
/// Returns weight of single parachain head storage update.
|
||||
///
|
||||
/// This weight only includes db write operations that happens if parachain head is actually
|
||||
/// updated. All extra weights (weight of storage proof validation, additional checks, ...) is
|
||||
/// not included.
|
||||
fn parachain_head_storage_write_weight(db_weight: RuntimeDbWeight) -> Weight {
|
||||
// it's just a couple of operations - we need to write the hash (`ImportedParaHashes`) and
|
||||
// the head itself (`ImportedParaHeads`. Pruning is not included here
|
||||
db_weight.writes(2)
|
||||
}
|
||||
|
||||
/// Returns weight of single parachain head pruning.
|
||||
fn parachain_head_pruning_weight(db_weight: RuntimeDbWeight) -> Weight {
|
||||
// it's just one write operation, we don't want any benchmarks for that
|
||||
db_weight.writes(1)
|
||||
}
|
||||
|
||||
/// Returns weight that needs to be accounted when storage proof of given size is received.
|
||||
fn storage_proof_size_overhead(extra_proof_bytes: u32) -> Weight {
|
||||
let extra_byte_weight = (Self::submit_parachain_heads_with_16kb_proof() -
|
||||
Self::submit_parachain_heads_with_1kb_proof()) /
|
||||
(15 * 1024);
|
||||
extra_byte_weight.saturating_mul(extra_proof_bytes as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl WeightInfoExt for () {
|
||||
fn expected_extra_storage_proof_size() -> u32 {
|
||||
EXTRA_STORAGE_PROOF_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: frame_system::Config> WeightInfoExt for BridgeWeight<T> {
|
||||
fn expected_extra_storage_proof_size() -> u32 {
|
||||
EXTRA_STORAGE_PROOF_SIZE
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user