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

Added Trusted Query API calls #6039

Merged
merged 32 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
529397e
WIP: trusted API implementation. Dunno how to convert VersionedAsset …
x3c41a Oct 7, 2024
1b2e653
finished tests and moved them to trusted_query file
x3c41a Oct 14, 2024
a3f2e18
code cleanup
x3c41a Oct 14, 2024
65d9f80
moved api implementation into pallet-xcm
x3c41a Oct 14, 2024
5190ae1
added API implementation for AH westend
x3c41a Oct 14, 2024
2eb2cfb
added error message to abstract asset test
x3c41a Oct 14, 2024
4fda268
formatted the test
x3c41a Oct 14, 2024
90bca8c
added new API to all the runtimes
x3c41a Oct 14, 2024
0c41137
Added missing penpal runtime and PRDOC
x3c41a Oct 14, 2024
a07ecfa
removed unused import
x3c41a Oct 15, 2024
a3b2378
formatted API
x3c41a Oct 15, 2024
e40a689
improved error logging
x3c41a Oct 16, 2024
a08d659
improved error logging[2]
x3c41a Oct 16, 2024
cbeb369
changed log::error! to log::trace
x3c41a Oct 16, 2024
f8fe180
Update prdoc/pr_6039.prdoc
x3c41a Oct 16, 2024
6925659
Update prdoc/pr_6039.prdoc
x3c41a Oct 16, 2024
fd30553
Update comment in polkadot/xcm/xcm-runtime-apis/src/lib.rs
x3c41a Oct 16, 2024
6993c51
Removed newline in polkadot/xcm/xcm-runtime-apis/tests/mock.rs
x3c41a Oct 16, 2024
de36457
Merge branch 'master' into new-runtime-call
franciscoaguirre Oct 16, 2024
4b715a1
changed logging to tracing
x3c41a Oct 16, 2024
451fcab
replaced tabs with spaces in the PRDOC
x3c41a Oct 16, 2024
873ebc4
formatted lib.rs
x3c41a Oct 16, 2024
688f164
added Invalid asset conversion test
x3c41a Oct 16, 2024
67c2e9b
unified API naming
x3c41a Oct 16, 2024
fe134b5
removed unwanted test
x3c41a Oct 16, 2024
909e711
changed bump from patch to minor
x3c41a Oct 16, 2024
bd36c5d
added API documentation
x3c41a Oct 16, 2024
8b75323
refactor leftovers
x3c41a Oct 16, 2024
2739f1d
tiny change to prdoc to re-run the check
x3c41a Oct 16, 2024
151745b
Merge branch 'master' into new-runtime-call
x3c41a Oct 16, 2024
bcbd187
refactored error name
x3c41a Oct 16, 2024
225a055
added XcmTrustedQueryResult type and removed extra argument lines
x3c41a Oct 17, 2024
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
11 changes: 10 additions & 1 deletion cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
x3c41a marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ use xcm::latest::prelude::{
};
use xcm::{
latest::prelude::{AssetId, BodyId},
VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
VersionedAsset, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_runtime_apis::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
Expand Down Expand Up @@ -1780,6 +1780,15 @@ impl_runtime_apis! {
genesis_config_presets::preset_names()
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
11 changes: 10 additions & 1 deletion cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ use assets_common::{
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use xcm::{
latest::prelude::AssetId,
prelude::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm},
prelude::{VersionedAsset, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm},
};

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -1876,6 +1876,15 @@ impl_runtime_apis! {
genesis_config_presets::preset_names()
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,15 @@ impl_runtime_apis! {
genesis_config_presets::preset_names()
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,15 @@ impl_runtime_apis! {
genesis_config_presets::preset_names()
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,15 @@ impl_runtime_apis! {
genesis_config_presets::preset_names()
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,15 @@ impl_runtime_apis! {
vec![]
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,15 @@ impl_runtime_apis! {
vec![]
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,15 @@ impl_runtime_apis! {
vec![]
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
9 changes: 9 additions & 0 deletions cumulus/parachains/runtimes/people/people-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,15 @@ impl_runtime_apis! {
vec![]
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
9 changes: 9 additions & 0 deletions cumulus/parachains/runtimes/people/people-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,15 @@ impl_runtime_apis! {
vec![]
}
}

impl xcm_runtime_apis::trust_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trust_query::Error> {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
49 changes: 49 additions & 0 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ use xcm_executor::{
use xcm_runtime_apis::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
trust_query::Error as TrustQueryApiError,
};

#[cfg(any(feature = "try-runtime", test))]
Expand Down Expand Up @@ -2569,6 +2570,54 @@ impl<T: Config> Pallet<T> {
})
}

pub fn is_trusted_reserve(
x3c41a marked this conversation as resolved.
Show resolved Hide resolved
asset: VersionedAsset,
location: VersionedLocation,
) -> Result<bool, TrustQueryApiError> {
let location: Location = location.try_into().map_err(|e| {
log::error!(
target: "xcm::TrustedQueryApi::is_trusted_reserve",
"Asset version conversion failed with error: {:?}",
e,
);
TrustQueryApiError::VersionedLocationConversionFailed
})?;

let ass: Asset = asset.try_into().map_err(|e| {
log::error!(
target: "xcm::TrustedQueryApi::is_trusted_reserve",
"Location version conversion failed with error: {:?}",
e,
);
TrustQueryApiError::VersionedAssetConversionFailed
})?;

Ok(<T::XcmExecutor as XcmAssetTransfers>::IsReserve::contains(&ass, &location))
}

pub fn is_trusted_teleporter(
x3c41a marked this conversation as resolved.
Show resolved Hide resolved
asset: VersionedAsset,
location: VersionedLocation,
) -> Result<bool, TrustQueryApiError> {
let location: Location = location.try_into().map_err(|e| {
log::error!(
target: "xcm::TrustedQueryApi::is_trusted_teleporter",
"Asset version conversion failed with error: {:?}",
e,
);
TrustQueryApiError::VersionedLocationConversionFailed
})?;
let ass: Asset = asset.try_into().map_err(|e| {
log::error!(
target: "xcm::TrustedQueryApi::is_trusted_teleporter",
"Location version conversion failed with error: {:?}",
e,
);
TrustQueryApiError::VersionedAssetConversionFailed
})?;
Ok(<T::XcmExecutor as XcmAssetTransfers>::IsTeleporter::contains(&ass, &location))
}

pub fn query_delivery_fees(
destination: VersionedLocation,
message: VersionedXcm<()>,
Expand Down
3 changes: 3 additions & 0 deletions polkadot/xcm/xcm-runtime-apis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ pub mod dry_run;
/// Fee estimation API.
/// Given an XCM program, it will return the fees needed to execute it properly or send it.
pub mod fees;

// Exposes runtime API for querying trusted reservers and teleporters.
x3c41a marked this conversation as resolved.
Show resolved Hide resolved
pub mod trust_query;
38 changes: 38 additions & 0 deletions polkadot/xcm/xcm-runtime-apis/src/trust_query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Runtime API definition for getting XCM fees.
x3c41a marked this conversation as resolved.
Show resolved Hide resolved

use codec::{Decode, Encode};
use frame_support::pallet_prelude::TypeInfo;
use xcm::{VersionedAsset, VersionedLocation};

sp_api::decl_runtime_apis! {
pub trait TrustedQueryApi {
x3c41a marked this conversation as resolved.
Show resolved Hide resolved
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, Error>;
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, Error>;
}
}

#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
pub enum Error {
/// Converting a versioned Asset structure from one version to another failed.
#[codec(index = 1)]
VersionedAssetConversionFailed,
/// Converting a versioned Location structure from one version to another failed.
#[codec(index = 1)]
VersionedLocationConversionFailed,
}
12 changes: 12 additions & 0 deletions polkadot/xcm/xcm-runtime-apis/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use xcm_runtime_apis::{
conversions::{Error as LocationToAccountApiError, LocationToAccountApi},
dry_run::{CallDryRunEffects, DryRunApi, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::{Error as XcmPaymentApiError, XcmPaymentApi},
trust_query::{Error as TrustedQueryApiError, TrustedQueryApi},
};

construct_runtime! {
Expand Down Expand Up @@ -414,6 +415,17 @@ impl sp_api::ProvideRuntimeApi<Block> for TestClient {
}

sp_api::mock_impl_runtime_apis! {

x3c41a marked this conversation as resolved.
Show resolved Hide resolved
impl TrustedQueryApi<Block> for RuntimeApi {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, TrustedQueryApiError> {
XcmPallet::is_trusted_reserve(asset, location)
}

fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, TrustedQueryApiError> {
XcmPallet::is_trusted_teleporter(asset, location)
}
}

impl LocationToAccountApi<Block, AccountId> for RuntimeApi {
fn convert_location(location: VersionedLocation) -> Result<AccountId, LocationToAccountApiError> {
let location = location.try_into().map_err(|_| LocationToAccountApiError::VersionedConversionFailed)?;
Expand Down
Loading
Loading