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

XcmDryRunApi - Dry-running extrinsics to get their XCM effects #3872

Merged
merged 74 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
43faca7
feat(xcm-fee-payment-runtime-api): add XcmTransfersApi and tests
franciscoaguirre Mar 27, 2024
dd0376d
feat(xcm-fee-payment-runtime-api): changed XcmTransfersApi to XcmDryR…
franciscoaguirre Mar 28, 2024
cd1838a
feat(xcm-dry-run-api): get forwarded messages from the queues
franciscoaguirre Mar 29, 2024
7e04d50
feat(xcm-dry-run-api): updated test works
franciscoaguirre Mar 31, 2024
ec04b80
feat(xcm-dry-run-api): add test for a reserve asset transfer
franciscoaguirre Mar 31, 2024
c5c48ca
feat(xcm-dry-run-api): add dry_run_xcm call
franciscoaguirre Mar 31, 2024
df90feb
feat(xcm-dry-run-api): grab XCM that's about to be executed
franciscoaguirre Apr 9, 2024
ccda0df
chore(xcm-dry-run-api): remove dbgs
franciscoaguirre Apr 9, 2024
a9e0ec4
chore(xcm-dry-run-api): fmt
franciscoaguirre Apr 9, 2024
e09a9a7
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 9, 2024
4bec8ee
fix: compilation issues
franciscoaguirre Apr 9, 2024
3502666
chore(pallet-xcm): revert refactor
franciscoaguirre Apr 10, 2024
7ccd0e4
docs(xcm-executor): update comments about RecordXcm
franciscoaguirre Apr 10, 2024
7b825f2
feat(xcm-dry-run-api): add emitted events to XcmDryRunEffects
franciscoaguirre Apr 10, 2024
3767e4d
chore(pallet-xcm): remove refactor leftovers
franciscoaguirre Apr 10, 2024
f7c55ac
feat(xcm-fee-payment-runtime-api): improve test
franciscoaguirre Apr 10, 2024
26c2b7d
feat(xcm-dry-run-api): add execution result to XcmDryRunEffects and E…
franciscoaguirre Apr 10, 2024
609137b
feat(xcm-dry-run-api): add error enum and return error when extrinsic…
franciscoaguirre Apr 12, 2024
465e5ee
Update polkadot/xcm/xcm-fee-payment-runtime-api/tests/mock.rs
franciscoaguirre Apr 12, 2024
8c47443
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 12, 2024
b6864fe
fix(xcm-fee-payment-runtime-api): reexport inner modules instead of s…
franciscoaguirre Apr 12, 2024
aba11e8
fix(xcm-recorder): add XcmRecorder config item to all XCM configs
franciscoaguirre Apr 12, 2024
3a4210b
fix: fmt
franciscoaguirre Apr 12, 2024
eca20db
fix(xcm-fee-payment-runtime-api): add missing BenchmarkHelper in mock
franciscoaguirre Apr 12, 2024
34cdb17
doc: add prdoc
franciscoaguirre Apr 12, 2024
317fb6e
feat(xcm-dry-run-api): add XcmDryRunApi to fake_runtime_api
franciscoaguirre Apr 12, 2024
08d5ebc
doc: update prdoc
franciscoaguirre Apr 12, 2024
a202ddf
fix(xcm-fee-payment-runtime-api): add runtime-benchmarks feature and …
franciscoaguirre Apr 12, 2024
2462d7a
fix(prdoc): fix crate names and add xcm-builder
franciscoaguirre Apr 12, 2024
84b1e0b
fix(xcm-fee-payment-runtime-api): propagate features and format Cargo…
franciscoaguirre Apr 12, 2024
114860f
fix(xcm-fee-payment-runtime-api): fix weight update issue in tests
franciscoaguirre Apr 12, 2024
6f6cb91
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 12, 2024
c696674
fix: fmt
franciscoaguirre Apr 12, 2024
3e7dc0c
fix(xcm-fee-payment-runtime-api): propagate std feature to log
franciscoaguirre Apr 12, 2024
ea13755
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 12, 2024
f304400
fix(xcm-fee-payment-runtime-api): fix feature propagation
franciscoaguirre Apr 12, 2024
f80aaf5
fix(xcm-fee-payment-runtime-api): format Cargo.toml
franciscoaguirre Apr 12, 2024
43496f3
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 15, 2024
2a7af71
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 16, 2024
16d3a54
fix(xcm-builder): remove XcmRecorder from polkadot-test-runtime
franciscoaguirre Apr 16, 2024
030255c
feat(xcm-dry-run-api): add test setup with emulator
franciscoaguirre Apr 17, 2024
0d2e19c
feat(xcm-fee-estimation): add xcm emulator test for fee estimation
franciscoaguirre Apr 19, 2024
97ee470
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 25, 2024
9fcf4b2
fix(pallet-xcm): RecordXcm test was using old function
franciscoaguirre Apr 25, 2024
5aeae3a
fix: fmt
franciscoaguirre Apr 25, 2024
a90c091
feat: finish implementing XcmDryRunApi for westend and asset hub westend
franciscoaguirre Apr 25, 2024
6a35294
fix(xcm-dry-run-api): fix multiple forwarded messages instead of one
franciscoaguirre Apr 26, 2024
cc2b177
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 26, 2024
51b279c
feat: add multi-hop example to xcm estimation
franciscoaguirre Apr 29, 2024
cad8cd5
fix: remove unnecessary clone
franciscoaguirre Apr 29, 2024
3c12610
fix(xcm-fee-estimation-tests): use immortal transactions
franciscoaguirre Apr 30, 2024
a498649
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 30, 2024
6246d7f
fix: fmt
franciscoaguirre Apr 30, 2024
69a26ec
fix: Cargo.toml format
franciscoaguirre Apr 30, 2024
29a0b8a
Update cumulus/parachains/runtimes/testing/penpal/src/lib.rs
franciscoaguirre Apr 30, 2024
6d785f3
feat: implement InspectMessageQueues on the bridge router
franciscoaguirre Apr 30, 2024
3298ff2
feat(xcm-dry-run-api): remove unnecessary weight parameter
franciscoaguirre Apr 30, 2024
f153875
feat(record-xcm): add getters and setters to trait
franciscoaguirre Apr 30, 2024
9be1146
chore(xcm-dry-run-api): change program and message to xcm
franciscoaguirre Apr 30, 2024
b71536e
fix(xcm-fee-payment-runtime-api): remove no longer used parameter
franciscoaguirre Apr 30, 2024
36927bd
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre Apr 30, 2024
6080edb
fix: fmt
franciscoaguirre Apr 30, 2024
8c9a090
Update cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
franciscoaguirre May 1, 2024
720f0c0
chore: address feedback
franciscoaguirre May 6, 2024
bb712bb
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre May 7, 2024
ccf6a70
fix: merge conflicts
franciscoaguirre May 7, 2024
a30de00
fix(xcm-fee-payment-runtime-api): deal with local xcm being an option…
franciscoaguirre May 7, 2024
5a2cbf5
feat(rococo-runtime): add XcmDryRunApi
franciscoaguirre May 7, 2024
a5c4c67
feat(asset-hub-rococo-runtime): add XcmDryRunApi
franciscoaguirre May 7, 2024
e7beae4
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre May 7, 2024
0a42dea
fix(asset-hub-rococo-runtime): feature propagation
franciscoaguirre May 7, 2024
93c5b83
fix(asset-hub-rococo): taplo
franciscoaguirre May 7, 2024
7edc8b8
fix: clippy
franciscoaguirre May 8, 2024
186ea04
Merge branch 'master' into xcm-transfers-fee-estimation
franciscoaguirre May 8, 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
33 changes: 33 additions & 0 deletions Cargo.lock

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

