snarkOS
snarkOS copied to clipboard
[Bug] Race Condition on reading latest_epoch_challenge/latest_block_header
🐛 Bug Report
Here is write part: https://github.com/AleoHQ/snarkOS/blob/7716d98a04884c3004c4fd76b29bf5c0fa4ae486/node/src/prover/router.rs#L172-L175
Here is read part: https://github.com/AleoHQ/snarkOS/blob/d832e4f539e042d03f60704fb6b297e1c191074e/node/src/prover/mod.rs#L164-L172
So it's possible that:
1-thread: will read self.latest_epoch_challenge
(than unlock it).
2-thread: lock self.latest_epoch_challenge
, replace it and lock self.latest_block_header
and replace it
1-thread: lock and read self.latest_block_header
(already new one)
So 1 thread will have wrong state previous latest_epoch_challenge
and new latest_block_header
Indeed, it seems like there can be a mismatch here.
@howardwu should these 2 values always be read and changed together or should we just extend the epoch_challenge
lock to avoid this particular issue?