aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp69
1 files changed, 45 insertions, 24 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 293e7bca5c..8468027138 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -564,7 +564,7 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs,
// Continuously rate-limit free transactions
// This mitigates 'penny-flooding' -- sending thousands of free transactions just to
- // be annoying or make other's transactions take longer to confirm.
+ // be annoying or make others' transactions take longer to confirm.
if (nFees < MIN_RELAY_TX_FEE)
{
static CCriticalSection cs;
@@ -811,6 +811,24 @@ bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock)
// CBlock and CBlockIndex
//
+static CBlockIndex* pblockindexFBBHLast;
+CBlockIndex* FindBlockByHeight(int nHeight)
+{
+ CBlockIndex *pblockindex;
+ if (nHeight < nBestHeight / 2)
+ pblockindex = pindexGenesisBlock;
+ else
+ pblockindex = pindexBest;
+ if (pblockindexFBBHLast && abs(nHeight - pblockindex->nHeight) > abs(nHeight - pblockindexFBBHLast->nHeight))
+ pblockindex = pblockindexFBBHLast;
+ while (pblockindex->nHeight > nHeight)
+ pblockindex = pblockindex->pprev;
+ while (pblockindex->nHeight < nHeight)
+ pblockindex = pblockindex->pnext;
+ pblockindexFBBHLast = pblockindex;
+ return pblockindex;
+}
+
bool CBlock::ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions)
{
if (!fReadTransactions)
@@ -988,7 +1006,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
hashBestChain.ToString().substr(0,20).c_str(), nBestHeight, bnBestChainWork.ToString().c_str(),
DateTimeStrFormat("%x %H:%M:%S", pindexBest->GetBlockTime()).c_str());
if (pindexBest && bnBestInvalidWork > bnBestChainWork + pindexBest->GetBlockWork() * 6)
- printf("InvalidChainFound: WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n");
+ printf("InvalidChainFound: Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n");
}
void CBlock::UpdateTime(const CBlockIndex* pindexPrev)
@@ -1039,7 +1057,7 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
// Remove transaction from index
// 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.
+ // spent, so erasing it would be a no-op anyway.
txdb.EraseTxIndex(*this);
return true;
@@ -1102,7 +1120,7 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTes
}
}
- // Make sure all prevout.n's are valid:
+ // Make sure all prevout.n indexes are valid:
for (unsigned int i = 0; i < vin.size(); i++)
{
const COutPoint prevout = vin[i].prevout;
@@ -1338,7 +1356,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
// 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.
+ // already refuses previously-known transaction ids entirely.
// This rule applies to all blocks whose timestamp is after March 15, 2012, 0:00 UTC.
int64 nBIP30SwitchTime = 1331769600;
bool fEnforceBIP30 = (pindex->nTime > nBIP30SwitchTime);
@@ -1604,7 +1622,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
return error("SetBestChain() : Reorganize failed");
}
- // Connect futher blocks
+ // Connect further blocks
BOOST_REVERSE_FOREACH(CBlockIndex *pindex, vpindexSecondary)
{
CBlock block;
@@ -1634,6 +1652,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
// New best block
hashBestChain = hash;
pindexBest = pindexNew;
+ pblockindexFBBHLast = NULL;
nBestHeight = pindexBest->nHeight;
bnBestChainWork = pindexNew->bnChainWork;
nTimeBestReceived = GetTime();
@@ -1657,7 +1676,7 @@ bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
printf("SetBestChain: %d of last 100 blocks above version %d\n", nUpgraded, CBlock::CURRENT_VERSION);
if (nUpgraded > 100/2)
// strMiscWarning is read by GetWarnings(), called by Qt and the JSON-RPC code to warn the user:
- strMiscWarning = _("Warning: this version is obsolete, upgrade required");
+ strMiscWarning = _("Warning: This version is obsolete, upgrade required!");
}
std::string strCmd = GetArg("-blocknotify", "");
@@ -1769,7 +1788,7 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot) const
if (nSigOps > MAX_BLOCK_SIGOPS)
return DoS(100, error("CheckBlock() : out-of-bounds SigOpCount"));
- // Check merkleroot
+ // Check merkle root
if (fCheckMerkleRoot && hashMerkleRoot != BuildMerkleTree())
return DoS(100, error("CheckBlock() : hashMerkleRoot mismatch"));
@@ -1805,7 +1824,7 @@ bool CBlock::AcceptBlock()
// Check that the block chain matches the known block chain up to a checkpoint
if (!Checkpoints::CheckBlock(nHeight, hash))
- return DoS(100, error("AcceptBlock() : rejected by checkpoint lockin at %d", nHeight));
+ return DoS(100, error("AcceptBlock() : rejected by checkpoint lock-in at %d", nHeight));
// Write block to history file
if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK, CLIENT_VERSION)))
@@ -1923,7 +1942,7 @@ bool CheckDiskSpace(uint64 nAdditionalBytes)
if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes)
{
fShutdown = true;
- string strMessage = _("Warning: Disk space is low");
+ string strMessage = _("Warning: Disk space is low!");
strMiscWarning = strMessage;
printf("*** %s\n", strMessage.c_str());
uiInterface.ThreadSafeMessageBox(strMessage, "Bitcoin", CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
@@ -1963,8 +1982,8 @@ FILE* AppendBlockFile(unsigned int& nFileRet)
return NULL;
if (fseek(file, 0, SEEK_END) != 0)
return NULL;
- // FAT32 filesize max 4GB, fseek and ftell max 2GB, so we must stay under 2GB
- if (ftell(file) < 0x7F000000 - MAX_SIZE)
+ // FAT32 file size max 4GB, fseek and ftell max 2GB, so we must stay under 2GB
+ if (ftell(file) < (long)(0x7F000000 - MAX_SIZE))
{
nFileRet = nCurrentBlockFile;
return file;
@@ -2055,7 +2074,7 @@ bool LoadBlockIndex(bool fAllowNew)
void PrintBlockTree()
{
- // precompute tree structure
+ // pre-compute tree structure
map<CBlockIndex*, vector<CBlockIndex*> > mapNext;
for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
{
@@ -2108,7 +2127,7 @@ void PrintBlockTree()
PrintWallets(block);
- // put the main timechain first
+ // put the main time-chain first
vector<CBlockIndex*>& vNext = mapNext[pindex];
for (unsigned int i = 0; i < vNext.size(); i++)
{
@@ -2127,6 +2146,8 @@ void PrintBlockTree()
bool LoadExternalBlockFile(FILE* fileIn)
{
+ int64 nStart = GetTimeMillis();
+
int nLoaded = 0;
{
LOCK(cs_main);
@@ -2179,7 +2200,7 @@ bool LoadExternalBlockFile(FILE* fileIn)
__PRETTY_FUNCTION__);
}
}
- printf("Loaded %i blocks from external file\n", nLoaded);
+ printf("Loaded %i blocks from external file in %"PRI64d"ms\n", nLoaded, GetTimeMillis() - nStart);
return nLoaded > 0;
}
@@ -2218,7 +2239,7 @@ string GetWarnings(string strFor)
if (pindexBest && bnBestInvalidWork > bnBestChainWork + pindexBest->GetBlockWork() * 6)
{
nPriority = 2000;
- strStatusBar = strRPC = "WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.";
+ strStatusBar = strRPC = _("Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.");
}
// Alerts
@@ -2347,7 +2368,7 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv)
// The message start string is designed to be unlikely to occur in normal data.
-// The characters are rarely used upper ascii, not valid as UTF-8, and produce
+// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
unsigned char pchMessageStart[4] = { 0xf9, 0xbe, 0xb4, 0xd9 };
@@ -3059,12 +3080,12 @@ bool ProcessMessages(CNode* pfrom)
{
if (strstr(e.what(), "end of data"))
{
- // Allow exceptions from underlength message on vRecv
+ // Allow exceptions from under-length message on vRecv
printf("ProcessMessages(%s, %u bytes) : Exception '%s' caught, normally caused by a message being shorter than its stated length\n", strCommand.c_str(), nMessageSize, e.what());
}
else if (strstr(e.what(), "size too large"))
{
- // Allow exceptions from overlong size
+ // Allow exceptions from over-long size
printf("ProcessMessages(%s, %u bytes) : Exception '%s' caught\n", strCommand.c_str(), nMessageSize, e.what());
}
else
@@ -3313,9 +3334,9 @@ unsigned int static ScanHash_CryptoPP(char* pmidstate, char* pdata, char* phash1
unsigned int& nNonce = *(unsigned int*)(pdata + 12);
for (;;)
{
- // Crypto++ SHA-256
+ // Crypto++ SHA256
// Hash pdata using pmidstate as the starting state into
- // preformatted buffer phash1, then hash phash1 into phash
+ // pre-formatted buffer phash1, then hash phash1 into phash
nNonce++;
SHA256Transform(phash1, pdata, pmidstate);
SHA256Transform(phash, phash1, pSHA256InitState);
@@ -3652,7 +3673,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash1)
{
//
- // Prebuild hash buffers
+ // Pre-build hash buffers
//
struct
{
@@ -3780,7 +3801,7 @@ void static BitcoinMiner(CWallet *pwallet)
//
- // Prebuild hash buffers
+ // Pre-build hash buffers
//
char pmidstatebuf[32+16]; char* pmidstate = alignup<16>(pmidstatebuf);
char pdatabuf[128+16]; char* pdata = alignup<16>(pdatabuf);
@@ -3805,7 +3826,7 @@ void static BitcoinMiner(CWallet *pwallet)
unsigned int nHashesDone = 0;
unsigned int nNonceFound;
- // Crypto++ SHA-256
+ // Crypto++ SHA256
nNonceFound = ScanHash_CryptoPP(pmidstate, pdata + 64, phash1,
(char*)&hash, nHashesDone);