43 changes: 41 additions & 2 deletions bridges/modules/xcm-bridge-hub-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ use codec::Encode;
use frame_support::traits::Get;
use sp_core::H256;
use sp_runtime::{FixedPointNumber, FixedU128, Saturating};
use sp_std::vec::Vec;
use xcm::prelude::*;
use xcm_builder::{ExporterFor, SovereignPaidRemoteExporter};
use xcm_builder::{ExporterFor, InspectMessageQueues, SovereignPaidRemoteExporter};

pub use pallet::*;
pub use weights::WeightInfo;
Expand Down Expand Up @@ -95,7 +96,7 @@ pub mod pallet {
/// Origin of the sibling bridge hub that is allowed to report bridge status.
type BridgeHubOrigin: EnsureOrigin<Self::RuntimeOrigin>;
/// Actual message sender (`HRMP` or `DMP`) to the sibling bridge hub location.
type ToBridgeHubSender: SendXcm;
type ToBridgeHubSender: SendXcm + InspectMessageQueues;
/// Underlying channel with the sibling bridge hub. It must match the channel, used
/// by the `Self::ToBridgeHubSender`.
type WithBridgeHubChannel: XcmChannelStatusProvider;
Expand Down Expand Up @@ -396,6 +397,12 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
}
}

impl<T: Config<I>, I: 'static> InspectMessageQueues for Pallet<T, I> {
fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
ViaBridgeHubExporter::<T, I>::get_messages()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -635,4 +642,36 @@ mod tests {
);
});
}

