-
Notifications
You must be signed in to change notification settings - Fork 77
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
feat!: XCM Rate Limiter Integration #638
Merged
Merged
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
445ba54
correct rate limiter Cargo.toml
apopiak cb275b6
Merge branch 'feat/xcm-defer' into feat/xcm-rate-limiter
apopiak db44625
bump crate versions
apopiak 79a64a1
Revert "remove xcm rate limiter from runtime"
apopiak 144605e
update xcmp queue pallet
apopiak 673f54e
Merge branch 'master' of github.com:galacticcouncil/HydraDX-node into…
apopiak 33828ce
Merge branch 'master' into feat/xcm-rate-limiter
mrq1911 4d48737
Merge branch 'master' into feat/xcm-rate-limiter
apopiak 353a6c6
Merge branch 'master' into feat/xcm-rate-limiter
mrq1911 a6ee5de
bump integration tests
dmoka 8797e19
Merge remote-tracking branch 'origin/feat/xcm-rate-limiter' into feat…
dmoka a931eb0
bump runtime version
dmoka 21f5866
change function order to follow execution orders
dmoka b743f77
bump patch versions of touched packages
dmoka c95d0e5
fix xcm rate limiter non deterministic tests as we use different rela…
dmoka ce57dbb
merge master to feat/xcm-rate-limiter
dmoka 62ecd90
bump versions
dmoka b33182c
merge master to feat/xcm-rate-limiter
dmoka 04440f3
bump runtime version
dmoka 0671025
bump patch versions for touched packages
dmoka 658b7be
update lock
dmoka fed4df2
Merge branch 'master' of github.com:galacticcouncil/HydraDX-node into…
apopiak 54744fe
bump versions
apopiak c90e469
remove duplicate assert macro definitions
apopiak 0a0682a
update xcmp queue pallet to new extended version
apopiak ff7c102
update integration tests
apopiak 7a1eaed
formatting
apopiak d958f16
configure defer duration
apopiak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,253 @@ | ||
#![cfg(test)] | ||
|
||
use crate::polkadot_test_net::*; | ||
|
||
use frame_support::{assert_ok, pallet_prelude::Weight}; | ||
use orml_traits::currency::MultiCurrency; | ||
use pallet_asset_registry::AssetType; | ||
use polkadot_xcm::prelude::*; | ||
use xcm_emulator::TestExt; | ||
|
||
/// Returns the message hash in the `XcmpMessageSent` event at the `n`th last event (1-indexed, so if the second to last | ||
/// event has the hash, pass `2`); | ||
fn get_message_hash_from_event(n: usize) -> Option<[u8; 32]> { | ||
use cumulus_pallet_xcmp_queue::Event; | ||
use hydradx_runtime::RuntimeEvent; | ||
let RuntimeEvent::XcmpQueue(Event::XcmpMessageSent { message_hash }) = &last_hydra_events(n)[0] else { | ||
panic!("expecting to find message sent event"); | ||
}; | ||
*message_hash | ||
} | ||
|
||
#[test] | ||
fn xcm_rate_limiter_should_limit_aca_when_limit_is_exceeded() { | ||
// Arrange | ||
TestNet::reset(); | ||
|
||
Hydra::execute_with(|| { | ||
assert_ok!(hydradx_runtime::AssetRegistry::set_location( | ||
hydradx_runtime::RuntimeOrigin::root(), | ||
ACA, | ||
hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) | ||
)); | ||
|
||
// set an xcm rate limit | ||
assert_ok!(hydradx_runtime::AssetRegistry::update( | ||
hydradx_runtime::RuntimeOrigin::root(), | ||
ACA, | ||
b"ACA".to_vec(), | ||
AssetType::Token, | ||
None, | ||
Some(50 * UNITS), | ||
)); | ||
|
||
assert_eq!(hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), 0); | ||
|
||
//Set it to same as the relay block number should be in XcmDeferFilter | ||
//since we use different RelayChainBlockNumberProvider in runtime-benchmark feature | ||
//where we return frame_system current time | ||
frame_system::Pallet::<hydradx_runtime::Runtime>::set_block_number(4); | ||
}); | ||
|
||
let amount = 100 * UNITS; | ||
let mut message_hash = None; | ||
Acala::execute_with(|| { | ||
// Act | ||
assert_ok!(hydradx_runtime::XTokens::transfer( | ||
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), | ||
0, | ||
amount, | ||
Box::new( | ||
MultiLocation::new( | ||
1, | ||
X2( | ||
Junction::Parachain(HYDRA_PARA_ID), | ||
Junction::AccountId32 { id: BOB, network: None } | ||
) | ||
) | ||
.into() | ||
), | ||
WeightLimit::Limited(Weight::from_ref_time(399_600_000_000)) | ||
)); | ||
|
||
message_hash = get_message_hash_from_event(2); | ||
|
||
// Assert | ||
assert_eq!( | ||
hydradx_runtime::Balances::free_balance(&AccountId::from(ALICE)), | ||
ALICE_INITIAL_NATIVE_BALANCE - amount | ||
); | ||
}); | ||
|
||
Hydra::execute_with(|| { | ||
expect_hydra_events(vec![ | ||
cumulus_pallet_xcmp_queue::Event::XcmDeferred { | ||
sender: ACALA_PARA_ID.into(), | ||
sent_at: 3, | ||
deferred_to: 604, // received at 4 plus 600 blocks of deferral | ||
message_hash, | ||
} | ||
.into(), | ||
pallet_relaychain_info::Event::CurrentBlockNumbers { | ||
parachain_block_number: 4, | ||
relaychain_block_number: 5, | ||
} | ||
.into(), | ||
]); | ||
assert_eq!(hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), 0); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn xcm_rate_limiter_should_not_limit_aca_when_limit_is_not_exceeded() { | ||
// Arrange | ||
TestNet::reset(); | ||
|
||
Hydra::execute_with(|| { | ||
assert_ok!(hydradx_runtime::AssetRegistry::set_location( | ||
hydradx_runtime::RuntimeOrigin::root(), | ||
ACA, | ||
hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) | ||
)); | ||
|
||
// set an xcm rate limit | ||
assert_ok!(hydradx_runtime::AssetRegistry::update( | ||
hydradx_runtime::RuntimeOrigin::root(), | ||
ACA, | ||
b"ACA".to_vec(), | ||
AssetType::Token, | ||
None, | ||
Some(101 * UNITS), | ||
)); | ||
}); | ||
|
||
let amount = 100 * UNITS; | ||
Acala::execute_with(|| { | ||
// Act | ||
assert_ok!(hydradx_runtime::XTokens::transfer( | ||
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), | ||
0, | ||
amount, | ||
Box::new( | ||
MultiLocation::new( | ||
1, | ||
X2( | ||
Junction::Parachain(HYDRA_PARA_ID), | ||
Junction::AccountId32 { id: BOB, network: None } | ||
) | ||
) | ||
.into() | ||
), | ||
WeightLimit::Limited(Weight::from_ref_time(399_600_000_000)) | ||
)); | ||
|
||
// Assert | ||
assert_eq!( | ||
hydradx_runtime::Balances::free_balance(&AccountId::from(ALICE)), | ||
ALICE_INITIAL_NATIVE_BALANCE - amount | ||
); | ||
}); | ||
|
||
Hydra::execute_with(|| { | ||
let fee = hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()); | ||
assert_eq!( | ||
hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), | ||
amount - fee | ||
); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn deferred_messages_should_be_executable_by_root() { | ||
// Arrange | ||
TestNet::reset(); | ||
|
||
Hydra::execute_with(|| { | ||
assert_ok!(hydradx_runtime::AssetRegistry::set_location( | ||
hydradx_runtime::RuntimeOrigin::root(), | ||
ACA, | ||
hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) | ||
)); | ||
|
||
// set an xcm rate limit | ||
assert_ok!(hydradx_runtime::AssetRegistry::update( | ||
hydradx_runtime::RuntimeOrigin::root(), | ||
ACA, | ||
b"ACA".to_vec(), | ||
AssetType::Token, | ||
None, | ||
Some(50 * UNITS), | ||
)); | ||
|
||
assert_eq!(hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), 0); | ||
|
||
//Set it to same as the relay block number should be in XcmDeferFilter | ||
//since we use different RelayChainBlockNumberProvider in runtime-benchmark feature | ||
//where we return frame_system current time | ||
frame_system::Pallet::<hydradx_runtime::Runtime>::set_block_number(4); | ||
}); | ||
|
||
let amount = 100 * UNITS; | ||
let mut message_hash = None; | ||
let max_weight = Weight::from_ref_time(399_600_000_000); | ||
Acala::execute_with(|| { | ||
// Act | ||
assert_ok!(hydradx_runtime::XTokens::transfer( | ||
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), | ||
0, | ||
amount, | ||
Box::new( | ||
MultiLocation::new( | ||
1, | ||
X2( | ||
Junction::Parachain(HYDRA_PARA_ID), | ||
Junction::AccountId32 { id: BOB, network: None } | ||
) | ||
) | ||
.into() | ||
), | ||
WeightLimit::Limited(max_weight), | ||
)); | ||
|
||
message_hash = get_message_hash_from_event(2); | ||
|
||
// Assert | ||
assert_eq!( | ||
hydradx_runtime::Balances::free_balance(&AccountId::from(ALICE)), | ||
ALICE_INITIAL_NATIVE_BALANCE - amount | ||
); | ||
}); | ||
|
||
Hydra::execute_with(|| { | ||
expect_hydra_events(vec![ | ||
cumulus_pallet_xcmp_queue::Event::XcmDeferred { | ||
sender: ACALA_PARA_ID.into(), | ||
sent_at: 3, | ||
deferred_to: 604, // received at 4 plus 600 blocks of deferral | ||
message_hash, | ||
} | ||
.into(), | ||
pallet_relaychain_info::Event::CurrentBlockNumbers { | ||
parachain_block_number: 4, | ||
relaychain_block_number: 5, | ||
} | ||
.into(), | ||
]); | ||
assert_eq!(hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), 0); | ||
|
||
set_relaychain_block_number(604); | ||
|
||
assert_eq!(hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), 0); | ||
assert_ok!(hydradx_runtime::XcmpQueue::service_deferred( | ||
hydradx_runtime::RuntimeOrigin::root(), | ||
max_weight, | ||
ACALA_PARA_ID.into(), | ||
)); | ||
|
||
let fee = hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()); | ||
assert_eq!( | ||
hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), | ||
amount - fee | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably also test clearing of the limits in similar fashion after blocks pass