Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
fix synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Oct 27, 2019
1 parent 7db6905 commit bbf41f8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions core/consensus/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ impl<Adapter: ConsensusAdapter + 'static> Consensus for OverlordConsensus<Adapte
info!("self {}, chain {}", current_epoch_id, rich_epoch_id);
info!("consensus: start synchronization");

let mut state_root = Hash::from_empty();
let mut current_hash = if current_epoch_id != 0 {
let mut current_epoch = self
.engine
.get_epoch_by_id(ctx.clone(), current_epoch_id)
.await?;
state_root = current_epoch.header.state_root.clone();
let tmp = Hash::digest(current_epoch.encode().await?);

// Check epoch for the first time.
Expand Down Expand Up @@ -140,31 +142,27 @@ impl<Adapter: ConsensusAdapter + 'static> Consensus for OverlordConsensus<Adapte
.pull_txs(ctx.clone(), epoch.ordered_tx_hashes.clone())
.await?;

let last_epoch = self
.engine
.get_epoch_by_id(ctx.clone(), epoch.header.epoch_id - 1)
.await?;
// After get the signed transactions:
// 1. Execute the signed transactions.
// 2. Save the signed transactions.
// 3. Save the latest proof.
// 4. Save the new epoch.
// 5. Save the receipt.
debug!("consensus: synchronization executor the epoch");

let exec_resp = self
.engine
.exec(
last_epoch.header.state_root.clone(),
state_root.clone(),
epoch.header.epoch_id,
Address::User(epoch.header.proposer.clone()),
txs.clone(),
)
.await?;
state_root = exec_resp.state_root.clone();

debug!("consensus: synchronization update the rich status");
self.engine
.update_status(id, epoch.clone(), proof, exec_resp, txs)
.update_status(epoch.header.epoch_id, epoch.clone(), proof, exec_resp, txs)
.await?;

// Update the previous hash and last epoch.
Expand Down

0 comments on commit bbf41f8

Please sign in to comment.