Skip to content

Commit

Permalink
move snowbridge config to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Mar 22, 2024
1 parent b4ac868 commit e8bb09c
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use asset_hub_polkadot_runtime::xcm_config::bridging::to_ethereum::{
};
use bp_bridge_hub_polkadot::snowbridge::CreateAssetCall;
use bridge_hub_polkadot_runtime::{
bridge_to_ethereum_config::EthereumGatewayAddress,
EthereumBeaconClient, EthereumInboundQueue, Runtime, RuntimeOrigin,
bridge_to_ethereum_config::EthereumGatewayAddress, EthereumBeaconClient, EthereumInboundQueue,
Runtime, RuntimeOrigin,
};
use codec::{Decode, Encode};
use emulated_integration_tests_common::xcm_emulator::ConvertLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use crate::{xcm_config::UniversalLocation, Runtime};
use crate::{
xcm_config, xcm_config::UniversalLocation, Balances, EthereumInboundQueue,
EthereumOutboundQueue, EthereumSystem, MessageQueue, Runtime, RuntimeEvent, TransactionByteFee,
TreasuryAccount,
};
pub use bp_bridge_hub_kusama::snowbridge::EthereumNetwork;
use frame_support::parameter_types;
use bp_bridge_hub_kusama::snowbridge::{CreateAssetCall, InboundQueuePalletInstance, Parameters};
use frame_support::{parameter_types, weights::ConstantMultiplier};
use pallet_xcm::EnsureXcm;
use parachains_common::{AccountId, Balance};
use snowbridge_beacon_primitives::{Fork, ForkVersions};
use snowbridge_router_primitives::outbound::EthereumBlobExporter;
use snowbridge_core::AllowSiblingsOnly;
use snowbridge_router_primitives::{inbound::MessageToXcm, outbound::EthereumBlobExporter};
use sp_core::H160;
use sp_runtime::traits::{ConstU32, ConstU8, Keccak256};
use system_parachains_constants::polkadot::fee::WeightToFee;

/// Exports message to the Ethereum Gateway contract.
pub type SnowbridgeExporter = EthereumBlobExporter<
Expand All @@ -32,7 +42,48 @@ pub type SnowbridgeExporter = EthereumBlobExporter<
parameter_types! {
// The gateway address is set by governance.
pub storage EthereumGatewayAddress: H160 = H160::zero();
pub const MaxExecutionHeadersToKeep: u32 = 8192 * 20;
}

impl snowbridge_pallet_inbound_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Verifier = snowbridge_pallet_ethereum_client::Pallet<Runtime>;
type Token = Balances;
#[cfg(not(feature = "runtime-benchmarks"))]
type XcmSender = xcm_config::XcmRouter;
#[cfg(feature = "runtime-benchmarks")]
type XcmSender = benchmark_helpers::DoNothingRouter;
type ChannelLookup = EthereumSystem;
type GatewayAddress = EthereumGatewayAddress;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
type MessageConverter = MessageToXcm<
CreateAssetCall,
bp_asset_hub_kusama::CreateForeignAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
>;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type MaxMessageSize = ConstU32<2048>;
type WeightInfo = crate::weights::snowbridge_pallet_inbound_queue::WeightInfo<Runtime>;
type PricingParameters = EthereumSystem;
type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;
}

impl snowbridge_pallet_outbound_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Hashing = Keccak256;
type MessageQueue = MessageQueue;
type Decimals = ConstU8<12>;
type MaxMessagePayloadSize = ConstU32<2048>;
type MaxMessagesPerBlock = ConstU32<32>;
type GasMeter = snowbridge_core::outbound::ConstantGasMeter;
type Balance = Balance;
type WeightToFee = WeightToFee;
type WeightInfo = crate::weights::snowbridge_pallet_outbound_queue::WeightInfo<Runtime>;
type PricingParameters = EthereumSystem;
type Channels = EthereumSystem;
}

#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))]
Expand Down Expand Up @@ -87,9 +138,37 @@ parameter_types! {
};
}

parameter_types! {
pub const MaxExecutionHeadersToKeep: u32 = 8192 * 20;
}

impl snowbridge_pallet_ethereum_client::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ForkVersions = ChainForkVersions;
type MaxExecutionHeadersToKeep = MaxExecutionHeadersToKeep;
type WeightInfo = crate::weights::snowbridge_pallet_ethereum_client::WeightInfo<Runtime>;
}

