Skip to content

Commit

Permalink
Improve existing check (#191)
Browse files Browse the repository at this point in the history
* Improve existing check

* Remove unused variable
  • Loading branch information
AurevoirXavier authored Jan 9, 2023
1 parent f720b56 commit f15a0bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
25 changes: 9 additions & 16 deletions tool/state-processor/src/balances/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ impl<S> Processor<S> {
let mut solo_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::TotalIssuance`, `Kton::TotalIssuance`, `Balances::Locks` and `Kton::Locks`");
Expand All @@ -31,16 +30,16 @@ impl<S> Processor<S> {
solo_kton_total_issuance.adjust();

log::info!("take para `Balances::TotalIssuance` and `Balances::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);
self.para_state.take_value(
b"Balances",
b"TotalIssuance",
"",
&mut para_ring_total_issuance,
);

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);
if self.para_state.exists(b"Balances", b"Locks") {
log::error!("check para `Balances::Locks`, it isn't empty");
}

(solo_ring_total_issuance + para_ring_total_issuance, solo_kton_total_issuance)
}
Expand Down Expand Up @@ -81,9 +80,3 @@ fn prune(locks: &mut Map<Locks>) {
!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)));
}
8 changes: 2 additions & 6 deletions tool/state-processor/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,10 @@ impl<R> State<R> {
self.map.contains_key(key)
}

pub fn starts_with(&self, key: &str) -> bool {
self.map.keys().into_iter().any(|k| k.starts_with(key))
pub fn exists(&self, pallet: &[u8], item: &[u8]) -> bool {
self.map.keys().into_iter().any(|k| k.starts_with(&item_key(pallet, item)))
}

// pub fn inc_consumers(&mut self, who: &str) {}

// pub fn transfer(&mut self, from: &str, to: &str, amount: u128) {}

pub fn unreserve<A>(&mut self, account_id_32: A, amount: u128)
where
A: AsRef<[u8]>,
Expand Down
15 changes: 7 additions & 8 deletions tool/state-processor/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ impl<S> Processor<S> {
pub fn process_proxy(&mut self) -> &mut Self {
// Storage items.
// https://github.dev/darwinia-network/substrate/blob/darwinia-v0.12.5/frame/proxy/src/lib.rs#L599
let announcements_key = item_key(b"Proxy", b"Announcements");
if self.solo_state.starts_with(&announcements_key) {
log::error!("The solo chain `Proxy::Announcements` not empty");
if self.solo_state.exists(b"Proxy", b"Announcements") {
log::error!("check solo `Proxy::Announcements`, it isn't empty");
}
if self.para_state.starts_with(&announcements_key) {
log::error!("The para chain `Proxy::Announcements` not empty");
if self.para_state.exists(b"Proxy", b"Announcements") {
log::error!("check para `Proxy::Announcements`, it isn't empty");
}

// The size of encoded `pallet_proxy::ProxyDefinition` is 37 bytes.
Expand All @@ -26,9 +25,9 @@ impl<S> Processor<S> {
self.shell_state.unreserve(array_bytes::hex2bytes_unchecked(get_last_64(&a)), v);
});

// Make sure the Proxy::Proxies storage of para chain is empty.
if self.para_state.starts_with(&item_key(b"Proxy", b"Proxies")) {
log::error!("The para chain `Proxy::Proxies` not empty");
// Make sure the para `Proxy::Proxies` is empty.
if self.para_state.exists(b"Proxy", b"Proxies") {
log::error!("check para `Proxy::Proxies`, it isn't empty");
}

self
Expand Down

0 comments on commit f15a0bc

Please sign in to comment.