Skip to content

Commit

Permalink
Merge branch 'vincent/outbound-fees' into ron/oak-30
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Oct 5, 2023
2 parents 5eeec0b + 28e108b commit 210976f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

47 changes: 29 additions & 18 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,35 @@ pub mod xcm_config;

use constants::currency::*;
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use snowbridge_beacon_primitives::{Fork, ForkVersions};
use snowbridge_router_primitives::outbound::AgentHashedDescription;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, H160, OpaqueMetadata};
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Keccak256},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};

use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
#[cfg(feature = "runtime-benchmarks")]
pub use snowbridge_ethereum_beacon_client::ExecutionHeaderBuffer;
use snowbridge_beacon_primitives::CompactExecutionHeader;
#[cfg(feature = "runtime-benchmarks")]
use snowbridge_core::RingBufferMap;
#[cfg(feature = "runtime-benchmarks")]
use snowbridge_inbound_queue::BenchmarkHelper;
pub use snowbridge_ethereum_beacon_client::ExecutionHeaderBuffer;
#[cfg(feature = "runtime-benchmarks")]
use snowbridge_beacon_primitives::CompactExecutionHeader;
use snowbridge_inbound_queue::BenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
use sp_core::H256;
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
traits::{ConstBool, ConstU32, ConstU64, ConstU8, Everything},
traits::{ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Everything},
weights::{ConstantMultiplier, Weight},
PalletId,
};
Expand All @@ -74,7 +72,10 @@ use pallet_xcm::EnsureXcm;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm::v3::NetworkId::{self, Rococo};
use xcm_config::{EthereumGatewayAddress, RelayLocation, UniversalLocation, XcmConfig, XcmOriginToTransactDispatchOrigin};
use xcm_config::{
EthereumGatewayAddress, RelayLocation, UniversalLocation, XcmConfig,
XcmOriginToTransactDispatchOrigin,
};

use bp_parachains::SingleParaStoredHeaderDataBuilder;
use bp_runtime::HeaderId;
Expand All @@ -83,6 +84,7 @@ use bp_runtime::HeaderId;
pub use sp_runtime::BuildStorage;

use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use sp_runtime::traits::AccountIdConversion;
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};

