oxen-io / oxen-core

Oxen core repository, containing oxend and oxen cli wallets
https://oxen.io
Other
317 stars 120 forks source link

Fix stale top hash on reorg #1728

Closed Doy-lee closed 1 month ago

Doy-lee commented 2 months ago

Prior to this, when the blockchain reorg-ed to the same height (e.g: replaced the top block) the top height remains the same but the block has changed which means the next Pulse quorum has changed. We were only tracking the top height which meant that it was essentially guaranteed that after a reorg we would churn through a bunch of quorums until we found a quorum that consisted primarily of nodes that didn't reorg. The nodes that did reorg will be generating the incorrect quorums and hence trying to conduct Pulse with the wrong nodes.

Instead track the hash which means if we encounter this situation, the nodes will detect it immediately and reconfigure the Pulse state machine to work with the new data.

This change also simplifies the initial gathering of state to extracting information from the top block instead of going back to the DB for the top height, timestamp and top hash which is subject to a data race (if we by chance happen to initiate a Pulse round just as we received new blocks).