Skip to content

Commit

Permalink
fix: load chain state on fast-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbillw committed Aug 12, 2024
1 parent c742eb4 commit 46b7960
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 2 additions & 4 deletions crates/cestory/src/ceseal_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> Ceseal<Platform> {
git_revision: self.args.git_revision.clone(),
memory_usage: Some(self.platform.memory_usage()),
system: system_info,
can_load_chain_state: self.can_load_chain_state,
can_load_chain_state: self.can_load_chain_state(),
safe_mode_level: self.args.safe_mode_level as _,
current_block_time,
external_server_state,
Expand All @@ -654,7 +654,6 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> Ceseal<Platform> {
),
"sync_header",
);
self.can_load_chain_state = false;
let last_header = self
.runtime_state()?
.storage_synchronizer
Expand Down Expand Up @@ -1083,7 +1082,7 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> Ceseal<Platform> {
}

pub fn load_chain_state(&mut self, block: chain::BlockNumber, storage: StorageState) -> anyhow::Result<()> {
if !self.can_load_chain_state {
if !self.can_load_chain_state() {
anyhow::bail!("Can not load chain state");
}
if block == 0 {
Expand All @@ -1105,7 +1104,6 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> Ceseal<Platform> {
.map_err(|e| anyhow!("Failed to set synchronizer state:{e}"))?;
state.chain_storage = Arc::new(parking_lot::RwLock::new(chain_storage));
system.genesis_block = block;
self.can_load_chain_state = false;
Ok(())
}

Expand Down
20 changes: 13 additions & 7 deletions crates/cestory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,7 @@ pub struct Ceseal<Platform> {
#[serde(skip)]
#[serde(default = "Instant::now")]
last_checkpoint: Instant,

#[codec(skip)]
#[serde(skip)]
can_load_chain_state: bool,


#[codec(skip)]
#[serde(skip)]
trusted_sk: bool,
Expand Down Expand Up @@ -337,7 +333,6 @@ impl<Platform: pal::Platform> Ceseal<Platform> {
handover_ecdh_key: None,
handover_last_challenge: None,
last_checkpoint: Instant::now(),
can_load_chain_state: false,
trusted_sk: false,
rcu_dispatching: false,
started_at: Instant::now(),
Expand All @@ -349,7 +344,6 @@ impl<Platform: pal::Platform> Ceseal<Platform> {
}

pub fn init(&mut self, args: InitArgs) {
self.can_load_chain_state = !system::is_master_key_exists_on_local(&args.sealing_path);
self.args = Arc::new(args);
}

Expand Down Expand Up @@ -378,6 +372,18 @@ impl<Platform: pal::Platform> Ceseal<Platform> {
}
}

fn is_keyfairy_ready(&self) -> bool {
if let Some(ref system) = self.system {
system.keyfairy.is_some()
} else {
false
}
}

fn can_load_chain_state(&self) -> bool {
!self.is_keyfairy_ready()
}

fn init_runtime_data(
&self,
genesis_block_hash: H256,
Expand Down

0 comments on commit 46b7960

Please sign in to comment.