Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
asset hub rococo
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Oct 20, 2023
1 parent 53fd05a commit 4a15f7d
Show file tree
Hide file tree
Showing 12 changed files with 506 additions and 271 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

21 changes: 12 additions & 9 deletions cumulus/pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ pub struct ConfigData {
impl Default for ConfigData {
fn default() -> Self {
Self {
// For beacon checkpoint to work require a bigger default
max_individual: Weight::from_parts(
10u64 * WEIGHT_REF_TIME_PER_MILLIS, // 10 ms of execution time maximum by default
DEFAULT_POV_SIZE, // 64 KB of proof size by default
20u64 * 10u64 * WEIGHT_REF_TIME_PER_MILLIS, // 200 ms of execution time maximum by default
10u64 * DEFAULT_POV_SIZE, // 640 KB of proof size by default
),
}
}
Expand Down Expand Up @@ -230,7 +231,7 @@ pub mod pallet {
if *messages_processed >= MAX_MESSAGES_PER_BLOCK {
// Exceeded block message limit - put the remaining messages back and bail
Pages::<T>::insert(page_index.begin_used, &page[i..]);
return used
return used;
}
*messages_processed += 1;
match Self::try_service_message(limit.saturating_sub(used), sent_at, &data[..])
Expand All @@ -239,7 +240,7 @@ pub mod pallet {
Err(..) => {
// Too much weight needed - put the remaining messages back and bail
Pages::<T>::insert(page_index.begin_used, &page[i..]);
return used
return used;
},
}
}
Expand Down Expand Up @@ -288,8 +289,9 @@ pub mod pallet {
Weight::zero(),
);
match outcome {
Outcome::Error(XcmError::WeightLimitReached(required_weight)) =>
Err(ServiceMessageError { message_hash, message_id, required_weight }),
Outcome::Error(XcmError::WeightLimitReached(required_weight)) => {
Err(ServiceMessageError { message_hash, message_id, required_weight })
},
outcome => {
let weight_used = outcome.weight_used();
Self::deposit_event(Event::ExecutedDownward {
Expand Down Expand Up @@ -370,7 +372,7 @@ pub mod pallet {
// Not needed for control flow, but only to ensure that the
// compiler understands that we won't attempt to re-use `data`
// later.
continue
continue;
} else {
// not overweight. stop executing inline and enqueue normally
// from here on.
Expand Down Expand Up @@ -517,8 +519,9 @@ mod tests {
) -> Outcome {
let message = prepared.0;
let o = match (message.0.len(), &message.0.first()) {
(1, Some(Transact { require_weight_at_most, .. })) =>
Outcome::Complete(*require_weight_at_most),
(1, Some(Transact { require_weight_at_most, .. })) => {
Outcome::Complete(*require_weight_at_most)
},
// use 1000 to decide that it's not supported.
_ => Outcome::Incomplete(Weight::from_parts(1, 1), XcmError::Unimplemented),
};
Expand Down
6 changes: 3 additions & 3 deletions cumulus/parachain-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn development_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
1000.into(),
1001.into(),
)
},
Vec::new(),
Expand All @@ -112,7 +112,7 @@ pub fn development_config() -> ChainSpec {
None,
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: 1000,
para_id: 1001,
},
)
}
Expand Down Expand Up @@ -174,7 +174,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
7 changes: 7 additions & 0 deletions cumulus/parachain-template/pallets/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ serde = { version = "1.0.188" }
sp-core = { path = "../../../../substrate/primitives/core", default-features = false}
sp-io = { path = "../../../../substrate/primitives/io", default-features = false}
sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false}
sp-std = { path = "../../../../substrate/primitives/std", default-features = false}

pallet-xcm = { path = "../../../../polkadot/xcm/pallet-xcm", default-features = false}
xcm = { package = "staging-xcm", path = "../../../../polkadot/xcm", default-features = false}

[features]
default = [ "std" ]
Expand All @@ -45,6 +49,9 @@ std = [
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"pallet-xcm/std",
"xcm/std",
]
try-runtime = [
"frame-support/try-runtime",
Expand Down
37 changes: 36 additions & 1 deletion cumulus/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(())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ bridge-hub-rococo-runtime = { path = "../../../../../parachains/runtimes/bridge-
# Local
xcm-emulator = { path = "../../../../../xcm/xcm-emulator", default-features = false}
integration-tests-common = { path = "../../common", default-features = false}

# Snowbridge
snowbridge-control = { path = "../../../../../../../parachain/pallets/control" }
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
// limitations under the License.

mod example;
mod snowbridge;
mod teleport;
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::*;
use integration_tests_common::BridgeHubRococoPallet;
use snowbridge_control;

#[test]
fn create_agent() {
let sudo_origin = <Rococo as Chain>::RuntimeOrigin::root();
let destination = Rococo::child_location_of(BridgeHubRococo::para_id()).into();

let remote_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: WeightLimit::Unlimited, check_origin: None },
DescendOrigin(X1(Parachain(1000))),
Transact {
require_weight_at_most: 3000000000.into(),
origin_kind: OriginKind::Xcm,
call: vec![51, 1].into(),
},
]));

//Rococo Global Consensus
// Send XCM message from Relay Chain to Bridge Hub source Parachain
Rococo::execute_with(|| {
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send(
sudo_origin,
bx!(destination),
bx!(remote_xcm),
));

type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;

assert_expected_events!(
Rococo,
vec![
RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
]
);
});

BridgeHubRococo::execute_with(|| {
type RuntimeEvent = <BridgeHubRococo as Chain>::RuntimeEvent;

assert_expected_events!(
BridgeHubRococo,
vec![
RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward {
outcome: Outcome::Complete(_),
..
}) => {},
RuntimeEvent::EthereumControl(snowbridge_control::Event::CreateAgent {
..
}) => {},
]
);
});
}