impl snowbridge_pallet_system::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OutboundQueue = EthereumOutboundQueue;
type SiblingOrigin = EnsureXcm<AllowSiblingsOnly>;
type AgentIdOf = snowbridge_core::AgentIdOf;
type TreasuryAccount = TreasuryAccount;
type Token = Balances;
type WeightInfo = crate::weights::snowbridge_pallet_system::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type DefaultPricingParameters = Parameters;
type InboundDeliveryCost = EthereumInboundQueue;
}

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmark_helpers {
use crate::{bridge_to_ethereum_config::EthereumGatewayAddress, EthereumBeaconClient, Runtime, RuntimeOrigin};
use crate::{
bridge_to_ethereum_config::EthereumGatewayAddress, EthereumBeaconClient, Runtime,
RuntimeOrigin,
};
use codec::Encode;
use hex_literal::hex;
use snowbridge_beacon_primitives::CompactExecutionHeader;
Expand Down Expand Up @@ -126,3 +205,16 @@ pub mod benchmark_helpers {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn bridge_hub_inbound_queue_pallet_index_is_correct() {
assert_eq!(
InboundQueuePalletInstance::get(),
<EthereumInboundQueue as frame_support::traits::PalletInfoAccess>::index() as u8
);
}
}
79 changes: 3 additions & 76 deletions system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@ pub mod bridge_to_polkadot_config;
mod weights;
pub mod xcm_config;

use bp_bridge_hub_kusama::snowbridge::{CreateAssetCall, InboundQueuePalletInstance, Parameters};
use bridge_hub_common::message_queue::{
AggregateMessageOrigin, NarrowOriginToSibling, ParaIdToSibling,
};
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::ParaId;
use snowbridge_core::{outbound::Message, AgentId, AllowSiblingsOnly};
use snowbridge_router_primitives::inbound::MessageToXcm;
use snowbridge_core::{outbound::Message, AgentId};

use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Keccak256},
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
Expand Down Expand Up @@ -498,70 +497,6 @@ impl pallet_utility::Config for Runtime {
type WeightInfo = weights::pallet_utility::WeightInfo<Runtime>;
}

// Ethereum Bridge pallets
impl snowbridge_pallet_inbound_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Verifier = snowbridge_pallet_ethereum_client::Pallet<Runtime>;
type Token = Balances;
#[cfg(not(feature = "runtime-benchmarks"))]
type XcmSender = xcm_config::XcmRouter;
#[cfg(feature = "runtime-benchmarks")]
type XcmSender = bridge_to_ethereum_config::benchmark_helpers::DoNothingRouter;
type ChannelLookup = EthereumSystem;
type GatewayAddress = bridge_to_ethereum_config::EthereumGatewayAddress;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
type MessageConverter = MessageToXcm<
CreateAssetCall,
bp_asset_hub_kusama::CreateForeignAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
>;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type MaxMessageSize = ConstU32<2048>;
type WeightInfo = weights::snowbridge_pallet_inbound_queue::WeightInfo<Runtime>;
type PricingParameters = EthereumSystem;
type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;
}

impl snowbridge_pallet_outbound_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Hashing = Keccak256;
type MessageQueue = MessageQueue;
type Decimals = ConstU8<12>;
type MaxMessagePayloadSize = ConstU32<2048>;
type MaxMessagesPerBlock = ConstU32<32>;
type GasMeter = snowbridge_core::outbound::ConstantGasMeter;
type Balance = Balance;
type WeightToFee = WeightToFee;
type WeightInfo = weights::snowbridge_pallet_outbound_queue::WeightInfo<Runtime>;
type PricingParameters = EthereumSystem;
type Channels = EthereumSystem;
}

impl snowbridge_pallet_ethereum_client::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ForkVersions = bridge_to_ethereum_config::ChainForkVersions;
type MaxExecutionHeadersToKeep = bridge_to_ethereum_config::MaxExecutionHeadersToKeep;
type WeightInfo = weights::snowbridge_pallet_ethereum_client::WeightInfo<Runtime>;
}

