Skip to content

Commit

Permalink
Add Max Time Since Best Block
Browse files Browse the repository at this point in the history
Be more agressive with Blockchain download to prevent sticky Blocks
  • Loading branch information
Crestington authored and IngCr3at1on committed Apr 3, 2015
1 parent 0d3672e commit dee9f83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3028,6 +3028,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)

cPeerBlockCounts.input(pfrom->nStartingHeight);

// Be more aggressive with blockchain download. Send new getblocks() message after connection
// to new node if waited longer than MAX_TIME_SINCE_BEST_BLOCK.
int64_t TimeSinceBestBlock = GetTime() - nTimeBestReceived;
if (TimeSinceBestBlock > MAX_TIME_SINCE_BEST_BLOCK) {
printf("INFO: Waiting %"PRId64" sec which is too long. Sending GetBlocks(0)\n", TimeSinceBestBlock);
pfrom->PushGetBlocks(pindexBest, uint256(0));
}

// paycoin: ask for pending sync-checkpoint if any
if (!IsInitialBlockDownload())
Checkpoints::AskForPendingSyncCheckpoint(pfrom);
Expand Down Expand Up @@ -3237,7 +3245,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
// Send the rest of the chain
if (pindex)
pindex = pindex->pnext;
int nLimit = 500 + locator.GetDistanceBack();
int nLimit = 1500 + locator.GetDistanceBack();
unsigned int nBytes = 0;
printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str(), nLimit);
for (; pindex; pindex = pindex->pnext)
Expand Down Expand Up @@ -3383,8 +3391,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CInv inv(MSG_BLOCK, block.GetHash());
pfrom->AddInventoryKnown(inv);

if (ProcessBlock(pfrom, &block))
if (ProcessBlock(pfrom, &block)) {
mapAlreadyAskedFor.erase(inv);
} else {
// Be more aggressive with blockchain download. Send getblocks() message after
// an error related to new block download.
int64_t TimeSinceBestBlock = GetTime() - nTimeBestReceived;
if (TimeSinceBestBlock > MAX_TIME_SINCE_BEST_BLOCK) {
printf("INFO: Waiting %"PRId64" sec which is too long. Sending GetBlocks(0)\n", TimeSinceBestBlock);
pfrom->PushGetBlocks(pindexBest, uint256(0));
}
}
if (block.nDoS) pfrom->Misbehaving(block.nDoS);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ static const unsigned int MODIFIER_INTERVAL = 10 * 60;
static const int64 NUMBER_OF_PRIMENODE = 50;
static const int64 MINIMUM_FOR_ORION = 50 * COIN;
static const int64 MINIMUM_FOR_PRIMENODE = 125000 * COIN;
static const int MAX_TIME_SINCE_BEST_BLOCK = 10; // how many seconds to wait before sending next PushGetBlocks()


#ifdef USE_UPNP
static const int fHaveUPnP = true;
Expand Down

0 comments on commit dee9f83

Please sign in to comment.