Skip to content

Commit

Permalink
Re-export static_assertions for macro
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Jul 24, 2024
1 parent f5fa5ec commit 1492ca9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions bridges/bin/runtime-common/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,25 @@ use frame_support::{storage::generator::StorageValue, traits::Get, weights::Weig
use frame_system::limits;
use pallet_bridge_messages::WeightInfoExt as _;

// Re-export to avoid include all dependencies everywhere.
#[doc(hidden)]
pub mod __private {
pub use bp_xcm_bridge_hub;
pub use static_assertions;
}

/// Macro that ensures that the runtime configuration and chain primitives crate are sharing
/// the same types (nonce, block number, hash, hasher, account id and header).
#[macro_export]
macro_rules! assert_chain_types(
( runtime: $r:path, this_chain: $this:path ) => {
{
use frame_system::{Config as SystemConfig, pallet_prelude::{BlockNumberFor, HeaderFor}};
use $crate::integrity::__private::static_assertions::assert_type_eq_all;

// if one of asserts fail, then either bridge isn't configured properly (or alternatively - non-standard
// configuration is used), or something has broke existing configuration (meaning that all bridged chains
// and relays will stop functioning)
use frame_system::{Config as SystemConfig, pallet_prelude::{BlockNumberFor, HeaderFor}};
use static_assertions::assert_type_eq_all;

assert_type_eq_all!(<$r as SystemConfig>::Nonce, bp_runtime::NonceOf<$this>);
assert_type_eq_all!(BlockNumberFor<$r>, bp_runtime::BlockNumberOf<$this>);
Expand All @@ -60,14 +68,15 @@ macro_rules! assert_bridge_messages_pallet_types(
bridged_chain: $bridged:path,
) => {
{
// if one of asserts fail, then either bridge isn't configured properly (or alternatively - non-standard
// configuration is used), or something has broke existing configuration (meaning that all bridged chains
// and relays will stop functioning)
use $crate::messages_xcm_extension::XcmAsPlainPayload;
use $crate::integrity::__private::static_assertions::assert_type_eq_all;
use bp_messages::ChainWithMessages;
use bp_runtime::Chain;
use pallet_bridge_messages::Config as MessagesConfig;
use static_assertions::assert_type_eq_all;

// if one of asserts fail, then either bridge isn't configured properly (or alternatively - non-standard
// configuration is used), or something has broke existing configuration (meaning that all bridged chains
// and relays will stop functioning)

assert_type_eq_all!(<$r as MessagesConfig<$i>>::ThisChain, $this);
assert_type_eq_all!(<$r as MessagesConfig<$i>>::BridgedChain, $bridged);
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 @@ -63,7 +63,7 @@ pub fn verify_messages_proof<T: Config<I>, I: 'static>(
let nonces_range = nonces_start..=nonces_end;

// receiving proofs where end < begin is ok (if proof includes outbound lane state)
let messages_in_the_proof = nonces_range.checked_len().unwrap_or(0);
let messages_in_the_proof = nonces_range.saturating_len();
if messages_in_the_proof != MessageNonce::from(messages_count) {
return Err(VerificationError::MessagesCountMismatch)
}
Expand Down
2 changes: 1 addition & 1 deletion bridges/modules/xcm-bridge-hub/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use crate::{Config, Pallet, LOG_TARGET};

use bp_messages::source_chain::MessagesBridge;
use bp_runtime::RangeInclusiveExt;
use bp_xcm_bridge_hub::XcmAsPlainPayload;
use bridge_runtime_common::messages_xcm_extension::{LocalXcmQueueManager, SenderAndLane};
use pallet_bridge_messages::{Config as BridgeMessagesConfig, Pallet as BridgeMessagesPallet};
Expand Down Expand Up @@ -132,6 +131,7 @@ impl HaulBlob for DummyHaulBlob {
mod tests {
use super::*;
use crate::mock::*;
use bp_runtime::RangeInclusiveExt;
use frame_support::assert_ok;
use xcm_executor::traits::export_xcm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ snowbridge-runtime-common = { workspace = true }
bridge-hub-common = { workspace = true }

[dev-dependencies]
static_assertions = { workspace = true, default-features = true }
bridge-hub-test-utils = { workspace = true, default-features = true }
bridge-runtime-common = { features = [
"integrity-test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ bridge-runtime-common = { workspace = true }
bridge-hub-common = { workspace = true }

[dev-dependencies]
static_assertions = { workspace = true, default-features = true }
bridge-hub-test-utils = { workspace = true, default-features = true }
bridge-runtime-common = { features = ["integrity-test"], workspace = true, default-features = true }
sp-keyring = { workspace = true, default-features = true }
Expand Down

0 comments on commit 1492ca9

Please sign in to comment.