From 6703b69c24315f7df6503a420cd3f32f6c067098 Mon Sep 17 00:00:00 2001 From: Tranz5 Date: Tue, 19 Aug 2014 20:58:25 -0400 Subject: [PATCH] remove fClient --- src/main.cpp | 114 +++++++++---------------------------------- src/main.h | 1 - src/net.cpp | 3 +- src/net.h | 1 - src/txdb-bdb.cpp | 7 --- src/txdb-leveldb.cpp | 7 --- src/wallet.cpp | 2 +- 7 files changed, 26 insertions(+), 109 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4ed5536..5ecc7f1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -524,44 +524,36 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock) { AssertLockHeld(cs_main); - if (fClient) + CBlock blockTmp; + if (pblock == NULL) { - if (hashBlock == 0) + // Load the block this tx is in + CTxIndex txindex; + if (!CTxDB("r").ReadTxIndex(GetHash(), txindex)) + return 0; + if (!blockTmp.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos)) return 0; + pblock = &blockTmp; } - else - { - CBlock blockTmp; - if (pblock == NULL) - { - // Load the block this tx is in - CTxIndex txindex; - if (!CTxDB("r").ReadTxIndex(GetHash(), txindex)) - return 0; - if (!blockTmp.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos)) - return 0; - pblock = &blockTmp; - } - // Update the tx's hashBlock - hashBlock = pblock->GetHash(); + // Update the tx's hashBlock + hashBlock = pblock->GetHash(); - // Locate the transaction - for (nIndex = 0; nIndex < (int)pblock->vtx.size(); nIndex++) - if (pblock->vtx[nIndex] == *(CTransaction*)this) - break; - if (nIndex == (int)pblock->vtx.size()) - { - vMerkleBranch.clear(); - nIndex = -1; - printf("ERROR: SetMerkleBranch() : couldn't find tx in block\n"); - return 0; - } - - // Fill in merkle branch - vMerkleBranch = pblock->GetMerkleBranch(nIndex); + // Locate the transaction + for (nIndex = 0; nIndex < (int)pblock->vtx.size(); nIndex++) + if (pblock->vtx[nIndex] == *(CTransaction*)this) + break; + if (nIndex == (int)pblock->vtx.size()) + { + vMerkleBranch.clear(); + nIndex = -1; + printf("ERROR: SetMerkleBranch() : couldn't find tx in block\n"); + return 0; } + // Fill in merkle branch + vMerkleBranch = pblock->GetMerkleBranch(nIndex); + // Is the tx in a block that's in the main chain map::iterator mi = mapBlockIndex.find(hashBlock); if (mi == mapBlockIndex.end()) @@ -926,16 +918,7 @@ int CMerkleTx::GetBlocksToMaturity() const bool CMerkleTx::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs) { - if (fClient) - { - if (!IsInMainChain() && !ClientConnectInputs()) - return false; - return CTransaction::AcceptToMemoryPool(txdb, false); - } - else - { - return CTransaction::AcceptToMemoryPool(txdb, fCheckInputs); - } + return CTransaction::AcceptToMemoryPool(txdb, fCheckInputs); } bool CMerkleTx::AcceptToMemoryPool() @@ -1607,55 +1590,6 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, return true; } - -bool CTransaction::ClientConnectInputs() -{ - if (IsCoinBase()) - return false; - - // Take over previous transactions' spent pointers - { - int64 nValueIn = 0; - for (unsigned int i = 0; i < vin.size(); i++) - { - // Get prev tx from single transactions in memory - COutPoint prevout = vin[i].prevout; - CTransaction txPrev; - if (!mempool.lookup(prevout.hash, txPrev)) - return false; - - if (prevout.n >= txPrev.vout.size()) - return false; - - // Verify signature - if (!VerifySignature(txPrev, *this, i, 0)) - return error("ConnectInputs() : VerifySignature failed"); - - ///// this is redundant with the mempool.mapNextTx stuff, - ///// not sure which I want to get rid of - ///// this has to go away now that posNext is gone - // // Check for conflicts - // if (!txPrev.vout[prevout.n].posNext.IsNull()) - // return error("ConnectInputs() : prev tx already used"); - // - // // Flag outpoints as used - // txPrev.vout[prevout.n].posNext = posThisTx; - - nValueIn += txPrev.vout[prevout.n].nValue; - - if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn)) - return error("ClientConnectInputs() : txin values out of range"); - } - if (GetValueOut() > nValueIn) - return false; - } - - return true; -} - - - - bool CBlock::DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex) { // Disconnect in reverse order diff --git a/src/main.h b/src/main.h index 1753804..66bf44e 100644 --- a/src/main.h +++ b/src/main.h @@ -700,7 +700,6 @@ class CTransaction bool ConnectInputs(CTxDB& txdb, MapPrevTx inputs, std::map& mapTestPool, const CDiskTxPos& posThisTx, const CBlockIndex* pindexBlock, bool fBlock, bool fMiner); - bool ClientConnectInputs(); bool CheckTransaction() const; bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL); bool GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const; // ppcoin: get transaction coin age diff --git a/src/net.cpp b/src/net.cpp index 81bb64e..cc09228 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -46,10 +46,9 @@ struct LocalServiceInfo { // // Global state variables // -bool fClient = false; bool fDiscover = true; bool fUseUPnP = false; -uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK); +uint64 nLocalServices = NODE_NETWORK; static CCriticalSection cs_mapLocalHost; static map mapLocalHost; static bool vfReachable[NET_MAX] = {}; diff --git a/src/net.h b/src/net.h index bf97578..416e528 100644 --- a/src/net.h +++ b/src/net.h @@ -113,7 +113,6 @@ enum threadId THREAD_MAX }; -extern bool fClient; extern bool fDiscover; extern bool fUseUPnP; extern uint64 nLocalServices; diff --git a/src/txdb-bdb.cpp b/src/txdb-bdb.cpp index d9ed8da..f59d6e6 100644 --- a/src/txdb-bdb.cpp +++ b/src/txdb-bdb.cpp @@ -33,21 +33,17 @@ void MakeMockTXDB() { bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex) { - assert(!fClient); txindex.SetNull(); return Read(make_pair(string("tx"), hash), txindex); } bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex) { - assert(!fClient); return Write(make_pair(string("tx"), hash), txindex); } bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight) { - assert(!fClient); - // Add to tx index uint256 hash = tx.GetHash(); CTxIndex txindex(pos, tx.vout.size()); @@ -56,7 +52,6 @@ bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeigh bool CTxDB::EraseTxIndex(const CTransaction& tx) { - assert(!fClient); uint256 hash = tx.GetHash(); return Erase(make_pair(string("tx"), hash)); @@ -64,13 +59,11 @@ bool CTxDB::EraseTxIndex(const CTransaction& tx) bool CTxDB::ContainsTx(uint256 hash) { - assert(!fClient); return Exists(make_pair(string("tx"), hash)); } bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex) { - assert(!fClient); tx.SetNull(); if (!ReadTxIndex(hash, txindex)) return false; diff --git a/src/txdb-leveldb.cpp b/src/txdb-leveldb.cpp index 232f784..5c99527 100644 --- a/src/txdb-leveldb.cpp +++ b/src/txdb-leveldb.cpp @@ -198,21 +198,17 @@ bool CTxDB::ScanBatch(const CDataStream &key, string *value, bool *deleted) cons bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex) { - assert(!fClient); txindex.SetNull(); return Read(make_pair(string("tx"), hash), txindex); } bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex) { - assert(!fClient); return Write(make_pair(string("tx"), hash), txindex); } bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight) { - assert(!fClient); - // Add to tx index uint256 hash = tx.GetHash(); CTxIndex txindex(pos, tx.vout.size()); @@ -221,7 +217,6 @@ bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeigh bool CTxDB::EraseTxIndex(const CTransaction& tx) { - assert(!fClient); uint256 hash = tx.GetHash(); return Erase(make_pair(string("tx"), hash)); @@ -229,13 +224,11 @@ bool CTxDB::EraseTxIndex(const CTransaction& tx) bool CTxDB::ContainsTx(uint256 hash) { - assert(!fClient); return Exists(make_pair(string("tx"), hash)); } bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex) { - assert(!fClient); tx.SetNull(); if (!ReadTxIndex(hash, txindex)) return false; diff --git a/src/wallet.cpp b/src/wallet.cpp index a28a38e..0fa7a00 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -810,7 +810,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) { tx = *mapWalletPrev[hash]; } - else if (!fClient && txdb.ReadDiskTx(hash, tx)) + else if (txdb.ReadDiskTx(hash, tx)) { ; }