In all the 3 functions, reject transactions creating new money earlier. Consensus::CheckTxInputs gets nTxFee as output parameter and is separated from main::CheckInputs [renamed CheckInputsScripts]. This continues #6061.
Detailed optimizations:
- Consensus::CheckTxInputs (called by the rest):
Don’t calculate nValueOut twice Don’t check nFees < 0 twice
- main::AcceptToMemoryPool:
Don’t calculate nValueOut 5 times Don’t calculate nValueIn 3 times Don’t call CCoinsViewCache::HaveInputs 3 times
- miner::CreateNewBlock:
Don’t calculate nValueOut 3 times Don’t calculate nValueIn twice Don’t call CCoinsViewCache::HaveInputs twice
- main::ConnectBlock:
Don’t calculate nValueOut 3 times Don’t calculate nValueIn twice Still call CCoinsViewCache::HaveInputs twice