aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-07-05 10:06:55 -0700
committerJeff Garzik <jgarzik@exmulti.com>2012-07-05 10:06:55 -0700
commitb47d2bc164bd21d4bec988fa8abfecc74d5ce5da (patch)
treed774fba77702003137e81d5a20d29d9ea558b05e /src
parenta2709fad7f57b000333371954016045e12fc4bed (diff)
parentf77654a0e9424f13cad04f82c014abd78fbb5e38 (diff)
Merge pull request #1554 from jgarzik/dup-gethash
Remove duplicate GetHash() in ConnectBlock
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp34
-rw-r--r--src/main.h2
2 files changed, 17 insertions, 19 deletions
diff --git a/src/main.cpp b/src/main.cpp
index d2cb154c1f..8e1deac4bb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -600,7 +600,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs,
printf("CTxMemPool::accept() : replacing tx %s with new version\n", ptxOld->GetHash().ToString().c_str());
remove(*ptxOld);
}
- addUnchecked(tx);
+ addUnchecked(hash, tx);
}
///// are we sure this is ok when loading transactions or restoring block txes
@@ -619,13 +619,11 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
return mempool.accept(txdb, *this, fCheckInputs, pfMissingInputs);
}
-bool CTxMemPool::addUnchecked(CTransaction &tx)
+bool CTxMemPool::addUnchecked(const uint256& hash, CTransaction &tx)
{
// Add to memory pool without checking anything. Don't call this directly,
// call CTxMemPool::accept to properly check the transaction first.
{
- LOCK(cs);
- uint256 hash = tx.GetHash();
mapTx[hash] = tx;
for (unsigned int i = 0; i < tx.vin.size(); i++)
mapNextTx[tx.vin[i].prevout] = CInPoint(&mapTx[hash], i);
@@ -1325,19 +1323,8 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
// 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 (pindex->nTime > 1331769600)
- {
- BOOST_FOREACH(CTransaction& tx, vtx)
- {
- CTxIndex txindexOld;
- if (txdb.ReadTxIndex(tx.GetHash(), txindexOld))
- {
- BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent)
- if (pos.IsNull())
- return false;
- }
- }
- }
+ int64 nBIP30SwitchTime = 1331769600;
+ bool fEnforceBIP30 = (pindex->nTime > nBIP30SwitchTime);
// BIP16 didn't become active until Apr 1 2012
int64 nBIP16SwitchTime = 1333238400;
@@ -1351,6 +1338,17 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
unsigned int nSigOps = 0;
BOOST_FOREACH(CTransaction& tx, vtx)
{
+ uint256 hashTx = tx.GetHash();
+
+ if (fEnforceBIP30) {
+ CTxIndex txindexOld;
+ if (txdb.ReadTxIndex(hashTx, txindexOld)) {
+ BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent)
+ if (pos.IsNull())
+ return false;
+ }
+ }
+
nSigOps += tx.GetLegacySigOpCount();
if (nSigOps > MAX_BLOCK_SIGOPS)
return DoS(100, error("ConnectBlock() : too many sigops"));
@@ -1381,7 +1379,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
return false;
}
- mapQueuedChanges[tx.GetHash()] = CTxIndex(posThisTx, tx.vout.size());
+ mapQueuedChanges[hashTx] = CTxIndex(posThisTx, tx.vout.size());
}
// Write queued txindex changes
diff --git a/src/main.h b/src/main.h
index bb094ad3c7..c841fdaf18 100644
--- a/src/main.h
+++ b/src/main.h
@@ -1602,7 +1602,7 @@ public:
bool accept(CTxDB& txdb, CTransaction &tx,
bool fCheckInputs, bool* pfMissingInputs);
- bool addUnchecked(CTransaction &tx);
+ bool addUnchecked(const uint256& hash, CTransaction &tx);
bool remove(CTransaction &tx);
void queryHashes(std::vector<uint256>& vtxid);