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

Commit 6b5e144

Browse files
juangiriniEgorPopelyaev
authored andcommitted
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
1 parent e13ce1c commit 6b5e144

File tree

132 files changed

+234
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+234
-235
lines changed

bin/node-template/node/src/rpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use std::sync::Arc;
99

1010
use jsonrpsee::RpcModule;
11-
use node_template_runtime::{opaque::Block, AccountId, Balance, Index};
11+
use node_template_runtime::{opaque::Block, AccountId, Balance, Nonce};
1212
use sc_transaction_pool_api::TransactionPool;
1313
use sp_api::ProvideRuntimeApi;
1414
use sp_block_builder::BlockBuilder;
@@ -34,7 +34,7 @@ where
3434
C: ProvideRuntimeApi<Block>,
3535
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
3636
C: Send + Sync + 'static,
37-
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
37+
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
3838
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
3939
C::Api: BlockBuilder<Block>,
4040
P: TransactionPool + 'static,

bin/node-template/pallets/template/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl frame_system::Config for Test {
2424
type DbWeight = ();
2525
type RuntimeOrigin = RuntimeOrigin;
2626
type RuntimeCall = RuntimeCall;
27-
type Index = u64;
27+
type Nonce = u64;
2828
type Hash = H256;
2929
type Hashing = BlakeTwo256;
3030
type AccountId = u64;

bin/node-template/runtime/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account
6363
pub type Balance = u128;
6464

6565
/// Index of a transaction in the chain.
66-
pub type Index = u32;
66+
pub type Nonce = u32;
6767

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

458-
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
459-
fn account_nonce(account: AccountId) -> Index {
458+
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
459+
fn account_nonce(account: AccountId) -> Nonce {
460460
System::account_nonce(account)
461461
}
462462
}

bin/node/executor/tests/basic.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn panic_execution_with_foreign_code_gives_error() {
183183
let mut t = new_test_ext(bloaty_code_unwrap());
184184
t.insert(
185185
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
186-
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
186+
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
187187
providers: 1,
188188
data: (69u128, 0u128, 0u128, 1u128 << 127),
189189
..Default::default()
@@ -209,7 +209,7 @@ fn bad_extrinsic_with_native_equivalent_code_gives_error() {
209209
let mut t = new_test_ext(compact_code_unwrap());
210210
t.insert(
211211
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
212-
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
212+
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
213213
providers: 1,
214214
data: (69u128, 0u128, 0u128, 1u128 << 127),
215215
..Default::default()
@@ -235,7 +235,7 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
235235
let mut t = new_test_ext(compact_code_unwrap());
236236
t.insert(
237237
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
238-
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
238+
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
239239
providers: 1,
240240
data: (111 * DOLLARS, 0u128, 0u128, 1u128 << 127),
241241
..Default::default()
@@ -245,7 +245,7 @@ fn successful_execution_with_native_equivalent_code_gives_ok() {
245245
t.insert(
246246
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
247247
AccountInfo::<
248-
<Runtime as frame_system::Config>::Index,
248+
<Runtime as frame_system::Config>::Nonce,
249249
<Runtime as frame_system::Config>::AccountData,
250250
>::default()
251251
.encode(),
@@ -277,7 +277,7 @@ fn successful_execution_with_foreign_code_gives_ok() {
277277
let mut t = new_test_ext(bloaty_code_unwrap());
278278
t.insert(
279279
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
280-
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
280+
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
281281
providers: 1,
282282
data: (111 * DOLLARS, 0u128, 0u128, 1u128 << 127),
283283
..Default::default()
@@ -287,7 +287,7 @@ fn successful_execution_with_foreign_code_gives_ok() {
287287
t.insert(
288288
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
289289
AccountInfo::<
290-
<Runtime as frame_system::Config>::Index,
290+
<Runtime as frame_system::Config>::Nonce,
291291
<Runtime as frame_system::Config>::AccountData,
292292
>::default()
293293
.encode(),
@@ -766,7 +766,7 @@ fn panic_execution_gives_error() {
766766
let mut t = new_test_ext(bloaty_code_unwrap());
767767
t.insert(
768768
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
769-
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
769+
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
770770
data: (0 * DOLLARS, 0u128, 0u128, 0u128),
771771
..Default::default()
772772
}
@@ -795,7 +795,7 @@ fn successful_execution_gives_ok() {
795795
let mut t = new_test_ext(compact_code_unwrap());
796796
t.insert(
797797
<frame_system::Account<Runtime>>::hashed_key_for(alice()),
798-
AccountInfo::<<Runtime as frame_system::Config>::Index, _> {
798+
AccountInfo::<<Runtime as frame_system::Config>::Nonce, _> {
799799
providers: 1,
800800
data: (111 * DOLLARS, 0u128, 0u128, 1u128 << 127),
801801
..Default::default()
@@ -805,7 +805,7 @@ fn successful_execution_gives_ok() {
805805
t.insert(
806806
<frame_system::Account<Runtime>>::hashed_key_for(bob()),
807807
AccountInfo::<
808-
<Runtime as frame_system::Config>::Index,
808+
<Runtime as frame_system::Config>::Nonce,
809809
<Runtime as frame_system::Config>::AccountData,
810810
>::default()
811811
.encode(),

bin/node/executor/tests/fees.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn transaction_fee_is_correct() {
196196
fn block_weight_capacity_report() {
197197
// Just report how many transfer calls you could fit into a block. The number should at least
198198
// be a few hundred (250 at the time of writing but can change over time). Runs until panic.
199-
use node_primitives::Index;
199+
use node_primitives::Nonce;
200200

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

206206
let factor = 50;
207207
let mut time = 10;
208-
let mut nonce: Index = 0;
208+
let mut nonce: Nonce = 0;
209209
let mut block_number = 1;
210210
let mut previous_hash: node_primitives::Hash = GENESIS_HASH.into();
211211

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

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

276276
let factor = 256 * 1024;
277277
let mut time = 10;
278-
let mut nonce: Index = 0;
278+
let mut nonce: Nonce = 0;
279279
let mut block_number = 1;
280280
let mut previous_hash: node_primitives::Hash = GENESIS_HASH.into();
281281

bin/node/primitives/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub type Balance = u128;
4646
pub type Moment = u64;
4747

4848
/// Index of a transaction in the chain.
49-
pub type Index = u32;
49+
pub type Nonce = u32;
5050

5151
/// A hash of some data used by the chain.
5252
pub type Hash = sp_core::H256;

bin/node/rpc/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
use std::sync::Arc;
3535

3636
use jsonrpsee::RpcModule;
37-
use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index};
37+
use node_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Nonce};
3838
use sc_client_api::AuxStore;
3939
use sc_consensus_babe::BabeWorkerHandle;
4040
use sc_consensus_grandpa::{
@@ -117,7 +117,7 @@ where
117117
+ Sync
118118
+ Send
119119
+ 'static,
120-
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
120+
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
121121
C::Api: mmr_rpc::MmrRuntimeApi<Block, <Block as sp_runtime::traits::Block>::Hash, BlockNumber>,
122122
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
123123
C::Api: BabeApi<Block>,

bin/node/runtime/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use frame_system::{
5353
EnsureRoot, EnsureRootWithSuccess, EnsureSigned, EnsureSignedBy, EnsureWithSuccess,
5454
};
5555
pub use node_primitives::{AccountId, Signature};
56-
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
56+
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce};
5757
use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter};
5858
#[cfg(feature = "runtime-benchmarks")]
5959
use pallet_contracts::NoopMigration;
@@ -226,7 +226,7 @@ impl frame_system::Config for Runtime {
226226
type DbWeight = RocksDbWeight;
227227
type RuntimeOrigin = RuntimeOrigin;
228228
type RuntimeCall = RuntimeCall;
229-
type Index = Index;
229+
type Nonce = Nonce;
230230
type Hash = Hash;
231231
type Hashing = BlakeTwo256;
232232
type AccountId = AccountId;
@@ -1279,7 +1279,7 @@ where
12791279
call: RuntimeCall,
12801280
public: <Signature as traits::Verify>::Signer,
12811281
account: AccountId,
1282-
nonce: Index,
1282+
nonce: Nonce,
12831283
) -> Option<(RuntimeCall, <UncheckedExtrinsic as traits::Extrinsic>::SignaturePayload)> {
12841284
let tip = 0;
12851285
// take the biggest period possible.
@@ -2254,8 +2254,8 @@ impl_runtime_apis! {
22542254
}
22552255
}
22562256

2257-
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
2258-
fn account_nonce(account: AccountId) -> Index {
2257+
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
2258+
fn account_nonce(account: AccountId) -> Nonce {
22592259
System::account_nonce(account)
22602260
}
22612261
}

bin/node/testing/src/keyring.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
use codec::Encode;
2222
use kitchensink_runtime::{CheckedExtrinsic, SessionKeys, SignedExtra, UncheckedExtrinsic};
23-
use node_primitives::{AccountId, Balance, Index};
23+
use node_primitives::{AccountId, Balance, Nonce};
2424
use sp_keyring::{AccountKeyring, Ed25519Keyring, Sr25519Keyring};
2525
use sp_runtime::generic::Era;
2626

@@ -68,7 +68,7 @@ pub fn to_session_keys(
6868
}
6969

7070
/// Returns transaction extra.
71-
pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
71+
pub fn signed_extra(nonce: Nonce, extra_fee: Balance) -> SignedExtra {
7272
(
7373
frame_system::CheckNonZeroSender::new(),
7474
frame_system::CheckSpecVersion::new(),

client/transaction-pool/tests/pool.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use sp_runtime::{
3939
};
4040
use std::{collections::BTreeSet, pin::Pin, sync::Arc};
4141
use substrate_test_runtime_client::{
42-
runtime::{Block, Extrinsic, ExtrinsicBuilder, Hash, Header, Index, Transfer, TransferData},
42+
runtime::{Block, Extrinsic, ExtrinsicBuilder, Hash, Header, Nonce, Transfer, TransferData},
4343
AccountKeyring::*,
4444
ClientBlockImportExt,
4545
};
@@ -119,7 +119,7 @@ fn early_nonce_should_be_culled() {
119119
.ready()
120120
.map(|a| TransferData::try_from(&a.data).unwrap().nonce)
121121
.collect();
122-
assert_eq!(pending, Vec::<Index>::new());
122+
assert_eq!(pending, Vec::<Nonce>::new());
123123
}
124124

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

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

187187
// then
188188
block_on(pool.submit_one(&BlockId::number(0), SOURCE, uxt.clone())).unwrap_err();

frame/alliance/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl frame_system::Config for Test {
5151
type BlockLength = ();
5252
type RuntimeOrigin = RuntimeOrigin;
5353
type RuntimeCall = RuntimeCall;
54-
type Index = u64;
54+
type Nonce = u64;
5555
type Hash = H256;
5656
type Hashing = BlakeTwo256;
5757
type AccountId = AccountId;

frame/asset-conversion/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl frame_system::Config for Test {
5353
type BlockLength = ();
5454
type RuntimeOrigin = RuntimeOrigin;
5555
type RuntimeCall = RuntimeCall;
56-
type Index = u64;
56+
type Nonce = u64;
5757
type Hash = H256;
5858
type Hashing = BlakeTwo256;
5959
type AccountId = u128;

frame/asset-rate/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl frame_system::Config for Test {
4343
type DbWeight = ();
4444
type RuntimeOrigin = RuntimeOrigin;
4545
type RuntimeCall = RuntimeCall;
46-
type Index = u64;
46+
type Nonce = u64;
4747
type Hash = H256;
4848
type Hashing = BlakeTwo256;
4949
type AccountId = u64;

frame/assets/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl frame_system::Config for Test {
5252
type BlockLength = ();
5353
type RuntimeOrigin = RuntimeOrigin;
5454
type RuntimeCall = RuntimeCall;
55-
type Index = u64;
55+
type Nonce = u64;
5656
type Hash = H256;
5757
type Hashing = BlakeTwo256;
5858
type AccountId = AccountId;

frame/atomic-swap/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl frame_system::Config for Test {
2727
type BlockLength = ();
2828
type DbWeight = ();
2929
type RuntimeOrigin = RuntimeOrigin;
30-
type Index = u64;
30+
type Nonce = u64;
3131
type Hash = H256;
3232
type RuntimeCall = RuntimeCall;
3333
type Hashing = BlakeTwo256;

frame/aura/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl frame_system::Config for Test {
4545
type BlockLength = ();
4646
type DbWeight = ();
4747
type RuntimeOrigin = RuntimeOrigin;
48-
type Index = u64;
48+
type Nonce = u64;
4949
type RuntimeCall = RuntimeCall;
5050
type Hash = H256;
5151
type Hashing = ::sp_runtime::traits::BlakeTwo256;

frame/authority-discovery/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ mod tests {
231231
type BlockLength = ();
232232
type DbWeight = ();
233233
type RuntimeOrigin = RuntimeOrigin;
234-
type Index = u64;
234+
type Nonce = u64;
235235
type RuntimeCall = RuntimeCall;
236236
type Hash = H256;
237237
type Hashing = ::sp_runtime::traits::BlakeTwo256;

frame/authorship/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ mod tests {
125125
type BlockLength = ();
126126
type DbWeight = ();
127127
type RuntimeOrigin = RuntimeOrigin;
128-
type Index = u64;
128+
type Nonce = u64;
129129
type RuntimeCall = RuntimeCall;
130130
type Hash = H256;
131131
type Hashing = BlakeTwo256;

frame/babe/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl frame_system::Config for Test {
6565
type BlockLength = ();
6666
type DbWeight = ();
6767
type RuntimeOrigin = RuntimeOrigin;
68-
type Index = u64;
68+
type Nonce = u64;
6969
type RuntimeCall = RuntimeCall;
7070
type Hash = H256;
7171
type Version = ();

frame/bags-list/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl frame_system::Config for Runtime {
5252
type SS58Prefix = ();
5353
type BaseCallFilter = frame_support::traits::Everything;
5454
type RuntimeOrigin = RuntimeOrigin;
55-
type Index = u64;
55+
type Nonce = u64;
5656
type RuntimeCall = RuntimeCall;
5757
type Hash = sp_core::H256;
5858
type Hashing = sp_runtime::traits::BlakeTwo256;

0 commit comments

Comments
 (0)