#[test]
fn get_messages_works() {
run_test(|| {
assert_ok!(send_xcm::<XcmBridgeHubRouter>(
(Parent, Parent, GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)).into(),
vec![ClearOrigin].into()
));
assert_eq!(
XcmBridgeHubRouter::get_messages(),
vec![(
VersionedLocation::V4((Parent, Parachain(1002)).into()),
vec![VersionedXcm::V4(
Xcm::builder()
.withdraw_asset((Parent, 1_002_000))
.buy_execution((Parent, 1_002_000), Unlimited)
.set_appendix(
Xcm::builder_unsafe()
.deposit_asset(AllCounted(1), (Parent, Parachain(1000)))
.build()
)
.export_message(
Kusama,
Parachain(1000),
Xcm::builder_unsafe().clear_origin().build()
)
.build()
)],
),],
);
});
}
}
47 changes: 38 additions & 9 deletions bridges/modules/xcm-bridge-hub-router/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
use crate as pallet_xcm_bridge_hub_router;

use bp_xcm_bridge_hub_router::XcmChannelStatusProvider;
use codec::Encode;
use frame_support::{
construct_runtime, derive_impl, parameter_types,
traits::{Contains, Equals},
};
use frame_system::EnsureRoot;
use sp_runtime::{traits::ConstU128, BuildStorage};
use sp_std::cell::RefCell;
use xcm::prelude::*;
use xcm_builder::{NetworkExportTable, NetworkExportTableItem};
use xcm_builder::{InspectMessageQueues, NetworkExportTable, NetworkExportTableItem};

pub type AccountId = u64;
type Block = frame_system::mocking::MockBlock<TestRuntime>;
Expand Down Expand Up @@ -102,23 +104,46 @@ pub struct TestToBridgeHubSender;

impl TestToBridgeHubSender {
pub fn is_message_sent() -> bool {
frame_support::storage::unhashed::get_or_default(b"TestToBridgeHubSender.Sent")
!Self::get_messages().is_empty()
}
}

thread_local! {
pub static SENT_XCM: RefCell<Vec<(Location, Xcm<()>)>> = RefCell::new(Vec::new());
}

impl SendXcm for TestToBridgeHubSender {
type Ticket = ();
type Ticket = (Location, Xcm<()>);

fn validate(
_destination: &mut Option<Location>,
_message: &mut Option<Xcm<()>>,
destination: &mut Option<Location>,
message: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> {
Ok(((), (BridgeFeeAsset::get(), HRMP_FEE).into()))
let pair = (destination.take().unwrap(), message.take().unwrap());
Ok((pair, (BridgeFeeAsset::get(), HRMP_FEE).into()))
}

fn deliver(_ticket: Self::Ticket) -> Result<XcmHash, SendError> {
frame_support::storage::unhashed::put(b"TestToBridgeHubSender.Sent", &true);
Ok([0u8; 32])
fn deliver(pair: Self::Ticket) -> Result<XcmHash, SendError> {
let hash = fake_message_hash(&pair.1);
SENT_XCM.with(|q| q.borrow_mut().push(pair));
serban300 marked this conversation as resolved.
Show resolved Hide resolved
Ok(hash)
}
}

impl InspectMessageQueues for TestToBridgeHubSender {
fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
SENT_XCM.with(|q| {
(*q.borrow())
.clone()
.iter()
.map(|(location, message)| {
(
VersionedLocation::V4(location.clone()),
vec![VersionedXcm::V4(message.clone())],
)
})
.collect()
})
}
}

Expand Down Expand Up @@ -146,3 +171,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn run_test<T>(test: impl FnOnce() -> T) -> T {
new_test_ext().execute_with(test)
}

pub(crate) fn fake_message_hash<T>(message: &Xcm<T>) -> XcmHash {
message.using_encoded(sp_io::hashing::blake2_256)
}
3 changes: 3 additions & 0 deletions cumulus/pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ polkadot-parachain-primitives = { path = "../../../polkadot/parachain", default-
polkadot-runtime-parachains = { path = "../../../polkadot/runtime/parachains", default-features = false }
polkadot-runtime-common = { path = "../../../polkadot/runtime/common", default-features = false, optional = true }
xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false }
xcm-builder = { package = "staging-xcm-builder", path = "../../../polkadot/xcm/xcm-builder", default-features = false }

# Cumulus
cumulus-pallet-parachain-system-proc-macro = { path = "proc-macro", default-features = false }
Expand Down Expand Up @@ -95,6 +96,7 @@ std = [
"sp-tracing/std",
"sp-trie/std",
"trie-db/std",
"xcm-builder/std",
"xcm/std",
]

Expand All @@ -109,6 +111,7 @@ runtime-benchmarks = [
"polkadot-runtime-common/runtime-benchmarks",
"polkadot-runtime-parachains/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]

try-runtime = [
Expand Down
16 changes: 15 additions & 1 deletion cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ use sp_runtime::{
BoundedSlice, FixedU128, RuntimeDebug, Saturating,
};
use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*};
use xcm::latest::XcmHash;
use xcm::{latest::XcmHash, VersionedLocation, VersionedXcm};
use xcm_builder::InspectMessageQueues;

mod benchmarking;
pub mod migration;
Expand Down Expand Up @@ -1608,6 +1609,19 @@ impl<T: Config> UpwardMessageSender for Pallet<T> {
}
}

impl<T: Config> InspectMessageQueues for Pallet<T> {
fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
use xcm::prelude::*;

let messages: Vec<VersionedXcm<()>> = PendingUpwardMessages::<T>::get()
.iter()
.map(|encoded_message| VersionedXcm::<()>::decode(&mut &encoded_message[..]).unwrap())
.collect();

vec![(VersionedLocation::V4(Parent.into()), messages)]
}
}

