Skip to content

Commit

Permalink
Process parachain system (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier authored Feb 13, 2023
1 parent 6a75a6a commit a661f99
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions tool/state-processor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use type_registry::*;
mod balances;
mod evm;
mod identity;
mod parachain_system;
mod staking;
mod system;
mod vesting;
Expand Down
3 changes: 3 additions & 0 deletions tool/state-processor/src/parachain_system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Process steps
- take para `ParachainSystem::LastDmqMqcHead` and `ParachainSystem::LastHrmpMqcHeads`
- set `ParachainSystem::LastDmqMqcHead` and `ParachainSystem::LastHrmpMqcHeads`
30 changes: 30 additions & 0 deletions tool/state-processor/src/parachain_system/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// darwinia
use crate::*;

impl<S> Processor<S> {
pub fn process_parachain_system(&mut self) -> &mut Self {
// Storage items.
// https://github.com/darwinia-network/darwinia-2.0/issues/275#issuecomment-1427725708
// https://github.com/paritytech/cumulus/blob/09418fc04c2608b123f36ca80f16df3d2096753b/pallets/parachain-system/src/lib.rs#L582-L595
let last_dmq_mqc_head_key =
"0x45323df7cc47150b3930e2666b0aa313911a5dd3f1155f5b7d0c5aa102a757f9";
let last_hrmp_mqc_heads_key =
"0x45323df7cc47150b3930e2666b0aa3133dca42deb008c6559ee789c9b9f70a2c";
let mut last_dmq_mqc_head = String::new();
let mut last_hrmp_mqc_heads = String::new();

log::info!(
"take para `ParachainSystem::LastDmqMqcHead` and `ParachainSystem::LastHrmpMqcHeads`"
);
self.solo_state
.take_raw_value(last_dmq_mqc_head_key, &mut last_dmq_mqc_head)
.take_raw_value(last_hrmp_mqc_heads_key, &mut last_hrmp_mqc_heads);

log::info!("set `ParachainSystem::LastDmqMqcHead` and `ParachainSystem::LastHrmpMqcHeads`");
self.shell_state
.insert_raw_key_raw_value(last_dmq_mqc_head_key.into(), last_dmq_mqc_head)
.insert_raw_key_raw_value(last_hrmp_mqc_heads_key.into(), last_hrmp_mqc_heads);

self
}
}
19 changes: 17 additions & 2 deletions tool/state-processor/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ where

assert!(*_guard != 0);

self.process_system().process_identity().process_vesting().process_staking().process_evm();
self.process_parachain_system()
.process_system()
.process_identity()
.process_vesting()
.process_staking()
.process_evm();

self
}
Expand Down Expand Up @@ -192,6 +197,16 @@ impl<R> State<R> {
self.map.keys().into_iter().any(|k| k.starts_with(&item_key(pallet, item)))
}

pub fn take_raw_value(&mut self, key: &str, value: &mut String) -> &mut Self {
if let Some(v) = self.map.remove(key) {
*value = v;
} else {
log::error!("`key({key})` not found");
}

self
}

pub fn take_raw_map<F>(
&mut self,
prefix: &str,
Expand Down Expand Up @@ -237,7 +252,7 @@ impl<R> State<R> {
}
} else {
log::error!(
"key not found `{}::{}::{hash}`",
"`key({}::{}::{hash})` not found",
String::from_utf8_lossy(pallet),
String::from_utf8_lossy(item),
);
Expand Down

0 comments on commit a661f99

Please sign in to comment.