Guard longest chain and GetNodeStateStats
This commit is contained in:
33
src/main.cpp
33
src/main.cpp
@@ -532,17 +532,28 @@ namespace {
|
|||||||
|
|
||||||
} // anon namespace
|
} // anon namespace
|
||||||
|
|
||||||
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
|
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
|
||||||
LOCK(cs_main);
|
{
|
||||||
CNodeState *state = State(nodeid);
|
static int32_t depth;
|
||||||
if (state == NULL)
|
if ( depth < 0 )
|
||||||
return false;
|
depth = 0;
|
||||||
stats.nMisbehavior = state->nMisbehavior;
|
if ( depth == 0 )
|
||||||
stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
|
{
|
||||||
stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1;
|
LOCK(cs_main);
|
||||||
BOOST_FOREACH(const QueuedBlock& queue, state->vBlocksInFlight) {
|
CNodeState *state = State(nodeid);
|
||||||
if (queue.pindex)
|
if (state == NULL)
|
||||||
stats.vHeightInFlight.push_back(queue.pindex->nHeight);
|
{
|
||||||
|
depth--;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
stats.nMisbehavior = state->nMisbehavior;
|
||||||
|
stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
|
||||||
|
stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1;
|
||||||
|
BOOST_FOREACH(const QueuedBlock& queue, state->vBlocksInFlight) {
|
||||||
|
if (queue.pindex)
|
||||||
|
stats.vHeightInFlight.push_back(queue.pindex->nHeight);
|
||||||
|
}
|
||||||
|
depth--;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,43 +168,51 @@ 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;
|
||||||
vector<CNodeStats> vstats;
|
if ( depth < 0 )
|
||||||
|
depth = 0;
|
||||||
|
if ( depth == 0 )
|
||||||
{
|
{
|
||||||
//LOCK(cs_main);
|
depth++;
|
||||||
CopyNodeStats(vstats);
|
vector<CNodeStats> vstats;
|
||||||
|
{
|
||||||
|
//LOCK(cs_main);
|
||||||
|
CopyNodeStats(vstats);
|
||||||
|
}
|
||||||
|
BOOST_FOREACH(const CNodeStats& stats, vstats)
|
||||||
|
{
|
||||||
|
//fprintf(stderr,"komodo_longestchain iter.%d\n",n);
|
||||||
|
CNodeStateStats statestats;
|
||||||
|
bool fStateStats = GetNodeStateStats(stats.nodeid,statestats);
|
||||||
|
if ( statestats.nSyncHeight < 0 )
|
||||||
|
continue;
|
||||||
|
ht = 0;
|
||||||
|
if ( stats.nStartingHeight > ht )
|
||||||
|
ht = stats.nStartingHeight;
|
||||||
|
if ( statestats.nSyncHeight > ht )
|
||||||
|
ht = statestats.nSyncHeight;
|
||||||
|
if ( statestats.nCommonHeight > ht )
|
||||||
|
ht = statestats.nCommonHeight;
|
||||||
|
if ( maxheight == 0 || ht > maxheight*1.01 )
|
||||||
|
maxheight = ht, num = 1;
|
||||||
|
else if ( ht > maxheight*0.99 )
|
||||||
|
num++;
|
||||||
|
if ( ht > height )
|
||||||
|
height = ht;
|
||||||
|
}
|
||||||
|
depth--;
|
||||||
|
if ( num > (n >> 1) )
|
||||||
|
{
|
||||||
|
extern char ASSETCHAINS_SYMBOL[];
|
||||||
|
if ( 0 && height != KOMODO_LONGESTCHAIN )
|
||||||
|
fprintf(stderr,"set %s KOMODO_LONGESTCHAIN <- %d\n",ASSETCHAINS_SYMBOL,height);
|
||||||
|
KOMODO_LONGESTCHAIN = height;
|
||||||
|
return(height);
|
||||||
|
}
|
||||||
|
KOMODO_LONGESTCHAIN = 0;
|
||||||
}
|
}
|
||||||
BOOST_FOREACH(const CNodeStats& stats, vstats)
|
return(KOMODO_LONGESTCHAIN);
|
||||||
{
|
|
||||||
//fprintf(stderr,"komodo_longestchain iter.%d\n",n);
|
|
||||||
CNodeStateStats statestats;
|
|
||||||
bool fStateStats = GetNodeStateStats(stats.nodeid,statestats);
|
|
||||||
if ( statestats.nSyncHeight < 0 )
|
|
||||||
continue;
|
|
||||||
ht = 0;
|
|
||||||
if ( stats.nStartingHeight > ht )
|
|
||||||
ht = stats.nStartingHeight;
|
|
||||||
if ( statestats.nSyncHeight > ht )
|
|
||||||
ht = statestats.nSyncHeight;
|
|
||||||
if ( statestats.nCommonHeight > ht )
|
|
||||||
ht = statestats.nCommonHeight;
|
|
||||||
if ( maxheight == 0 || ht > maxheight*1.01 )
|
|
||||||
maxheight = ht, num = 1;
|
|
||||||
else if ( ht > maxheight*0.99 )
|
|
||||||
num++;
|
|
||||||
if ( ht > height )
|
|
||||||
height = ht;
|
|
||||||
}
|
|
||||||
if ( num > (n >> 1) )
|
|
||||||
{
|
|
||||||
extern char ASSETCHAINS_SYMBOL[];
|
|
||||||
if ( 0 && height != KOMODO_LONGESTCHAIN )
|
|
||||||
fprintf(stderr,"set %s KOMODO_LONGESTCHAIN <- %d\n",ASSETCHAINS_SYMBOL,height);
|
|
||||||
KOMODO_LONGESTCHAIN = height;
|
|
||||||
return(height);
|
|
||||||
}
|
|
||||||
KOMODO_LONGESTCHAIN = 0;
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue addnode(const UniValue& params, bool fHelp)
|
UniValue addnode(const UniValue& params, bool fHelp)
|
||||||
|
|||||||
Reference in New Issue
Block a user