Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix potential race condition between add_block and sync (#4677)
Description --- This fixes a potential race condition. It is possible for `add_block` to pass the `is_add_block_disabled()`, start doing orphan validation (which can take quite long). While this is happening, `sync` sets the `add_block_disabled` flag and acquires a read_lock to then do pre-processing to determine sync mode, etc. While this is busy, `add_block` asks for a write_lock. `Add_block` gets its write_lock before `sync` gets its write_block because of the prioritization of RWLock. Also moved the `if db.contains(&DbKey::BlockHash(block_hash))` before the orphan validation as this is a much cheaper operation.
- Loading branch information