-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle EVM accounts and pruge locks Signed-off-by: Xavier Lau <xavier@inv.cafe> * Refactor account genesis * Purge locks * Update scope * Update special accounts list Signed-off-by: Xavier Lau <xavier@inv.cafe>
- Loading branch information
1 parent
5b19e28
commit d4922e1
Showing
7 changed files
with
281 additions
and
148 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,89 @@ | ||
// darwinia | ||
use crate::*; | ||
|
||
type Locks = Vec<BalanceLock>; | ||
|
||
impl Processor { | ||
pub fn process_balances( | ||
&mut self, | ||
ring_locks: &mut Map<Vec<BalanceLock>>, | ||
kton_locks: &mut Map<Vec<BalanceLock>>, | ||
) -> &mut Self { | ||
log::info!("take solo balance locks"); | ||
pub fn process_balances(&mut self) -> (u128, u128) { | ||
let mut solo_ring_total_issuance = u128::default(); | ||
let mut kton_total_issuance = u128::default(); | ||
let mut solo_ring_locks = <Map<Locks>>::default(); | ||
let mut solo_kton_locks = <Map<Locks>>::default(); | ||
let mut para_ring_locks = <Map<Locks>>::default(); | ||
let mut para_ring_total_issuance = u128::default(); | ||
|
||
log::info!("take solo balances total issuances and locks"); | ||
self.solo_state | ||
.take::<Vec<BalanceLock>, _>( | ||
b"Balances", | ||
b"Locks", | ||
ring_locks, | ||
get_blake2_128_concat_suffix, | ||
) | ||
.take::<Vec<BalanceLock>, _>( | ||
b"Kton", | ||
b"Locks", | ||
kton_locks, | ||
get_blake2_128_concat_suffix, | ||
); | ||
|
||
// --- | ||
// Currently, there are only fee-market locks. | ||
// I suggest shutting down the fee-market before merging. | ||
// So, we could ignore the para balance locks migration. | ||
// --- | ||
|
||
log::info!("adjust solo balance lock decimals"); | ||
ring_locks.iter_mut().for_each(|(_, v)| v.iter_mut().for_each(|l| l.amount *= GWEI)); | ||
kton_locks.iter_mut().for_each(|(_, v)| v.iter_mut().for_each(|l| l.amount *= GWEI)); | ||
|
||
self | ||
.take_value(b"Balances", b"TotalIssuance", &mut solo_ring_total_issuance) | ||
.take_value(b"Kton", b"TotalIssuance", &mut kton_total_issuance) | ||
.take_map(b"Balances", b"Locks", &mut solo_ring_locks, get_hashed_key) | ||
.take_map(b"Kton", b"Locks", &mut solo_kton_locks, get_hashed_key); | ||
|
||
log::info!("prune solo balance locks"); | ||
prune(&mut solo_ring_locks); | ||
prune(&mut solo_kton_locks); | ||
|
||
log::info!("adjust solo balances items' decimals"); | ||
solo_ring_total_issuance *= GWEI; | ||
kton_total_issuance *= GWEI; | ||
// solo_ring_locks.iter_mut().for_each(|(_, v)| v.iter_mut().for_each(|l| l.amount *= | ||
// GWEI)); solo_kton_locks.iter_mut().for_each(|(_, v)| v.iter_mut().for_each(|l| l.amount | ||
// *= GWEI)); | ||
|
||
log::info!("take para balances total issuances and locks"); | ||
self.para_state | ||
.take_value(b"Balances", b"TotalIssuance", &mut para_ring_total_issuance) | ||
.take_map(b"Balances", b"Locks", &mut para_ring_locks, get_hashed_key); | ||
|
||
log::info!("check solo ring locks, there should not be any `solo_ring_locks`"); | ||
check_locks(solo_ring_locks); | ||
log::info!("check solo kton locks, there should not be any `solo_kton_locks`"); | ||
check_locks(solo_kton_locks); | ||
log::info!("check para locks, there should not be any `para_ring_locks`"); | ||
check_locks(para_ring_locks); | ||
|
||
(solo_ring_total_issuance + para_ring_total_issuance, kton_total_issuance) | ||
} | ||
} | ||
|
||
fn prune(locks: &mut Map<Locks>) { | ||
// https://github.dev/darwinia-network/darwinia-common/blob/6a9392cfb9fe2c99b1c2b47d0c36125d61991bb7/frame/staking/src/primitives.rs#L39 | ||
const STAKING: [u8; 8] = *b"da/staki"; | ||
// https://github.dev/darwinia-network/darwinia/blob/2d1c1436594b2c397d450e317c35eb16c71105d6/runtime/crab/src/pallets/elections_phragmen.rs#L8 | ||
const PHRAGMEN_ELECTION: [u8; 8] = *b"phrelect"; | ||
// https://github.dev/paritytech/substrate/blob/19162e43be45817b44c7d48e50d03f074f60fbf4/frame/democracy/src/lib.rs#L190 | ||
const DEMOCRACY: [u8; 8] = *b"democrac"; | ||
// https://github.dev/paritytech/substrate/blob/19162e43be45817b44c7d48e50d03f074f60fbf4/frame/vesting/src/lib.rs#L86 | ||
const VESTING: [u8; 8] = *b"vesting "; | ||
const RELAY_AUTHORITY: [u8; 8] = *b"ethrauth"; | ||
// https://github.dev/darwinia-network/darwinia/blob/2d1c1436594b2c397d450e317c35eb16c71105d6/runtime/crab/src/pallets/fee_market.rs#L35 | ||
const FEE_MARKET_0: [u8; 8] = *b"da/feelf"; | ||
// https://github.dev/darwinia-network/darwinia/blob/2d1c1436594b2c397d450e317c35eb16c71105d6/runtime/crab/src/pallets/fee_market.rs#L36 | ||
const FEE_MARKET_1: [u8; 8] = *b"da/feecp"; | ||
// https://github.dev/darwinia-network/darwinia/blob/2d1c1436594b2c397d450e317c35eb16c71105d6/runtime/darwinia/src/pallets/fee_market.rs#L37 | ||
const FEE_MARKET_2: [u8; 8] = *b"da/feedp"; | ||
|
||
locks.retain(|k, v| { | ||
v.retain(|l| match l.id { | ||
STAKING | PHRAGMEN_ELECTION | DEMOCRACY | VESTING | RELAY_AUTHORITY | FEE_MARKET_0 | ||
| FEE_MARKET_1 | FEE_MARKET_2 => false, | ||
id => { | ||
log::error!( | ||
"pruned unknown lock id({}) of account({})", | ||
String::from_utf8_lossy(&id), | ||
get_last_64(k) | ||
); | ||
|
||
false | ||
}, | ||
}); | ||
|
||
!v.is_empty() | ||
}); | ||
} | ||
|
||
fn check_locks(locks: Map<Locks>) { | ||
locks | ||
.into_iter() | ||
.for_each(|(k, _)| log::error!("found unexpected locks of account({})", get_last_64(&k))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
### Process steps | ||
- take solo account infos and remaining balances | ||
- merge solo remaining balances | ||
- adjust solo balance decimals | ||
- take para account infos | ||
- process balances | ||
- take solo balances total issuances and locks | ||
- prune solo balance locks | ||
- prune staking, phragmen election, democracy, vesting, relay authority, fee market locks | ||
- check if there are any other locks | ||
- adjust solo balances items' decimals | ||
- take para balances total issuances and locks | ||
- there should not be any locks on parachain | ||
- use all previous data to build the new accounts and calculate total issuances | ||
- merge solo and para account infos | ||
- how to deal with the account references? - TODO | ||
- set `Balances::TotalIssuance` | ||
- compare the calculated one with the storage one | ||
- remove para backing account - TODO | ||
- check remaining sum - TODO | ||
- XCM relate - TODO | ||
- set KTON total issuances - TODO | ||
- compare the calculated one with the storage one | ||
- check remaining sum - TODO | ||
- set accounts | ||
- if is EVM address | ||
- insert to `System::Account` | ||
- if is Substrate address | ||
- reset the nonce | ||
- insert to `AccountMigration::Accounts` | ||
- calculate misc frozen and fee frozen | ||
|
||
- some remaining accounts, bridge endpoint accounts - TODO | ||
- special accounts - TODO | ||
- parachain backing account 0x8c585F9791EE5b4B23fe82888cE576DBB69607eB | ||
- bridge root account 0x726f6f7400000000000000000000000000000000 |
Oops, something went wrong.