Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

standalone: Retain coinbase detection semantics. #2391

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Sep 29, 2020

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%.

@davecgh davecgh added this to the 1.6.0 milestone Sep 29, 2020
@davecgh davecgh force-pushed the blockchain_standalone_retain_iscoinbasetx_semantics branch from 80a4019 to 6e645d2 Compare September 29, 2020 05:20
Copy link
Member

@matheusd matheusd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a small typo

blockchain/standalone/tx.go Outdated Show resolved Hide resolved
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%.
@davecgh davecgh force-pushed the blockchain_standalone_retain_iscoinbasetx_semantics branch from 6e645d2 to e6c0a43 Compare September 29, 2020 16:18
@davecgh davecgh merged commit e6c0a43 into decred:master Sep 29, 2020
@davecgh davecgh deleted the blockchain_standalone_retain_iscoinbasetx_semantics branch September 29, 2020 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants