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

[XCM-Transactor] Make fee_payer field optional in transact_through_sovereign #2709

Merged
merged 79 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
050af7e
Use polkadot-sdk to version 1.7.2
RomarQ Feb 29, 2024
3e2a418
fix test compilation
RomarQ Mar 1, 2024
cf063dd
Fix runtime API
RomarQ Mar 4, 2024
4693b73
fix runtime-benchmarks for pallet-identity
RomarQ Mar 5, 2024
48ee91e
fix identity precompile
RomarQ Mar 6, 2024
677fe97
format code
RomarQ Mar 6, 2024
cefa404
fix rust tests
RomarQ Mar 6, 2024
0e2995d
fix license check
RomarQ Mar 6, 2024
fd4cc41
fix format
RomarQ Mar 6, 2024
f8469eb
chore(ci): explicitly set rust toolchain before running the jobs
RomarQ Mar 7, 2024
0a57a6b
chore(ci): add rust-src component
RomarQ Mar 7, 2024
eec0501
chore(ci): fix rust-toolchain component installation
RomarQ Mar 7, 2024
90bd671
chore(ci): remove deprectated actions-rs/toolchain action
RomarQ Mar 7, 2024
de0fcf5
chore(ci): try to fix CI
RomarQ Mar 7, 2024
d50f207
chore(ci): try to fix CI
RomarQ Mar 7, 2024
52787b1
chore(ci): try to fix CI
RomarQ Mar 7, 2024
504b560
chore(ci): try to fix CI
RomarQ Mar 7, 2024
11ee0f0
disable crate default-features
RomarQ Mar 7, 2024
20bd522
fix tests
RomarQ Mar 7, 2024
e1269b0
fix try-runtime
RomarQ Mar 7, 2024
40b48c5
update crowdloan-rewards crate
RomarQ Mar 7, 2024
b802da9
revert Xtokens.sol change
RomarQ Mar 7, 2024
b039d4d
remove TODO's
RomarQ Mar 8, 2024
08a3303
chore update typescript test
RomarQ Mar 11, 2024
7541a7e
Merge branch 'master' into rq/update-polkadot-v1.7.2
RomarQ Mar 12, 2024
111eef2
replace NativeElseWasmExecutor with WasmExecutor to fix runtime overr…
RomarQ Mar 12, 2024
b60e8f1
rename trait
RomarQ Mar 12, 2024
7e56168
fix benchmarks
RomarQ Mar 12, 2024
de96dab
attempt to fix tracing-tests
RomarQ Mar 12, 2024
d8e66f4
revert change
RomarQ Mar 13, 2024
2e5a24e
set delayed_best_block to true in ParachainBlockImport
RomarQ Mar 13, 2024
ec2dbda
initialize block inside tracing method in the runtime api
RomarQ Mar 14, 2024
4901b7e
fix formatting in typescript tests
RomarQ Mar 14, 2024
fa5cd63
try new runtime-overrides
RomarQ Mar 14, 2024
116b473
fix some xcm tests tests
RomarQ Mar 14, 2024
8598662
fix tracing tests
RomarQ Mar 15, 2024
938ea52
fix formatting
RomarQ Mar 15, 2024
18080a1
fix rust tests
RomarQ Mar 15, 2024
d0d4e36
Revert "try new runtime-overrides"
RomarQ Mar 15, 2024
bd49b4e
keep using xcm v3 in some places to avoid having many breaking changes
RomarQ Mar 15, 2024
c31a6b8
fix benchmarks
RomarQ Mar 15, 2024
72c9578
fix tracing tests
RomarQ Mar 15, 2024
541c416
fix typescript tests
RomarQ Mar 17, 2024
d19e6ce
revert removal of RewardDestination::Controller
RomarQ Mar 18, 2024
2615ca5
fix tests in test-proxy
RomarQ Mar 18, 2024
5f5d08b
fix tests in test-precompile-wormhole.ts
RomarQ Mar 18, 2024
46a9db2
fix test-pov tests
RomarQ Mar 18, 2024
bdc8482
fix dmp queue tests
RomarQ Mar 18, 2024
472bf9f
fix fee tests and add xcm v4 tests
RomarQ Mar 18, 2024
6e2c17e
add xcm v4 tests
RomarQ Mar 18, 2024
b15a5c2
fix fmt
RomarQ Mar 18, 2024
170d159
make feePayer field optional
Agusrodri Mar 18, 2024
31ead3d
update moonkit dependency branch
RomarQ Mar 18, 2024
ba61606
add new type parameter to pallet async-backing config
RomarQ Mar 19, 2024
915b9ef
fix coverage job
RomarQ Mar 19, 2024
d3afb94
update github jobs
RomarQ Mar 19, 2024
74711dc
derive new test id's
RomarQ Mar 19, 2024
b93ea02
update rustc to version 1.75
RomarQ Mar 19, 2024
6e89943
add tests
Agusrodri Mar 19, 2024
5b90e07
Revert "update rustc to version 1.75"
RomarQ Mar 19, 2024
8064258
update Cargo.lock
RomarQ Mar 19, 2024
1a3aea5
revert changes to .gihub folder
RomarQ Mar 19, 2024
52bea1f
fix formatting
RomarQ Mar 19, 2024
aee9b69
removed unused script
RomarQ Mar 19, 2024
b3a4287
try disabling coverage
RomarQ Mar 19, 2024
9b0962d
Revert "try disabling coverage"
RomarQ Mar 19, 2024
1397d9c
update mold linker
RomarQ Mar 19, 2024
d5b049b
use default linker
RomarQ Mar 19, 2024
9de0703
Revert "use default linker"
RomarQ Mar 19, 2024
f5d2287
fix leaked dependencies
RomarQ Mar 19, 2024
a850bc8
apply suggestions from reviews
RomarQ Mar 20, 2024
e389a70
Revert "Revert "use default linker""
RomarQ Mar 20, 2024
4301aff
Revert "Revert "Revert "use default linker"""
RomarQ Mar 20, 2024
c7c7a37
increase timeout for coverage job
RomarQ Mar 20, 2024
6dff7e7
Merge branch 'master' into rq/update-polkadot-v1.7.2
RomarQ Mar 20, 2024
2f1726b
fix comment
Agusrodri Mar 20, 2024
b636164
Merge remote-tracking branch 'origin/rq/update-polkadot-v1.7.2' into …
Agusrodri Mar 21, 2024
93f16af
Merge remote-tracking branch 'origin/master' into agustin-fee-payer-f…
Agusrodri Mar 27, 2024
5cfcbe9
revert coverage timeout
Agusrodri Mar 27, 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
2 changes: 1 addition & 1 deletion pallets/xcm-transactor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ benchmarks! {
let result = Pallet::<T>::transact_through_sovereign(
RawOrigin::Root.into(),
Box::new(xcm::VersionedLocation::V4(location.clone())),
user.clone(),
Some(user.clone()),
CurrencyPayment {
// This might involve a db Read when translating, therefore worst case
currency: Currency::AsCurrencyId(currency),
Expand Down
6 changes: 3 additions & 3 deletions pallets/xcm-transactor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ pub mod pallet {
},
/// Transacted the call through the sovereign account in a destination chain.
TransactedSovereign {
fee_payer: T::AccountId,
fee_payer: Option<T::AccountId>,
dest: Location,
call: Vec<u8>,
},
Expand Down Expand Up @@ -598,7 +598,7 @@ pub mod pallet {
// destination to which the message should be sent
dest: Box<VersionedLocation>,
// account paying for fees
fee_payer: T::AccountId,
fee_payer: Option<T::AccountId>,
// fee to be used
fee: CurrencyPayment<CurrencyIdOf<T>>,
// call to be executed in destination
Expand Down Expand Up @@ -657,7 +657,7 @@ pub mod pallet {
// Grab the destination
Self::transact_in_dest_chain_asset_non_signed(
dest.clone(),
Some(fee_payer.clone()),
fee_payer.clone(),
fee,
call.clone(),
origin_kind,
Expand Down
75 changes: 70 additions & 5 deletions pallets/xcm-transactor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ fn test_root_can_transact_through_sovereign() {
XcmTransactor::transact_through_sovereign(
RuntimeOrigin::signed(1),
Box::new(xcm::VersionedLocation::V4(Location::parent())),
1u64,
Some(1u64),
CurrencyPayment {
currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4(
Location::parent()
Expand Down Expand Up @@ -521,7 +521,7 @@ fn test_root_can_transact_through_sovereign() {
assert_ok!(XcmTransactor::transact_through_sovereign(
RuntimeOrigin::root(),
Box::new(xcm::VersionedLocation::V4(Location::parent())),
1u64,
Some(1u64),
CurrencyPayment {
currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4(
Location::parent()
Expand Down Expand Up @@ -551,7 +551,7 @@ fn test_root_can_transact_through_sovereign() {
fee_per_second: 1,
},
crate::Event::TransactedSovereign {
fee_payer: 1u64,
fee_payer: Some(1u64),
dest: Location::parent(),
call: vec![1u8],
},
Expand Down Expand Up @@ -982,7 +982,7 @@ fn test_send_through_sovereign_with_custom_weight_and_fee() {
assert_ok!(XcmTransactor::transact_through_sovereign(
RuntimeOrigin::root(),
Box::new(xcm::VersionedLocation::V4(Location::parent())),
1u64,
Some(1u64),
CurrencyPayment {
currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4(
Location::parent()
Expand All @@ -1004,7 +1004,7 @@ fn test_send_through_sovereign_with_custom_weight_and_fee() {
index: 1,
},
crate::Event::TransactedSovereign {
fee_payer: 1u64,
fee_payer: Some(1u64),
dest: Location::parent(),
call: vec![1u8],
},
Expand All @@ -1028,6 +1028,71 @@ fn test_send_through_sovereign_with_custom_weight_and_fee() {
})
}

#[test]
fn test_transact_through_sovereign_with_fee_payer_none() {
ExtBuilder::default()
.with_balances(vec![])
.build()
.execute_with(|| {
// Root can register
assert_ok!(XcmTransactor::register(RuntimeOrigin::root(), 1u64, 1));

let total_weight: Weight = 10_100u64.into();
let tx_weight: Weight = 100_u64.into();
let total_fee = 100u128;

assert_ok!(XcmTransactor::transact_through_sovereign(
RuntimeOrigin::root(),
Box::new(xcm::VersionedLocation::V4(Location::parent())),
// We don't specify any fee_payer, instead we pay fees with the
// sovereign account funds directly on the destination.
None,
CurrencyPayment {
currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4(
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
Location::parent()
))),
fee_amount: Some(total_fee)
},
vec![1u8],
OriginKind::SovereignAccount,
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(Limited(total_weight))
},
false
));

let expected = vec![
crate::Event::RegisteredDerivative {
account_id: 1u64,
index: 1,
},
crate::Event::TransactedSovereign {
fee_payer: None,
dest: Location::parent(),
call: vec![1u8],
},
];
assert_eq!(events(), expected);
let sent_messages = mock::sent_xcm();
let (_, sent_message) = sent_messages.first().unwrap();
// Lets make sure the message is as expected even if we haven't indicated a
// fee_payer.
assert!(sent_message
elfedy marked this conversation as resolved.
Show resolved Hide resolved
.0
.contains(&WithdrawAsset((Location::here(), total_fee).into())));
assert!(sent_message.0.contains(&BuyExecution {
fees: (Location::here(), total_fee).into(),
weight_limit: Limited(total_weight),
}));
assert!(sent_message.0.contains(&Transact {
origin_kind: OriginKind::SovereignAccount,
require_weight_at_most: tx_weight,
call: vec![1u8].into(),
}));
})
}

#[test]
fn test_send_through_signed_with_custom_weight_and_fee() {
ExtBuilder::default()
Expand Down
111 changes: 108 additions & 3 deletions runtime/moonbase/tests/xcm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ fn transact_through_sovereign() {
assert_ok!(XcmTransactor::transact_through_sovereign(
parachain::RuntimeOrigin::root(),
Box::new(xcm::VersionedLocation::V4(dest)),
PARAALICE.into(),
Some(PARAALICE.into()),
CurrencyPayment {
currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4(
Location::parent()
Expand All @@ -1599,6 +1599,111 @@ fn transact_through_sovereign() {
});
}

#[test]
fn transact_through_sovereign_fee_payer_none() {
MockNet::reset();

ParaA::execute_with(|| {
// Root can set transact info
assert_ok!(XcmTransactor::set_transact_info(
parachain::RuntimeOrigin::root(),
Box::new(xcm::VersionedLocation::V4(Location::parent())),
// Relay charges 1000 for every instruction, and we have 3, so 3000
3000.into(),
20000000000.into(),
None
));
// Root can set transact info
assert_ok!(XcmTransactor::set_fee_per_second(
parachain::RuntimeOrigin::root(),
Box::new(xcm::VersionedLocation::V4(Location::parent())),
WEIGHT_REF_TIME_PER_SECOND as u128,
));
});

let derivative_address = derivative_account_id(para_a_account(), 0);

Relay::execute_with(|| {
// Transfer 100 tokens to derivative_address on the relay
assert_ok!(RelayBalances::transfer_keep_alive(
relay_chain::RuntimeOrigin::signed(RELAYALICE),
derivative_address.clone(),
100u128
));

// Transfer the XCM execution fee amount to ParaA's sovereign account
assert_ok!(RelayBalances::transfer_keep_alive(
relay_chain::RuntimeOrigin::signed(RELAYALICE),
para_a_account(),
4000003000u128
));
});

// Check balances before the transact call
Relay::execute_with(|| {
assert_eq!(RelayBalances::free_balance(&para_a_account()), 4000003000);
assert_eq!(RelayBalances::free_balance(&derivative_address), 100);
assert_eq!(RelayBalances::free_balance(&RELAYBOB), 0);
});

// Encode the call. Balances transfer of 100 relay tokens to RELAYBOB
let mut encoded: Vec<u8> = Vec::new();
let index = <relay_chain::Runtime as frame_system::Config>::PalletInfo::index::<
relay_chain::Balances,
>()
.unwrap() as u8;

encoded.push(index);

let mut call_bytes = pallet_balances::Call::<relay_chain::Runtime>::transfer_allow_death {
dest: RELAYBOB,
value: 100u32.into(),
}
.encode();
encoded.append(&mut call_bytes);

// The final call will be an AsDerivative using index 0
let utility_bytes = parachain::MockTransactors::Relay.encode_call(
xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded),
);

// We send the xcm transact operation to parent
let dest = Location {
parents: 1,
interior: /* Here */ [].into(),
};

// Root can directly pass the execution byes to the sovereign
ParaA::execute_with(|| {
assert_ok!(XcmTransactor::transact_through_sovereign(
parachain::RuntimeOrigin::root(),
Box::new(xcm::VersionedLocation::V4(dest)),
// No fee_payer here. The sovereign account will pay the fees on destination.
None,
CurrencyPayment {
currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4(
Location::parent()
))),
fee_amount: None
},
utility_bytes,
OriginKind::SovereignAccount,
TransactWeights {
transact_required_weight_at_most: 4000000000.into(),
overall_weight: None
},
false
));
});

// Check balances after the transact call are correct
Relay::execute_with(|| {
assert_eq!(RelayBalances::free_balance(&para_a_account()), 0);
assert_eq!(RelayBalances::free_balance(&derivative_address), 0);
assert_eq!(RelayBalances::free_balance(&RELAYBOB), 100);
});
}

#[test]
fn transact_through_sovereign_with_custom_fee_weight() {
MockNet::reset();
Expand Down Expand Up @@ -1726,7 +1831,7 @@ fn transact_through_sovereign_with_custom_fee_weight() {
assert_ok!(XcmTransactor::transact_through_sovereign(
parachain::RuntimeOrigin::root(),
Box::new(xcm::VersionedLocation::V4(dest)),
PARAALICE.into(),
Some(PARAALICE.into()),
CurrencyPayment {
currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4(
Location::parent()
Expand Down Expand Up @@ -1879,7 +1984,7 @@ fn transact_through_sovereign_with_custom_fee_weight_refund() {
assert_ok!(XcmTransactor::transact_through_sovereign(
parachain::RuntimeOrigin::root(),
Box::new(xcm::VersionedLocation::V4(dest)),
PARAALICE.into(),
Some(PARAALICE.into()),
CurrencyPayment {
currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4(
Location::parent()
Expand Down
Loading
Loading