Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clara/sno 645 #62

Draft
wants to merge 9 commits into
base: snowbridge
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions parachain-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn local_testnet_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
1000.into(),
1001.into(),
)
},
// Bootnodes
Expand All @@ -172,7 +172,7 @@ pub fn local_testnet_config() -> ChainSpec {
// Extensions
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: 1000,
para_id: 1001,
},
)
}
Expand Down
9 changes: 8 additions & 1 deletion parachain-template/pallets/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ scale-info = { version = "2.2.0", default-features = false, features = ["derive"
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" }

pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "master" }

[dev-dependencies]
serde = { version = "1.0.163" }
Expand All @@ -37,5 +41,8 @@ std = [
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"sp-std/std",
"pallet-xcm/std",
"xcm/std",
]
try-runtime = [ "frame-support/try-runtime" ]
try-runtime = [ "frame-support/try-runtime", "pallet-xcm/try-runtime" ]
37 changes: 36 additions & 1 deletion parachain-template/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ mod benchmarking;
pub mod pallet {
use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*};
use frame_system::pallet_prelude::*;
use sp_std::boxed::Box;
use xcm::{v3::prelude::*, VersionedMultiLocation, VersionedXcm};

/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config {
pub trait Config: frame_system::Config + pallet_xcm::Config {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
Expand All @@ -45,6 +47,8 @@ pub mod pallet {
/// Event documentation should end with an array that provides descriptive names for event
/// parameters. [something, who]
SomethingStored(u32, T::AccountId),
/// XCM message sent. \[to, message\]
Sent { from: T::AccountId, to: MultiLocation, message: Xcm<()> },
}

// Errors inform users that something went wrong.
Expand All @@ -54,6 +58,15 @@ pub mod pallet {
NoneValue,
/// Errors should have helpful documentation associated with them.
StorageOverflow,
/// The message and destination combination was not recognized as being
/// reachable.
Unreachable,
/// The message and destination was recognized as being reachable but
/// the operation could not be completed.
SendFailure,
/// The version of the `Versioned` value used is not able to be
/// interpreted.
BadVersion,
}

#[pallet::hooks]
Expand Down Expand Up @@ -102,5 +115,27 @@ pub mod pallet {
},
}
}

/// Send an XCM message as parachain sovereign.
#[pallet::call_index(2)]
#[pallet::weight(Weight::from_parts(100_000_000, 0))]
pub fn send_xcm(
origin: OriginFor<T>,
dest: Box<VersionedMultiLocation>,
message: Box<VersionedXcm<()>>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let dest = MultiLocation::try_from(*dest).map_err(|()| Error::<T>::BadVersion)?;
let message: Xcm<()> = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;

pallet_xcm::Pallet::<T>::send_xcm(Here, dest, message.clone()).map_err(
|e| match e {
SendError::Unroutable => Error::<T>::Unreachable,
_ => Error::<T>::SendFailure,
},
)?;
Self::deposit_event(Event::Sent { from: who, to: dest, message });
Ok(())
}
}
}
6 changes: 5 additions & 1 deletion parachains/pallets/bridge-transfer/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ impl<T: Config> Pallet<T> {
pub(crate) fn ensure_reachable_remote_destination(
remote_destination: MultiLocation,
) -> Result<ReachableDestination, Error<T>> {
log::info!(target: LOG_TARGET, "Checking destination");
let devolved = ensure_is_remote(T::UniversalLocation::get(), remote_destination)
.map_err(|_| Error::<T>::UnsupportedDestination)?;
.map_err(|e| {
log::error!(target: LOG_TARGET, "Is not global consenus: {:?}", e);
Error::<T>::UnsupportedDestination
})?;
let (remote_network, _) = devolved;

T::BridgedDestinationValidator::ensure_destination(remote_network, remote_destination)
Expand Down
4 changes: 2 additions & 2 deletions parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ pub mod bridging {
// The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets.
pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get()
.pushed_with_interior(
AccountKey20 {
network: None,
AccountKey20 {
network: None,
key: hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"),
}
).unwrap();
Expand Down
15 changes: 3 additions & 12 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ use snowbridge_inbound_queue::BenchmarkHelper;
use snowbridge_beacon_primitives::CompactExecutionHeader;
#[cfg(feature = "runtime-benchmarks")]
use sp_core::H256;
#[cfg(feature = "runtime-benchmarks")]
use xcm_builder::EnsureXcmOrigin;
#[cfg(feature = "runtime-benchmarks")]
use crate::xcm_config::LocalOriginToLocation;

use frame_support::{
construct_runtime,
Expand All @@ -73,7 +69,6 @@ use frame_system::{
EnsureRoot,
};

#[cfg(not(feature = "runtime-benchmarks"))]
use pallet_xcm::EnsureXcm;

pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
Expand All @@ -100,7 +95,7 @@ use crate::{
WithBridgeHubRococoMessageBridge,
},
constants::fee::WeightToFee,
xcm_config::XcmRouter,
xcm_config::{AllowSiblingsOnly, XcmRouter},
};
use bridge_runtime_common::{
messages::{source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter},
Expand Down Expand Up @@ -689,12 +684,8 @@ impl snowbridge_control::Config for Runtime {
type AgentHashedDescription = AgentHashedDescription;
type UniversalLocation = UniversalLocation;
type RelayLocation = RelayLocation;

#[cfg(feature = "runtime-benchmarks")]
type CreateAgentOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;

#[cfg(not(feature = "runtime-benchmarks"))]
type CreateAgentOrigin = EnsureXcm<Everything>;
type AgentOrigin = EnsureXcm<Everything>;
type ChannelOrigin = EnsureXcm<AllowSiblingsOnly>;
}

// 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 @@ -79,4 +79,49 @@ impl<T: frame_system::Config> snowbridge_control::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
}

/// Todo: update with benchmarked
fn create_channel() -> Weight {
// Proof Size summary in bytes:
// Measured: `84`
// Estimated: `3517`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
}

fn update_channel() -> Weight {
// Proof Size summary in bytes:
// Measured: `84`
// Estimated: `3517`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
}

fn set_operating_mode() -> Weight {
// Proof Size summary in bytes:
// Measured: `84`
// Estimated: `3517`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
}

fn transfer_native_from_agent() -> Weight {
// Proof Size summary in bytes:
// Measured: `84`
// Estimated: `3517`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use xcm_executor::{
traits::{ExportXcm, WithOriginFilter},
XcmExecutor,
};
use xcm_executor::traits::{FeeManager, FeeReason};

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
Expand Down Expand Up @@ -217,12 +218,9 @@ impl Contains<RuntimeCall> for SafeCallFilter {
| snowbridge_inbound_queue::Call::set_gateway { .. }
| snowbridge_inbound_queue::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumOutboundQueue(
snowbridge_outbound_queue::Call::set_owner { .. }
| snowbridge_outbound_queue::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumControl(
snowbridge_control::Call::upgrade { .. }
| snowbridge_control::Call::create_agent { .. },
)
snowbridge_outbound_queue::Call::set_owner { .. } |
snowbridge_outbound_queue::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumControl(..)
)
}
}
Expand Down Expand Up @@ -255,6 +253,17 @@ pub type Barrier = TrailingSetTopicAsId<
>;

pub struct XcmConfig;

impl FeeManager for XcmConfig {
fn is_waived(origin: Option<&MultiLocation>, r: FeeReason) -> bool {
todo!()
}

fn handle_fee(fee: MultiAssets) {
todo!()
}
}

impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
Expand Down Expand Up @@ -411,3 +420,14 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter {
}
}
}

/// [`Contains`] implementation that allows multiLocation from sibling chains only
pub struct AllowSiblingsOnly;
impl Contains<MultiLocation> for AllowSiblingsOnly {
fn contains(l: &MultiLocation) -> bool {
match l {
MultiLocation { parents: 1, interior: X1(Parachain(_)) } => true,
_ => false,
}
}
}
Loading