Skip to content

Commit

Permalink
remove fClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Tranz5 committed Aug 20, 2014
1 parent d9a625a commit 6703b69
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 109 deletions.
114 changes: 24 additions & 90 deletions src/main.cpp
Expand Up @@ -524,44 +524,36 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock)
{ {
AssertLockHeld(cs_main); 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; 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 // Update the tx's hashBlock
hashBlock = pblock->GetHash(); hashBlock = pblock->GetHash();


// Locate the transaction // Locate the transaction
for (nIndex = 0; nIndex < (int)pblock->vtx.size(); nIndex++) for (nIndex = 0; nIndex < (int)pblock->vtx.size(); nIndex++)
if (pblock->vtx[nIndex] == *(CTransaction*)this) if (pblock->vtx[nIndex] == *(CTransaction*)this)
break; break;
if (nIndex == (int)pblock->vtx.size()) if (nIndex == (int)pblock->vtx.size())
{ {
vMerkleBranch.clear(); vMerkleBranch.clear();
nIndex = -1; nIndex = -1;
printf("ERROR: SetMerkleBranch() : couldn't find tx in block\n"); printf("ERROR: SetMerkleBranch() : couldn't find tx in block\n");
return 0; return 0;
}

// Fill in merkle branch
vMerkleBranch = pblock->GetMerkleBranch(nIndex);
} }


// Fill in merkle branch
vMerkleBranch = pblock->GetMerkleBranch(nIndex);

// Is the tx in a block that's in the main chain // Is the tx in a block that's in the main chain
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock); map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
if (mi == mapBlockIndex.end()) if (mi == mapBlockIndex.end())
Expand Down Expand Up @@ -926,16 +918,7 @@ int CMerkleTx::GetBlocksToMaturity() const


bool CMerkleTx::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs) bool CMerkleTx::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs)
{ {
if (fClient) return CTransaction::AcceptToMemoryPool(txdb, fCheckInputs);
{
if (!IsInMainChain() && !ClientConnectInputs())
return false;
return CTransaction::AcceptToMemoryPool(txdb, false);
}
else
{
return CTransaction::AcceptToMemoryPool(txdb, fCheckInputs);
}
} }


bool CMerkleTx::AcceptToMemoryPool() bool CMerkleTx::AcceptToMemoryPool()
Expand Down Expand Up @@ -1607,55 +1590,6 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
return true; 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) bool CBlock::DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex)
{ {
// Disconnect in reverse order // Disconnect in reverse order
Expand Down
1 change: 0 additions & 1 deletion src/main.h
Expand Up @@ -700,7 +700,6 @@ class CTransaction
bool ConnectInputs(CTxDB& txdb, MapPrevTx inputs, bool ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
std::map<uint256, CTxIndex>& mapTestPool, const CDiskTxPos& posThisTx, std::map<uint256, CTxIndex>& mapTestPool, const CDiskTxPos& posThisTx,
const CBlockIndex* pindexBlock, bool fBlock, bool fMiner); const CBlockIndex* pindexBlock, bool fBlock, bool fMiner);
bool ClientConnectInputs();
bool CheckTransaction() const; bool CheckTransaction() const;
bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL); bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);
bool GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const; // ppcoin: get transaction coin age bool GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const; // ppcoin: get transaction coin age
Expand Down
3 changes: 1 addition & 2 deletions src/net.cpp
Expand Up @@ -46,10 +46,9 @@ struct LocalServiceInfo {
// //
// Global state variables // Global state variables
// //
bool fClient = false;
bool fDiscover = true; bool fDiscover = true;
bool fUseUPnP = false; bool fUseUPnP = false;
uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK); uint64 nLocalServices = NODE_NETWORK;
static CCriticalSection cs_mapLocalHost; static CCriticalSection cs_mapLocalHost;
static map<CNetAddr, LocalServiceInfo> mapLocalHost; static map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfReachable[NET_MAX] = {}; static bool vfReachable[NET_MAX] = {};
Expand Down
1 change: 0 additions & 1 deletion src/net.h
Expand Up @@ -113,7 +113,6 @@ enum threadId
THREAD_MAX THREAD_MAX
}; };


