Skip to content

Commit cb94db1

Browse files
committed
validation, index: Add unspendable coinbase helper functions
Making the checks to identify BIP30 available outside of validation.cpp is needed for reporting and tracking statistics on specific blocks and the UTXO set correctly.
1 parent 6d40484 commit cb94db1

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/index/coinstatsindex.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,13 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
144144
}
145145
}
146146

147-
// TODO: Deduplicate BIP30 related code
148-
bool is_bip30_block{(block.height == 91722 && block.hash == uint256S("0x00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e")) ||
149-
(block.height == 91812 && block.hash == uint256S("0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f"))};
150-
151147
// Add the new utxos created from the block
152148
assert(block.data);
153149
for (size_t i = 0; i < block.data->vtx.size(); ++i) {
154150
const auto& tx{block.data->vtx.at(i)};
155151

156152
// Skip duplicate txid coinbase transactions (BIP30).
157-
if (is_bip30_block && tx->IsCoinBase()) {
153+
if (IsBIP30Unspendable(*pindex) && tx->IsCoinBase()) {
158154
m_total_unspendable_amount += block_subsidy;
159155
m_total_unspendables_bip30 += block_subsidy;
160156
continue;

src/validation.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,8 +2083,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
20832083
// Now that the whole chain is irreversibly beyond that time it is applied to all blocks except the
20842084
// two in the chain that violate it. This prevents exploiting the issue against nodes during their
20852085
// initial block download.
2086-
bool fEnforceBIP30 = !((pindex->nHeight==91842 && pindex->GetBlockHash() == uint256S("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) ||
2087-
(pindex->nHeight==91880 && pindex->GetBlockHash() == uint256S("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")));
2086+
bool fEnforceBIP30 = !IsBIP30Repeat(*pindex);
20882087

20892088
// Once BIP34 activated it was not possible to create new duplicate coinbases and thus other than starting
20902089
// with the 2 existing duplicate coinbase pairs, not possible to create overwriting txs. But by the
@@ -5290,3 +5289,15 @@ Chainstate& ChainstateManager::ActivateExistingSnapshot(CTxMemPool* mempool, uin
52905289
m_active_chainstate = m_snapshot_chainstate.get();
52915290
return *m_snapshot_chainstate;
52925291
}
5292+
5293+
bool IsBIP30Repeat(const CBlockIndex& block_index)
5294+
{
5295+
return (block_index.nHeight==91842 && block_index.GetBlockHash() == uint256S("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) ||
5296+
(block_index.nHeight==91880 && block_index.GetBlockHash() == uint256S("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721"));
5297+
}
5298+
5299+
bool IsBIP30Unspendable(const CBlockIndex& block_index)
5300+
{
5301+
return (block_index.nHeight==91722 && block_index.GetBlockHash() == uint256S("0x00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e")) ||
5302+
(block_index.nHeight==91812 && block_index.GetBlockHash() == uint256S("0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f"));
5303+
}

src/validation.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,4 +1082,10 @@ bool DeploymentEnabled(const ChainstateManager& chainman, DEP dep)
10821082
*/
10831083
const AssumeutxoData* ExpectedAssumeutxo(const int height, const CChainParams& params);
10841084

1085+
/** Identifies blocks that overwrote an existing coinbase output in the UTXO set (see BIP30) */
1086+
bool IsBIP30Repeat(const CBlockIndex& block_index);
1087+
1088+
/** Identifies blocks which coinbase output was subsequently overwritten in the UTXO set (see BIP30) */
1089+
bool IsBIP30Unspendable(const CBlockIndex& block_index);
1090+
10851091
#endif // BITCOIN_VALIDATION_H

0 commit comments

Comments
 (0)