Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
12da39c
first refactor of the lib.rs
Krayt78 Aug 28, 2025
efb4cdb
replaced some benchamarking values with equivalent in fungibles
Krayt78 Aug 28, 2025
e1e17b3
added a few more
Krayt78 Aug 29, 2025
5efb4d5
finished tests and benchmarks
Krayt78 Aug 30, 2025
b7ac33f
Merge branch 'master' into Refactor-Indices-pallet-to-use-fungible-tr…
Krayt78 Aug 30, 2025
91b9b20
started working on migration code
Krayt78 Sep 14, 2025
af778f6
Merge branch 'Refactor-Indices-pallet-to-use-fungible-traits' of http…
Krayt78 Sep 14, 2025
6bdd173
basic migration step
Krayt78 Sep 14, 2025
4947a75
added some work on migrations based on sigurpol s code
Krayt78 Sep 14, 2025
26bf885
going back on the migration file
Krayt78 Oct 1, 2025
44bcd48
writting test for migration
Krayt78 Oct 1, 2025
fef7f09
draft migration
Krayt78 Oct 8, 2025
149a8b1
Merge branch 'master' into Refactor-Indices-pallet-to-use-fungible-tr…
Krayt78 Oct 8, 2025
ca0e0f6
fmt
Krayt78 Oct 8, 2025
24f2af9
removed unused imports
Krayt78 Oct 8, 2025
5350404
Revert "removed unused imports"
Krayt78 Oct 8, 2025
3b24eea
runtime configs updated
Krayt78 Oct 8, 2025
a108227
added more runtime changes
Krayt78 Oct 10, 2025
1d93008
removed unused imports
Krayt78 Oct 11, 2025
1216242
fix unused imports
Krayt78 Oct 12, 2025
e66ed58
change currency name to NativeBalance
Krayt78 Oct 28, 2025
61ea714
updated runtime configs after variable renaming
Krayt78 Oct 29, 2025
1b86474
fix runtime config
Krayt78 Oct 29, 2025
784cda3
fmt
Krayt78 Oct 29, 2025
78b8035
refactored migration
Krayt78 Nov 12, 2025
9bdfa03
renaming and fmt
Krayt78 Nov 12, 2025
511de1f
Update substrate/frame/indices/src/lib.rs
Krayt78 Nov 27, 2025
ae8f3f6
Update substrate/frame/indices/src/lib.rs
Krayt78 Nov 27, 2025
fb89803
fixed transfer according to gui's comment
Krayt78 Nov 27, 2025
6607824
Remove RuntimeHoldReason from Test Config implementation
Krayt78 Nov 27, 2025
3c7a951
Changed precision from Exact to BestEffort to better follow previous …
Krayt78 Nov 27, 2025
cd0e2a1
Set precision as BestEffort to have the same implementation as before
Krayt78 Nov 27, 2025
7c4208d
added logging to silent error from force_transfer
Krayt78 Nov 27, 2025
880a225
taplo
Krayt78 Nov 27, 2025
74df615
fmt
Krayt78 Nov 27, 2025
f63d689
adding error handling
Krayt78 Nov 27, 2025
c735e61
Merge branch 'master' into Refactor-Indices-pallet-to-use-fungible-tr…
Krayt78 Nov 27, 2025
51f1fcc
handling case where a migrated account didnt have ED
Krayt78 Nov 27, 2025
693bca4
starting on weight and bencharking the migration
Krayt78 Nov 27, 2025
53f1fb4
Remove RuntimeHoldReason from various Runtime configurations
Krayt78 Nov 27, 2025
4902199
fmt
Krayt78 Nov 27, 2025
ff5c446
working towards benchmarking
Krayt78 Dec 11, 2025
592de62
test benchmarking
Krayt78 Dec 11, 2025
826779e
added weight to step
Krayt78 Dec 11, 2025
89b92e8
new weights (need t o check if correct)
Krayt78 Dec 12, 2025
da6f1e6
changed imports back to frame_support
Krayt78 Dec 12, 2025
044727a
fmt
Krayt78 Dec 12, 2025
95dd98e
Refactor migration logic to ensure correct versioning and improve wei…
Krayt78 Dec 18, 2025
7c5f3e5
fix according to comments
Krayt78 Jan 15, 2026
5cd6192
using actual amount for transfer in case Polite gives less
Krayt78 Jan 15, 2026
c2bf25c
Removes pallet balances to use more generic way, also added extra to …
Krayt78 Jan 15, 2026
c649d8c
Refactor migration logic to use hold_amount instead of reserve_to_mig…
Krayt78 Jan 19, 2026
65b6fdf
removed dep
Krayt78 Jan 19, 2026
2326714
fmt
Krayt78 Jan 19, 2026
70dd9f7
Refactor migration logic to remove version check and adjust storage v…
Krayt78 Jan 24, 2026
6fa3408
fmt
Krayt78 Jan 24, 2026
18fba23
Implement migration logic for account storage in pallet_indices
Krayt78 Jan 30, 2026
f37ac96
removed std for core
Krayt78 Jan 30, 2026
ebc83c1
fmt
Krayt78 Jan 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ parameter_types! {

impl pallet_indices::Config for Runtime {
type AccountIndex = AccountIndex;
type Currency = Balances;
type NativeBalance = Balances;
type Deposit = IndexDeposit;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_indices::WeightInfo<Runtime>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,20 @@ impl<T: frame_system::Config> pallet_indices::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: UNKNOWN KEY `0x1a736d37504c2e3fb73dad160c55b2915c858e3f3bd0a1a1c78c656baa95f5b5` (r:2 w:0)
/// Proof: UNKNOWN KEY `0x1a736d37504c2e3fb73dad160c55b2915c858e3f3bd0a1a1c78c656baa95f5b5` (r:2 w:0)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`)
/// Storage: `Indices::Accounts` (r:0 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn migrate_account_step() -> Weight {
// Proof Size summary in bytes:
// Measured: `138`
// Estimated: `6078`
// Minimum execution time: 38_131_000 picoseconds.
Weight::from_parts(38_749_000, 0)
.saturating_add(Weight::from_parts(0, 6078))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
}
2 changes: 1 addition & 1 deletion polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ parameter_types! {

impl pallet_indices::Config for Runtime {
type AccountIndex = AccountIndex;
type Currency = Balances;
type NativeBalance = Balances;
type Deposit = IndexDeposit;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_indices::WeightInfo<Runtime>;
Expand Down
16 changes: 16 additions & 0 deletions polkadot/runtime/rococo/src/weights/pallet_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,20 @@ impl<T: frame_system::Config> pallet_indices::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: UNKNOWN KEY `0x1a736d37504c2e3fb73dad160c55b2915c858e3f3bd0a1a1c78c656baa95f5b5` (r:2 w:0)
/// Proof: UNKNOWN KEY `0x1a736d37504c2e3fb73dad160c55b2915c858e3f3bd0a1a1c78c656baa95f5b5` (r:2 w:0)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`)
/// Storage: `Indices::Accounts` (r:0 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn migrate_account_step() -> Weight {
// Proof Size summary in bytes:
// Measured: `138`
// Estimated: `6078`
// Minimum execution time: 38_131_000 picoseconds.
Weight::from_parts(38_749_000, 0)
.saturating_add(Weight::from_parts(0, 6078))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
}
2 changes: 1 addition & 1 deletion polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ parameter_types! {

impl pallet_indices::Config for Runtime {
type AccountIndex = AccountIndex;
type Currency = Balances;
type NativeBalance = Balances;
type Deposit = IndexDeposit;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ parameter_types! {

impl pallet_indices::Config for Runtime {
type AccountIndex = AccountIndex;
type Currency = Balances;
type NativeBalance = Balances;
type Deposit = IndexDeposit;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_indices::WeightInfo<Runtime>;
Expand Down
16 changes: 16 additions & 0 deletions polkadot/runtime/westend/src/weights/pallet_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,20 @@ impl<T: frame_system::Config> pallet_indices::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: UNKNOWN KEY `0x1a736d37504c2e3fb73dad160c55b2915c858e3f3bd0a1a1c78c656baa95f5b5` (r:2 w:0)
/// Proof: UNKNOWN KEY `0x1a736d37504c2e3fb73dad160c55b2915c858e3f3bd0a1a1c78c656baa95f5b5` (r:2 w:0)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`)
/// Storage: `Indices::Accounts` (r:0 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn migrate_account_step() -> Weight {
// Proof Size summary in bytes:
// Measured: `138`
// Estimated: `6078`
// Minimum execution time: 38_131_000 picoseconds.
Weight::from_parts(38_749_000, 0)
.saturating_add(Weight::from_parts(0, 6078))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
}
2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ parameter_types! {

impl pallet_indices::Config for Runtime {
type AccountIndex = AccountIndex;
type Currency = Balances;
type NativeBalance = Balances;
type Deposit = IndexDeposit;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_indices::weights::SubstrateWeight<Runtime>;
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/indices/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ codec = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
Expand All @@ -35,6 +36,7 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"scale-info/std",
"sp-core/std",
Expand Down
141 changes: 121 additions & 20 deletions substrate/frame/indices/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,37 @@ use crate::*;
use frame_benchmarking::v2::*;
use frame_support::traits::Get;
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;

const SEED: u32 = 0;

#[benchmarks]
#[benchmarks(
where
// For the migration benchmark, T::NativeBalance needs to implement the old Currency traits
// to set up the pre-migration state.
T::NativeBalance: Currency<T::AccountId, Balance = BalanceOf<T>>
+ ReservableCurrency<T::AccountId>,
)]
mod benchmarks {
use super::*;
use crate::migration::v1::MigrateCurrencyToFungibles;
use frame_support::{
migrations::SteppedMigration,
traits::{
fungible::{Inspect as FungibleInspect, Mutate as FungibleMutate},
Currency, ReservableCurrency,
},
weights::WeightMeter,
};

#[benchmark]
fn claim() {
let account_index = T::AccountIndex::from(SEED);
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
<T::NativeBalance as FungibleMutate<T::AccountId>>::set_balance(
&caller,
<T::NativeBalance as FungibleInspect<T::AccountId>>::minimum_balance() +
T::Deposit::get(),
);

#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), account_index);
Expand All @@ -48,10 +66,18 @@ mod benchmarks {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
<T::NativeBalance as FungibleMutate<T::AccountId>>::set_balance(
&caller,
<T::NativeBalance as FungibleInspect<T::AccountId>>::minimum_balance() +
T::Deposit::get(),
);
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
<T::NativeBalance as FungibleMutate<T::AccountId>>::set_balance(
&recipient,
<T::NativeBalance as FungibleInspect<T::AccountId>>::minimum_balance() +
T::Deposit::get(),
);
// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;

Expand All @@ -67,7 +93,11 @@ mod benchmarks {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
<T::NativeBalance as FungibleMutate<T::AccountId>>::set_balance(
&caller,
<T::NativeBalance as FungibleInspect<T::AccountId>>::minimum_balance() +
T::Deposit::get(),
);
// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;

Expand All @@ -83,10 +113,18 @@ mod benchmarks {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let original: T::AccountId = account("original", 0, SEED);
T::Currency::make_free_balance_be(&original, BalanceOf::<T>::max_value());
<T::NativeBalance as FungibleMutate<T::AccountId>>::set_balance(
&original,
<T::NativeBalance as FungibleInspect<T::AccountId>>::minimum_balance() +
T::Deposit::get(),
);
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
<T::NativeBalance as FungibleMutate<T::AccountId>>::set_balance(
&recipient,
<T::NativeBalance as FungibleInspect<T::AccountId>>::minimum_balance() +
T::Deposit::get(),
);
// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(original).into(), account_index)?;

Expand All @@ -102,7 +140,11 @@ mod benchmarks {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
<T::NativeBalance as FungibleMutate<T::AccountId>>::set_balance(
&caller,
<T::NativeBalance as FungibleInspect<T::AccountId>>::minimum_balance() +
T::Deposit::get(),
);
// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;

Expand All @@ -118,26 +160,35 @@ mod benchmarks {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

// The additional amount we'll add to the deposit for the index
let additional_amount = 2u32.into();

<T::NativeBalance as FungibleMutate<T::AccountId>>::set_balance(
&caller,
<T::NativeBalance as FungibleInspect<T::AccountId>>::minimum_balance() +
T::Deposit::get() +
additional_amount,
);

let original_deposit = T::Deposit::get();

// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;

// Verify the initial deposit amount in storage and reserved balance
// Verify the initial deposit amount in storage and held balance
assert_eq!(Accounts::<T>::get(account_index).unwrap().1, original_deposit);
assert_eq!(T::Currency::reserved_balance(&caller), original_deposit);

// The additional amount we'll add to the deposit for the index
let additional_amount = 2u32.into();
assert_eq!(
T::NativeBalance::balance_on_hold(&HoldReason::DepositForIndex.into(), &caller),
original_deposit
);

// Reserve the additional amount from the caller's balance
T::Currency::reserve(&caller, additional_amount)?;
// Hold the additional amount from the caller's balance
T::NativeBalance::hold(&HoldReason::DepositForIndex.into(), &caller, additional_amount)?;

// Verify the additional amount was reserved
// Verify the additional amount was held
assert_eq!(
T::Currency::reserved_balance(&caller),
T::NativeBalance::balance_on_hold(&HoldReason::DepositForIndex.into(), &caller),
original_deposit.saturating_add(additional_amount)
);

Expand All @@ -162,7 +213,57 @@ mod benchmarks {
assert!(Accounts::<T>::contains_key(account_index));
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, caller);
assert_eq!(Accounts::<T>::get(account_index).unwrap().1, original_deposit);
assert_eq!(T::Currency::reserved_balance(&caller), original_deposit);
assert_eq!(
T::NativeBalance::balance_on_hold(&HoldReason::DepositForIndex.into(), &caller),
original_deposit
);
Ok(())
}

#[benchmark(extra)]
fn migrate_account_step() -> Result<(), BenchmarkError> {
use crate::migration::v1::v0;

// Setup: Create an account in the OLD currency system that needs migration
let account_index = T::AccountIndex::from(SEED);
let caller: T::AccountId = whitelisted_caller();
let deposit = T::Deposit::get();

// Give the account some balance (enough for deposit + existential deposit)
<T::NativeBalance as FungibleMutate<T::AccountId>>::set_balance(
&caller,
<T::NativeBalance as FungibleInspect<T::AccountId>>::minimum_balance() +
deposit + deposit,
);

// Reserve funds using the old Currency system
<T::NativeBalance as ReservableCurrency<T::AccountId>>::reserve(&caller, deposit)?;

// Insert into the OLD storage (v0) to simulate pre-migration state
v0::OldAccounts::<T>::insert(account_index, (caller.clone(), deposit, false));

#[block]
{
let _ = MigrateCurrencyToFungibles::<T, T::NativeBalance>::step(
None,
&mut WeightMeter::new(),
);
}

// Verify the account was migrated to the new storage
assert!(Accounts::<T>::contains_key(account_index));
let (migrated_account, migrated_deposit, frozen) =
Accounts::<T>::get(account_index).unwrap();
assert_eq!(migrated_account, caller);
assert_eq!(migrated_deposit, deposit);
assert_eq!(frozen, false);

// Verify the hold was created in the new fungible system
assert_eq!(
T::NativeBalance::balance_on_hold(&HoldReason::DepositForIndex.into(), &caller),
deposit
);

Ok(())
}

Expand Down
Loading
Loading