Account proof size in weight formula (#679)

* fix broken message lane benchmarks

* proof-size related benchmarks

* impl Size for proof parameters

* include proof weight into weight formula

* left TODO

* fixed proof size

* WeightInfoExt::receive_messages_proof_weight

* charge for extra message bytes delivery in send_message

* removed default impl of WeightsInfoExt

* moved weight formulas to WeightInfoExt

* receive_messages_proof_outbound_lane_state_overhead is included twice in weight

* typo

* typo

* fixed TODO

* more asserts

* started wotk on message-lane documentation

* expected_extra_storage_proof_size() is actually expected in delivery confirmation tx

* update README.md

* ensure_able_to_receive_confirmation

* test rialto message lane weights

* removed TODO

* removed unnecessary trait requirements

* fixed arguments

* fix compilation

* decreased basic delivery tx weight

* fmt

* clippy

* Update modules/message-lane/src/benchmarking.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* structs

* Update primitives/millau/src/lib.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* removed readme.md

* removed obsolete trait bounds

* Revert "removed readme.md"

This reverts commit 50b7376a41687a94c27bf77565434be153f87ca1.

* Update bin/runtime-common/src/messages.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update bin/runtime-common/src/messages.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update bin/runtime-common/src/messages.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update bin/runtime-common/src/messages.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update bin/runtime-common/src/messages.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update bin/runtime-common/src/messages.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update bin/runtime-common/src/messages.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* PreComputedSize

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
Svyatoslav Nikolsky
2021-02-10 20:26:47 +03:00
committed by Bastian Köcher
parent fb7c191234
commit 2f457775bb
25 changed files with 918 additions and 303 deletions
+144 -64
View File
@@ -16,6 +16,7 @@
//! Message lane pallet benchmarking.
use crate::weights_ext::EXPECTED_DEFAULT_MESSAGE_LENGTH;
use crate::{inbound_lane::InboundLaneStorage, inbound_lane_storage, outbound_lane, Call, Instance};
use bp_message_lane::{
@@ -37,8 +38,9 @@ pub struct Module<T: Config<I>, I: crate::Instance>(crate::Module<T, I>);
/// Proof size requirements.
pub enum ProofSize {
/// The proof is expected to be minimal.
Minimal,
/// The proof is expected to be minimal. If value size may be changed, then it is expected to
/// have given size.
Minimal(u32),
/// The proof is expected to have at least given size and grow by increasing number of trie nodes
/// included in the proof.
HasExtraNodes(u32),
@@ -73,6 +75,8 @@ pub struct MessageDeliveryProofParams<ThisChainAccountId> {
pub lane: LaneId,
/// The proof needs to include this inbound lane data.
pub inbound_lane_data: InboundLaneData<ThisChainAccountId>,
/// Proof size requirements.
pub size: ProofSize,
}
/// Trait that must be implemented by runtime.
@@ -224,17 +228,20 @@ benchmarks_instance! {
let relayer_id_on_source = T::bridged_relayer_id();
let relayer_id_on_target = account("relayer", 0, SEED);
// mark messages 1..=20 as delivered
receive_messages::<T, I>(20);
let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams {
lane: bench_lane_id(),
message_nonces: 1..=1,
message_nonces: 21..=21,
outbound_lane_data: None,
size: ProofSize::Minimal,
size: ProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH),
});
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify {
assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
1,
21,
);
}
@@ -252,17 +259,20 @@ benchmarks_instance! {
let relayer_id_on_source = T::bridged_relayer_id();
let relayer_id_on_target = account("relayer", 0, SEED);
// mark messages 1..=20 as delivered
receive_messages::<T, I>(20);
let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams {
lane: bench_lane_id(),
message_nonces: 1..=2,
message_nonces: 21..=22,
outbound_lane_data: None,
size: ProofSize::Minimal,
size: ProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH),
});
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 2, dispatch_weight)
verify {
assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
2,
22,
);
}
@@ -291,7 +301,7 @@ benchmarks_instance! {
latest_received_nonce: 20,
latest_generated_nonce: 21,
}),
size: ProofSize::Minimal,
size: ProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH),
});
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify {
@@ -305,6 +315,68 @@ benchmarks_instance! {
);
}
// Benchmark `receive_messages_proof` extrinsic with single minimal-weight message and following conditions:
// * the proof has many redundand trie nodes with total size of approximately 1KB;
// * proof does not include outbound lane state proof;
// * inbound lane already has state, so it needs to be read and decoded;
// * message is successfully dispatched;
// * message requires all heavy checks done by dispatcher.
//
// With single KB of messages proof, the weight of the call is increased (roughly) by
// `(receive_single_message_proof_16KB - receive_single_message_proof_1_kb) / 15`.
receive_single_message_proof_1_kb {
let relayer_id_on_source = T::bridged_relayer_id();
let relayer_id_on_target = account("relayer", 0, SEED);
// mark messages 1..=20 as delivered
receive_messages::<T, I>(20);
let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams {
lane: bench_lane_id(),
message_nonces: 21..=21,
outbound_lane_data: None,
size: ProofSize::HasExtraNodes(1024),
});
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify {
assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
21,
);
}
// Benchmark `receive_messages_proof` extrinsic with single minimal-weight message and following conditions:
// * the proof has many redundand trie nodes with total size of approximately 16KB;
// * proof does not include outbound lane state proof;
// * inbound lane already has state, so it needs to be read and decoded;
// * message is successfully dispatched;
// * message requires all heavy checks done by dispatcher.
//
// Size of proof grows because it contains extra trie nodes in it.
//
// With single KB of messages proof, the weight of the call is increased (roughly) by
// `(receive_single_message_proof_16KB - receive_single_message_proof) / 15`.
receive_single_message_proof_16_kb {
let relayer_id_on_source = T::bridged_relayer_id();
let relayer_id_on_target = account("relayer", 0, SEED);
// mark messages 1..=20 as delivered
receive_messages::<T, I>(20);
let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams {
lane: bench_lane_id(),
message_nonces: 21..=21,
outbound_lane_data: None,
size: ProofSize::HasExtraNodes(16 * 1024),
});
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify {
assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
21,
);
}
// Benchmark `receive_messages_delivery_proof` extrinsic with following conditions:
// * single relayer is rewarded for relaying single message;
// * relayer account does not exist (in practice it needs to exist in production environment).
@@ -329,7 +401,8 @@ benchmarks_instance! {
inbound_lane_data: InboundLaneData {
relayers: vec![(1, 1, relayer_id.clone())].into_iter().collect(),
last_confirmed_nonce: 0,
}
},
size: ProofSize::Minimal(0),
});
}: receive_messages_delivery_proof(RawOrigin::Signed(relayer_id.clone()), proof, relayers_state)
verify {
@@ -366,7 +439,8 @@ benchmarks_instance! {
inbound_lane_data: InboundLaneData {
relayers: vec![(1, 2, relayer_id.clone())].into_iter().collect(),
last_confirmed_nonce: 0,
}
},
size: ProofSize::Minimal(0),
});
}: receive_messages_delivery_proof(RawOrigin::Signed(relayer_id.clone()), proof, relayers_state)
verify {
@@ -405,7 +479,8 @@ benchmarks_instance! {
(2, 2, relayer2_id.clone()),
].into_iter().collect(),
last_confirmed_nonce: 0,
}
},
size: ProofSize::Minimal(0),
});
}: receive_messages_delivery_proof(RawOrigin::Signed(relayer1_id.clone()), proof, relayers_state)
verify {
@@ -459,43 +534,7 @@ benchmarks_instance! {
// `weight(receive_two_messages_proof) - weight(receive_single_message_proof)`. So it may be used
// to verify that the other approximation is correct.
receive_multiple_messages_proof {
let i in 1..128;
let relayer_id_on_source = T::bridged_relayer_id();
let relayer_id_on_target = account("relayer", 0, SEED);
let messages_count = i as _;
let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams {
lane: bench_lane_id(),
message_nonces: 1..=i as _,
outbound_lane_data: None,
size: ProofSize::Minimal,
});
}: receive_messages_proof(
RawOrigin::Signed(relayer_id_on_target),
relayer_id_on_source,
proof,
messages_count,
dispatch_weight
)
verify {
assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
i as MessageNonce,
);
}
// Benchmark `receive_messages_proof` extrinsic with multiple minimal-weight messages and following conditions:
// * proof includes outbound lane state proof;
// * inbound lane already has state, so it needs to be read and decoded;
// * message is successfully dispatched;
// * message requires all heavy checks done by dispatcher.
//
// This benchmarks gives us an approximation of outbound lane state delivery weight. It is similar to the
// `weight(receive_single_message_proof_with_outbound_lane_state) - weight(receive_single_message_proof)`.
// So it may be used to verify that the other approximation is correct.
receive_multiple_messages_proof_with_outbound_lane_state {
let i in 1..128;
let i in 1..64;
let relayer_id_on_source = T::bridged_relayer_id();
let relayer_id_on_target = account("relayer", 0, SEED);
@@ -506,13 +545,9 @@ benchmarks_instance! {
let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams {
lane: bench_lane_id(),
message_nonces: 21..=20 + i as MessageNonce,
outbound_lane_data: Some(OutboundLaneData {
oldest_unpruned_nonce: 21,
latest_received_nonce: 20,
latest_generated_nonce: 21,
}),
size: ProofSize::Minimal,
message_nonces: 21..=(20 + i as MessageNonce),
outbound_lane_data: None,
size: ProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH),
});
}: receive_messages_proof(
RawOrigin::Signed(relayer_id_on_target),
@@ -526,10 +561,6 @@ benchmarks_instance! {
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
20 + i as MessageNonce,
);
assert_eq!(
crate::Module::<T, I>::inbound_latest_confirmed_nonce(bench_lane_id()),
20,
);
}
// Benchmark `receive_messages_proof` extrinsic with single minimal-weight message and following conditions:
@@ -538,7 +569,7 @@ benchmarks_instance! {
// * message is successfully dispatched;
// * message requires all heavy checks done by dispatcher.
//
// Results of this benchmark may be used to check how extra nodes in proof affect transaction performance.
// Results of this benchmark may be used to check how proof size affects `receive_message_proof` performance.
receive_message_proofs_with_extra_nodes {
let i in 0..T::maximal_message_size();
@@ -575,7 +606,7 @@ benchmarks_instance! {
// * message is successfully dispatched;
// * message requires all heavy checks done by dispatcher.
//
// Results of this benchmark may be used to check how large (extra) leaf in proof affect transaction performance.
// Results of this benchmark may be used to check how message size affects `receive_message_proof` performance.
receive_message_proofs_with_large_leaf {
let i in 0..T::maximal_message_size();
@@ -606,6 +637,53 @@ benchmarks_instance! {
);
}
// Benchmark `receive_messages_proof` extrinsic with multiple minimal-weight messages and following conditions:
// * proof includes outbound lane state proof;
// * inbound lane already has state, so it needs to be read and decoded;
// * message is successfully dispatched;
// * message requires all heavy checks done by dispatcher.
//
// This benchmarks gives us an approximation of outbound lane state delivery weight. It is similar to the
// `weight(receive_single_message_proof_with_outbound_lane_state) - weight(receive_single_message_proof)`.
// So it may be used to verify that the other approximation is correct.
receive_multiple_messages_proof_with_outbound_lane_state {
let i in 1..128;
let relayer_id_on_source = T::bridged_relayer_id();
let relayer_id_on_target = account("relayer", 0, SEED);
let messages_count = i as _;
// mark messages 1..=20 as delivered
receive_messages::<T, I>(20);
let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams {
lane: bench_lane_id(),
message_nonces: 21..=20 + i as MessageNonce,
outbound_lane_data: Some(OutboundLaneData {
oldest_unpruned_nonce: 21,
latest_received_nonce: 20,
latest_generated_nonce: 21,
}),
size: ProofSize::Minimal(0),
});
}: receive_messages_proof(
RawOrigin::Signed(relayer_id_on_target),
relayer_id_on_source,
proof,
messages_count,
dispatch_weight
)
verify {
assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
20 + i as MessageNonce,
);
assert_eq!(
crate::Module::<T, I>::inbound_latest_confirmed_nonce(bench_lane_id()),
20,
);
}
// Benchmark `receive_messages_delivery_proof` extrinsic where single relayer delivers multiple messages.
receive_delivery_proof_for_multiple_messages_by_single_relayer {
// there actually should be used value of `MaxUnrewardedRelayerEntriesAtInboundLane` from the bridged
@@ -634,7 +712,8 @@ benchmarks_instance! {
inbound_lane_data: InboundLaneData {
relayers: vec![(1, i as MessageNonce, relayer_id.clone())].into_iter().collect(),
last_confirmed_nonce: 0,
}
},
size: ProofSize::Minimal(0),
});
}: receive_messages_delivery_proof(RawOrigin::Signed(relayer_id.clone()), proof, relayers_state)
verify {
@@ -679,7 +758,8 @@ benchmarks_instance! {
.map(|(j, relayer_id)| (j as MessageNonce + 1, j as MessageNonce + 1, relayer_id.clone()))
.collect(),
last_confirmed_nonce: 0,
}
},
size: ProofSize::Minimal(0),
});
}: receive_messages_delivery_proof(RawOrigin::Signed(confirmation_relayer_id), proof, relayers_state)
verify {
+27 -32
View File
@@ -35,7 +35,10 @@
#![cfg_attr(not(feature = "std"), no_std)]
pub use crate::weights_ext::{ensure_weights_are_correct, WeightInfoExt};
pub use crate::weights_ext::{
ensure_able_to_receive_confirmation, ensure_able_to_receive_message, ensure_weights_are_correct, WeightInfoExt,
EXPECTED_DEFAULT_MESSAGE_LENGTH,
};
use crate::inbound_lane::{InboundLane, InboundLaneStorage};
use crate::outbound_lane::{OutboundLane, OutboundLaneStorage};
@@ -267,9 +270,7 @@ decl_module! {
}
/// Send message over lane.
#[weight = T::WeightInfo::send_message_overhead()
.saturating_add(T::WeightInfo::send_message_size_overhead(Size::size_hint(payload)))
]
#[weight = T::WeightInfo::send_message_weight(payload)]
pub fn send_message(
origin,
lane_id: LaneId,
@@ -351,11 +352,7 @@ decl_module! {
/// The weight of the call assumes that the transaction always brings outbound lane
/// state update. Because of that, the submitter (relayer) has no benefit of not including
/// this data in the transaction, so reward confirmations lags should be minimal.
#[weight = T::WeightInfo::receive_messages_proof_overhead()
.saturating_add(T::WeightInfo::receive_messages_proof_outbound_lane_state_overhead())
.saturating_add(T::WeightInfo::receive_messages_proof_messages_overhead(MessageNonce::from(*messages_count)))
.saturating_add(*dispatch_weight)
]
#[weight = T::WeightInfo::receive_messages_proof_weight(proof, *messages_count, *dispatch_weight)]
pub fn receive_messages_proof(
origin,
relayer_id: T::InboundRelayer,
@@ -444,14 +441,7 @@ decl_module! {
}
/// Receive messages delivery proof from bridged chain.
#[weight = T::WeightInfo::receive_messages_delivery_proof_overhead()
.saturating_add(T::WeightInfo::receive_messages_delivery_proof_messages_overhead(
relayers_state.total_messages
))
.saturating_add(T::WeightInfo::receive_messages_delivery_proof_relayers_overhead(
relayers_state.unrewarded_relayer_entries
))
]
#[weight = T::WeightInfo::receive_messages_delivery_proof_weight(proof, relayers_state)]
pub fn receive_messages_delivery_proof(
origin,
proof: MessagesDeliveryProofOf<T, I>,
@@ -774,8 +764,9 @@ fn verify_and_decode_messages_proof<Chain: SourceHeaderChain<Fee>, Fee, Dispatch
mod tests {
use super::*;
use crate::mock::{
message, run_test, Origin, TestEvent, TestMessageDeliveryAndDispatchPayment, TestMessagesProof, TestPayload,
TestRuntime, PAYLOAD_REJECTED_BY_TARGET_CHAIN, REGULAR_PAYLOAD, TEST_LANE_ID, TEST_RELAYER_A, TEST_RELAYER_B,
message, run_test, Origin, TestEvent, TestMessageDeliveryAndDispatchPayment, TestMessagesDeliveryProof,
TestMessagesProof, TestPayload, TestRuntime, PAYLOAD_REJECTED_BY_TARGET_CHAIN, REGULAR_PAYLOAD, TEST_LANE_ID,
TEST_RELAYER_A, TEST_RELAYER_B,
};
use bp_message_lane::UnrewardedRelayersState;
use frame_support::{assert_noop, assert_ok};
@@ -814,13 +805,13 @@ mod tests {
assert_ok!(Module::<TestRuntime>::receive_messages_delivery_proof(
Origin::signed(1),
Ok((
TestMessagesDeliveryProof(Ok((
TEST_LANE_ID,
InboundLaneData {
last_confirmed_nonce: 1,
..Default::default()
},
)),
))),
Default::default(),
));
@@ -924,13 +915,13 @@ mod tests {
assert_noop!(
Module::<TestRuntime>::receive_messages_delivery_proof(
Origin::signed(1),
Ok((
TestMessagesDeliveryProof(Ok((
TEST_LANE_ID,
InboundLaneData {
last_confirmed_nonce: 1,
..Default::default()
},
)),
))),
Default::default(),
),
Error::<TestRuntime, DefaultInstance>::Halted,
@@ -1140,13 +1131,13 @@ mod tests {
// this reports delivery of message 1 => reward is paid to TEST_RELAYER_A
assert_ok!(Module::<TestRuntime>::receive_messages_delivery_proof(
Origin::signed(1),
Ok((
TestMessagesDeliveryProof(Ok((
TEST_LANE_ID,
InboundLaneData {
relayers: vec![(1, 1, TEST_RELAYER_A)].into_iter().collect(),
..Default::default()
}
)),
))),
UnrewardedRelayersState {
unrewarded_relayer_entries: 1,
total_messages: 1,
@@ -1165,7 +1156,7 @@ mod tests {
// this reports delivery of both message 1 and message 2 => reward is paid only to TEST_RELAYER_B
assert_ok!(Module::<TestRuntime>::receive_messages_delivery_proof(
Origin::signed(1),
Ok((
TestMessagesDeliveryProof(Ok((
TEST_LANE_ID,
InboundLaneData {
relayers: vec![(1, 1, TEST_RELAYER_A), (2, 2, TEST_RELAYER_B)]
@@ -1173,7 +1164,7 @@ mod tests {
.collect(),
..Default::default()
}
)),
))),
UnrewardedRelayersState {
unrewarded_relayer_entries: 2,
total_messages: 2,
@@ -1195,7 +1186,11 @@ mod tests {
fn receive_messages_delivery_proof_rejects_invalid_proof() {
run_test(|| {
assert_noop!(
Module::<TestRuntime>::receive_messages_delivery_proof(Origin::signed(1), Err(()), Default::default(),),
Module::<TestRuntime>::receive_messages_delivery_proof(
Origin::signed(1),
TestMessagesDeliveryProof(Err(())),
Default::default(),
),
Error::<TestRuntime, DefaultInstance>::InvalidMessagesDeliveryProof,
);
});
@@ -1208,7 +1203,7 @@ mod tests {
assert_noop!(
Module::<TestRuntime>::receive_messages_delivery_proof(
Origin::signed(1),
Ok((
TestMessagesDeliveryProof(Ok((
TEST_LANE_ID,
InboundLaneData {
relayers: vec![(1, 1, TEST_RELAYER_A), (2, 2, TEST_RELAYER_B)]
@@ -1216,7 +1211,7 @@ mod tests {
.collect(),
..Default::default()
}
)),
))),
UnrewardedRelayersState {
unrewarded_relayer_entries: 1,
total_messages: 2,
@@ -1230,7 +1225,7 @@ mod tests {
assert_noop!(
Module::<TestRuntime>::receive_messages_delivery_proof(
Origin::signed(1),
Ok((
TestMessagesDeliveryProof(Ok((
TEST_LANE_ID,
InboundLaneData {
relayers: vec![(1, 1, TEST_RELAYER_A), (2, 2, TEST_RELAYER_B)]
@@ -1238,7 +1233,7 @@ mod tests {
.collect(),
..Default::default()
}
)),
))),
UnrewardedRelayersState {
unrewarded_relayer_entries: 2,
total_messages: 1,
+18 -2
View File
@@ -183,6 +183,12 @@ pub struct TestMessagesProof {
pub result: Result<MessagesByLaneVec, ()>,
}
impl Size for TestMessagesProof {
fn size_hint(&self) -> u32 {
0
}
}
impl From<Result<Vec<Message<TestMessageFee>>, ()>> for TestMessagesProof {
fn from(result: Result<Vec<Message<TestMessageFee>>, ()>) -> Self {
Self {
@@ -202,6 +208,16 @@ impl From<Result<Vec<Message<TestMessageFee>>, ()>> for TestMessagesProof {
}
}
/// Messages delivery proof used in tests.
#[derive(Debug, Encode, Decode, Eq, Clone, PartialEq)]
pub struct TestMessagesDeliveryProof(pub Result<(LaneId, InboundLaneData<TestRelayer>), ()>);
impl Size for TestMessagesDeliveryProof {
fn size_hint(&self) -> u32 {
0
}
}
/// Target header chain that is used in tests.
#[derive(Debug, Default)]
pub struct TestTargetHeaderChain;
@@ -209,7 +225,7 @@ pub struct TestTargetHeaderChain;
impl TargetHeaderChain<TestPayload, TestRelayer> for TestTargetHeaderChain {
type Error = &'static str;
type MessagesDeliveryProof = Result<(LaneId, InboundLaneData<TestRelayer>), ()>;
type MessagesDeliveryProof = TestMessagesDeliveryProof;
fn verify_message(payload: &TestPayload) -> Result<(), Self::Error> {
if *payload == PAYLOAD_REJECTED_BY_TARGET_CHAIN {
@@ -222,7 +238,7 @@ impl TargetHeaderChain<TestPayload, TestRelayer> for TestTargetHeaderChain {
fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<TestRelayer>), Self::Error> {
proof.map_err(|_| TEST_ERROR)
proof.0.map_err(|_| TEST_ERROR)
}
}
+70 -48
View File
@@ -17,7 +17,7 @@
//! Autogenerated weights for pallet_message_lane
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.1
//! DATE: 2021-01-25, STEPS: [50, ], REPEAT: 20
//! DATE: 2021-02-01, STEPS: [50, ], REPEAT: 20
//! LOW RANGE: [], HIGH RANGE: []
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled
//! CHAIN: Some("local"), DB CACHE: 128
@@ -54,14 +54,16 @@ pub trait WeightInfo {
fn receive_single_message_proof() -> Weight;
fn receive_two_messages_proof() -> Weight;
fn receive_single_message_proof_with_outbound_lane_state() -> Weight;
fn receive_single_message_proof_1_kb() -> Weight;
fn receive_single_message_proof_16_kb() -> Weight;
fn receive_delivery_proof_for_single_message() -> Weight;
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight;
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight;
fn send_messages_of_various_lengths(i: u32) -> Weight;
fn receive_multiple_messages_proof(i: u32) -> Weight;
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight;
fn receive_message_proofs_with_extra_nodes(i: u32) -> Weight;
fn receive_message_proofs_with_large_leaf(i: u32) -> Weight;
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight;
fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight;
fn receive_delivery_proof_for_multiple_messages_by_multiple_relayers(i: u32) -> Weight;
}
@@ -70,90 +72,100 @@ pub trait WeightInfo {
pub struct RialtoWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for RialtoWeight<T> {
fn send_minimal_message_worst_case() -> Weight {
(123_511_000 as Weight)
(138_421_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(12 as Weight))
}
fn send_1_kb_message_worst_case() -> Weight {
(132_218_000 as Weight)
(142_633_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(12 as Weight))
}
fn send_16_kb_message_worst_case() -> Weight {
(187_458_000 as Weight)
(194_483_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(12 as Weight))
}
fn receive_single_message_proof() -> Weight {
(156_005_000 as Weight)
(154_651_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_two_messages_proof() -> Weight {
(266_292_000 as Weight)
(271_722_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_single_message_proof_with_outbound_lane_state() -> Weight {
(171_319_000 as Weight)
(170_821_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_single_message_proof_1_kb() -> Weight {
(189_540_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_single_message_proof_16_kb() -> Weight {
(484_899_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_delivery_proof_for_single_message() -> Weight {
(127_537_000 as Weight)
(145_328_000 as Weight)
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
(135_281_000 as Weight)
(150_165_000 as Weight)
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
(180_862_000 as Weight)
(215_954_000 as Weight)
.saturating_add(T::DbWeight::get().reads(8 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
fn send_messages_of_various_lengths(i: u32) -> Weight {
(98_452_000 as Weight)
(117_961_000 as Weight)
.saturating_add((3_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(12 as Weight))
}
fn receive_multiple_messages_proof(i: u32) -> Weight {
(0 as Weight)
.saturating_add((124_098_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight {
(0 as Weight)
.saturating_add((128_267_000 as Weight).saturating_mul(i as Weight))
.saturating_add((117_783_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_message_proofs_with_extra_nodes(i: u32) -> Weight {
(437_756_000 as Weight)
(448_951_000 as Weight)
.saturating_add((10_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_message_proofs_with_large_leaf(i: u32) -> Weight {
(164_484_000 as Weight)
(97_174_000 as Weight)
.saturating_add((7_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight {
(0 as Weight)
.saturating_add((120_176_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight {
(122_609_000 as Weight)
.saturating_add((7_289_000 as Weight).saturating_mul(i as Weight))
(132_970_000 as Weight)
.saturating_add((7_243_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
fn receive_delivery_proof_for_multiple_messages_by_multiple_relayers(i: u32) -> Weight {
(129_622_000 as Weight)
.saturating_add((53_214_000 as Weight).saturating_mul(i as Weight))
(62_936_000 as Weight)
.saturating_add((67_932_000 as Weight).saturating_mul(i as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
@@ -164,90 +176,100 @@ impl<T: frame_system::Config> WeightInfo for RialtoWeight<T> {
// For backwards compatibility and tests
impl WeightInfo for () {
fn send_minimal_message_worst_case() -> Weight {
(123_511_000 as Weight)
(138_421_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
}
fn send_1_kb_message_worst_case() -> Weight {
(132_218_000 as Weight)
(142_633_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
}
fn send_16_kb_message_worst_case() -> Weight {
(187_458_000 as Weight)
(194_483_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
}
fn receive_single_message_proof() -> Weight {
(156_005_000 as Weight)
(154_651_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_two_messages_proof() -> Weight {
(266_292_000 as Weight)
(271_722_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_single_message_proof_with_outbound_lane_state() -> Weight {
(171_319_000 as Weight)
(170_821_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_single_message_proof_1_kb() -> Weight {
(189_540_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_single_message_proof_16_kb() -> Weight {
(484_899_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_delivery_proof_for_single_message() -> Weight {
(127_537_000 as Weight)
(145_328_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(6 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
(135_281_000 as Weight)
(150_165_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(7 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
(180_862_000 as Weight)
(215_954_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(8 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
fn send_messages_of_various_lengths(i: u32) -> Weight {
(98_452_000 as Weight)
(117_961_000 as Weight)
.saturating_add((3_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(12 as Weight))
}
fn receive_multiple_messages_proof(i: u32) -> Weight {
(0 as Weight)
.saturating_add((124_098_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight {
(0 as Weight)
.saturating_add((128_267_000 as Weight).saturating_mul(i as Weight))
.saturating_add((117_783_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_message_proofs_with_extra_nodes(i: u32) -> Weight {
(437_756_000 as Weight)
(448_951_000 as Weight)
.saturating_add((10_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_message_proofs_with_large_leaf(i: u32) -> Weight {
(164_484_000 as Weight)
(97_174_000 as Weight)
.saturating_add((7_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_multiple_messages_proof_with_outbound_lane_state(i: u32) -> Weight {
(0 as Weight)
.saturating_add((120_176_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn receive_delivery_proof_for_multiple_messages_by_single_relayer(i: u32) -> Weight {
(122_609_000 as Weight)
.saturating_add((7_289_000 as Weight).saturating_mul(i as Weight))
(132_970_000 as Weight)
.saturating_add((7_243_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
fn receive_delivery_proof_for_multiple_messages_by_multiple_relayers(i: u32) -> Weight {
(129_622_000 as Weight)
.saturating_add((53_214_000 as Weight).saturating_mul(i as Weight))
(62_936_000 as Weight)
.saturating_add((67_932_000 as Weight).saturating_mul(i as Weight))
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
.saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
+206 -20
View File
@@ -18,52 +18,213 @@
use crate::weights::WeightInfo;
use bp_message_lane::MessageNonce;
use bp_message_lane::{MessageNonce, UnrewardedRelayersState};
use bp_runtime::{PreComputedSize, Size};
use frame_support::weights::Weight;
/// Size of the message being delivered in benchmarks.
pub const EXPECTED_DEFAULT_MESSAGE_LENGTH: u32 = 128;
/// We assume that size of signed extensions on all our chains and size of all 'small' arguments of calls
/// we're checking here would fit 1KB.
const SIGNED_EXTENSIONS_SIZE: u32 = 1024;
/// Ensure that weights from `WeightInfoExt` implementation are looking correct.
pub fn ensure_weights_are_correct<W: WeightInfoExt>(
expected_max_single_message_delivery_tx_weight: Weight,
expected_max_messages_delivery_tx_weight: Weight,
expected_single_regular_message_delivery_tx_weight: Weight,
expected_messages_delivery_confirmation_tx_weight: Weight,
) {
// verify `send_message` weight components
assert_ne!(W::send_message_overhead(), 0);
assert_ne!(W::send_message_size_overhead(0), 0);
// verify `receive_messages_proof` weight components
assert_ne!(W::receive_messages_proof_overhead(), 0);
assert_ne!(W::receive_messages_proof_messages_overhead(1), 0);
assert_ne!(W::receive_messages_proof_outbound_lane_state_overhead(), 0);
assert_ne!(W::storage_proof_size_overhead(1), 0);
let actual_max_single_message_delivery_tx_weight = W::receive_messages_proof_overhead()
.checked_add(W::receive_messages_proof_messages_overhead(1))
.expect("weights are too large")
.checked_add(W::receive_messages_proof_outbound_lane_state_overhead())
.expect("weights are too large");
// verify that the hardcoded value covers `receive_messages_proof` weight
let actual_single_regular_message_delivery_tx_weight = W::receive_messages_proof_weight(
&PreComputedSize((EXPECTED_DEFAULT_MESSAGE_LENGTH + W::expected_extra_storage_proof_size()) as usize),
1,
0,
);
assert!(
actual_max_single_message_delivery_tx_weight <= expected_max_single_message_delivery_tx_weight,
actual_single_regular_message_delivery_tx_weight <= expected_single_regular_message_delivery_tx_weight,
"Single message delivery transaction weight {} is larger than expected weight {}",
actual_max_single_message_delivery_tx_weight,
expected_max_single_message_delivery_tx_weight,
actual_single_regular_message_delivery_tx_weight,
expected_single_regular_message_delivery_tx_weight,
);
// verify `receive_messages_delivery_proof` weight components
assert_ne!(W::receive_messages_delivery_proof_overhead(), 0);
assert_ne!(W::receive_messages_delivery_proof_messages_overhead(1), 0);
assert_ne!(W::receive_messages_delivery_proof_relayers_overhead(1), 0);
assert_ne!(W::storage_proof_size_overhead(1), 0);
let actual_max_messages_delivery_tx_weight = W::receive_messages_delivery_proof_overhead()
.checked_add(W::receive_messages_delivery_proof_messages_overhead(1))
.expect("weights are too large")
.checked_add(W::receive_messages_delivery_proof_relayers_overhead(1))
.expect("weights are too large");
// verify that the hardcoded value covers `receive_messages_delivery_proof` weight
let actual_messages_delivery_confirmation_tx_weight = W::receive_messages_delivery_proof_weight(
&PreComputedSize(W::expected_extra_storage_proof_size() as usize),
&UnrewardedRelayersState {
unrewarded_relayer_entries: 1,
total_messages: 1,
..Default::default()
},
);
assert!(
actual_max_messages_delivery_tx_weight <= expected_max_messages_delivery_tx_weight,
actual_messages_delivery_confirmation_tx_weight <= expected_messages_delivery_confirmation_tx_weight,
"Messages delivery confirmation transaction weight {} is larger than expected weight {}",
actual_max_messages_delivery_tx_weight,
expected_max_messages_delivery_tx_weight,
actual_messages_delivery_confirmation_tx_weight,
expected_messages_delivery_confirmation_tx_weight,
);
}
/// Ensure that we're able to receive maximal (by-size and by-weight) message from other chain.
pub fn ensure_able_to_receive_message<W: WeightInfoExt>(
max_extrinsic_size: u32,
max_extrinsic_weight: Weight,
max_incoming_message_proof_size: u32,
// This is a base weight (which includes cost of tx itself, per-byte cost, adjusted per-byte cost) of single
// message delivery transaction that brings `max_incoming_message_proof_size` proof.
max_incoming_message_proof_base_weight: Weight,
max_incoming_message_dispatch_weight: Weight,
) {
// verify that we're able to receive proof of maximal-size message
let max_delivery_transaction_size = max_incoming_message_proof_size.saturating_add(SIGNED_EXTENSIONS_SIZE);
assert!(
max_delivery_transaction_size <= max_extrinsic_size,
"Size of maximal message delivery transaction {} + {} is larger than maximal possible transaction size {}",
max_incoming_message_proof_size,
SIGNED_EXTENSIONS_SIZE,
max_extrinsic_size,
);
// verify that we're able to receive proof of maximal-size message with maximal dispatch weight
let max_delivery_transaction_dispatch_weight = W::receive_messages_proof_weight(
&PreComputedSize((max_incoming_message_proof_size + W::expected_extra_storage_proof_size()) as usize),
1,
max_incoming_message_dispatch_weight,
);
let max_delivery_transaction_weight =
max_incoming_message_proof_base_weight.saturating_add(max_delivery_transaction_dispatch_weight);
assert!(
max_delivery_transaction_weight <= max_extrinsic_weight,
"Weight of maximal message delivery transaction {} + {} is larger than maximal possible transaction weight {}",
max_delivery_transaction_weight,
max_delivery_transaction_dispatch_weight,
max_extrinsic_weight,
);
}
/// Ensure that we're able to receive maximal confirmation from other chain.
pub fn ensure_able_to_receive_confirmation<W: WeightInfoExt>(
max_extrinsic_size: u32,
max_extrinsic_weight: Weight,
max_inbound_lane_data_proof_size_from_peer_chain: u32,
max_unrewarded_relayer_entries_at_peer_inbound_lane: MessageNonce,
max_unconfirmed_messages_at_inbound_lane: MessageNonce,
// This is a base weight (which includes cost of tx itself, per-byte cost, adjusted per-byte cost) of single
// confirmation transaction that brings `max_inbound_lane_data_proof_size_from_peer_chain` proof.
max_incoming_delivery_proof_base_weight: Weight,
) {
// verify that we're able to receive confirmation of maximal-size
let max_confirmation_transaction_size =
max_inbound_lane_data_proof_size_from_peer_chain.saturating_add(SIGNED_EXTENSIONS_SIZE);
assert!(
max_confirmation_transaction_size <= max_extrinsic_size,
"Size of maximal message delivery confirmation transaction {} + {} is larger than maximal possible transaction size {}",
max_inbound_lane_data_proof_size_from_peer_chain,
SIGNED_EXTENSIONS_SIZE,
max_extrinsic_size,
);
// verify that we're able to reward maximal number of relayers that have delivered maximal number of messages
let max_confirmation_transaction_dispatch_weight = W::receive_messages_delivery_proof_weight(
&PreComputedSize(max_inbound_lane_data_proof_size_from_peer_chain as usize),
&UnrewardedRelayersState {
unrewarded_relayer_entries: max_unrewarded_relayer_entries_at_peer_inbound_lane,
total_messages: max_unconfirmed_messages_at_inbound_lane,
..Default::default()
},
);
let max_confirmation_transaction_weight =
max_incoming_delivery_proof_base_weight.saturating_add(max_confirmation_transaction_dispatch_weight);
assert!(
max_confirmation_transaction_weight <= max_extrinsic_weight,
"Weight of maximal confirmation transaction {} + {} is larger than maximal possible transaction weight {}",
max_incoming_delivery_proof_base_weight,
max_confirmation_transaction_dispatch_weight,
max_extrinsic_weight,
);
}
/// Extended weight info.
pub trait WeightInfoExt: WeightInfo {
/// Size of proof that is already included in the single message delivery weight.
///
/// The message submitter (at source chain) has already covered this cost. But there are two
/// factors that may increase proof size: (1) the message size may be larger than predefined
/// and (2) relayer may add extra trie nodes to the proof. So if proof size is larger than
/// this value, we're going to charge relayer for that.
fn expected_extra_storage_proof_size() -> u32;
// Functions that are directly mapped to extrinsics weights.
/// Weight of message send extrinsic.
fn send_message_weight(message: &impl Size) -> Weight {
let transaction_overhead = Self::send_message_overhead();
let message_size_overhead = Self::send_message_size_overhead(message.size_hint());
transaction_overhead.saturating_add(message_size_overhead)
}
/// Weight of message delivery extrinsic.
fn receive_messages_proof_weight(proof: &impl Size, messages_count: u32, dispatch_weight: Weight) -> Weight {
// basic components of extrinsic weight
let transaction_overhead = Self::receive_messages_proof_overhead();
let outbound_state_delivery_weight = Self::receive_messages_proof_outbound_lane_state_overhead();
let messages_delivery_weight =
Self::receive_messages_proof_messages_overhead(MessageNonce::from(messages_count));
let messages_dispatch_weight = dispatch_weight;
// proof size overhead weight
let expected_proof_size = EXPECTED_DEFAULT_MESSAGE_LENGTH
.saturating_mul(messages_count.saturating_sub(1))
.saturating_add(Self::expected_extra_storage_proof_size());
let actual_proof_size = proof.size_hint();
let proof_size_overhead =
Self::storage_proof_size_overhead(actual_proof_size.saturating_sub(expected_proof_size));
transaction_overhead
.saturating_add(outbound_state_delivery_weight)
.saturating_add(messages_delivery_weight)
.saturating_add(messages_dispatch_weight)
.saturating_add(proof_size_overhead)
}
/// Weight of confirmation delivery extrinsic.
fn receive_messages_delivery_proof_weight(proof: &impl Size, relayers_state: &UnrewardedRelayersState) -> Weight {
// basic components of extrinsic weight
let transaction_overhead = Self::receive_messages_delivery_proof_overhead();
let messages_overhead = Self::receive_messages_delivery_proof_messages_overhead(relayers_state.total_messages);
let relayers_overhead =
Self::receive_messages_delivery_proof_relayers_overhead(relayers_state.unrewarded_relayer_entries);
// proof size overhead weight
let expected_proof_size = Self::expected_extra_storage_proof_size();
let actual_proof_size = proof.size_hint();
let proof_size_overhead =
Self::storage_proof_size_overhead(actual_proof_size.saturating_sub(expected_proof_size));
transaction_overhead
.saturating_add(messages_overhead)
.saturating_add(relayers_overhead)
.saturating_add(proof_size_overhead)
}
// Functions that are used by extrinsics weights formulas.
/// Returns weight of message send transaction (`send_message`).
fn send_message_overhead() -> Weight {
Self::send_minimal_message_worst_case()
@@ -130,6 +291,31 @@ pub trait WeightInfoExt: WeightInfo {
.saturating_sub(weight_of_two_messages_by_single_relayer)
.saturating_mul(relayers as Weight)
}
/// Returns weight that needs to be accounted when storage proof of given size is recieved (either in
/// `receive_messages_proof` or `receive_messages_delivery_proof`).
///
/// **IMPORTANT**: this overhead is already included in the 'base' transaction cost - e.g. proof
/// size depends on messages count or number of entries in the unrewarded relayers set. So this
/// shouldn't be added to cost of transaction, but instead should act as a minimal cost that the
/// relayer must pay when it relays proof of given size (even if cost based on other parameters
/// is less than that cost).
fn storage_proof_size_overhead(proof_size: u32) -> Weight {
let proof_size_in_bytes = proof_size as Weight;
let byte_weight =
(Self::receive_single_message_proof_16_kb() - Self::receive_single_message_proof_1_kb()) / (15 * 1024);
proof_size_in_bytes * byte_weight
}
}
impl<T: WeightInfo> WeightInfoExt for T {}
impl WeightInfoExt for () {
fn expected_extra_storage_proof_size() -> u32 {
bp_rialto::EXTRA_STORAGE_PROOF_SIZE
}
}
impl<T: frame_system::Config> WeightInfoExt for crate::weights::RialtoWeight<T> {
fn expected_extra_storage_proof_size() -> u32 {
bp_rialto::EXTRA_STORAGE_PROOF_SIZE
}
}