impl snowbridge_pallet_system::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OutboundQueue = EthereumOutboundQueue;
type SiblingOrigin = EnsureXcm<AllowSiblingsOnly>;
type AgentIdOf = snowbridge_core::AgentIdOf;
type TreasuryAccount = TreasuryAccount;
type Token = Balances;
type WeightInfo = weights::snowbridge_pallet_system::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type DefaultPricingParameters = Parameters;
type InboundDeliveryCost = EthereumInboundQueue;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime
Expand Down Expand Up @@ -1262,14 +1197,6 @@ cumulus_pallet_parachain_system::register_validate_block! {
mod tests {
use super::*;

#[test]
fn bridge_hub_inbound_queue_pallet_index_is_correct() {
assert_eq!(
InboundQueuePalletInstance::get(),
<EthereumInboundQueue as frame_support::traits::PalletInfoAccess>::index() as u8
);
}

#[test]
fn test_transasction_byte_fee_is_one_tenth_of_relay() {
let relay_tbf = kusama_runtime_constants::fee::TRANSACTION_BYTE_FEE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use crate::{xcm_config::UniversalLocation, Runtime};
use crate::{
xcm_config, xcm_config::UniversalLocation, Balances, EthereumInboundQueue,
EthereumOutboundQueue, EthereumSystem, MessageQueue, Runtime, RuntimeEvent, TransactionByteFee,
TreasuryAccount,
};
pub use bp_bridge_hub_polkadot::snowbridge::EthereumNetwork;
use frame_support::parameter_types;
use bp_bridge_hub_polkadot::snowbridge::{CreateAssetCall, InboundQueuePalletInstance, Parameters};
use frame_support::{parameter_types, weights::ConstantMultiplier};
use pallet_xcm::EnsureXcm;
use parachains_common::{AccountId, Balance};
use snowbridge_beacon_primitives::{Fork, ForkVersions};
use snowbridge_router_primitives::outbound::EthereumBlobExporter;
use snowbridge_core::AllowSiblingsOnly;
use snowbridge_router_primitives::{inbound::MessageToXcm, outbound::EthereumBlobExporter};
use sp_core::H160;
use sp_runtime::traits::{ConstU32, ConstU8, Keccak256};
use system_parachains_constants::polkadot::fee::WeightToFee;

/// Exports message to the Ethereum Gateway contract.
pub type SnowbridgeExporter = EthereumBlobExporter<
Expand All @@ -32,7 +42,48 @@ pub type SnowbridgeExporter = EthereumBlobExporter<
parameter_types! {
// The gateway address is set by governance.
pub storage EthereumGatewayAddress: H160 = H160::zero();
pub const MaxExecutionHeadersToKeep: u32 = 8192 * 20;
}

impl snowbridge_pallet_inbound_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Verifier = snowbridge_pallet_ethereum_client::Pallet<Runtime>;
type Token = Balances;
#[cfg(not(feature = "runtime-benchmarks"))]
type XcmSender = xcm_config::XcmRouter;
#[cfg(feature = "runtime-benchmarks")]
type XcmSender = benchmark_helpers::DoNothingRouter;
type ChannelLookup = EthereumSystem;
type GatewayAddress = EthereumGatewayAddress;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
type MessageConverter = MessageToXcm<
CreateAssetCall,
bp_asset_hub_polkadot::CreateForeignAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
>;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type MaxMessageSize = ConstU32<2048>;
type WeightInfo = crate::weights::snowbridge_pallet_inbound_queue::WeightInfo<Runtime>;
type PricingParameters = EthereumSystem;
type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;
}

impl snowbridge_pallet_outbound_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Hashing = Keccak256;
type MessageQueue = MessageQueue;
type Decimals = ConstU8<10>;
type MaxMessagePayloadSize = ConstU32<2048>;
type MaxMessagesPerBlock = ConstU32<32>;
type GasMeter = snowbridge_core::outbound::ConstantGasMeter;
type Balance = Balance;
type WeightToFee = WeightToFee;
type WeightInfo = crate::weights::snowbridge_pallet_outbound_queue::WeightInfo<Runtime>;
type PricingParameters = EthereumSystem;
type Channels = EthereumSystem;
}

#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))]
Expand Down Expand Up @@ -87,9 +138,37 @@ parameter_types! {
};
}

parameter_types! {
pub const MaxExecutionHeadersToKeep: u32 = 8192 * 20;
}

impl snowbridge_pallet_ethereum_client::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ForkVersions = ChainForkVersions;
type MaxExecutionHeadersToKeep = MaxExecutionHeadersToKeep;
type WeightInfo = crate::weights::snowbridge_pallet_ethereum_client::WeightInfo<Runtime>;
}

impl snowbridge_pallet_system::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OutboundQueue = EthereumOutboundQueue;
type SiblingOrigin = EnsureXcm<AllowSiblingsOnly>;
type AgentIdOf = snowbridge_core::AgentIdOf;
type TreasuryAccount = TreasuryAccount;
type Token = Balances;
type WeightInfo = crate::weights::snowbridge_pallet_system::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type DefaultPricingParameters = Parameters;
type InboundDeliveryCost = EthereumInboundQueue;
}

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmark_helpers {
use crate::{bridge_to_ethereum_config::EthereumGatewayAddress, EthereumBeaconClient, Runtime, RuntimeOrigin};
use crate::{
bridge_to_ethereum_config::EthereumGatewayAddress, EthereumBeaconClient, Runtime,
RuntimeOrigin,
};
use codec::Encode;
use hex_literal::hex;
use snowbridge_beacon_primitives::CompactExecutionHeader;
Expand Down Expand Up @@ -126,3 +205,16 @@ pub mod benchmark_helpers {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn bridge_hub_inbound_queue_pallet_index_is_correct() {
assert_eq!(
InboundQueuePalletInstance::get(),
<EthereumInboundQueue as frame_support::traits::PalletInfoAccess>::index() as u8
);
}
}
Loading

0 comments on commit e8bb09c

Please sign in to comment.