Don't accept duplicate UTXOs
Is your feature request related to a problem? Please describe Initial discussion started in this PR https://github.com/dtr-org/unit-e/pull/522 after the merge. We removed BIP34 flag which introduced the height in the CoinBase and by this removed a possible valid condition when 2 different transactions have the same ID and must be valid. Since we made BIP34 active from the beginning, we should also remove the code that accepts duplicate outputs.
Describe the solution you'd like In the following function:
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check) {
bool fCoinbase = tx.IsCoinBase();
const uint256& txid = tx.GetHash();
for (size_t i = 0; i < tx.vout.size(); ++i) {
bool overwrite = check ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
// Always set the possible_overwrite flag to AddCoin for coinbase txn, in order to correctly
// deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
}
}
we should remove bool check parameter and from cache.AddCoin remove overwrite flag and all down the code where it's used.
The reason for removing this code is because we removed all references from comments and chainparams to this feature and this code becomes misleading.
Additional context
comment in the code about overwrite feature https://github.com/dtr-org/unit-e/blob/master/src/coins.h#L359-L360
the function that must be changed https://github.com/dtr-org/unit-e/blob/master/src/coins.cpp#L101-L110
I started working on this in https://github.com/scravy/unit-e/tree/dont-accept-duplicate-utxo
There's two tests to fix which I don't have the time to today or tomorrow, will follow up with it later this week. Feel free to look into it, anyone :-)