Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

XCM v3: Context & ID hash #4756

Merged
merged 81 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
fd5f8c2
send_xcm returns message hash
gavofyork Jan 20, 2022
1f5fdf4
cargo fmt
KiChjang Jan 21, 2022
1f2d3dc
Create topic register and instructions
KiChjang Jan 21, 2022
0194c91
Fix weights
KiChjang Jan 21, 2022
260025c
Use tabs
KiChjang Jan 21, 2022
e5ceb4c
Sketch out XcmContext
KiChjang Jan 21, 2022
870ac09
Merge branch 'gav-xcm-v3' into gav-xcm-v3-provide-hash
KiChjang Jan 24, 2022
0a19ace
Fix doc test
KiChjang Jan 25, 2022
25c55eb
Add the XCM context as a parameter to executor trait fns
KiChjang Jan 25, 2022
73af5b2
Fixes
KiChjang Jan 26, 2022
7973233
Add XcmContext parameter
KiChjang Jan 27, 2022
bc9cdca
Revert adding context as an arg to SendXcm trait methods
KiChjang Jan 29, 2022
ce34e1a
Revert adding context argument to ConvertOrigin trait methods
KiChjang Jan 29, 2022
9624125
cargo fmt
KiChjang Jan 29, 2022
10f1978
Do not change the API of XcmExecutor::execute
KiChjang Jan 29, 2022
fa0d0d0
Fixes
KiChjang Jan 29, 2022
b4661ea
Fixes
KiChjang Jan 29, 2022
eee33ac
Fixes
KiChjang Feb 2, 2022
46f598c
Merge branch 'gav-xcm-v3' into gav-xcm-v3-provide-hash
KiChjang Feb 2, 2022
149735b
Fixes
KiChjang Feb 2, 2022
e4be71e
Remove convenience method
KiChjang Feb 3, 2022
5b523b0
Fixes
KiChjang Feb 4, 2022
2a1f0e2
Fixes
KiChjang Feb 4, 2022
f431c55
cargo fmt
KiChjang Feb 4, 2022
d6fedf9
Fixes
KiChjang Feb 4, 2022
b044e79
Add benchmarks for XCM topic instructions
KiChjang Feb 5, 2022
163a456
cargo run --quiet --profile=production --features=runtime-benchmarks…
Feb 5, 2022
d897f92
Merge remote-tracking branch 'origin/gav-xcm-v3' into gav-xcm-v3-prov…
KiChjang Feb 19, 2022
62f4193
Remove context argument on FilterAssetLocation
KiChjang Feb 19, 2022
820232c
Merge branch 'gav-xcm-v3' into gav-xcm-v3-provide-hash
KiChjang Feb 19, 2022
166cac1
Fixes
KiChjang Feb 22, 2022
95a5855
Remove unused import
KiChjang Feb 22, 2022
c9b1ca7
Fixes
KiChjang Feb 22, 2022
8f41fbe
Fixes
KiChjang Feb 22, 2022
fd28e0e
Fixes
KiChjang Feb 22, 2022
5356680
Merge remote-tracking branch 'origin/gav-xcm-v3' into gav-xcm-v3-prov…
KiChjang Feb 22, 2022
d5819b3
Accept XCM hash parameter in ExecuteXcm trait methods
KiChjang Feb 22, 2022
03720b5
cargo fmt
KiChjang Feb 22, 2022
487e4e2
Properly enable sp-io/std
KiChjang Feb 22, 2022
85a151b
Fixes
KiChjang Feb 22, 2022
e83175a
default-features = false
KiChjang Feb 22, 2022
be3b4ff
Fixes
KiChjang Feb 22, 2022
3ba62db
Fixes
KiChjang Feb 22, 2022
33a4308
Fixes
KiChjang Feb 22, 2022
0de1a00
Make XcmContext optional in withdraw_asset
KiChjang Feb 23, 2022
f4751e2
Fixes
KiChjang Feb 23, 2022
f4cd038
Fixes
KiChjang Feb 23, 2022
8bf4f6a
Fixes
KiChjang Feb 23, 2022
4b62f97
Modify tests to check for the correct XCM hash
KiChjang Feb 24, 2022
8702ebc
Small refactor
KiChjang Feb 24, 2022
0cde431
cargo fmt
KiChjang Feb 24, 2022
2ca0117
Check for expected hash in xcm-builder unit tests
KiChjang Feb 24, 2022
3df1279
Add doc comment for the optionality of the XCM context in withdraw_asset
KiChjang Mar 1, 2022
3f36459
Merge branch 'gav-xcm-v3' into gav-xcm-v3-provide-hash
KiChjang Mar 2, 2022
a549286
Update xcm/src/v3/traits.rs
gavofyork Mar 5, 2022
18bb864
Update xcm/src/v3/traits.rs
gavofyork Mar 5, 2022
3c1117f
Store XcmContext and avoid rebuilding
gavofyork Mar 5, 2022
c554b97
Use ref for XcmContext
gavofyork Mar 5, 2022
292f8d4
Formatting
gavofyork Mar 5, 2022
4612154
Fix incorrect hash CC @KiChjang
gavofyork Mar 7, 2022
053c510
Refactor and make clear fake hashes
gavofyork Mar 7, 2022
9e463e1
Fixes
gavofyork Mar 7, 2022
63f7b60
Fixes
gavofyork Mar 7, 2022
e1933fa
Fixes
gavofyork Mar 7, 2022
c9d0e32
Fix broken hashing
gavofyork Mar 7, 2022
c3d1ddf
Docs
gavofyork Mar 7, 2022
a4e3656
Fixes
gavofyork Mar 7, 2022
788004d
Fixes
gavofyork Mar 7, 2022
c247f63
Fixes
gavofyork Mar 7, 2022
28899e4
Formatting
gavofyork Mar 7, 2022
8eab788
Merge branch 'gav-xcm-v3' into gav-xcm-v3-provide-hash
gavofyork Mar 7, 2022
f50e5d6
Fixes
gavofyork Mar 7, 2022
cd8b8dd
Fixes
gavofyork Mar 7, 2022
43f9ced
Fixes
gavofyork Mar 7, 2022
426370c
Remove unknowable hash
gavofyork Mar 7, 2022
84b3f98
Formatting
gavofyork Mar 7, 2022
145a876
Merge remote-tracking branch 'origin/gav-xcm-v3' into gav-xcm-v3-prov…
gavofyork Mar 8, 2022
46bda63
Use message hash for greater identifiability
gavofyork Mar 8, 2022
d1876fb
Formatting
gavofyork Mar 8, 2022
c7143c9
Fixes
gavofyork Mar 8, 2022
a2b1686
Formatting
gavofyork Mar 8, 2022
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
1 change: 1 addition & 0 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions runtime/common/src/xcm_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ pub struct ChildParachainRouter<T, W>(PhantomData<(T, W)>);
impl<T: configuration::Config + dmp::Config, W: xcm::WrapVersion> SendXcm
for ChildParachainRouter<T, W>
{
fn send_xcm(dest: impl Into<MultiLocation>, msg: Xcm<()>) -> SendResult {
fn send_xcm(dest: impl Into<MultiLocation>, msg: Xcm<()>, _context: XcmContext) -> SendResult {
let dest = dest.into();
match dest {
MultiLocation { parents: 0, interior: X1(Parachain(id)) } => {
// Downward message passing.
let versioned_xcm =
W::wrap_version(&dest, msg).map_err(|()| SendError::DestinationUnsupported)?;
let config = <configuration::Pallet<T>>::config();
let encoded = versioned_xcm.encode();
let hash = sp_io::hashing::blake2_256(&encoded[..]);
<dmp::Pallet<T>>::queue_downward_message(
&config,
id.into(),
versioned_xcm.encode(),
)
.map_err(Into::<SendError>::into)?;
Ok(())
Ok(hash)
},
dest => Err(SendError::CannotReachDestination(dest, msg)),
}
Expand Down
7 changes: 4 additions & 3 deletions runtime/test-runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use frame_support::{parameter_types, traits::Everything, weights::Weight};
use xcm::latest::prelude::*;
use parity_scale_codec::Encode;
use xcm::prelude::*;
use xcm_builder::{AllowUnpaidExecutionFrom, FixedWeightBounds, SignedToAccountId32};
use xcm_executor::{
traits::{InvertLocation, TransactAsset, WeightTrader},
Expand All @@ -37,8 +38,8 @@ pub type LocalOriginToLocation = (

pub struct DoNothingRouter;
impl SendXcm for DoNothingRouter {
fn send_xcm(_dest: impl Into<MultiLocation>, _msg: Xcm<()>) -> SendResult {
Ok(())
fn send_xcm(_dest: impl Into<MultiLocation>, msg: Xcm<()>, _context: XcmContext) -> SendResult {
Ok(VersionedXcm::from(msg).using_encoded(sp_io::hashing::blake2_256))
}
}

Expand Down
6 changes: 6 additions & 0 deletions runtime/westend/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,10 @@ impl<Call> XcmWeightInfo<Call> for WestendXcmWeight<Call> {
fn clear_transact_status() -> Weight {
XcmGeneric::<Runtime>::clear_transact_status()
}
fn set_topic(_topic: &[u8; 32]) -> Weight {
XcmGeneric::<Runtime>::set_topic()
}
fn clear_topic() -> Weight {
XcmGeneric::<Runtime>::clear_topic()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,10 @@ impl<T: frame_system::Config> WeightInfo<T> {
pub(crate) fn clear_transact_status() -> Weight {
(5_100_000 as Weight)
}
pub(crate) fn set_topic() -> Weight {
(1_000 as Weight)
}
pub(crate) fn clear_topic() -> Weight {
(1_000 as Weight)
}
}
3 changes: 3 additions & 0 deletions xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ derivative = {version = "2.2.0", default-features = false, features = [ "use_cor
log = { version = "0.4.14", default-features = false }
xcm-procedural = { path = "procedural" }

[dev-dependencies]
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }

[features]
default = ["std"]
wasm-api = []
Expand Down
5 changes: 3 additions & 2 deletions xcm/pallet-xcm-benchmarks/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

use crate::*;
use frame_support::{parameter_types, weights::Weight};
use xcm::VersionedXcm;
use xcm_executor::traits::FilterAssetLocation;

// An xcm sender/receiver akin to > /dev/null
pub struct DevNull;
impl xcm::opaque::latest::SendXcm for DevNull {
fn send_xcm(_: impl Into<MultiLocation>, _: Xcm<()>) -> SendResult {
Ok(())
fn send_xcm(_: impl Into<MultiLocation>, msg: Xcm<()>) -> SendResult {
Ok(VersionedXcm::from(msg).using_encoded(sp_io::hashing::blake2_256))
}
}

Expand Down
8 changes: 4 additions & 4 deletions xcm/pallet-xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ scale-info = { version = "1.0", default-features = false, features = ["derive"]
serde = { version = "1.0.132", optional = true, features = ["derive"] }
log = { version = "0.4.14", default-features = false }

sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, 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-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }

xcm = { path = "..", default-features = false }
xcm-executor = { path = "../xcm-executor", default-features = false }

[dev-dependencies]
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" }
polkadot-runtime-parachains = { path = "../../runtime/parachains" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
xcm-builder = { path = "../xcm-builder" }
polkadot-parachain = { path = "../../parachain" }

Expand Down
68 changes: 47 additions & 21 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod tests;
use codec::{Decode, Encode, EncodeLike};
use frame_support::traits::{Contains, EnsureOrigin, Get, OriginTrait};
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::{
traits::{BadOrigin, Saturating},
RuntimeDebug,
Expand Down Expand Up @@ -1046,8 +1047,10 @@ pub mod pallet {
let response = Response::Version(xcm_version);
let message =
Xcm(vec![QueryResponse { query_id, response, max_weight, querier: None }]);
let event = match T::XcmRouter::send_xcm(new_key.clone(), message) {
Ok(()) => {
let message_hash = message.using_encoded(blake2_256);
let context = XcmContext::with_message_hash(message_hash);
let event = match T::XcmRouter::send_xcm(new_key.clone(), message, context) {
Ok(_) => {
let value = (query_id, max_weight, xcm_version);
VersionNotifyTargets::<T>::insert(XCM_VERSION, key, value);
Event::VersionChangeNotified(new_key, xcm_version)
Expand Down Expand Up @@ -1097,17 +1100,21 @@ pub mod pallet {
max_weight,
querier: None,
}]);
let event = match T::XcmRouter::send_xcm(new_key.clone(), message) {
Ok(()) => {
VersionNotifyTargets::<T>::insert(
XCM_VERSION,
versioned_key,
(query_id, max_weight, xcm_version),
);
Event::VersionChangeNotified(new_key, xcm_version)
},
Err(e) => Event::NotifyTargetSendFail(new_key, query_id, e.into()),
};
let message_hash = message.using_encoded(blake2_256);
let context = XcmContext::with_message_hash(message_hash);
let event =
match T::XcmRouter::send_xcm(new_key.clone(), message, context) {
Ok(_) => {
VersionNotifyTargets::<T>::insert(
XCM_VERSION,
versioned_key,
(query_id, max_weight, xcm_version),
);
Event::VersionChangeNotified(new_key, xcm_version)
},
Err(e) =>
Event::NotifyTargetSendFail(new_key, query_id, e.into()),
};
Self::deposit_event(event);
weight_used.saturating_accrue(todo_vnt_notify_migrate_weight);
}
Expand All @@ -1133,7 +1140,10 @@ pub mod pallet {
});
// TODO #3735: Correct weight.
let instruction = SubscribeVersion { query_id, max_response_weight: 0 };
T::XcmRouter::send_xcm(dest, Xcm(vec![instruction]))?;
let message = Xcm(vec![instruction]);
let message_hash = message.using_encoded(blake2_256);
let context = XcmContext::with_message_hash(message_hash);
T::XcmRouter::send_xcm(dest, message, context)?;
VersionNotifiers::<T>::insert(XCM_VERSION, &versioned_dest, query_id);
let query_status =
QueryStatus::VersionNotifier { origin: versioned_dest, is_active: false };
Expand All @@ -1147,7 +1157,10 @@ pub mod pallet {
let versioned_dest = LatestVersionedMultiLocation(&dest);
let query_id = VersionNotifiers::<T>::take(XCM_VERSION, versioned_dest)
.ok_or(XcmError::InvalidLocation)?;
T::XcmRouter::send_xcm(dest.clone(), Xcm(vec![UnsubscribeVersion]))?;
let message = Xcm(vec![UnsubscribeVersion]);
let message_hash = message.using_encoded(blake2_256);
let context = XcmContext::with_message_hash(message_hash);
T::XcmRouter::send_xcm(dest.clone(), message, context)?;
Queries::<T>::remove(query_id);
Ok(())
}
Expand All @@ -1158,14 +1171,16 @@ pub mod pallet {
interior: impl Into<Junctions>,
dest: impl Into<MultiLocation>,
mut message: Xcm<()>,
) -> Result<(), SendError> {
) -> SendResult {
let interior = interior.into();
let dest = dest.into();
if interior != Junctions::Here {
message.0.insert(0, DescendOrigin(interior))
};
log::trace!(target: "xcm::send_xcm", "dest: {:?}, message: {:?}", &dest, &message);
T::XcmRouter::send_xcm(dest, message)
let message_hash = message.using_encoded(blake2_256);
let context = XcmContext::with_message_hash(message_hash);
T::XcmRouter::send_xcm(dest, message, context)
}

pub fn check_account() -> T::AccountId {
Expand Down Expand Up @@ -1354,15 +1369,23 @@ pub mod pallet {
///
/// If the `location` has an ongoing notification and when this function is called, then an
/// error should be returned.
fn start(dest: &MultiLocation, query_id: QueryId, max_weight: u64) -> XcmResult {
fn start(
dest: &MultiLocation,
query_id: QueryId,
max_weight: u64,
_context: XcmContext,
) -> XcmResult {
let versioned_dest = LatestVersionedMultiLocation(dest);
let already = VersionNotifyTargets::<T>::contains_key(XCM_VERSION, versioned_dest);
ensure!(!already, XcmError::InvalidLocation);

let xcm_version = T::AdvertisedXcmVersion::get();
let response = Response::Version(xcm_version);
let instruction = QueryResponse { query_id, response, max_weight, querier: None };
T::XcmRouter::send_xcm(dest.clone(), Xcm(vec![instruction]))?;
let message = Xcm(vec![instruction]);
let message_hash = message.using_encoded(blake2_256);
let context = XcmContext::with_message_hash(message_hash);
T::XcmRouter::send_xcm(dest.clone(), message, context)?;

let value = (query_id, max_weight, xcm_version);
VersionNotifyTargets::<T>::insert(XCM_VERSION, versioned_dest, value);
Expand All @@ -1371,7 +1394,7 @@ pub mod pallet {

/// Stop notifying `location` should the XCM change. This is a no-op if there was never a
/// subscription.
fn stop(dest: &MultiLocation) -> XcmResult {
fn stop(dest: &MultiLocation, _context: XcmContext) -> XcmResult {
VersionNotifyTargets::<T>::remove(XCM_VERSION, LatestVersionedMultiLocation(dest));
Ok(())
}
Expand All @@ -1384,7 +1407,7 @@ pub mod pallet {
}

impl<T: Config> DropAssets for Pallet<T> {
fn drop_assets(origin: &MultiLocation, assets: Assets) -> Weight {
fn drop_assets(origin: &MultiLocation, assets: Assets, _context: XcmContext) -> Weight {
if assets.is_empty() {
return 0
}
Expand All @@ -1402,6 +1425,7 @@ pub mod pallet {
origin: &MultiLocation,
ticket: &MultiLocation,
assets: &MultiAssets,
_context: XcmContext,
) -> bool {
let mut versioned = VersionedMultiAssets::from(assets.clone());
match (ticket.parents, &ticket.interior) {
Expand Down Expand Up @@ -1449,6 +1473,7 @@ pub mod pallet {
querier: Option<&MultiLocation>,
response: Response,
max_weight: Weight,
_context: XcmContext,
) -> Weight {
match (response, Queries::<T>::get(query_id)) {
(
Expand Down Expand Up @@ -1704,6 +1729,7 @@ impl<Origin: From<crate::Origin>> ConvertOrigin<Origin> for XcmPassthrough<Origi
fn convert_origin(
origin: impl Into<MultiLocation>,
kind: OriginKind,
_context: XcmContext,
) -> Result<Origin, MultiLocation> {
let origin = origin.into();
match kind {
Expand Down
11 changes: 6 additions & 5 deletions xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use codec::Encode;
use frame_support::{construct_runtime, parameter_types, traits::Everything, weights::Weight};
use polkadot_parachain::primitives::Id as ParaId;
use polkadot_runtime_parachains::origin;
use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
pub use sp_std::{cell::RefCell, fmt::Debug, marker::PhantomData};
use xcm::latest::prelude::*;
use xcm::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, Case, ChildParachainAsNative, ChildParachainConvertsVia,
Expand Down Expand Up @@ -153,8 +154,8 @@ pub(crate) fn take_sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> {
pub struct TestSendXcm;
impl SendXcm for TestSendXcm {
fn send_xcm(dest: impl Into<MultiLocation>, msg: Xcm<()>) -> SendResult {
SENT_XCM.with(|q| q.borrow_mut().push((dest.into(), msg)));
Ok(())
SENT_XCM.with(|q| q.borrow_mut().push((dest.into(), msg.clone())));
Ok(VersionedXcm::from(msg).using_encoded(sp_io::hashing::blake2_256))
}
}
/// Sender that returns error if `X8` junction and stops routing
Expand All @@ -165,8 +166,8 @@ impl SendXcm for TestSendXcmErrX8 {
if dest.len() == 8 {
Err(SendError::Transport("Destination location full"))
} else {
SENT_XCM.with(|q| q.borrow_mut().push((dest, msg)));
Ok(())
SENT_XCM.with(|q| q.borrow_mut().push((dest, msg.clone())));
Ok(VersionedXcm::from(msg).using_encoded(sp_io::hashing::blake2_256))
}
}
}
Expand Down
Loading