mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 18:35:41 +00:00
contracts: Add test to verify unique trie ids (#10914)
* Add test to verify unique trie ids * Rename trie_seed to nonce * Rename AccountCounter -> Nonce * fmt
This commit is contained in:
committed by
GitHub
parent
18aef02e87
commit
bef9b79d7b
@@ -134,7 +134,7 @@ type BalanceOf<T> =
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
|
||||
/// The current storage version.
|
||||
const STORAGE_VERSION: StorageVersion = StorageVersion::new(6);
|
||||
const STORAGE_VERSION: StorageVersion = StorageVersion::new(7);
|
||||
|
||||
/// Used as a sentinel value when reading and writing contract memory.
|
||||
///
|
||||
@@ -665,9 +665,30 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
pub(crate) type OwnerInfoOf<T: Config> = StorageMap<_, Identity, CodeHash<T>, OwnerInfo<T>>;
|
||||
|
||||
/// The subtrie counter.
|
||||
/// This is a **monotonic** counter incremented on contract instantiation.
|
||||
///
|
||||
/// This is used in order to generate unique trie ids for contracts.
|
||||
/// The trie id of a new contract is calculated from hash(account_id, nonce).
|
||||
/// The nonce is required because otherwise the following sequence would lead to
|
||||
/// a possible collision of storage:
|
||||
///
|
||||
/// 1. Create a new contract.
|
||||
/// 2. Terminate the contract.
|
||||
/// 3. Immediately recreate the contract with the same account_id.
|
||||
///
|
||||
/// This is bad because the contents of a trie are deleted lazily and there might be
|
||||
/// storage of the old instantiation still in it when the new contract is created. Please
|
||||
/// note that we can't replace the counter by the block number because the sequence above
|
||||
/// can happen in the same block. We also can't keep the account counter in memory only
|
||||
/// because storage is the only way to communicate across different extrinsics in the
|
||||
/// same block.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// Do not use it to determine the number of contracts. It won't be decremented if
|
||||
/// a contract is destroyed.
|
||||
#[pallet::storage]
|
||||
pub(crate) type AccountCounter<T: Config> = StorageValue<_, u64, ValueQuery>;
|
||||
pub(crate) type Nonce<T: Config> = StorageValue<_, u64, ValueQuery>;
|
||||
|
||||
/// The code associated with a given account.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user