@@ -59,7 +59,7 @@ std::string GetCurrentNeuralNetworkSupermajorityHash(double& out_popularity);
5959UniValue GetJSONNeuralNetworkReport ();
6060UniValue GetJSONCurrentNeuralNetworkReport ();
6161
62- extern UniValue GetJSONVersionReport ();
62+ extern UniValue GetJSONVersionReport (const int64_t lookback, const bool full_version );
6363extern UniValue GetJsonUnspentReport ();
6464
6565bool GetEarliestStakeTime (std::string grcaddress, std::string cpid);
@@ -1833,17 +1833,27 @@ UniValue tallyneural(const UniValue& params, bool fHelp)
18331833
18341834UniValue versionreport (const UniValue& params, bool fHelp )
18351835{
1836- if (fHelp || params.size () != 0 )
1836+ if (fHelp || params.size () > 2 )
18371837 throw runtime_error (
1838- " versionreport\n "
1838+ " versionreport <lookback:int> <full:bool>\n "
1839+ " \n "
1840+ " <lookback> --> Number of blocks to tally from the chain head "
1841+ " (default: " + std::to_string (BLOCKS_PER_DAY) + " ).\n "
1842+ " <full> ------> Classify by commit suffix (default: false).\n "
18391843 " \n "
1840- " Displays a report on various versions recently stake on the network \n " );
1844+ " Display the software versions of nodes that recently staked. \n " );
18411845
1842- LOCK (cs_main);
1846+ const int64_t lookback = params.size () > 0
1847+ ? std::max (params[0 ].get_int (), 1 )
1848+ : BLOCKS_PER_DAY;
18431849
1844- UniValue myNeuralJSON = GetJSONVersionReport ();
1850+ const bool full_version = params.size () > 1
1851+ ? params[1 ].get_bool ()
1852+ : false ;
1853+
1854+ LOCK (cs_main);
18451855
1846- return myNeuralJSON ;
1856+ return GetJSONVersionReport (lookback, full_version) ;
18471857}
18481858
18491859UniValue writedata (const UniValue& params, bool fHelp )
@@ -2500,42 +2510,48 @@ UniValue GetJSONCurrentNeuralNetworkReport()
25002510}
25012511
25022512
2503- UniValue GetJSONVersionReport ()
2513+ UniValue GetJSONVersionReport (const int64_t lookback, const bool full_version )
25042514{
2505- UniValue results (UniValue::VARR);
2506- // Returns a report of the GRC Version staking blocks over the last 100 blocks
2507- std::string report = " Version, Popularity\n " ;
2508- std::string row = " " ;
2509- double pct = 0 ;
2510- UniValue entry (UniValue::VOBJ);
2511- entry.pushKV (" Version" ," Popularity,Percent %" );
2512-
2513- double votes = 0 ;
2514- for (auto it : mvNeuralVersion)
2515- votes += it.second ;
2516-
2517- // Copy to a sorted map.
2518- std::map<std::string, double > sorted_versions (
2519- mvNeuralVersion.begin (),
2520- mvNeuralVersion.end ());
2521-
2522- for (auto & version : sorted_versions)
2515+ const int64_t min_height = std::max<int64_t >(nBestHeight - lookback, 0 );
2516+
2517+ std::map<std::string, uint64_t > version_tally;
2518+
2519+ for (const CBlockIndex* pindex = pindexBest;
2520+ pindex && pindex->nHeight > min_height;
2521+ pindex = pindex->pprev )
25232522 {
2524- auto & neural_ver = version.first ;
2525- auto & popularity = version.second ;
2526-
2527- // If the hash != empty_hash:
2528- if (popularity > 0 )
2529- {
2530- row = neural_ver + " ," + RoundToString (popularity,0 );
2531- report += row + " \n " ;
2532- pct = popularity/(votes+.01 )*100 ;
2533- entry.pushKV (neural_ver,RoundToString (popularity,0 ) + " ; " + RoundToString (pct,2 ) + " %" );
2523+ CBlock block;
2524+ block.ReadFromDisk (pindex);
2525+
2526+ std::string version = block.PullClaim ().m_client_version ;
2527+
2528+ if (version.empty ()) {
2529+ version = " unknown" ;
2530+ } else if (!full_version) {
2531+ // Ignore the source control version commit ID after the hyphen:
2532+ const size_t separator_position = version.find (' -' );
2533+
2534+ if (separator_position != std::string::npos) {
2535+ version.erase (separator_position);
2536+ }
25342537 }
2538+
2539+ ++version_tally[version];
25352540 }
2536-
2537- results.push_back (entry);
2538- return results;
2541+
2542+ UniValue json (UniValue::VARR);
2543+
2544+ for (const auto & version_pair : version_tally) {
2545+ UniValue entry (UniValue::VOBJ);
2546+
2547+ entry.pushKV (" version" , version_pair.first );
2548+ entry.pushKV (" count" , version_pair.second );
2549+ entry.pushKV (" percent" , ((double )version_pair.second / lookback) * 100 );
2550+
2551+ json.push_back (entry);
2552+ }
2553+
2554+ return json;
25392555}
25402556
25412557std::string YesNo (bool f)
0 commit comments