standalone: Retain coinbase detection semantics. #2391
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This modifies the
IsCoinBaseTx
function to retain the existing semantics regarding coinbase detection logic once the treasury agenda activates.Specifically, the existing consensus logic regarding the fast heuristic for detecting whether or not a transaction is likely to be coinbase has no restrictions regarding the number of outputs nor the the lengths of the scripts.
Later, once a coinbase is actually validated by consensus, it is required to have a payout to the treasury as well as a provably-prunable output that identifies the block height.
This means that it is technically possible for a miner to create a coinbase that burns coins if they so choose, even though, in practice, it is exceedingly unlikely.
Since the new treasury spend transaction type looks similar enough to existing coinbase transactions, they are also detected as coinbases under the existing code.
To combat this, the new treasury code introduces logic which consists of exempting transactions that look like treasury spends from being identified as a coinbase. Unfortunately, the logic reports that a transaction is not a coinbase when any of the conditions that lead up to the transaction being identified as a treasury spend are met instead of when all of the conditions are met.
The result is that the aforementioned semantics are changed which should not be the case.
This resolves that by modifying the logic accordingly such that the heuristic retains the same semantics for all transactions that are not specifically identified to likely be a treasury spend.
It also adds tests to ensure the new behavior works as intended bringing the test coverage of the function back up to 100%.