Skip to content

Commit

Permalink
Renamings (#2226)
Browse files Browse the repository at this point in the history
* StorageProofSize -> StorageSize

* Rename benchmarks

* StorageSize -> UnverifiedStorageProofParams

* Fix clippy

* Fix priority boost
  • Loading branch information
serban300 authored and bkontur committed May 21, 2024
1 parent a266572 commit 6006298
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 216 deletions.
16 changes: 6 additions & 10 deletions bridges/bin/runtime-common/src/messages_benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use bp_messages::{
target_chain::FromBridgedChainMessagesProof, MessagePayload,
};
use bp_polkadot_core::parachains::ParaHash;
use bp_runtime::{AccountIdOf, Chain, HashOf, Parachain, StorageProofSize};
use bp_runtime::{AccountIdOf, Chain, HashOf, Parachain};
use codec::Encode;
use frame_support::weights::Weight;
use pallet_bridge_messages::{
Expand All @@ -44,11 +44,7 @@ fn prepare_inbound_message(
params: &MessageProofParams,
successful_dispatch_message_generator: impl Fn(usize) -> MessagePayload,
) -> MessagePayload {
// we only care about **this** message size when message proof needs to be `Minimal`
let expected_size = match params.size {
StorageProofSize::Minimal(size) => size as usize,
_ => 0,
};
let expected_size = params.proof_params.db_size.unwrap_or(0) as usize;

// if we don't need a correct message, then we may just return some random blob
if !params.is_successful_dispatch_expected {
Expand Down Expand Up @@ -93,7 +89,7 @@ where
params.lane,
params.message_nonces.clone(),
params.outbound_lane_data.clone(),
params.size,
params.proof_params,
|_| prepare_inbound_message(&params, &message_generator),
encode_all_messages,
encode_lane_data,
Expand Down Expand Up @@ -140,7 +136,7 @@ where
params.lane,
params.message_nonces.clone(),
params.outbound_lane_data.clone(),
params.size,
params.proof_params,
|_| prepare_inbound_message(&params, &message_generator),
encode_all_messages,
encode_lane_data,
Expand Down Expand Up @@ -186,7 +182,7 @@ where
let (state_root, storage_proof) = prepare_message_delivery_storage_proof::<
BridgedChainOf<R, MI>,
ThisChainOf<R, MI>,
>(params.lane, params.inbound_lane_data, params.size);
>(params.lane, params.inbound_lane_data, params.proof_params);

// update runtime storage
let (_, bridged_header_hash) = insert_header_to_grandpa_pallet::<R, FI>(state_root);
Expand Down Expand Up @@ -217,7 +213,7 @@ where
let (state_root, storage_proof) = prepare_message_delivery_storage_proof::<
BridgedChainOf<R, MI>,
ThisChainOf<R, MI>,
>(params.lane, params.inbound_lane_data, params.size);
>(params.lane, params.inbound_lane_data, params.proof_params);

// update runtime storage
let (_, bridged_header_hash) =
Expand Down
12 changes: 6 additions & 6 deletions bridges/bin/runtime-common/src/parachains_benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::messages_benchmarking::insert_header_to_grandpa_pallet;

use bp_parachains::parachain_head_storage_key_at_source;
use bp_polkadot_core::parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId};
use bp_runtime::{grow_storage_value, Chain, StorageProofSize, UnverifiedStorageProof};
use bp_runtime::{grow_storage_value, Chain, UnverifiedStorageProof, UnverifiedStorageProofParams};
use codec::Encode;
use frame_support::{sp_runtime::StateVersion, traits::Get};
use pallet_bridge_grandpa::BridgedChain;
Expand All @@ -37,7 +37,7 @@ use sp_trie::{LayoutV0, LayoutV1, MemoryDB, TrieConfiguration, TrieDBMutBuilder,
pub fn prepare_parachain_heads_proof<R, PI>(
parachains: &[ParaId],
parachain_head_size: u32,
size: StorageProofSize,
proof_params: UnverifiedStorageProofParams,
) -> (RelayBlockNumber, RelayBlockHash, ParaHeadsProof, Vec<(ParaId, ParaHash)>)
where
R: pallet_bridge_parachains::Config<PI>
Expand All @@ -50,20 +50,20 @@ where
StateVersion::V0 => do_prepare_parachain_heads_proof::<R, PI, LayoutV0<RelayBlockHasher>>(
parachains,
parachain_head_size,
size,
proof_params,
),
StateVersion::V1 => do_prepare_parachain_heads_proof::<R, PI, LayoutV1<RelayBlockHasher>>(
parachains,
parachain_head_size,
size,
proof_params,
),
}
}

fn do_prepare_parachain_heads_proof<R, PI, L>(
parachains: &[ParaId],
parachain_head_size: u32,
size: StorageProofSize,
proof_params: UnverifiedStorageProofParams,
) -> (RelayBlockNumber, RelayBlockHash, ParaHeadsProof, Vec<(ParaId, ParaHash)>)
where
R: pallet_bridge_parachains::Config<PI>
Expand All @@ -88,7 +88,7 @@ where
let storage_key =
parachain_head_storage_key_at_source(R::ParasPalletName::get(), *parachain);
let leaf_data = if i == 0 {
grow_storage_value(parachain_head.encode(), size)
grow_storage_value(parachain_head.encode(), &proof_params)
} else {
parachain_head.encode()
};
Expand Down
32 changes: 19 additions & 13 deletions bridges/modules/messages/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use bp_messages::{
InboundLaneData, LaneId, LaneState, MessageNonce, OutboundLaneData, UnrewardedRelayer,
UnrewardedRelayersState,
};
use bp_runtime::{AccountIdOf, HashOf, StorageProofSize};
use bp_runtime::{AccountIdOf, HashOf, UnverifiedStorageProofParams};
use codec::Decode;
use frame_benchmarking::{account, v2::*};
use frame_support::weights::Weight;
Expand Down Expand Up @@ -57,7 +57,7 @@ pub struct MessageProofParams {
/// return `true` from the `is_message_successfully_dispatched`.
pub is_successful_dispatch_expected: bool,
/// Proof size requirements.
pub size: StorageProofSize,
pub proof_params: UnverifiedStorageProofParams,
}

/// Benchmark-specific message delivery proof parameters.
Expand All @@ -68,7 +68,7 @@ pub struct MessageDeliveryProofParams<ThisChainAccountId> {
/// The proof needs to include this inbound lane data.
pub inbound_lane_data: InboundLaneData<ThisChainAccountId>,
/// Proof size requirements.
pub size: StorageProofSize,
pub proof_params: UnverifiedStorageProofParams,
}

/// Trait that must be implemented by runtime.
Expand Down Expand Up @@ -215,7 +215,9 @@ mod benchmarks {
message_nonces: setup.nonces(),
outbound_lane_data: None,
is_successful_dispatch_expected: false,
size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH),
proof_params: UnverifiedStorageProofParams::from_db_size(
EXPECTED_DEFAULT_MESSAGE_LENGTH,
),
});

#[extrinsic_call]
Expand Down Expand Up @@ -246,7 +248,9 @@ mod benchmarks {
message_nonces: setup.nonces(),
outbound_lane_data: None,
is_successful_dispatch_expected: false,
size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH),
proof_params: UnverifiedStorageProofParams::from_db_size(
EXPECTED_DEFAULT_MESSAGE_LENGTH,
),
});

#[extrinsic_call]
Expand Down Expand Up @@ -287,7 +291,9 @@ mod benchmarks {
latest_generated_nonce: setup.last_nonce(),
}),
is_successful_dispatch_expected: false,
size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH),
proof_params: UnverifiedStorageProofParams::from_db_size(
EXPECTED_DEFAULT_MESSAGE_LENGTH,
),
});

#[extrinsic_call]
Expand All @@ -311,7 +317,7 @@ mod benchmarks {
// * message is dispatched (reminder: dispatch weight should be minimal);
// * message requires all heavy checks done by dispatcher.
#[benchmark]
fn receive_single_message_n_bytes_proof(
fn receive_single_n_bytes_message_proof(
/// Proof size in KB
n: Linear<1, { 16 * 1024 }>,
) {
Expand All @@ -322,7 +328,7 @@ mod benchmarks {
message_nonces: setup.nonces(),
outbound_lane_data: None,
is_successful_dispatch_expected: false,
size: StorageProofSize::Minimal(n),
proof_params: UnverifiedStorageProofParams::from_db_size(n),
});

#[extrinsic_call]
Expand Down Expand Up @@ -368,7 +374,7 @@ mod benchmarks {
.collect(),
last_confirmed_nonce: 0,
},
size: StorageProofSize::Minimal(0),
proof_params: UnverifiedStorageProofParams::default(),
});

