Skip to content

Commit

Permalink
Import Bitcoin Fixes
Browse files Browse the repository at this point in the history
Prevent stuck block download in large reorganisations
Speed up block downloading
  • Loading branch information
fanquake committed Mar 23, 2012
1 parent da21661 commit 6c44ac1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL)
string strErrorFile = strDataDir + "/db.log";
printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str());

int nDbCache = GetArg("-dbcache", 25);
dbenv.set_lg_dir(strLogDir.c_str());
dbenv.set_lg_max(10000000);
dbenv.set_cachesize(nDbCache / 1024, (nDbCache % 1024)*1048576, 1);
dbenv.set_lg_bsize(10485760);
dbenv.set_lg_max(104857600);
dbenv.set_lk_max_locks(10000);
dbenv.set_lk_max_objects(10000);
dbenv.set_errfile(fopen(strErrorFile.c_str(), "a")); /// debug
Expand Down Expand Up @@ -157,7 +160,7 @@ void CDB::Close()
nMinutes = 1;
if (strFile == "addr.dat")
nMinutes = 2;
if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 500 != 0)
if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 5000 != 0)
nMinutes = 1;
dbenv.txn_checkpoint(0, nMinutes, 0);

Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ bool AppInit2(int argc, char* argv[])
" -min \t\t " + _("Start minimized") + "\n" +
" -splash \t\t " + _("Show splash screen on startup (default: 1)") + "\n" +
" -datadir=<dir> \t\t " + _("Specify data directory") + "\n" +
" -dbcache=<n> \t\t " + _("Set database cache size in megabytes (default: 25)") + "\n" +
" -timeout=<n> \t " + _("Specify connection timeout (in milliseconds)") + "\n" +
" -proxy=<ip:port> \t " + _("Connect through socks4 proxy") + "\n" +
" -dns \t " + _("Allow DNS lookups for addnode and connect") + "\n" +
Expand Down
11 changes: 8 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2412,8 +2412,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}

CTxDB txdb("r");
BOOST_FOREACH(const CInv& inv, vInv)
for (int nInv = 0; nInv < vInv.size(); nInv++)
{
const CInv &inv = vInv[nInv];

if (fShutdown)
return true;
pfrom->AddInventoryKnown(inv);
Expand All @@ -2422,9 +2424,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
if (fDebug)
printf(" got inventory: %s %s\n", inv.ToString().c_str(), fAlreadyHave ? "have" : "new");

if (!fAlreadyHave)
// Always request the last block in an inv bundle (even if we already have it), as it is the
// trigger for the other side to send further invs. If we are stuck on a (very long) side chain,
// this is necessary to connect earlier received orphan blocks to the chain again.
if (!fAlreadyHave || (inv.type == MSG_BLOCK && nInv==vInv.size()-1))
pfrom->AskFor(inv);
else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash))
if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash))
pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(mapOrphanBlocks[inv.hash]));

// Track requests for our stuff
Expand Down

0 comments on commit 6c44ac1

Please sign in to comment.