Replace system config Index for Nonce (#14290)

* replace Index by Nonce

* replace Index by Nonce

* replace Index by Nonce

* replace Index by Nonce

* replace Index by Nonce

* wip

* remove index in lieu of nonce

* wip

* remove accountnonce in lieu of nonce

* add minor improvement

* rebase and merge conflicts
This commit is contained in:
Juan
2023-07-14 08:56:48 +02:00
committed by GitHub
parent 0fbeb31d50
commit 6a29a70a92
132 changed files with 234 additions and 235 deletions
@@ -37,11 +37,11 @@ use sp_std::vec;
/// some kind of priority upon validating transactions.
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct CheckNonce<T: Config>(#[codec(compact)] pub T::Index);
pub struct CheckNonce<T: Config>(#[codec(compact)] pub T::Nonce);
impl<T: Config> CheckNonce<T> {
/// utility constructor. Used only in client/factory code.
pub fn from(nonce: T::Index) -> Self {
pub fn from(nonce: T::Nonce) -> Self {
Self(nonce)
}
}
@@ -88,7 +88,7 @@ where
}
.into())
}
account.nonce += T::Index::one();
account.nonce += T::Nonce::one();
crate::Account::<T>::insert(who, account);
Ok(())
}
+10 -11
View File
@@ -50,7 +50,7 @@
//! - [`CheckWeight`]: Checks the weight and length of the block and ensure that it does not
//! exceed the limits.
//! - [`CheckNonce`]: Checks the nonce of the transaction. Contains a single payload of type
//! `T::Index`.
//! `T::Nonce`.
//! - [`CheckEra`]: Checks the era of the transaction. Contains a single payload of type `Era`.
//! - [`CheckGenesis`]: Checks the provided genesis hash of the transaction. Must be a part of the
//! signed payload of the transaction.
@@ -217,7 +217,7 @@ pub mod pallet {
#[frame_support::register_default_impl(TestDefaultConfig)]
impl DefaultConfig for TestDefaultConfig {
type Index = u32;
type Nonce = u32;
type Hash = sp_core::hash::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
@@ -273,9 +273,8 @@ pub mod pallet {
+ Debug
+ From<Call<Self>>;
/// Account index (aka nonce) type. This stores the number of previous transactions
/// associated with a sender account.
type Index: Parameter
/// This stores the number of previous transactions associated with a sender account.
type Nonce: Parameter
+ Member
+ MaybeSerializeDeserialize
+ Debug
@@ -554,7 +553,7 @@ pub mod pallet {
_,
Blake2_128Concat,
T::AccountId,
AccountInfo<T::Index, T::AccountData>,
AccountInfo<T::Nonce, T::AccountData>,
ValueQuery,
>;
@@ -732,9 +731,9 @@ pub type RefCount = u32;
/// Information of an account.
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub struct AccountInfo<Index, AccountData> {
pub struct AccountInfo<Nonce, AccountData> {
/// The number of transactions this account has sent.
pub nonce: Index,
pub nonce: Nonce,
/// The number of other modules that currently depend on this account's existence. The account
/// cannot be reaped until this is zero.
pub consumers: RefCount,
@@ -1570,13 +1569,13 @@ impl<T: Config> Pallet<T> {
}
/// Retrieve the account transaction counter from storage.
pub fn account_nonce(who: impl EncodeLike<T::AccountId>) -> T::Index {
pub fn account_nonce(who: impl EncodeLike<T::AccountId>) -> T::Nonce {
Account::<T>::get(who).nonce
}
/// Increment a particular account's nonce by 1.
pub fn inc_account_nonce(who: impl EncodeLike<T::AccountId>) {
Account::<T>::mutate(who, |a| a.nonce += T::Index::one());
Account::<T>::mutate(who, |a| a.nonce += T::Nonce::one());
}
/// Note what the extrinsic data of the current extrinsic index is.
@@ -1632,7 +1631,7 @@ impl<T: Config> Pallet<T> {
}
/// An account is being created.
pub fn on_created_account(who: T::AccountId, _a: &mut AccountInfo<T::Index, T::AccountData>) {
pub fn on_created_account(who: T::AccountId, _a: &mut AccountInfo<T::Nonce, T::AccountData>) {
T::OnNewAccount::on_new_account(&who);
Self::deposit_event(Event::NewAccount { account: who });
}
+8 -8
View File
@@ -31,8 +31,8 @@ type RefCount = u32;
/// Information of an account.
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode)]
struct AccountInfo<Index, AccountData> {
nonce: Index,
struct AccountInfo<Nonce, AccountData> {
nonce: Nonce,
consumers: RefCount,
providers: RefCount,
sufficients: RefCount,
@@ -47,8 +47,8 @@ pub trait V2ToV3 {
/// System config account id
type AccountId: 'static + FullCodec;
/// System config index
type Index: 'static + FullCodec + Copy;
/// System config nonce
type Nonce: 'static + FullCodec + Copy;
/// System config account data
type AccountData: 'static + FullCodec;
@@ -65,13 +65,13 @@ type Account<V, T: Config> = StorageMap<
Pallet<T>,
Blake2_128Concat,
<V as V2ToV3>::AccountId,
AccountInfo<<V as V2ToV3>::Index, <V as V2ToV3>::AccountData>,
AccountInfo<<V as V2ToV3>::Nonce, <V as V2ToV3>::AccountData>,
>;
/// Migrate from unique `u8` reference counting to triple `u32` reference counting.
pub fn migrate_from_single_u8_to_triple_ref_count<V: V2ToV3, T: Config>() -> Weight {
let mut translated: usize = 0;
<Account<V, T>>::translate::<(V::Index, u8, V::AccountData), _>(|_key, (nonce, rc, data)| {
<Account<V, T>>::translate::<(V::Nonce, u8, V::AccountData), _>(|_key, (nonce, rc, data)| {
translated += 1;
Some(AccountInfo { nonce, consumers: rc as RefCount, providers: 1, sufficients: 0, data })
});
@@ -88,7 +88,7 @@ pub fn migrate_from_single_u8_to_triple_ref_count<V: V2ToV3, T: Config>() -> Wei
/// Migrate from unique `u32` reference counting to triple `u32` reference counting.
pub fn migrate_from_single_to_triple_ref_count<V: V2ToV3, T: Config>() -> Weight {
let mut translated: usize = 0;
<Account<V, T>>::translate::<(V::Index, RefCount, V::AccountData), _>(
<Account<V, T>>::translate::<(V::Nonce, RefCount, V::AccountData), _>(
|_key, (nonce, consumers, data)| {
translated += 1;
Some(AccountInfo { nonce, consumers, providers: 1, sufficients: 0, data })
@@ -106,7 +106,7 @@ pub fn migrate_from_single_to_triple_ref_count<V: V2ToV3, T: Config>() -> Weight
/// Migrate from dual `u32` reference counting to triple `u32` reference counting.
pub fn migrate_from_dual_to_triple_ref_count<V: V2ToV3, T: Config>() -> Weight {
let mut translated: usize = 0;
<Account<V, T>>::translate::<(V::Index, RefCount, RefCount, V::AccountData), _>(
<Account<V, T>>::translate::<(V::Nonce, RefCount, RefCount, V::AccountData), _>(
|_key, (nonce, consumers, providers, data)| {
translated += 1;
Some(AccountInfo { nonce, consumers, providers, sufficients: 0, data })
+1 -1
View File
@@ -91,7 +91,7 @@ impl Config for Test {
type BlockLength = RuntimeBlockLength;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
+1 -1
View File
@@ -486,7 +486,7 @@ pub trait CreateSignedTransaction<LocalCall>:
call: Self::OverarchingCall,
public: Self::Public,
account: Self::AccountId,
nonce: Self::Index,
nonce: Self::Nonce,
) -> Option<(Self::OverarchingCall, <Self::Extrinsic as ExtrinsicT>::SignaturePayload)>;
}