#[extrinsic_call]
Expand Down Expand Up @@ -420,7 +426,7 @@ mod benchmarks {
.collect(),
last_confirmed_nonce: 0,
},
size: StorageProofSize::Minimal(0),
proof_params: UnverifiedStorageProofParams::default(),
});

#[extrinsic_call]
Expand Down Expand Up @@ -477,7 +483,7 @@ mod benchmarks {
.collect(),
last_confirmed_nonce: 0,
},
size: StorageProofSize::Minimal(0),
proof_params: UnverifiedStorageProofParams::default(),
});

#[extrinsic_call]
Expand Down Expand Up @@ -511,7 +517,7 @@ mod benchmarks {
// * message requires all heavy checks done by dispatcher.
// #[benchmark(extra)]
#[benchmark]
fn receive_single_message_n_bytes_proof_with_dispatch(
fn receive_single_n_bytes_message_proof_with_dispatch(
/// Proof size in KB
n: Linear<1, { 16 * 1024 }>,
) {
Expand All @@ -522,7 +528,7 @@ mod benchmarks {
message_nonces: setup.nonces(),
outbound_lane_data: None,
is_successful_dispatch_expected: true,
size: StorageProofSize::Minimal(n),
proof_params: UnverifiedStorageProofParams::from_db_size(n),
});

#[extrinsic_call]
Expand Down
2 changes: 1 addition & 1 deletion bridges/modules/messages/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mod tests {
test_lane_id(),
1..=nonces_end,
outbound_lane_data,
bp_runtime::StorageProofSize::Minimal(0),
bp_runtime::UnverifiedStorageProofParams::default(),
generate_dummy_message,
encode_message,
encode_outbound_lane_data,
Expand Down
24 changes: 12 additions & 12 deletions bridges/modules/messages/src/tests/messages_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use bp_messages::{
MessagePayload, OutboundLaneData,
};
use bp_runtime::{
grow_storage_value, AccountIdOf, Chain, HashOf, HasherOf, RangeInclusiveExt, StorageProofSize,
UnverifiedStorageProof,
grow_storage_value, AccountIdOf, Chain, HashOf, HasherOf, RangeInclusiveExt,
UnverifiedStorageProof, UnverifiedStorageProofParams,
};
use codec::Encode;
use frame_support::sp_runtime::StateVersion;
Expand Down Expand Up @@ -52,7 +52,7 @@ pub fn prepare_messages_storage_proof<BridgedChain: Chain, ThisChain: ChainWithM
lane: LaneId,
message_nonces: RangeInclusive<MessageNonce>,
outbound_lane_data: Option<OutboundLaneData>,
size: StorageProofSize,
proof_params: UnverifiedStorageProofParams,
generate_message: impl Fn(MessageNonce) -> MessagePayload,
encode_message: impl Fn(MessageNonce, &MessagePayload) -> Option<Vec<u8>>,
encode_outbound_lane_data: impl Fn(&OutboundLaneData) -> Vec<u8>,
Expand All @@ -71,7 +71,7 @@ where
lane,
message_nonces,
outbound_lane_data,
size,
proof_params,
generate_message,
encode_message,
encode_outbound_lane_data,
Expand All @@ -86,7 +86,7 @@ where
lane,
message_nonces,
outbound_lane_data,
size,
proof_params,
generate_message,
encode_message,
encode_outbound_lane_data,
Expand All @@ -100,7 +100,7 @@ where
pub fn prepare_message_delivery_storage_proof<BridgedChain: Chain, ThisChain: ChainWithMessages>(
lane: LaneId,
inbound_lane_data: InboundLaneData<AccountIdOf<ThisChain>>,
size: StorageProofSize,
proof_params: UnverifiedStorageProofParams,
) -> (HashOf<BridgedChain>, UnverifiedStorageProof)
where
HashOf<BridgedChain>: Copy + Default,
Expand All @@ -110,12 +110,12 @@ where
BridgedChain,
ThisChain,
LayoutV0<HasherOf<BridgedChain>>,
>(lane, inbound_lane_data, size),
>(lane, inbound_lane_data, proof_params),
StateVersion::V1 => do_prepare_message_delivery_storage_proof::<
BridgedChain,
ThisChain,
LayoutV1<HasherOf<BridgedChain>>,
>(lane, inbound_lane_data, size),
>(lane, inbound_lane_data, proof_params),
}
}

Expand All @@ -127,7 +127,7 @@ fn do_prepare_messages_storage_proof<BridgedChain: Chain, ThisChain: ChainWithMe
lane: LaneId,
message_nonces: RangeInclusive<MessageNonce>,
outbound_lane_data: Option<OutboundLaneData>,
size: StorageProofSize,
proof_params: UnverifiedStorageProofParams,
generate_message: impl Fn(MessageNonce) -> MessagePayload,
encode_message: impl Fn(MessageNonce, &MessagePayload) -> Option<Vec<u8>>,
encode_outbound_lane_data: impl Fn(&OutboundLaneData) -> Vec<u8>,
Expand All @@ -152,7 +152,7 @@ where
let message_payload = match encode_message(nonce, &generate_message(nonce)) {
Some(message_payload) =>
if i == 0 {
grow_storage_value(message_payload, size)
grow_storage_value(message_payload, &proof_params)
} else {
message_payload
},
Expand Down Expand Up @@ -212,7 +212,7 @@ where
fn do_prepare_message_delivery_storage_proof<BridgedChain: Chain, ThisChain: ChainWithMessages, L>(
lane: LaneId,
inbound_lane_data: InboundLaneData<AccountIdOf<ThisChain>>,
size: StorageProofSize,
proof_params: UnverifiedStorageProofParams,
) -> (HashOf<BridgedChain>, UnverifiedStorageProof)
where
L: TrieConfiguration<Hash = HasherOf<BridgedChain>>,
Expand All @@ -225,7 +225,7 @@ where
let mut mdb = MemoryDB::default();
{
let mut trie = TrieDBMutBuilder::<L>::new(&mut mdb, &mut root).build();
let inbound_lane_data = grow_storage_value(inbound_lane_data.encode(), size);
let inbound_lane_data = grow_storage_value(inbound_lane_data.encode(), &proof_params);
trie.insert(&storage_key, &inbound_lane_data)
.map_err(|_| "TrieMut::insert has failed")
.expect("TrieMut::insert should not fail in benchmarks");
Expand Down
16 changes: 10 additions & 6 deletions bridges/modules/messages/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ use bp_messages::{
ChainWithMessages, DeliveredMessages, InboundLaneData, LaneId, LaneState, Message, MessageKey,
MessageNonce, OutboundLaneData, UnrewardedRelayer, UnrewardedRelayersState,
};
use bp_runtime::{messages::MessageDispatchResult, Chain, ChainId, Size, StorageProofSize};
use bp_runtime::{
messages::MessageDispatchResult, Chain, ChainId, Size, UnverifiedStorageProofParams,
};
use codec::{Decode, Encode};
use frame_support::{
derive_impl, parameter_types,
Expand Down Expand Up @@ -488,7 +490,7 @@ pub fn prepare_messages_proof(
lane,
nonces_start..=nonces_end,
outbound_lane_data,
StorageProofSize::Minimal(0),
UnverifiedStorageProofParams::default(),
|nonce| messages[(nonce - nonces_start) as usize].payload.clone(),
encode_all_messages,
encode_lane_data,
Expand Down Expand Up @@ -522,10 +524,12 @@ pub fn prepare_messages_delivery_proof(
inbound_lane_data: InboundLaneData<AccountId>,
) -> FromBridgedChainMessagesDeliveryProof<BridgedHeaderHash> {
// first - let's generate storage proof
let (storage_root, storage_proof) = prepare_message_delivery_storage_proof::<
BridgedChain,
ThisChain,
>(lane, inbound_lane_data, StorageProofSize::Minimal(0));
let (storage_root, storage_proof) =
prepare_message_delivery_storage_proof::<BridgedChain, ThisChain>(
lane,
inbound_lane_data,
UnverifiedStorageProofParams::default(),
);

// let's now insert bridged chain header into the storage
let bridged_header_hash = Default::default();
Expand Down
Loading

0 comments on commit 6006298

Please sign in to comment.