#[cfg(feature = "runtime-benchmarks")]
impl<T: Config> polkadot_runtime_common::xcm_sender::EnsureForParachain for Pallet<T> {
fn ensure(para_id: ParaId) {
Expand Down
5 changes: 2 additions & 3 deletions cumulus/pallets/xcmp-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ polkadot-runtime-common = { path = "../../../polkadot/runtime/common", default-f
polkadot-runtime-parachains = { path = "../../../polkadot/runtime/parachains", default-features = false }
xcm = { package = "staging-xcm", path = "../../../polkadot/xcm", default-features = false }
xcm-executor = { package = "staging-xcm-executor", path = "../../../polkadot/xcm/xcm-executor", default-features = false }
xcm-builder = { package = "staging-xcm-builder", path = "../../../polkadot/xcm/xcm-builder", default-features = false }

# Cumulus
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
Expand All @@ -46,9 +47,6 @@ sp-core = { path = "../../../substrate/primitives/core" }
pallet-balances = { path = "../../../substrate/frame/balances" }
frame-support = { path = "../../../substrate/frame/support", features = ["experimental"] }

# Polkadot
xcm-builder = { package = "staging-xcm-builder", path = "../../../polkadot/xcm/xcm-builder" }

# Cumulus
cumulus-pallet-parachain-system = { path = "../parachain-system", features = ["parameterized-consensus-hook"] }

Expand All @@ -71,6 +69,7 @@ std = [
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
]
Expand Down
35 changes: 34 additions & 1 deletion cumulus/pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ use scale_info::TypeInfo;
use sp_core::MAX_POSSIBLE_ALLOCATION;
use sp_runtime::{FixedU128, RuntimeDebug, Saturating};
use sp_std::prelude::*;
use xcm::{latest::prelude::*, VersionedXcm, WrapVersion, MAX_XCM_DECODE_DEPTH};
use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm, WrapVersion, MAX_XCM_DECODE_DEPTH};
use xcm_builder::InspectMessageQueues;
use xcm_executor::traits::ConvertOrigin;

pub use pallet::*;
Expand Down Expand Up @@ -947,6 +948,38 @@ impl<T: Config> SendXcm for Pallet<T> {
}
}

impl<T: Config> InspectMessageQueues for Pallet<T> {
fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
use xcm::prelude::*;

OutboundXcmpMessages::<T>::iter()
.map(|(para_id, _, messages)| {
let mut data = &messages[..];
let decoded_format =
XcmpMessageFormat::decode_with_depth_limit(MAX_XCM_DECODE_DEPTH, &mut data)
.unwrap();
if decoded_format != XcmpMessageFormat::ConcatenatedVersionedXcm {
panic!("Unexpected format.")
}
let mut decoded_messages = Vec::new();
while !data.is_empty() {
let decoded_message = VersionedXcm::<()>::decode_with_depth_limit(
MAX_XCM_DECODE_DEPTH,
&mut data,
)
.unwrap();
decoded_messages.push(decoded_message);
}

(
VersionedLocation::V4((Parent, Parachain(para_id.into())).into()),
decoded_messages,
)
})
.collect()
}
}

impl<T: Config> FeeTracker for Pallet<T> {
type Id = ParaId;

Expand Down
1 change: 1 addition & 0 deletions cumulus/pallets/xcmp-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ impl xcm_executor::Config for XcmConfig {
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = ();
}

pub type XcmRouter = (
Expand Down
Loading
Loading