extern bool fClient;
extern bool fDiscover; extern bool fDiscover;
extern bool fUseUPnP; extern bool fUseUPnP;
extern uint64 nLocalServices; extern uint64 nLocalServices;
Expand Down
7 changes: 0 additions & 7 deletions src/txdb-bdb.cpp
Expand Up @@ -33,21 +33,17 @@ void MakeMockTXDB() {


bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex) bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex)
{ {
assert(!fClient);
txindex.SetNull(); txindex.SetNull();
return Read(make_pair(string("tx"), hash), txindex); return Read(make_pair(string("tx"), hash), txindex);
} }


bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex) bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex)
{ {
assert(!fClient);
return Write(make_pair(string("tx"), hash), txindex); return Write(make_pair(string("tx"), hash), txindex);
} }


bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight) bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight)
{ {
assert(!fClient);

// Add to tx index // Add to tx index
uint256 hash = tx.GetHash(); uint256 hash = tx.GetHash();
CTxIndex txindex(pos, tx.vout.size()); CTxIndex txindex(pos, tx.vout.size());
Expand All @@ -56,21 +52,18 @@ bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeigh


bool CTxDB::EraseTxIndex(const CTransaction& tx) bool CTxDB::EraseTxIndex(const CTransaction& tx)
{ {
assert(!fClient);
uint256 hash = tx.GetHash(); uint256 hash = tx.GetHash();


return Erase(make_pair(string("tx"), hash)); return Erase(make_pair(string("tx"), hash));
} }


bool CTxDB::ContainsTx(uint256 hash) bool CTxDB::ContainsTx(uint256 hash)
{ {
assert(!fClient);
return Exists(make_pair(string("tx"), hash)); return Exists(make_pair(string("tx"), hash));
} }


bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex) bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex)
{ {
assert(!fClient);
tx.SetNull(); tx.SetNull();
if (!ReadTxIndex(hash, txindex)) if (!ReadTxIndex(hash, txindex))
return false; return false;
Expand Down
7 changes: 0 additions & 7 deletions src/txdb-leveldb.cpp
Expand Up @@ -198,21 +198,17 @@ bool CTxDB::ScanBatch(const CDataStream &key, string *value, bool *deleted) cons


bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex) bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex)
{ {
assert(!fClient);
txindex.SetNull(); txindex.SetNull();
return Read(make_pair(string("tx"), hash), txindex); return Read(make_pair(string("tx"), hash), txindex);
} }


bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex) bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex)
{ {
assert(!fClient);
return Write(make_pair(string("tx"), hash), txindex); return Write(make_pair(string("tx"), hash), txindex);
} }


bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight) bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight)
{ {
assert(!fClient);

// Add to tx index // Add to tx index
uint256 hash = tx.GetHash(); uint256 hash = tx.GetHash();
CTxIndex txindex(pos, tx.vout.size()); CTxIndex txindex(pos, tx.vout.size());
Expand All @@ -221,21 +217,18 @@ bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeigh


bool CTxDB::EraseTxIndex(const CTransaction& tx) bool CTxDB::EraseTxIndex(const CTransaction& tx)
{ {
assert(!fClient);
uint256 hash = tx.GetHash(); uint256 hash = tx.GetHash();


return Erase(make_pair(string("tx"), hash)); return Erase(make_pair(string("tx"), hash));
} }


bool CTxDB::ContainsTx(uint256 hash) bool CTxDB::ContainsTx(uint256 hash)
{ {
assert(!fClient);
return Exists(make_pair(string("tx"), hash)); return Exists(make_pair(string("tx"), hash));
} }


bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex) bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex)
{ {
assert(!fClient);
tx.SetNull(); tx.SetNull();
if (!ReadTxIndex(hash, txindex)) if (!ReadTxIndex(hash, txindex))
return false; return false;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.cpp
Expand Up @@ -810,7 +810,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb)
{ {
tx = *mapWalletPrev[hash]; tx = *mapWalletPrev[hash];
} }
else if (!fClient && txdb.ReadDiskTx(hash, tx)) else if (txdb.ReadDiskTx(hash, tx))
{ {
; ;
} }
Expand Down

0 comments on commit 6703b69

Please sign in to comment.