Skip to content

Commit

Permalink
Merge pull request #4 from galacticcouncil/feat/extend-defer-queue
Browse files Browse the repository at this point in the history
Feature: Extend Defer Queue
  • Loading branch information
apopiak authored Oct 13, 2023
2 parents 9b3a8cc + fe8b340 commit bc34ec3
Show file tree
Hide file tree
Showing 24 changed files with 1,029 additions and 427 deletions.
71 changes: 62 additions & 9 deletions pallets/xcmp-queue/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,27 @@ benchmarks! {
// We set `deferred_to` to the current relay block number to make sure that the messages are serviced.
let deferred_message = DeferredMessage { sent_at: relay_block, deferred_to: relay_block, sender: para_id, xcm };
let deferred_xcm_messages = vec![deferred_message.clone(); max_messages];
crate::Pallet::<T>::inject_deferred_messages(para_id, deferred_xcm_messages.try_into().unwrap());
assert_eq!(crate::Pallet::<T>::deferred_messages(para_id).len(), max_messages);
crate::Pallet::<T>::inject_deferred_messages(para_id, (relay_block, 0), deferred_xcm_messages.try_into().unwrap());
let max_buckets = T::MaxDeferredBuckets::get();
let indices: Vec<DeferredIndex> = (1..(max_buckets)).map(|i| (relay_block, i as u16)).collect();
crate::Pallet::<T>::inject_bare_deferred_indices(para_id, indices);
assert_eq!(crate::Pallet::<T>::messages_deferred_to(para_id, (relay_block, 0)).len(), max_messages);
assert_eq!(crate::Pallet::<T>::deferred_indices(para_id).len(), max_buckets as usize);
// TODO: figure out how to get the weight of the xcm in a production runtime (Weigher not available)
let weight = Weight::from_parts(1_000_000 - 1_000, 1024);
assert!(crate::Pallet::<T>::update_xcmp_max_individual_weight(RawOrigin::Root.into(), weight).is_ok());
} :_(RawOrigin::Root, weight, para_id)
// account for the reads induced by trying to execute all `max_messages`
let weight_limit = weight.saturating_add(T::DbWeight::get().reads_writes(max_messages as u64 + 2, 2));
} :_(RawOrigin::Root, weight_limit, para_id)
verify
{
assert_eq!(crate::Pallet::<T>::deferred_messages(para_id).len(), 0);
assert_eq!(crate::Pallet::<T>::messages_deferred_to(para_id, (relay_block, 0)).len(), 0);
assert_eq!(crate::Pallet::<T>::deferred_indices(para_id).len(), max_buckets as usize - 1);
// worst case is placing the message in overweight, so check that they end up there
assert!(Overweight::<T>::contains_key(0));
assert!(Overweight::<T>::contains_key((max_messages - 1) as u64));
}
discard_deferred {
discard_deferred_bucket {
let para_id = ParaId::from(999);

let xcm = construct_xcm::<T::RuntimeCall>();
Expand All @@ -77,12 +85,57 @@ benchmarks! {
let max_messages = T::MaxDeferredMessages::get() as usize;
let deferred_message = DeferredMessage { sent_at, deferred_to, sender: para_id, xcm };
let deferred_xcm_messages = vec![deferred_message.clone(); max_messages];
crate::Pallet::<T>::inject_deferred_messages(para_id, deferred_xcm_messages.try_into().unwrap());
assert_eq!(crate::Pallet::<T>::deferred_messages(para_id).len(), max_messages);
} :_(RawOrigin::Root, para_id, sent_at, Some(deferred_to), Some(hash))
crate::Pallet::<T>::inject_deferred_messages(para_id, (deferred_to, 0), deferred_xcm_messages.try_into().unwrap());
assert_eq!(crate::Pallet::<T>::messages_deferred_to(para_id, (deferred_to, 0)).len(), max_messages);
} :discard_deferred(RawOrigin::Root, para_id, (deferred_to, 0), None)
verify
{
assert_eq!(crate::Pallet::<T>::deferred_messages(para_id).len(), 0);
assert_eq!(crate::Pallet::<T>::messages_deferred_to(para_id, (deferred_to, 0)).len(), 0);
}
discard_deferred_individual {
let para_id = ParaId::from(999);

let xcm = construct_xcm::<T::RuntimeCall>();
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);

let sent_at = 1;
let deferred_to = 6;
let max_messages = T::MaxDeferredMessages::get() as usize;
let deferred_message = DeferredMessage { sent_at, deferred_to, sender: para_id, xcm };
let deferred_xcm_messages = vec![deferred_message.clone(); max_messages];
crate::Pallet::<T>::inject_deferred_messages(para_id, (deferred_to, 0), deferred_xcm_messages.try_into().unwrap());
assert_eq!(crate::Pallet::<T>::messages_deferred_to(para_id, (deferred_to, 0)).len(), max_messages);
} :discard_deferred(RawOrigin::Root, para_id, (deferred_to, 0), Some(max_messages as u32 - 1))
verify
{
let messages = crate::Pallet::<T>::messages_deferred_to(para_id, (deferred_to, 0));
assert_eq!(messages.len(), max_messages);
assert_eq!(messages[max_messages - 1], None);
}
try_place_in_deferred_queue {
let para_id = ParaId::from(999);

let xcm = construct_xcm::<T::RuntimeCall>();

let max_messages = T::MaxDeferredMessages::get() as usize;
let relay_block = T::RelayChainBlockNumberProvider::current_block_number();
let max_buckets = T::MaxDeferredBuckets::get();
let indices: Vec<DeferredIndex> = (0..(max_buckets-1)).map(|i| (relay_block, i as u16)).collect();
crate::Pallet::<T>::inject_bare_deferred_indices(para_id, indices);
// We set the `deferred_to` to some time in the future.
let deferred_to = relay_block.saturating_add(20);
let deferred_message = DeferredMessage { sent_at: relay_block, deferred_to, sender: para_id, xcm };
let num_injected = max_messages.saturating_sub(1);
let deferred_xcm_messages = vec![deferred_message.clone(); num_injected];
let index = (deferred_to, max_buckets as u16);
crate::Pallet::<T>::inject_deferred_messages(para_id, index, deferred_xcm_messages.try_into().unwrap());
assert_eq!(crate::Pallet::<T>::messages_deferred_to(para_id, index).len(), num_injected);
assert_eq!(crate::Pallet::<T>::deferred_indices(para_id).len(), max_buckets as usize);
} :{ crate::Pallet::<T>::try_place_in_deferred_queue(para_id, deferred_to, deferred_message).unwrap(); }
verify
{
assert_eq!(crate::Pallet::<T>::messages_deferred_to(para_id, index).len(), max_messages);
assert_eq!(crate::Pallet::<T>::deferred_indices(para_id).len(), max_buckets as usize);
}
}

Expand Down
Loading

0 comments on commit bc34ec3

Please sign in to comment.