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
fed-franz committed Sep 5, 2024
1 parent 485c820 commit 52378e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 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
13 changes: 7 additions & 6 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 @@ -215,6 +215,7 @@ impl<T: Operations + 'static, D: Database + 'static> Consensus<T, D> {

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 52378e3

Please sign in to comment.