Fix active difficulty calculation (#2338)
Fix active difficulty calculation (#2338)

* Fix active difficulty calculation

Median for active difficulty calculation is now obtained from a sorted container.

- Increase high confirmation request count to 128 to reduce tally logging and escalations under load
- Switch order of active difficulty update and confirmation requesting
- Move mutex unlock/lock inside search_frontiers scope
- Only add active difficulty if more than 10 samples in container
- Obtain active difficulty only from top 10k elections, not the whole container which can contain temporary elections

* Missing check for non-empty container and simplify mutex owning check

clemahieu/raiblocks,SergiySW/raiblocks,clemahieu/raiblocks,SergiySW/raiblocks,clemahieu/raiblocks,SergiySW/raiblocks,SergiySW/raiblocks,clemahieu/raiblocks,clemahieu/raiblocks,SergiySW/raiblocks,clemahieu/raiblocks