parallelchain-io / hotstuff_rs

Rust implementation of the HotStuff consensus algorithm.
38 stars 5 forks source link

Must `insert` be atomically followed by `update`? #51

Open lyulka opened 2 months ago

lyulka commented 2 months ago

Affected version

v0.4 (branch: dev/v0.4)

Background

BlockTree::insert is called in two places in the library:

  1. In HotStuff::on_receive_proposal.
  2. In BlockSync::insert.

In both instances, the call to insert is followed by a call to update.

Potential Problem

insert and update each use separate WriteBatches to write their changes. This means that if a process running HotStuff-rs crashes after the changes of insert are written, but before the changes of update are written, the block tree could be left in an inconsistent state.

Question

I'm sure that Karolina must have ensured that crashing right after insert but before update is safe. What is the argument behind this? Let's find out and write documentation.