This reverts commit e2edf95cd3f43331843676e49a82830128a95050 6b04508 0df67f1f7ab4adfe9f0b3ba6276e737b37826464, except the changes to the RPC tests.
A generate RPC call is introduced based on the old code.
This is necessary because the slowdown in the new code in regtest mining is enough to cause travis failures.