Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
github PR commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Mar 30, 2023
1 parent 0b985aa commit dedef69
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ pub mod pallet {
/// A pair of monotonic counters used to track the latest contract marked for deletion
/// and the latest deleted contract in DeletionQueueMap.
///
/// When we iterate the map to remove contracts, we simply use the `delete_nonce` counter and
/// When we iterate the map to remove contracts, we simply use the delete counter and
/// don't pay the cost of an extra call to `sp_io::storage::next_key` to lookup the next entry
/// in the map
#[pallet::storage]
Expand Down
32 changes: 16 additions & 16 deletions frame/contracts/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub mod meter;
use crate::{
exec::{AccountIdOf, Key},
weights::WeightInfo,
AddressGenerator, BalanceOf, CodeHash, Config, ContractInfoOf, DeletionQueueMap,
DeletionQueueNonces, Error, Pallet, TrieId, SENTINEL,
AddressGenerator, BalanceOf, CodeHash, Config, ContractInfoOf,
DeletionQueue as DeletionQueueMap, DeletionQueueCounter, Error, Pallet, TrieId, SENTINEL,
};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
Expand Down Expand Up @@ -337,10 +337,10 @@ impl<T: Config> Deref for DepositAccount<T> {
#[derive(Encode, Decode, TypeInfo, MaxEncodedLen, DefaultNoBound, Clone)]
#[scale_info(skip_type_params(T))]
pub struct DeletionQueue<T: Config> {
/// Monotonic counter used as a key for inserting a new deleted contract in the DeletionQueueMap.
/// Monotonic counter used as a key for inserting a new deleted contract in the queue.
/// The counter is incremented after each insertion.
insert_counter: u32,
/// The index used to read the next element to be deleted in the DeletionQueueMap.
/// The index used to read the next element to be deleted in the queue.
/// The counter is incremented after each deletion.
delete_counter: u32,

Expand All @@ -358,29 +358,29 @@ struct DeletionQueueEntry<'a, T: Config> {
impl<'a, T: Config> DeletionQueueEntry<'a, T> {
/// Remove the contract from the deletion queue.
fn remove(self) {
<DeletionQueueMap<T>>::remove(self.queue.delete_nonce);
self.queue.delete_nonce = self.queue.delete_nonce.wrapping_add(1);
<DeletionQueueNonces<T>>::set(self.queue.clone());
<DeletionQueueMap<T>>::remove(self.queue.delete_counter);
self.queue.delete_counter = self.queue.delete_counter.wrapping_add(1);
<DeletionQueueCounter<T>>::set(self.queue.clone());
}
}

impl<T: Config> DeletionQueue<T> {
/// Load the Deletion Queue nonces, so we can perform read or write operations on the
/// DeletionQueueMap storage.
fn load() -> Self {
<DeletionQueueNonces<T>>::get()
<DeletionQueueCounter<T>>::get()
}

/// Returns `true` if the queue contains no elements.
fn is_empty(&self) -> bool {
self.insert_nonce.wrapping_sub(self.delete_nonce) == 0
self.insert_index.wrapping_sub(self.delete_counter) == 0
}

/// Insert a contract in the deletion queue.
fn insert(&mut self, trie_id: TrieId) {
<DeletionQueueMap<T>>::insert(self.insert_nonce, trie_id);
self.insert_nonce = self.insert_nonce.wrapping_add(1);
<DeletionQueueNonces<T>>::set(self.clone());
<DeletionQueueMap<T>>::insert(self.insert_index, trie_id);
self.insert_index = self.insert_index.wrapping_add(1);
<DeletionQueueCounter<T>>::set(self.clone());
}

/// Fetch the next contract to be deleted.
Expand All @@ -389,17 +389,17 @@ impl<T: Config> DeletionQueue<T> {
return None
}

let entry = <DeletionQueueMap<T>>::get(self.delete_nonce);
let entry = <DeletionQueueMap<T>>::get(self.delete_counter);
entry.map(|trie_id| DeletionQueueEntry { trie_id, queue: self })
}
}

#[cfg(test)]
impl<T: Config> DeletionQueue<T> {
pub fn from_test_values(insert_nonce: u32, delete_nonce: u32) -> Self {
DeletionQueue { insert_nonce, delete_nonce, _phantom: Default::default() }
pub fn from_test_values(insert_index: u32, delete_counter: u32) -> Self {
Self { insert_index, delete_counter, _phantom: Default::default() }
}
pub fn as_test_tuple(&self) -> (u32, u32) {
(self.insert_nonce, self.delete_nonce)
(self.insert_index, self.delete_counter)
}
}
6 changes: 3 additions & 3 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
wasm::{Determinism, PrefabWasmModule, ReturnCode as RuntimeReturnCode},
weights::WeightInfo,
BalanceOf, Code, CodeStorage, Config, ContractInfo, ContractInfoOf, DefaultAddressGenerator,
DeletionQueueNonces, Error, Pallet, Schedule,
DeletionQueueCounter, Error, Pallet, Schedule,
};
use assert_matches::assert_matches;
use codec::Encode;
Expand Down Expand Up @@ -2274,7 +2274,7 @@ fn deletion_queue_ring_buffer_overflow() {
ext.execute_with(|| {
// manually se the nonces of the deletion queue
let queue = DeletionQueue::from_test_values(u32::MAX - 1, u32::MAX - 1);
<DeletionQueueNonces<Test>>::set(queue);
<DeletionQueueCounter<Test>>::set(queue);
});

// commit the changes to the storage
Expand Down Expand Up @@ -2333,7 +2333,7 @@ fn deletion_queue_ring_buffer_overflow() {
}

// nonces values should go from u32::MAX - 1 to 1
assert_eq!(<DeletionQueueNonces<Test>>::get().as_test_tuple(), (1, 1));
assert_eq!(<DeletionQueueCounter<Test>>::get().as_test_tuple(), (1, 1));
})
}
#[test]
Expand Down
16 changes: 8 additions & 8 deletions frame/contracts/src/weights.rs

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

0 comments on commit dedef69

Please sign in to comment.