Guard longest chain and GetNodeStateStats

This commit is contained in:
jl777
2018-11-11 05:06:36 -11:00
parent 34b1a40307
commit 58b0fc23ac
2 changed files with 64 additions and 45 deletions

View File

@@ -532,11 +532,20 @@ namespace {
} // anon namespace } // anon namespace
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
{
static int32_t depth;
if ( depth < 0 )
depth = 0;
if ( depth == 0 )
{
LOCK(cs_main); LOCK(cs_main);
CNodeState *state = State(nodeid); CNodeState *state = State(nodeid);
if (state == NULL) if (state == NULL)
{
depth--;
return false; return false;
}
stats.nMisbehavior = state->nMisbehavior; stats.nMisbehavior = state->nMisbehavior;
stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1; stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1; stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1;
@@ -544,6 +553,8 @@ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
if (queue.pindex) if (queue.pindex)
stats.vHeightInFlight.push_back(queue.pindex->nHeight); stats.vHeightInFlight.push_back(queue.pindex->nHeight);
} }
depth--;
}
return true; return true;
} }

View File

@@ -168,7 +168,13 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp)
int32_t KOMODO_LONGESTCHAIN; int32_t KOMODO_LONGESTCHAIN;
int32_t komodo_longestchain() int32_t komodo_longestchain()
{ {
static int32_t depth;
int32_t ht,n=0,num=0,maxheight=0,height = 0; int32_t ht,n=0,num=0,maxheight=0,height = 0;
if ( depth < 0 )
depth = 0;
if ( depth == 0 )
{
depth++;
vector<CNodeStats> vstats; vector<CNodeStats> vstats;
{ {
//LOCK(cs_main); //LOCK(cs_main);
@@ -195,6 +201,7 @@ int32_t komodo_longestchain()
if ( ht > height ) if ( ht > height )
height = ht; height = ht;
} }
depth--;
if ( num > (n >> 1) ) if ( num > (n >> 1) )
{ {
extern char ASSETCHAINS_SYMBOL[]; extern char ASSETCHAINS_SYMBOL[];
@@ -204,7 +211,8 @@ int32_t komodo_longestchain()
return(height); return(height);
} }
KOMODO_LONGESTCHAIN = 0; KOMODO_LONGESTCHAIN = 0;
return(0); }
return(KOMODO_LONGESTCHAIN);
} }
UniValue addnode(const UniValue& params, bool fHelp) UniValue addnode(const UniValue& params, bool fHelp)