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

fix: load chain state on fast-sync #392

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading