Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Staking] Currency <> Fungible migration #5501

Draft
wants to merge 143 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
02d3a70
prep for abstracting out all currency calls in a separate mod
Ank4n Aug 18, 2024
fa1064f
replace ED calls
Ank4n Aug 18, 2024
babc205
replace ti, burn, and set balance calls
Ank4n Aug 18, 2024
2f0cd28
add read balance and update lock fn to asset
Ank4n Aug 18, 2024
4af4aee
replace all currency call with existing asset fn
Ank4n Aug 18, 2024
1995e06
add remaining currency fn
Ank4n Aug 18, 2024
f3a3081
all currency fn replaced
Ank4n Aug 18, 2024
6a03abb
fix imports
Ank4n Aug 18, 2024
040c630
remove unused import
Ank4n Aug 18, 2024
3d3ceac
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Aug 18, 2024
61eb7b7
fix clippy
Ank4n Aug 18, 2024
b8a0e4b
repalce Balances api calls in test to asset as well
Ank4n Aug 18, 2024
2926255
clippy
Ank4n Aug 19, 2024
9e38e8e
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Aug 26, 2024
34e1d48
rustdoc update
Ank4n Aug 26, 2024
31c6467
refactor
Ank4n Aug 26, 2024
851c5f3
reorder
Ank4n Aug 27, 2024
c92a0bd
add fungible to config
Ank4n Aug 18, 2024
ebf60ef
rustdoc fix
Ank4n Aug 27, 2024
07e3ca9
rename Fungible to Currency
Ank4n Aug 27, 2024
58e8e83
add support for fungible imbalance handler in pallet treasury
Ank4n Aug 27, 2024
fe893a8
add license
Ank4n Aug 27, 2024
087692b
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Aug 27, 2024
a9d0345
fix unused imports
Ank4n Aug 27, 2024
67bd3fa
fix rust doc
Ank4n Aug 27, 2024
5157b3b
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Aug 27, 2024
e6c705e
missing import
Ank4n Aug 27, 2024
c4a9c9d
conditional import of fun mutate
Ank4n Aug 27, 2024
994c6c5
refactor bench test since moving from currency to fungible change events
Ank4n Aug 28, 2024
940e5e0
improve test comments
Ank4n Aug 28, 2024
f5c6fe9
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Aug 28, 2024
0c296ab
refactor offence benchmark
Ank4n Aug 28, 2024
6f503f7
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Aug 28, 2024
61bac35
fix balance of
Ank4n Aug 28, 2024
6659456
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Aug 28, 2024
e5b80ce
fix event count with fungibles
Ank4n Aug 28, 2024
12607ec
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Aug 28, 2024
426ac1c
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Aug 28, 2024
9660a41
refactor root offences test to use staking asset
Ank4n Aug 28, 2024
b2cbe7d
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Aug 28, 2024
0cfd8e4
unused import
Ank4n Aug 28, 2024
6a7368c
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Aug 28, 2024
0ec6a3b
fix failing tests
Ank4n Aug 28, 2024
165261f
fix compile
Ank4n Aug 28, 2024
7f7e394
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Aug 28, 2024
f62354b
refactor epm e2e tests
Ank4n Aug 28, 2024
59f22f0
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Aug 28, 2024
0188158
best effort while minting money
Ank4n Aug 28, 2024
a156423
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Sep 1, 2024
d03469c
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Sep 1, 2024
0dc0ca4
fix ed bug while minting
Ank4n Sep 1, 2024
f0ef9d1
release/dec consumer before dec providers
Ank4n Sep 2, 2024
ca81fea
works, but hacky
Ank4n Sep 2, 2024
b15efb6
fix provider
Ank4n Sep 2, 2024
b1f313b
remove the hack provider logic
Ank4n Sep 3, 2024
32be80c
verify only for tests
Ank4n Sep 3, 2024
e0fac32
hacky to pass tests for now
Ank4n Sep 4, 2024
d74ebd6
unused import
Ank4n Sep 4, 2024
c5a7730
staking does not need to inc consumer anymore
Ank4n Sep 4, 2024
dedecbc
purge session key when trying to kill stash
Ank4n Sep 4, 2024
a8b78a7
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Sep 5, 2024
9053d4f
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Sep 5, 2024
bcdb749
small updates
Ank4n Sep 5, 2024
18928a4
kill stake is fallible
Ank4n Sep 5, 2024
6a7001e
fail ledger kill if stake cannot be killed
Ank4n Sep 5, 2024
ef54e9a
doc fixes
Ank4n Sep 5, 2024
4555209
fmt
Ank4n Sep 5, 2024
684828a
fix migrate test
Ank4n Sep 5, 2024
17144b0
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Sep 6, 2024
a7272be
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Sep 6, 2024
6d94601
rename agent kill function
Ank4n Sep 6, 2024
a3267af
small edits
Ank4n Sep 6, 2024
c1fc3dc
port some changes from migration pr back to base
Ank4n Sep 6, 2024
679f290
fmt
Ank4n Sep 6, 2024
dc4a9a4
fmt
Ank4n Sep 6, 2024
605f698
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Sep 6, 2024
9570a61
remove provider inc in pallet-delegated-staking
Ank4n Sep 10, 2024
49c2045
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Sep 11, 2024
09f20e1
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Sep 11, 2024
0e7e8d5
add migrate function to staking
Ank4n Sep 11, 2024
7fad817
remote test
Ank4n Sep 11, 2024
bb7b8a0
fmt
Ank4n Sep 11, 2024
5af34d5
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Sep 13, 2024
03242b2
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Sep 13, 2024
7bc7086
add OldCurrency to runtime configs
Ank4n Sep 13, 2024
9ed4716
add old currency to config
Ank4n Sep 13, 2024
c009a62
ensure ledger update also updates holds
Ank4n Sep 15, 2024
17c4aa3
new call to migrate currency
Ank4n Sep 15, 2024
c4af869
force withdraw test
Ank4n Sep 15, 2024
e1f1d42
fmt
Ank4n Sep 15, 2024
b57660d
add reap stash fail test
Ank4n Sep 15, 2024
dc55b97
split stakeable into staked and free to stake
Ank4n Sep 15, 2024
591945d
refactor remote test migration
Ank4n Sep 15, 2024
00841b6
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Sep 16, 2024
2760773
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Sep 16, 2024
a1ccab7
add bench for migrate currency
Ank4n Sep 16, 2024
8c59b58
fix try states
Ank4n Sep 17, 2024
36bb12e
prdoc
Ank4n Sep 17, 2024
c06e60b
clippy fix
Ank4n Sep 17, 2024
5c29547
improve tests
Ank4n Sep 17, 2024
d6258bc
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Sep 17, 2024
7f1165e
Merge branch 'ankan/staking-migrate-currency-to-fungible' of https://…
Sep 17, 2024
f07061b
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Sep 17, 2024
da0a7c3
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Sep 17, 2024
b3352dd
comment about ignoring resolve err
Ank4n Sep 18, 2024
f0d2d14
total balance for ED
Ank4n Sep 18, 2024
3ca1081
ensure ti is updated at reward
Ank4n Sep 19, 2024
7a16988
make slash resolve to treasury defensive
Ank4n Sep 19, 2024
b2d2245
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Sep 20, 2024
d67069a
migrate virtual stakers code
Ank4n Sep 20, 2024
39f520b
add test for migration of virtual stakers
Ank4n Sep 20, 2024
0f01445
add more cases to virtual staker migration
Ank4n Sep 20, 2024
9c5188e
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Sep 20, 2024
748ec96
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Sep 30, 2024
b2afa33
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Sep 30, 2024
e7c4e6e
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible
Ank4n Oct 7, 2024
6b3d246
Merge branch 'ankan/staking-migrate-currency-to-fungible' into ankan/…
Ank4n Oct 7, 2024
18e065a
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible-2
Ank4n Oct 8, 2024
423b950
apply donal suggestions
Ank4n Oct 8, 2024
c03df7f
fmt
Ank4n Oct 8, 2024
e218e3d
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible-2
Ank4n Oct 8, 2024
e688c93
stash needs ed to stay alive
Ank4n Oct 8, 2024
d9e0f86
update prdoc
Ank4n Oct 8, 2024
8db37b6
fix prdoc
Ank4n Oct 8, 2024
e87b5e4
fix prdoc
Ank4n Oct 8, 2024
31d04f8
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible-2
Ank4n Oct 8, 2024
b5e473b
".git/.scripts/commands/fmt/fmt.sh"
Oct 8, 2024
15961dc
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible-2
Ank4n Oct 10, 2024
02ecebd
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible-2
Ank4n Oct 15, 2024
3d5a7c0
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible-2
Ank4n Oct 22, 2024
ff1878d
update comment
Ank4n Oct 25, 2024
e6de610
test validator purge keys
Ank4n Oct 26, 2024
8e957ff
test session purge for reaping validators
Ank4n Oct 26, 2024
d2b1084
refactor migration code
Ank4n Oct 26, 2024
3e48265
add rustdoc for migrate
Ank4n Oct 26, 2024
8463df2
Merge branch 'master' into ankan/staking-migrate-currency-to-fungible-2
Ank4n Nov 6, 2024
7adfb85
staking should not add provider for accounts
Ank4n Nov 6, 2024
60972ca
49 fails
Ank4n Nov 6, 2024
7e7980d
20 fails
Ank4n Nov 6, 2024
69e7bcb
12 fails
Ank4n Nov 6, 2024
bec40b1
fix migration
Ank4n Nov 6, 2024
2451f93
staking all test pass
Ank4n Nov 7, 2024
5f8ec96
fmt
Ank4n Nov 7, 2024
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
2 changes: 2 additions & 0 deletions polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,13 @@ impl onchain::Config for OnChainSeqPhragmen {
const MAX_QUOTA_NOMINATIONS: u32 = 16;

impl pallet_staking::Config for Runtime {
type OldCurrency = Balances;
type Currency = Balances;
type CurrencyBalance = Balance;
type UnixTime = Timestamp;
type CurrencyToVote = polkadot_runtime_common::CurrencyToVote;
type RewardRemainder = ();
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeEvent = RuntimeEvent;
type Slash = ();
type Reward = ();
Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,10 @@ parameter_types! {
}

impl pallet_staking::Config for Runtime {
type OldCurrency = Balances;
type Currency = Balances;
type CurrencyBalance = Balance;
type RuntimeHoldReason = RuntimeHoldReason;
type UnixTime = Timestamp;
type CurrencyToVote = CurrencyToVote;
type RewardRemainder = ();
Expand Down
99 changes: 86 additions & 13 deletions polkadot/runtime/westend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,27 @@ mod remote_tests {

let transport: Transport = var("WS").unwrap_or("ws://127.0.0.1:9900".to_string()).into();
let maybe_state_snapshot: Option<SnapshotConfig> = var("SNAP").map(|s| s.into()).ok();
let online_config = OnlineConfig {
transport,
state_snapshot: maybe_state_snapshot.clone(),
child_trie: false,
pallets: vec![
"Staking".into(),
"System".into(),
"Balances".into(),
"NominationPools".into(),
"DelegatedStaking".into(),
],
..Default::default()
};
let mut ext = Builder::<Block>::default()
.mode(if let Some(state_snapshot) = maybe_state_snapshot {
Mode::OfflineOrElseOnline(
OfflineConfig { state_snapshot: state_snapshot.clone() },
OnlineConfig {
transport,
state_snapshot: Some(state_snapshot),
pallets: vec![
"staking".into(),
"system".into(),
"balances".into(),
"nomination-pools".into(),
"delegated-staking".into(),
],
..Default::default()
},
online_config,
)
} else {
Mode::Online(OnlineConfig { transport, ..Default::default() })
Mode::Online(online_config)
})
.build()
.await
Expand Down Expand Up @@ -241,6 +243,77 @@ mod remote_tests {
);
});
}

#[tokio::test]
async fn staking_curr_fun_migrate() {
// Intended to be run only manually.
if var("RUN_MIGRATION_TESTS").is_err() {
return;
}
sp_tracing::try_init_simple();

let transport: Transport = var("WS").unwrap_or("ws://127.0.0.1:9900".to_string()).into();
let maybe_state_snapshot: Option<SnapshotConfig> = var("SNAP").map(|s| s.into()).ok();
let online_config = OnlineConfig {
transport,
state_snapshot: maybe_state_snapshot.clone(),
child_trie: false,
pallets: vec!["Staking".into(), "System".into(), "Balances".into()],
..Default::default()
};
let mut ext = Builder::<Block>::default()
.mode(if let Some(state_snapshot) = maybe_state_snapshot {
Mode::OfflineOrElseOnline(
OfflineConfig { state_snapshot: state_snapshot.clone() },
online_config,
)
} else {
Mode::Online(online_config)
})
.build()
.await
.unwrap();
ext.execute_with(|| {
// create an account with some balance
let alice = AccountId::from([1u8; 32]);
use frame_support::traits::Currency;
let _ = Balances::deposit_creating(&alice, 100_000 * UNITS);

let mut success = 0;
let mut err = 0;
let mut force_withdraw_acc = 0;
// iterate over all pools
pallet_staking::Ledger::<Runtime>::iter().for_each(|(ctrl, ledger)| {
match pallet_staking::Pallet::<Runtime>::migrate_currency(
RuntimeOrigin::signed(alice.clone()).into(),
ledger.stash.clone(),
) {
Ok(_) => {
let updated_ledger =
pallet_staking::Ledger::<Runtime>::get(&ctrl).expect("ledger exists");
let force_withdraw = ledger.total - updated_ledger.total;
if force_withdraw > 0 {
force_withdraw_acc += force_withdraw;
log::info!(target: "remote_test", "Force withdraw from stash {:?}: value {:?}", ledger.stash, force_withdraw);
}
success += 1;
},
Err(e) => {
log::error!(target: "remote_test", "Error migrating {:?}: {:?}", ledger.stash, e);
err += 1;
},
}
});

log::info!(
target: "remote_test",
"Migration stats: success: {}, err: {}, total force withdrawn stake: {}",
success,
err,
force_withdraw_acc
);
});
}
}

#[test]
Expand Down
Loading
Loading