Skip to content

Commit

Permalink
Check BIP30 on all blocks that aren't checkpointed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Corallo committed Jul 17, 2012
1 parent 9fa85b8 commit b2667bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
14 changes: 14 additions & 0 deletions src/checkpoints.cpp
Expand Up @@ -81,4 +81,18 @@ namespace Checkpoints
}
return NULL;
}

bool HaveCheckpoint(int nHeight)
{
assert(nHeight >= 0);

if (!fTestNet && (unsigned int)nHeight < sizeof(LSBCheckpoints)/sizeof(int))
return true;

MapCheckpoints& checkpoints = (fTestNet ? mapCheckpointsTestnet : mapCheckpoints);

MapCheckpoints::const_iterator i = checkpoints.find(nHeight);
if (i == checkpoints.end()) return false;
return true;
}
}
3 changes: 3 additions & 0 deletions src/checkpoints.h
Expand Up @@ -22,6 +22,9 @@ namespace Checkpoints

// Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);

// Returns true if we have a checkpoint lock-in for the given height
bool HaveCheckpoint(int nHeight);
}

#endif
23 changes: 10 additions & 13 deletions src/main.cpp
Expand Up @@ -1322,18 +1322,6 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
if (!CheckBlock())
return false;

// Do not allow blocks that contain transactions which 'overwrite' older transactions,
// unless those are already completely spent.
// If such overwrites are allowed, coinbases and transactions depending upon those
// can be duplicated to remove the ability to spend the first instance -- even after
// being sent to another address.
// See BIP30 and http://r6.ca/blog/20120206T005236Z.html for more information.
// This logic is not necessary for memory pool transactions, as AcceptToMemoryPool
// already refuses previously-known transaction id's entirely.
// This rule applies to all blocks whose timestamp is after March 15, 2012, 0:00 UTC.
int64 nBIP30SwitchTime = 1331769600;
bool fEnforceBIP30 = (pindex->nTime > nBIP30SwitchTime);

// BIP16 didn't become active until Apr 1 2012
int64 nBIP16SwitchTime = 1333238400;
bool fStrictPayToScriptHash = (pindex->nTime >= nBIP16SwitchTime);
Expand All @@ -1348,7 +1336,16 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
{
uint256 hashTx = tx.GetHash();

if (fEnforceBIP30) {
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
// unless those are already completely spent.
// If such overwrites are allowed, coinbases and transactions depending upon those
// can be duplicated to remove the ability to spend the first instance -- even after
// being sent to another address.
// See BIP30 and http://r6.ca/blog/20120206T005236Z.html for more information.
// This logic is not necessary for memory pool transactions, as AcceptToMemoryPool
// already refuses previously-known transaction id's entirely.
// This rule applies to all blocks whose timestamp is after March 15, 2012, 0:00 UTC.
if (!Checkpoints::HaveCheckpoint(pindex->nHeight)) {
CTxIndex txindexOld;
if (txdb.ReadTxIndex(hashTx, txindexOld)) {
BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent)
Expand Down

0 comments on commit b2667bc

Please sign in to comment.