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

Changes needed to deploy the Rococo Demo #59

Draft
wants to merge 15 commits into
base: snowbridge
Choose a base branch
from
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.

2 changes: 1 addition & 1 deletion bridges/primitives/chain-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub type AccountSigner = MultiSigner;
pub type Address = MultiAddress<AccountId, ()>;

/// Identifier of BridgeHubRococo in the Rococo relay chain.
pub const BRIDGE_HUB_ROCOCO_PARACHAIN_ID: u32 = 1013;
pub const BRIDGE_HUB_ROCOCO_PARACHAIN_ID: u32 = 3016;

/// Name of the With-BridgeHubRococo messages pallet instance that is deployed at bridged chains.
pub const WITH_BRIDGE_HUB_ROCOCO_MESSAGES_PALLET_NAME: &str = "BridgeRococoMessages";
Expand Down
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(())
}
}
}
8 changes: 4 additions & 4 deletions parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

parameter_types! {
pub const KsmLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::Kusama);
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::Rococo);
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorMultiLocation =
X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into()));
Expand Down Expand Up @@ -527,7 +527,7 @@ pub mod bridging {
use xcm_builder::UnpaidRemoteExporter;

parameter_types! {
pub BridgeHubKusamaParaId: u32 = 1013;
pub BridgeHubKusamaParaId: u32 = 3016;
pub BridgeHubKusama: MultiLocation = MultiLocation::new(1, X1(Parachain(BridgeHubKusamaParaId::get())));
pub const PolkadotNetwork: NetworkId = NetworkId::Polkadot;
pub AssetHubPolkadot: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(PolkadotNetwork::get()), Parachain(1000)));
Expand All @@ -536,15 +536,15 @@ pub mod bridging {
pub DotLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(PolkadotNetwork::get())));

// Network and location for the local Ethereum testnet.
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 5 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

// 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,
key: hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"),
key: hex_literal::hex!("6eE23257bc91792eDFdCC2490A7B18502fDA01b4"),
}
).unwrap();

Expand Down
17 changes: 4 additions & 13 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 @@ -166,7 +161,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("bridge-hub-rococo"),
impl_name: create_runtime_str!("bridge-hub-rococo"),
authoring_version: 1,
spec_version: 9420,
spec_version: 9421,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
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 @@ -59,15 +59,15 @@ parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;

// Network and location for the local Ethereum testnet.
pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 5 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

// 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,
key: hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"),
key: hex_literal::hex!("6eE23257bc91792eDFdCC2490A7B18502fDA01b4"),
}
).unwrap();
}
Expand Down Expand Up @@ -183,6 +183,7 @@ impl Contains<RuntimeCall> for SafeCallFilter {
| RuntimeCall::System(
frame_system::Call::set_heap_pages { .. }
| frame_system::Call::set_code { .. }
| frame_system::Call::set_storage { .. }
| frame_system::Call::set_code_without_checks { .. }
| frame_system::Call::kill_prefix { .. },
) | RuntimeCall::ParachainSystem(..)
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 @@ -411,3 +409,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,
}
}
}
2 changes: 1 addition & 1 deletion polkadot-parachain/src/chain_spec/asset_hubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec {
pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 2.into());
properties.insert("tokenSymbol".into(), "KSM".into());
properties.insert("tokenSymbol".into(), "ROC".into());
properties.insert("tokenDecimals".into(), 12.into());

AssetHubKusamaChainSpec::from_genesis(
Expand Down