use crate::{
Expand All @@ -95,7 +97,7 @@ use crate::{
WithBridgeHubRococoMessageBridge,
},
constants::fee::WeightToFee,
xcm_config::{AllowSiblingsOnly, XcmRouter},
xcm_config::XcmRouter,
};
use bridge_runtime_common::{
messages::{source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter},
Expand All @@ -105,6 +107,7 @@ use parachains_common::{
impls::DealWithFees, opaque, AccountId, Balance, BlockNumber, Hash, Header, Index, Signature,
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
use snowbridge_beacon_primitives::{Fork, ForkVersions};
use xcm_executor::XcmExecutor;

/// The address format for describing accounts.
Expand Down Expand Up @@ -619,6 +622,10 @@ impl snowbridge_outbound_queue::Config for Runtime {
type MessageQueue = MessageQueue;
type MaxMessagePayloadSize = MaxMessagePayloadSize;
type MaxMessagesPerBlock = MaxMessagesPerBlock;
type GasMeter = snowbridge_core::outbound::ConstantGasMeter;
type Balance = Balance;
type Fee = ConstU128<10>;
type Reward = ConstU128<10>;
type WeightInfo = ();
}

Expand Down Expand Up @@ -679,20 +686,24 @@ parameter_types! {
// TODO: placeholder value - choose a real one
pub const MaxUpgradeDataSize: u32 = 1024;
pub const RelayNetwork: NetworkId = Rococo;
pub TreasuryAccount: AccountId = PalletId(*b"py/trsry").into_account_truncating();
}

impl snowbridge_control::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OwnParaId = ParachainInfo;
type OutboundQueue = EthereumOutboundQueue;
type MessageHasher = BlakeTwo256;
type WeightInfo = weights::snowbridge_control::WeightInfo<Runtime>;
type MaxUpgradeDataSize = MaxUpgradeDataSize;
type AgentHashedDescription = AgentHashedDescription;
type AgentIdOf = xcm_config::AgentIdOf;
type UniversalLocation = UniversalLocation;
type RelayLocation = RelayLocation;
type AgentOrigin = EnsureXcm<Everything>;
type ChannelOrigin = EnsureXcm<AllowSiblingsOnly>;
type AgentOrigin = EnsureXcm<xcm_config::AllowSiblingsChildrenOnly>;
type ChannelOrigin = EnsureXcm<xcm_config::AllowSiblingsOnly>;
type TreasuryAccount = TreasuryAccount;
type SovereignAccountOf = xcm_config::SovereignAccountOf;
type Fee = ConstU128<100000000000>; //should be enough to cover the existentialDeposit
type Token = Balances;
type WeightInfo = weights::snowbridge_control::WeightInfo<Runtime>;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ impl<T: frame_system::Config> snowbridge_control::WeightInfo for WeightInfo<T> {
/// Storage: MessageQueue Pages (r:0 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
/// The range of component `x` is `[0, 1023]`.
fn upgrade(x: u32, ) -> Weight {
fn upgrade() -> Weight {
// Proof Size summary in bytes:
// Measured: `80`
// Estimated: `3517`
// Minimum execution time: 29_000_000 picoseconds.
Weight::from_parts(30_740_411, 0)
.saturating_add(Weight::from_parts(0, 3517))
// Standard Error: 66
.saturating_add(Weight::from_parts(8_805, 0).saturating_mul(x.into()))
.saturating_add(Weight::from_parts(8_805, 0).saturating_mul(256))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(3))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use pallet_xcm::XcmPassthrough;
use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom};
use polkadot_parachain::primitives::Sibling;
use snowbridge_outbound_queue;
use snowbridge_router_primitives::outbound::{AgentHashedDescription, EthereumBlobExporter};
use sp_core::Get;
use snowbridge_router_primitives::outbound::EthereumBlobExporter;
use sp_core::{H256, Get};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand All @@ -45,6 +45,8 @@ use xcm_builder::{
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_builder::{HashedDescription, DescribeFamily, DescribeAllTerminal};

use xcm_executor::{
traits::{ExportXcm, WithOriginFilter},
XcmExecutor,
Expand Down Expand Up @@ -200,7 +202,7 @@ impl Contains<RuntimeCall> for SafeCallFilter {
) | RuntimeCall::Session(pallet_session::Call::purge_keys { .. })
| RuntimeCall::XcmpQueue(..)
| RuntimeCall::DmpQueue(..)
| RuntimeCall::Utility(pallet_utility::Call::as_derivative { .. })
| RuntimeCall::Utility(..)
| RuntimeCall::BridgeRococoGrandpa(pallet_bridge_grandpa::Call::<
Runtime,
BridgeGrandpaRococoInstance,
Expand All @@ -216,10 +218,8 @@ impl Contains<RuntimeCall> for SafeCallFilter {
) | RuntimeCall::EthereumInboundQueue(
snowbridge_inbound_queue::Call::set_owner { .. }
| snowbridge_inbound_queue::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumOutboundQueue(
snowbridge_outbound_queue::Call::set_owner { .. } |
snowbridge_outbound_queue::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumControl(..)
) | RuntimeCall::EthereumOutboundQueue(..)
| RuntimeCall::EthereumControl(..)
)
}
}
Expand Down Expand Up @@ -360,11 +360,22 @@ impl cumulus_pallet_xcm::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
}

pub type AgentIdOf = HashedDescription<H256, DescribeFamily<DescribeAllTerminal>>;

/// Ethereum control pallet: Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
/// when determining sovereign accounts for asset transacting
pub type SovereignAccountOf = (
// Relay chain, sibling parachains, and local children
LocationToAccountId,
// Other nested consensus systems on sibling parachains
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
);

pub type SnowbridgeExporter = EthereumBlobExporter<
UniversalLocation,
EthereumGatewayLocation,
snowbridge_outbound_queue::Pallet<Runtime>,
AgentHashedDescription
AgentIdOf,
>;

/// Hacky switch implementation, because we have just one runtime for Rococo and Wococo BridgeHub, so it means we have just one XcmConfig
Expand Down Expand Up @@ -435,3 +446,15 @@ impl Contains<MultiLocation> for AllowSiblingsOnly {
}
}
}

/// [`Contains`] implementation that allows multiLocation from sibling chains and children of sibling chains.
pub struct AllowSiblingsChildrenOnly;
impl Contains<MultiLocation> for AllowSiblingsChildrenOnly {
fn contains(l: &MultiLocation) -> bool {
match l.split_first_interior() {
(MultiLocation { parents: 1, .. }, Some(Parachain(_))) => true,
_ => false,

}
}
}

0 comments on commit 210976f

Please sign in to comment.