From f595c2e0f88583190c2bbd8153f6e897ed1ac094 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 Nov 2016 17:01:44 -0300 Subject: [PATCH] test --- src/main.cpp | 2 +- src/rpcmisc.cpp | 2 ++ src/rpcnet.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 41d21c7b8..d070178d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1179,7 +1179,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa view.GetBestBlock(); nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime); - if ( interest != 0 ) + if ( 0 && interest != 0 ) fprintf(stderr,"add interest %.8f\n",(double)interest/COIN); // we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool view.SetBackend(dummy); diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 9cc9d4d12..7f289723a 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -40,6 +40,7 @@ using namespace std; * Or alternatively, create a specific query method for the information. **/ uint64_t komodo_interestsum(); +int32_t komodo_longestchain(); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); Value getinfo(const Array& params, bool fHelp) @@ -98,6 +99,7 @@ Value getinfo(const Array& params, bool fHelp) } #endif obj.push_back(Pair("blocks", (int)chainActive.Height())); + obj.push_back(Pair("longestchain", komodo_longestchain())); obj.push_back(Pair("timeoffset", GetTimeOffset())); if ( chainActive.Tip() != 0 ) obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime)); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index e3d264a57..76c9fceb2 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -165,6 +165,36 @@ Value getpeerinfo(const Array& params, bool fHelp) return ret; } +int32_t komodo_longestchain() +{ + int32_t ht,n=0,num=0,maxheight=0,height = 0; + LOCK(cs_main); + vector vstats; + CopyNodeStats(vstats); + BOOST_FOREACH(const CNodeStats& stats, vstats) + { + CNodeStateStats statestats; + bool fStateStats = GetNodeStateStats(stats.nodeid,statestats); + ht = 0; + if ( stats.nStartingHeight > ht ) + ht = stats.nStartingHeight; + if ( stats.nSyncHeight > ht ) + ht = stats.nSyncHeight; + if ( stats.nCommonHeight > ht ) + ht = stats.nCommonHeight; + if ( maxheight == 0 || ht > maxheight*1.01 ) + maxheight = ht, num = 1; + else if ( ht > maxheight*0.99 ) + num++; + n++; + if ( ht > height ) + height = ht; + } + if ( num > (n >> 1) ) + return(height); + else return(0); +} + Value addnode(const Array& params, bool fHelp) { string strCommand;