From 09a54a65c0d05fe93c4a31603eca8a9a76ff6526 Mon Sep 17 00:00:00 2001 From: Huang Le <4tarhl@gmail.com> Date: Fri, 30 May 2014 23:44:44 +0800 Subject: [PATCH] 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> --- src/net.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index c2dde9704..b0e6699ed 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1455,13 +1455,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; int nBestHeight = g_signals.GetHeight().get_value_or(0); @@ -1473,10 +1473,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; } } }