Skip to content

Commit

Permalink
sno-692 (#69)
Browse files Browse the repository at this point in the history
* Upgrade for Control pallet

* Update dependency

* Allow utility call through xcm

* Add SovereignAccountOf

* More refactor

* Add FeeProvider config

* Allow xcm to config base_fee

* Remove unused

* Move config to outbound queue

* Update dependency

* Make RegisterCallIndex runtime const

* Use Treasury account to collect fees

* Remove unused const

* Add configs

* Clean dependencies

* Update dependencies

* Add estimate rpc

* Add runtime api

* runtime api for compute_fee_reward

* Use TreasuryAccount more specific

* Cleanup

* Update rococo runtime

* update

* Update weights

* Fix for smoke test

* Update rococo runtime

* Update for inbound MessageConverter

* update benchmarking logic in cumulus

* Chore

* Some polish

* Update for recent change

* Add CreateAssetExecutionFee as runtime config

* Fix format

---------

Co-authored-by: Vincent Geddes <vincent.geddes@hey.com>
  • Loading branch information
yrong and vgeddes authored Oct 18, 2023
1 parent 9feea84 commit 25267ed
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 56 deletions.
15 changes: 7 additions & 8 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ use sp_version::RuntimeVersion;

use frame_support::{
construct_runtime,
parameter_types,
dispatch::DispatchClass,
parameter_types,
traits::{ConstBool, ConstU32, ConstU64, ConstU8, Everything},
weights::{ConstantMultiplier, Weight},
PalletId,
Expand All @@ -72,15 +72,11 @@ use pallet_xcm::EnsureXcm;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm::VersionedMultiLocation;
use xcm_config::{
EthereumGatewayAddress, XcmConfig,
XcmOriginToTransactDispatchOrigin,
};
use xcm_config::{EthereumGatewayAddress, XcmConfig, XcmOriginToTransactDispatchOrigin};

use crate::xcm_config::RelayLocation;
use bp_parachains::SingleParaStoredHeaderDataBuilder;
use bp_runtime::HeaderId;
use snowbridge_router_primitives::inbound::MessageToXcm;

#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
Expand Down Expand Up @@ -111,6 +107,7 @@ use parachains_common::{
};
use snowbridge_beacon_primitives::{Fork, ForkVersions};
use snowbridge_core::AgentId;
use snowbridge_router_primitives::inbound::MessageToXcm;
use xcm_executor::XcmExecutor;

/// The address format for describing accounts.
Expand Down Expand Up @@ -589,6 +586,8 @@ parameter_types! {
pub const Reward: u128 = 10;
pub const GatewayAddress: H160 = H160(EthereumGatewayAddress::get());
pub const CreateAssetCall: [u8;2] = [53, 0];
pub const CreateAssetExecutionFee: u128 = 2_000_000_000;
pub const SendTokenExecutionFee: u128 = 1_000_000_000;
}

#[cfg(feature = "runtime-benchmarks")]
Expand All @@ -611,10 +610,10 @@ impl snowbridge_inbound_queue::Config for Runtime {
type GatewayAddress = GatewayAddress;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
type MessageConverter = MessageToXcm<CreateAssetCall>;
type MessageConverter =
MessageToXcm<CreateAssetCall, CreateAssetExecutionFee, SendTokenExecutionFee>;
}


pub const GWEI: u128 = 1_000_000_000;

parameter_types! {
Expand Down
98 changes: 50 additions & 48 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom
use polkadot_parachain::primitives::Sibling;
use snowbridge_outbound_queue;
use snowbridge_router_primitives::outbound::EthereumBlobExporter;
use sp_core::{H256, Get};
use sp_core::{Get, H256};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin,
IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal,
DescribeFamily, EnsureXcmOrigin, HashedDescription, IsConcrete, ParentAsSuperuser,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};
use xcm_builder::{HashedDescription, DescribeFamily, DescribeAllTerminal};

use xcm_executor::{
traits::{ExportXcm, WithOriginFilter},
Expand Down Expand Up @@ -182,44 +181,44 @@ impl Contains<RuntimeCall> for SafeCallFilter {

matches!(
call,
RuntimeCall::PolkadotXcm(pallet_xcm::Call::force_xcm_version { .. })
| RuntimeCall::System(
frame_system::Call::set_heap_pages { .. }
| frame_system::Call::set_code { .. }
| frame_system::Call::set_code_without_checks { .. }
| frame_system::Call::kill_prefix { .. },
) | RuntimeCall::ParachainSystem(..)
| RuntimeCall::Timestamp(..)
| RuntimeCall::Balances(..)
| RuntimeCall::CollatorSelection(
pallet_collator_selection::Call::set_desired_candidates { .. }
| pallet_collator_selection::Call::set_candidacy_bond { .. }
| pallet_collator_selection::Call::register_as_candidate { .. }
| pallet_collator_selection::Call::leave_intent { .. }
| pallet_collator_selection::Call::set_invulnerables { .. }
| pallet_collator_selection::Call::add_invulnerable { .. }
| pallet_collator_selection::Call::remove_invulnerable { .. },
) | RuntimeCall::Session(pallet_session::Call::purge_keys { .. })
| RuntimeCall::XcmpQueue(..)
| RuntimeCall::DmpQueue(..)
| RuntimeCall::Utility(..)
| RuntimeCall::BridgeRococoGrandpa(pallet_bridge_grandpa::Call::<
RuntimeCall::PolkadotXcm(pallet_xcm::Call::force_xcm_version { .. }) |
RuntimeCall::System(
frame_system::Call::set_heap_pages { .. } |
frame_system::Call::set_code { .. } |
frame_system::Call::set_code_without_checks { .. } |
frame_system::Call::kill_prefix { .. },
) | RuntimeCall::ParachainSystem(..) |
RuntimeCall::Timestamp(..) |
RuntimeCall::Balances(..) |
RuntimeCall::CollatorSelection(
pallet_collator_selection::Call::set_desired_candidates { .. } |
pallet_collator_selection::Call::set_candidacy_bond { .. } |
pallet_collator_selection::Call::register_as_candidate { .. } |
pallet_collator_selection::Call::leave_intent { .. } |
pallet_collator_selection::Call::set_invulnerables { .. } |
pallet_collator_selection::Call::add_invulnerable { .. } |
pallet_collator_selection::Call::remove_invulnerable { .. },
) | RuntimeCall::Session(pallet_session::Call::purge_keys { .. }) |
RuntimeCall::XcmpQueue(..) |
RuntimeCall::DmpQueue(..) |
RuntimeCall::Utility(..) |
RuntimeCall::BridgeRococoGrandpa(pallet_bridge_grandpa::Call::<
Runtime,
BridgeGrandpaRococoInstance,
>::initialize { .. })
| RuntimeCall::BridgeWococoGrandpa(pallet_bridge_grandpa::Call::<
>::initialize { .. }) |
RuntimeCall::BridgeWococoGrandpa(pallet_bridge_grandpa::Call::<
Runtime,
BridgeGrandpaWococoInstance,
>::initialize { .. })
| RuntimeCall::EthereumBeaconClient(
snowbridge_ethereum_beacon_client::Call::force_checkpoint { .. }
| snowbridge_ethereum_beacon_client::Call::set_owner { .. }
| snowbridge_ethereum_beacon_client::Call::set_operating_mode { .. },
>::initialize { .. }) |
RuntimeCall::EthereumBeaconClient(
snowbridge_ethereum_beacon_client::Call::force_checkpoint { .. } |
snowbridge_ethereum_beacon_client::Call::set_owner { .. } |
snowbridge_ethereum_beacon_client::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumInboundQueue(
snowbridge_inbound_queue::Call::set_owner { .. }
| snowbridge_inbound_queue::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumOutboundQueue(..)
| RuntimeCall::EthereumControl(..)
snowbridge_inbound_queue::Call::set_owner { .. } |
snowbridge_inbound_queue::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumOutboundQueue(..) |
RuntimeCall::EthereumControl(..)
)
}
}
Expand Down Expand Up @@ -302,12 +301,17 @@ pub type XcmRouter = WithUniqueTopic<(

#[cfg(feature = "runtime-benchmarks")]
pub(crate) mod benchmark_helper {
use crate::xcm_config::{MultiAssets, MultiLocation, SendError, SendResult, SendXcm, Xcm, XcmHash};
use crate::xcm_config::{
MultiAssets, MultiLocation, SendError, SendResult, SendXcm, Xcm, XcmHash,
};

pub struct DoNothingRouter;
impl SendXcm for DoNothingRouter {
type Ticket = ();
fn validate(_dest: &mut Option<MultiLocation>, _msg: &mut Option<Xcm<()>>) -> SendResult<()> {
fn validate(
_dest: &mut Option<MultiLocation>,
_msg: &mut Option<Xcm<()>>,
) -> SendResult<()> {
Ok(((), MultiAssets::new()))
}
fn deliver(_: ()) -> Result<XcmHash, SendError> {
Expand Down Expand Up @@ -399,16 +403,15 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter {
message,
)
.map(|result| ((Wococo, result.0), result.1)),
location if location == EthereumNetwork::get() && relay == NetworkId::Rococo => {
location if location == EthereumNetwork::get() && relay == NetworkId::Rococo =>
SnowbridgeExporter::validate(
network,
channel,
universal_source,
destination,
message,
)
.map(|result| ((EthereumNetwork::get(), (result.0, XcmHash::default())), result.1))
},
.map(|result| ((EthereumNetwork::get(), (result.0, XcmHash::default())), result.1)),
_ => unimplemented!("Unsupported network: {:?}", network),
}
}
Expand All @@ -419,9 +422,8 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter {
match network {
Rococo => ToBridgeHubRococoHaulBlobExporter::deliver(ticket),
Wococo => ToBridgeHubWococoHaulBlobExporter::deliver(ticket),
location if location == EthereumNetwork::get() && relay == NetworkId::Rococo => {
SnowbridgeExporter::deliver(ticket.0)
},
location if location == EthereumNetwork::get() && relay == NetworkId::Rococo =>
SnowbridgeExporter::deliver(ticket.0),
_ => unimplemented!("Unsupported network: {:?}", network),
}
}
Expand Down

0 comments on commit 25267ed

Please sign in to comment.