hot-stuff / libhotstuff

A general-purpose BFT state machine replication library with modularity and simplicity, suitable for building hybrid consensus cryptocurrencies.
Apache License 2.0
239 stars 81 forks source link

OnReceiveProPosal question #26

Open fxj-github opened 2 years ago

fxj-github commented 2 years ago

I noticed in the latest paper's Event-driven code, Update() called after sending vote. But in libhotstuff code, Update() called before sending vote. I'm confused as Update() may update lock and sending vote depends on lock. So which is correct? Or both can be correct? Thanks.

AeonSw4n commented 2 years ago

Hey, been digging into the code for the past few days and I also found this intriguing. I think the answer is that update and the conditional logic gating the vote don't conflict with one another and so their ordering doesn't matter. Notice that in HotStuffCore::update, we update the b_lock to blk1 (ref), which is equal to bnew.justify.justify, and as long blk1.height > b_lock.height. However, the on_receive_proposal condition checks whether bnew.justify.height > b_lock.height which would evaluate identically regardless of the update since bnew.justify.height > blk1.height.