aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp98
1 files changed, 50 insertions, 48 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 05f13dfda6..83a640d7f3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -74,53 +74,54 @@ const string strMessageMagic = "Bitcoin Signed Message:\n";
// Internal stuff
namespace {
-struct CBlockIndexWorkComparator
-{
- bool operator()(CBlockIndex *pa, CBlockIndex *pb) {
- // First sort by most total work, ...
- if (pa->nChainWork > pb->nChainWork) return false;
- if (pa->nChainWork < pb->nChainWork) return true;
-
- // ... then by earliest time received, ...
- if (pa->nSequenceId < pb->nSequenceId) return false;
- if (pa->nSequenceId > pb->nSequenceId) return true;
+ struct CBlockIndexWorkComparator
+ {
+ bool operator()(CBlockIndex *pa, CBlockIndex *pb) {
+ // First sort by most total work, ...
+ if (pa->nChainWork > pb->nChainWork) return false;
+ if (pa->nChainWork < pb->nChainWork) return true;
- // Use pointer address as tie breaker (should only happen with blocks
- // loaded from disk, as those all have id 0).
- if (pa < pb) return false;
- if (pa > pb) return true;
+ // ... then by earliest time received, ...
+ if (pa->nSequenceId < pb->nSequenceId) return false;
+ if (pa->nSequenceId > pb->nSequenceId) return true;
- // Identical blocks.
- return false;
- }
-};
+ // Use pointer address as tie breaker (should only happen with blocks
+ // loaded from disk, as those all have id 0).
+ if (pa < pb) return false;
+ if (pa > pb) return true;
-CBlockIndex *pindexBestInvalid;
-set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid; // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed
-
-CCriticalSection cs_LastBlockFile;
-CBlockFileInfo infoLastBlockFile;
-int nLastBlockFile = 0;
-
-// Every received block is assigned a unique and increasing identifier, so we
-// know which one to give priority in case of a fork.
-CCriticalSection cs_nBlockSequenceId;
-// Blocks loaded from disk are assigned id 0, so start the counter at 1.
-uint32_t nBlockSequenceId = 1;
-
-// Sources of received blocks, to be able to send them reject messages or ban
-// them, if processing happens afterwards. Protected by cs_main.
-map<uint256, NodeId> mapBlockSource;
-
-// Blocks that are in flight, and that are in the queue to be downloaded.
-// Protected by cs_main.
-struct QueuedBlock {
- uint256 hash;
- int64_t nTime; // Time of "getdata" request in microseconds.
- int nQueuedBefore; // Number of blocks in flight at the time of request.
-};
-map<uint256, pair<NodeId, list<QueuedBlock>::iterator> > mapBlocksInFlight;
-map<uint256, pair<NodeId, list<uint256>::iterator> > mapBlocksToDownload;
+ // Identical blocks.
+ return false;
+ }
+ };
+
+ CBlockIndex *pindexBestInvalid;
+ // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed
+ set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid;
+
+ CCriticalSection cs_LastBlockFile;
+ CBlockFileInfo infoLastBlockFile;
+ int nLastBlockFile = 0;
+
+ // Every received block is assigned a unique and increasing identifier, so we
+ // know which one to give priority in case of a fork.
+ CCriticalSection cs_nBlockSequenceId;
+ // Blocks loaded from disk are assigned id 0, so start the counter at 1.
+ uint32_t nBlockSequenceId = 1;
+
+ // Sources of received blocks, to be able to send them reject messages or ban
+ // them, if processing happens afterwards. Protected by cs_main.
+ map<uint256, NodeId> mapBlockSource;
+
+ // Blocks that are in flight, and that are in the queue to be downloaded.
+ // Protected by cs_main.
+ struct QueuedBlock {
+ uint256 hash;
+ int64_t nTime; // Time of "getdata" request in microseconds.
+ int nQueuedBefore; // Number of blocks in flight at the time of request.
+ };
+ map<uint256, pair<NodeId, list<QueuedBlock>::iterator> > mapBlocksInFlight;
+ map<uint256, pair<NodeId, list<uint256>::iterator> > mapBlocksToDownload;
}
//////////////////////////////////////////////////////////////////////////////
@@ -1032,11 +1033,11 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
fseek(file, postx.nTxOffset, SEEK_CUR);
file >> txOut;
} catch (std::exception &e) {
- return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
+ return error("%s : Deserialize or I/O error - %s", __func__, e.what());
}
hashBlock = header.GetHash();
if (txOut.GetHash() != hash)
- return error("%s : txid mismatch", __PRETTY_FUNCTION__);
+ return error("%s : txid mismatch", __func__);
return true;
}
}
@@ -1120,7 +1121,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
filein >> block;
}
catch (std::exception &e) {
- return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
+ return error("%s : Deserialize or I/O error - %s", __func__, e.what());
}
// Check the header
@@ -2955,6 +2956,7 @@ bool static LoadBlockIndexDB()
bool VerifyDB(int nCheckLevel, int nCheckDepth)
{
+ LOCK(cs_main);
if (chainActive.Tip() == NULL || chainActive.Tip()->pprev == NULL)
return true;
@@ -3208,7 +3210,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
break;
}
} catch (std::exception &e) {
- LogPrintf("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
+ LogPrintf("%s : Deserialize or I/O error - %s", __func__, e.what());
}
}
fclose(fileIn);