From: Huang Le <4tarhl@gmail.com> Date: Fri, 30 May 2014 15:44:44 +0000 (+0800) Subject: Use pnode->nLastRecv as sync score directly X-Git-Tag: nvc-v0.5.4~4^2~2^2 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=c1153fd4f8717ba1ae62ec7f89c5d0d50718b37b Use pnode->nLastRecv as sync score directly NodeSyncScore() should find the node which we recv data most recently, so put a negative sign to pnode->nLastRecv is indeed wrong. Also change the return value type to int64_t. Signed-off-by: Huang Le <4tarhl@gmail.com> --- diff --git a/src/net.cpp b/src/net.cpp index f289bd5..74edc1d 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1600,13 +1600,13 @@ bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOu // for now, use a very simple selection metric: the node from which we received // most recently -double static NodeSyncScore(const CNode *pnode) { - return -pnode->nLastRecv; +static int64_t NodeSyncScore(const CNode *pnode) { + return pnode->nLastRecv; } void static StartSync(const vector &vNodes) { CNode *pnodeNewSync = NULL; - double dBestScore = 0; + int64_t nBestScore = 0; // Iterate over all nodes BOOST_FOREACH(CNode* pnode, vNodes) { @@ -1616,10 +1616,10 @@ void static StartSync(const vector &vNodes) { (pnode->nStartingHeight > (nBestHeight - 144)) && (pnode->nVersion < NOBLKS_VERSION_START || pnode->nVersion >= NOBLKS_VERSION_END)) { // if ok, compare node's score with the best so far - double dScore = NodeSyncScore(pnode); - if (pnodeNewSync == NULL || dScore > dBestScore) { + int64_t nScore = NodeSyncScore(pnode); + if (pnodeNewSync == NULL || nScore > nBestScore) { pnodeNewSync = pnode; - dBestScore = dScore; + nBestScore = nScore; } } }