Skip to content

Commit

Permalink
consensus: store and load last_iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia authored and fed-franz committed Sep 2, 2024
1 parent 185422e commit 3c97280
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions consensus/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ impl From<BlsSigError> for ConsensusError {
#[async_trait::async_trait]
pub trait Database: Send + Sync {
fn store_candidate_block(&mut self, b: Block);
async fn get_last_iter(&self) -> (Hash, u8);
async fn store_last_iter(&mut self, data: (Hash, u8));
}

#[derive(Clone)]
Expand Down
16 changes: 8 additions & 8 deletions consensus/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ impl<T: Operations + 'static, D: Database + 'static> Consensus<T, D> {
ru.base_timeouts.clone(),
);

// TODO: load save iteration
let saved_iter = 0;
let (prev_block_hash, saved_iter) =
db.lock().await.get_last_iter().await;

// If starting from `saved_iter`, we regenerate all committees
// in case they are needed to process past-iteration messages in
// Emergency Mode
if saved_iter != 0 {
if ru.hash() == prev_block_hash {
// If starting from `saved_iter`, we regenerate all committees
// in case they are needed to process past-iteration messages in
// Emergency Mode
while iter <= saved_iter {
iter_ctx.on_begin(iter);
iter_ctx.generate_committee(
Expand All @@ -209,13 +209,13 @@ impl<T: Operations + 'static, D: Database + 'static> Consensus<T, D> {
provisioners.as_ref(),
ru.seed(),
);
iter = saved_iter + 1;
}

iter = saved_iter + 1;
}

loop {
Self::consensus_delay().await;
db.lock().await.store_last_iter((ru.hash(), iter)).await;

iter_ctx.on_begin(iter);

Expand Down

0 comments on commit 3c97280

Please sign in to comment.