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

Polkadot sdk update #2

Closed
wants to merge 29 commits into from
Closed
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
293 changes: 293 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 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
4 changes: 2 additions & 2 deletions cumulus/parachain-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn local_testnet_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
1000.into(),
1001.into(),
)
},
// Bootnodes
Expand All @@ -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 @@ -19,6 +19,10 @@ scale-info = { version = "2.2.0", default-features = false, features = ["derive"
frame-benchmarking = { path = "../../../../substrate/frame/benchmarking", default-features = false, optional = true}
frame-support = { path = "../../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../../substrate/frame/system", 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}

[dev-dependencies]
serde = { version = "1.0.188" }
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 @@ -31,3 +31,6 @@ bp-messages = { path = "../../../../../../bridges/primitives/messages", default-
# 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,3 +14,4 @@
// limitations under the License.

mod example;
mod snowbridge;
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 snowbridge_control;
use integration_tests_common::BridgeHubRococoPallet;

#[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 @@ -325,6 +325,7 @@ decl_test_parachains! {
pallets = {
PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm,
Balances: bridge_hub_rococo_runtime::Balances,
EthereumControl: bridge_hub_rococo_runtime::EthereumControl,
}
},
// AssetHubRococo (aka Rockmine/Rockmine2) mirrors AssetHubKusama
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pallet-xcm-bridge-hub-router = { path = "../../../../../bridges/modules/xcm-brid
bp-asset-hub-kusama = { path = "../../../../../bridges/primitives/chain-asset-hub-kusama", default-features = false }
bp-asset-hub-polkadot = { path = "../../../../../bridges/primitives/chain-asset-hub-polkadot", default-features = false }
bp-bridge-hub-kusama = { path = "../../../../../bridges/primitives/chain-bridge-hub-kusama", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../parachain/primitives/router", default-features = false }

[dev-dependencies]
asset-test-utils = { path = "../test-utils" }
Expand Down Expand Up @@ -216,6 +217,7 @@ std = [
"polkadot-core-primitives/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
"snowbridge-router-primitives/std",
"scale-info/std",
"sp-api/std",
"sp-block-builder/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type AssetIdParameter = MultiLocationForAssetId;
type Currency = Balances;
type CreateOrigin = ForeignCreators<
(FromSiblingParachain<parachain_info::Pallet<Runtime>>,),
(FromSiblingParachain<parachain_info::Pallet<Runtime>>,
snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus<
xcm_config::bridging::EthereumGatewayLocation,
>,
),
ForeignCreatorsSovereignAccountOf,
AccountId,
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use parachains_common::{
xcm_config::{AllowUnpaidTransactsFrom, AssetFeeAsExistentialDepositMultiplier},
};
use polkadot_parachain_primitives::primitives::Sibling;
use snowbridge_router_primitives::inbound::GlobalConsensusEthereumAccountConvertsFor;
use sp_runtime::traits::ConvertInto;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -86,6 +87,9 @@ pub type LocationToAccountId = (
// Different global consensus parachain sovereign account.
// (Used for over-bridge transfers and reserve processing)
GlobalConsensusParachainConvertsFor<UniversalLocation, AccountId>,
// Ethereum contract sovereign account.
// (Used to get convert ethereum contract locations to sovereign account)
GlobalConsensusEthereumAccountConvertsFor<AccountId>,
);

/// Means for transacting the native currency on this chain.
Expand Down Expand Up @@ -641,6 +645,7 @@ pub type ForeignCreatorsSovereignAccountOf = (
SiblingParachainConvertsVia<Sibling, AccountId>,
AccountId32Aliases<RelayNetwork, AccountId>,
ParentIsPreset<AccountId>,
GlobalConsensusEthereumAccountConvertsFor<AccountId>,
);

/// Simple conversion of `u32` into an `AssetId` for use in benchmarking.
Expand Down Expand Up @@ -687,7 +692,7 @@ pub mod bridging {
use sp_std::collections::btree_set::BTreeSet;

parameter_types! {
pub BridgeHubKusamaParaId: u32 = 1002;
pub BridgeHubKusamaParaId: u32 = 1013;
pub BridgeHubKusama: MultiLocation = MultiLocation::new(1, X1(Parachain(BridgeHubKusamaParaId::get())));
pub BridgeHubKusamaWithBridgeHubPolkadotInstance: MultiLocation = MultiLocation::new(
1,
Expand All @@ -700,6 +705,19 @@ pub mod bridging {
pub AssetHubPolkadot: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(PolkadotNetwork::get()), Parachain(bp_asset_hub_polkadot::ASSET_HUB_POLKADOT_PARACHAIN_ID)));
pub DotLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(PolkadotNetwork::get())));

pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); // TODO: Maybe registry address belongs here

pub const EthereumGatewayAddress: [u8; 20] = hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39");
// 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: EthereumGatewayAddress::get(),
}
).unwrap();

/// Router expects payment with this `AssetId`.
/// (`AssetId` has to be aligned with `BridgeTable`)
pub XcmBridgeHubRouterFeeAssetId: AssetId = KsmLocation::get().into();
Expand All @@ -721,7 +739,15 @@ pub mod bridging {
XcmBridgeHubRouterFeeAssetId::get(),
bp_asset_hub_kusama::BridgeHubKusamaBaseFeeInDots::get(),
).into())
),
(
EthereumNetwork::get(),
LocationFilter::default()
.add_equals(EthereumLocation::get().interior.split_global().expect("invalid configuration for Ethereum").1),
BridgeHubKusama::get(),
None
)
// TODO Add Ethereum here
];

/// Set up trusted bridged reserve locations.
Expand All @@ -734,7 +760,17 @@ pub mod bridging {
// allow receive DOT
.add_equals(DotLocation::get())
// and nothing else
)
),
(
EthereumLocation::get(),
LocationFilter::default()
.add_starts_with(EthereumGatewayLocation::get())
),
(
EthereumGatewayLocation::get(),
LocationFilter::default()
.add_starts_with(EthereumGatewayLocation::get())
),
];

/// Allowed reserve transfer assets per destination.
Expand All @@ -753,7 +789,8 @@ pub mod bridging {
/// Universal aliases
pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter(
sp_std::vec![
(BridgeHubKusamaWithBridgeHubPolkadotInstance::get(), GlobalConsensus(PolkadotNetwork::get()))
(BridgeHubKusamaWithBridgeHubPolkadotInstance::get(), GlobalConsensus(PolkadotNetwork::get())),
(BridgeHubKusama::get(), GlobalConsensus(EthereumNetwork::get())),
]
);

Expand Down
Loading
Loading