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

Commit

Permalink
Replace system config Index for Nonce (#14290)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
juangirini authored and EgorPopelyaev committed Jul 18, 2023
1 parent e13ce1c commit 6b5e144
Show file tree
Hide file tree
Showing 132 changed files with 234 additions and 235 deletions.
4 changes: 2 additions & 2 deletions bin/node-template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use std::sync::Arc;

use jsonrpsee::RpcModule;
use node_template_runtime::{opaque::Block, AccountId, Balance, Index};
use node_template_runtime::{opaque::Block, AccountId, Balance, Nonce};
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
Expand All @@ -34,7 +34,7 @@ where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
C: Send + Sync + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + 'static,
Expand Down
2 changes: 1 addition & 1 deletion bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
Expand Down
10 changes: 5 additions & 5 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account
pub type Balance = u128;

/// Index of a transaction in the chain.
pub type Index = u32;
pub type Nonce = u32;

/// A hash of some data used by the chain.
pub type Hash = sp_core::H256;
Expand Down Expand Up @@ -167,8 +167,8 @@ impl frame_system::Config for Runtime {
type RuntimeCall = RuntimeCall;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The type for storing how many extrinsics an account has signed.
type Nonce = Nonce;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
Expand Down Expand Up @@ -455,8 +455,8 @@ impl_runtime_apis! {
}
}

impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(account: AccountId) -> Index {
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
fn account_nonce(account: AccountId) -> Nonce {
System::account_nonce(account)
}
}
Expand Down
18 changes: 9 additions & 9 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn panic_execution_with_foreign_code_gives_error() {
let mut t = new_test_ext(bloaty_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
providers: 1,
data: (69u128, 0u128, 0u128, 1u128 << 127),
..Default::default()
Expand All @@ -209,7 +209,7 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
let mut t = new_test_ext(compact_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
providers: 1,
data: (69u128, 0u128, 0u128, 1u128 << 127),
..Default::default()
Expand All @@ -235,7 +235,7 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
let mut t = new_test_ext(compact_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
providers: 1,
data: (111 * DOLLARS, 0u128, 0u128, 1u128 << 127),
..Default::default()
Expand All @@ -245,7 +245,7 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
AccountInfo::<
<Runtime as frame_system::Config>::Index,
<Runtime as frame_system::Config>::Nonce,
<Runtime as frame_system::Config>::AccountData,
>::default()
.encode(),
Expand Down Expand Up @@ -277,7 +277,7 @@ fn successful_execution_with_foreign_code_gives_ok() {
let mut t = new_test_ext(bloaty_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
providers: 1,
data: (111 * DOLLARS, 0u128, 0u128, 1u128 << 127),
..Default::default()
Expand All @@ -287,7 +287,7 @@ fn successful_execution_with_foreign_code_gives_ok() {
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
AccountInfo::<
<Runtime as frame_system::Config>::Index,
<Runtime as frame_system::Config>::Nonce,
<Runtime as frame_system::Config>::AccountData,
>::default()
.encode(),
Expand Down Expand Up @@ -766,7 +766,7 @@ fn panic_execution_gives_error() {
let mut t = new_test_ext(bloaty_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
data: (0 * DOLLARS, 0u128, 0u128, 0u128),
..Default::default()
}
Expand Down Expand Up @@ -795,7 +795,7 @@ fn successful_execution_gives_ok() {
let mut t = new_test_ext(compact_code_unwrap());
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
providers: 1,
data: (111 * DOLLARS, 0u128, 0u128, 1u128 << 127),
..Default::default()
Expand All @@ -805,7 +805,7 @@ fn successful_execution_gives_ok() {
t.insert(
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
AccountInfo::<
<Runtime as frame_system::Config>::Index,
<Runtime as frame_system::Config>::Nonce,
<Runtime as frame_system::Config>::AccountData,
>::default()
.encode(),
Expand Down
10 changes: 5 additions & 5 deletions bin/node/executor/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn transaction_fee_is_correct() {
fn block_weight_capacity_report() {
// Just report how many transfer calls you could fit into a block. The number should at least
// be a few hundred (250 at the time of writing but can change over time). Runs until panic.
use node_primitives::Index;
use node_primitives::Nonce;

// execution ext.
let mut t = new_test_ext(compact_code_unwrap());
Expand All @@ -205,15 +205,15 @@ fn block_weight_capacity_report() {

let factor = 50;
let mut time = 10;
let mut nonce: Index = 0;
let mut nonce: Nonce = 0;
let mut block_number = 1;
let mut previous_hash: node_primitives::Hash = GENESIS_HASH.into();

loop {
let num_transfers = block_number * factor;
let mut xts = (0..num_transfers)
.map(|i| CheckedExtrinsic {
signed: Some((charlie(), signed_extra(nonce + i as Index, 0))),
signed: Some((charlie(), signed_extra(nonce + i as Nonce, 0))),
function: RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death {
dest: bob().into(),
value: 0,
Expand Down Expand Up @@ -266,7 +266,7 @@ fn block_length_capacity_report() {
// Just report how big a block can get. Executes until panic. Should be ignored unless if
// manually inspected. The number should at least be a few megabytes (5 at the time of
// writing but can change over time).
use node_primitives::Index;
use node_primitives::Nonce;

// execution ext.
let mut t = new_test_ext(compact_code_unwrap());
Expand All @@ -275,7 +275,7 @@ fn block_length_capacity_report() {

let factor = 256 * 1024;
let mut time = 10;
let mut nonce: Index = 0;
let mut nonce: Nonce = 0;
let mut block_number = 1;
let mut previous_hash: node_primitives::Hash = GENESIS_HASH.into();

Expand Down
2 changes: 1 addition & 1 deletion bin/node/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub type Balance = u128;
pub type Moment = u64;

/// Index of a transaction in the chain.
pub type Index = u32;
pub type Nonce = u32;

/// A hash of some data used by the chain.
pub type Hash = sp_core::H256;
Expand Down
4 changes: 2 additions & 2 deletions bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
use std::sync::Arc;

use jsonrpsee::RpcModule;
use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index};
use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Nonce};
use sc_client_api::AuxStore;
use sc_consensus_babe::BabeWorkerHandle;
use sc_consensus_grandpa::{
Expand Down Expand Up @@ -117,7 +117,7 @@ where
+ Sync
+ Send
+ 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: mmr_rpc::MmrRuntimeApi<Block, <Block as sp_runtime::traits::Block>::Hash, BlockNumber>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>,
Expand Down
10 changes: 5 additions & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use frame_system::{
EnsureRoot, EnsureRootWithSuccess, EnsureSigned, EnsureSignedBy, EnsureWithSuccess,
};
pub use node_primitives::{AccountId, Signature};
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce};
use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter};
#[cfg(feature = "runtime-benchmarks")]
use pallet_contracts::NoopMigration;
Expand Down Expand Up @@ -226,7 +226,7 @@ impl frame_system::Config for Runtime {
type DbWeight = RocksDbWeight;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = Index;
type Nonce = Nonce;
type Hash = Hash;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
Expand Down Expand Up @@ -1279,7 +1279,7 @@ where
call: RuntimeCall,
public: <Signature as traits::Verify>::Signer,
account: AccountId,
nonce: Index,
nonce: Nonce,
) -> Option<(RuntimeCall, <UncheckedExtrinsic as traits::Extrinsic>::SignaturePayload)> {
let tip = 0;
// take the biggest period possible.
Expand Down Expand Up @@ -2254,8 +2254,8 @@ impl_runtime_apis! {
}
}

impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(account: AccountId) -> Index {
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
fn account_nonce(account: AccountId) -> Nonce {
System::account_nonce(account)
}
}
Expand Down
4 changes: 2 additions & 2 deletions bin/node/testing/src/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use codec::Encode;
use kitchensink_runtime::{CheckedExtrinsic, SessionKeys, SignedExtra, UncheckedExtrinsic};
use node_primitives::{AccountId, Balance, Index};
use node_primitives::{AccountId, Balance, Nonce};
use sp_keyring::{AccountKeyring, Ed25519Keyring, Sr25519Keyring};
use sp_runtime::generic::Era;

Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn to_session_keys(
}

/// Returns transaction extra.
pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
pub fn signed_extra(nonce: Nonce, extra_fee: Balance) -> SignedExtra {
(
frame_system::CheckNonZeroSender::new(),
frame_system::CheckSpecVersion::new(),
Expand Down
8 changes: 4 additions & 4 deletions client/transaction-pool/tests/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use sp_runtime::{
};
use std::{collections::BTreeSet, pin::Pin, sync::Arc};
use substrate_test_runtime_client::{
runtime::{Block, Extrinsic, ExtrinsicBuilder, Hash, Header, Index, Transfer, TransferData},
runtime::{Block, Extrinsic, ExtrinsicBuilder, Hash, Header, Nonce, Transfer, TransferData},
AccountKeyring::*,
ClientBlockImportExt,
};
Expand Down Expand Up @@ -119,7 +119,7 @@ fn early_nonce_should_be_culled() {
.ready()
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
.collect();
assert_eq!(pending, Vec::<Index>::new());
assert_eq!(pending, Vec::<Nonce>::new());
}

#[test]
Expand All @@ -132,7 +132,7 @@ fn late_nonce_should_be_queued() {
.ready()
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
.collect();
assert_eq!(pending, Vec::<Index>::new());
assert_eq!(pending, Vec::<Nonce>::new());

block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt(Alice, 209))).unwrap();
let pending: Vec<_> = pool
Expand Down Expand Up @@ -182,7 +182,7 @@ fn should_ban_invalid_transactions() {
.ready()
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
.collect();
assert_eq!(pending, Vec::<Index>::new());
assert_eq!(pending, Vec::<Nonce>::new());

// then
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt.clone())).unwrap_err();
Expand Down
2 changes: 1 addition & 1 deletion frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
Expand Down
2 changes: 1 addition & 1 deletion frame/asset-conversion/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u128;
Expand Down
2 changes: 1 addition & 1 deletion frame/asset-rate/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
Expand Down
2 changes: 1 addition & 1 deletion frame/assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
Expand Down
2 changes: 1 addition & 1 deletion frame/atomic-swap/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl frame_system::Config for Test {
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type Nonce = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
Expand Down
2 changes: 1 addition & 1 deletion frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl frame_system::Config for Test {
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type Nonce = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
Expand Down
2 changes: 1 addition & 1 deletion frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ mod tests {
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type Nonce = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
Expand Down
2 changes: 1 addition & 1 deletion frame/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ mod tests {
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type Nonce = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
Expand Down
2 changes: 1 addition & 1 deletion frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl frame_system::Config for Test {
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type Nonce = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Version = ();
Expand Down
2 changes: 1 addition & 1 deletion frame/bags-list/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl frame_system::Config for Runtime {
type SS58Prefix = ();
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type Nonce = u64;
type RuntimeCall = RuntimeCall;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
Expand Down
Loading

0 comments on commit 6b5e144

Please sign in to comment.