aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2012-03-03 12:59:09 -0500
committerLuke Dashjr <luke-jr+git@utopios.org>2012-03-03 12:59:09 -0500
commite9865a41d669db0f9245d4494e1620e943ecddf8 (patch)
tree7ffce7b77b1278e4152490e558f9a884eb978d92
parent3108aed0f210fe6cb698237c7eeac8715fb95e31 (diff)
parentd7962747c4bfe90f9991d121fd22ac625ae2de30 (diff)
downloadbitcoin-e9865a41d669db0f9245d4494e1620e943ecddf8.tar.xz
Merge remote branch 'sipa/nooverwritetx_v0.4.0' into 0.4.x
-rw-r--r--src/main.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 8b11c2bbf0..652d4c1f98 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -844,8 +844,10 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
}
// Remove transaction from index
- if (!txdb.EraseTxIndex(*this))
- return error("DisconnectInputs() : EraseTxPos failed");
+ // This can fail if a duplicate of this transaction was in a chain that got
+ // reorganized away. This is only possible if this transaction was completely
+ // spent, so erasing it would be a no-op anway.
+ txdb.EraseTxIndex(*this);
return true;
}
@@ -1046,6 +1048,26 @@ 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.
+ // On testnet it is enabled as of februari 20, 2012, 0:00 UTC.
+ if (pindex->nTime > 1331769600 || (fTestNet && pindex->nTime > 1329696000))
+ BOOST_FOREACH(CTransaction& tx, vtx)
+ {
+ CTxIndex txindexOld;
+ if (txdb.ReadTxIndex(tx.GetHash(), txindexOld))
+ BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent)
+ if (pos.IsNull())
+ return false;
+ }
+
//// issue here: it doesn't know the version
unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size());