#[test]
fn create_channel() {
let sudo_origin = <Rococo as Chain>::RuntimeOrigin::root();
let destination = Rococo::child_location_of(BridgeHubRococo::para_id()).into();

let remote_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: WeightLimit::Unlimited, check_origin: None },
DescendOrigin(X1(Parachain(1000))),
Transact {
require_weight_at_most: 8000000000.into(),
origin_kind: OriginKind::Xcm,
call: vec![51, 2].into(),
},
]));

//BridgeHubRococo::execute_with(|| { // TODO Create agent in storage
// <BridgeHubRococo as BridgeHubRococoPallet>::EthereumControl::create_agent(sudo_origin);
//});

//Rococo Global Consensus
// Send XCM message from Relay Chain to Bridge Hub source Parachain
Rococo::execute_with(|| {
assert_ok!(<Rococo as RococoPallet>::XcmPallet::send(
sudo_origin,
bx!(destination),
bx!(remote_xcm),
));

type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;

assert_expected_events!(
Rococo,
vec![
RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
]
);
});

BridgeHubRococo::execute_with(|| {
type RuntimeEvent = <BridgeHubRococo as Chain>::RuntimeEvent;

assert_expected_events!(
BridgeHubRococo,
vec![
RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward {
outcome: Outcome::Complete(_),
..
}) => {},
RuntimeEvent::EthereumControl(snowbridge_control::Event::CreateChannel {
..
}) => {},
]
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ decl_test_parachains! {
pallets = {
PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm,
Balances: bridge_hub_rococo_runtime::Balances,
EthereumControl: bridge_hub_rococo_runtime::EthereumControl,
}
},
// AssetHubRococo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pallet-collator-selection = { path = "../../../../pallets/collator-selection", d
parachain-info = { path = "../../../pallets/parachain-info", default-features = false }
parachains-common = { path = "../../../common", default-features = false }
assets-common = { path = "../common", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../parachain/primitives/router", default-features = false }

# Bridges
pallet-xcm-bridge-hub-router = { path = "../../../../../bridges/modules/xcm-bridge-hub-router", default-features = false }
Expand Down Expand Up @@ -223,6 +224,7 @@ std = [
"rococo-runtime-constants/std",
"rococo-runtime/std",
"scale-info/std",
"snowbridge-router-primitives/std",
"sp-api/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
Expand Down
Loading

0 comments on commit 4a15f7d

Please sign in to comment.