@bsunau7
Thanks for the info and I will implement a small sieve for validation and use a single exponentiation test at each end point; it should be at least 100x faster and less than 1/(2128) probability of it being a larger gap.
There was talk on GMP mailing lists about speeding up gmp_nextprime in a very similar manner, sieve the start/end gap before running expensive MR tests. As the gap has been pre-sieved you might just be able to MR test the non-composite in the mining sieve and get the same result.
I personally didn't bother with the PoW validation code as for larger gaps it just isn't called enough to matter.
Also you can tweak the pprocessor->process() to terminate the sieve early which will cure the stales and get you to the next "block" a few seconds faster at the risk of having a slightly wrong difficulty (in effect a non issue).
PS. Just pushed testnet to >8 might slow down your stale shares some (I am only getting only 75-90% stale at this difficulty).
Regards,
--
bsunau7