Skip to content

Commit

Permalink
save the dag state directly when resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
jackzhhuang committed Oct 10, 2024
1 parent 68c433f commit fb1b5c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions flexidag/src/blockdag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ impl BlockDAG {
Ok(self.storage.state_store.read().get_state_by_hash(hash)?)
}

pub fn save_dag_state_directly(&self, hash: Hash, state: DagState) -> anyhow::Result<()> {
self.storage.state_store.write().insert(hash, state)?;
anyhow::Ok(())
}

pub fn save_dag_state(&self, hash: Hash, state: DagState) -> anyhow::Result<()> {
let writer = self.storage.state_store.write();
match writer.get_state_by_hash(hash) {
Expand Down
6 changes: 3 additions & 3 deletions sync/src/block_connector/write_block_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,20 @@ where
.get_storage()
.get_genesis()?
.ok_or_else(|| format_err!("Cannot get the genesis in storage!"))?;
self.main.dag().save_dag_state(
self.main.dag().save_dag_state_directly(
genesis,
DagState {
tips: vec![new_head_block.header().id()],
},
)?;
self.main.dag().save_dag_state(
self.main.dag().save_dag_state_directly(
HashValue::zero(),
DagState {
tips: vec![new_head_block.header().id()],
},
)?;
} else {
self.main.dag().save_dag_state(
self.main.dag().save_dag_state_directly(
new_head_block.header().pruning_point(),
DagState {
tips: vec![new_head_block.header().id()],
Expand Down

0 comments on commit fb1b5c6

Please sign in to comment.