The wallet is async, so after generating a block, we must call syncwithvalidationinterfacequeue. Otherwise the timestamp will be of the previous block.
getbestblockhash directly accesses the chainstate, so it is not needed there.
This is a backport of Core PR18753