Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fluxnodecount index flag #239

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ class CBlockIndex
//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
uint32_t nSequenceId;

int nStratus = 0;
int nNimbus = 0;
int nCumulus = 0;

void SetNull()
{
phashBlock = NULL;
Expand Down Expand Up @@ -270,6 +274,10 @@ class CBlockIndex
nBits = 0;
nNonce = uint256();
nSolution.clear();

nStratus = 0;
nNimbus = 0;
nCumulus = 0;
}

CBlockIndex()
Expand Down Expand Up @@ -455,6 +463,10 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(nSaplingValue);
}

READWRITE(nStratus);
READWRITE(nNimbus);
READWRITE(nCumulus);

// If you have just added new serialized fields above, remember to add
// them to CBlockTreeDB::LoadBlockIndexGuts() in txdb.cpp :)
}
Expand Down
1 change: 0 additions & 1 deletion src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ class CMainParams : public CChainParams {
strFoundationFundingAddress = "t3XjYMBvwxnXVv9jqg4CgokZ3f7kAoXPQL8";
nFoundationFundingHeight = 836994; // Around 11th April 2021
nFoundationFundingAmount = 2500000 * COIN; // 2.5 Million

strSwapPoolAddress = "t3ThbWogDoAjGuS6DEnmN1GWJBRbVjSUK4T";
nSwapPoolStartHeight = 837714; // // Around 12th April 2021
nSwapPoolAmount = 22000000 * COIN; // 22 Million every time
Expand Down
6 changes: 6 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
break;
}

// Check for changed -fluxnodecount state
if (fFluxNodeCountIndex != GetBoolArg("-fluxnodecount", false)) {
strLoadError = _("You need to rebuild the database using -reindex to change -fluxnodecount");
break;
}

// Check for changed -insightexplorer state
if (fInsightExplorer != GetBoolArg("-insightexplorer", false)) {
strLoadError = _("You need to rebuild the database using -reindex to change -insightexplorer");
Expand Down
26 changes: 26 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ bool fExperimentalMode = false;
bool fImporting = false;
bool fReindex = false;
bool fTxIndex = false;
bool fFluxNodeCountIndex = false;
bool fInsightExplorer = false; // insightexplorer
bool fAddressIndex = false; // insightexplorer
bool fSpentIndex = false; // insightexplorer
Expand Down Expand Up @@ -4425,6 +4426,23 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
}
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
pindexNew->RaiseValidity(BLOCK_VALID_TREE);

if (fFluxNodeCountIndex) {
int ipv4 = 0, ipv6 = 0, onion = 0, nTotal = 0;
std::vector<int> vNodeCount(GetNumberOfTiers());
g_fluxnodeCache.CountNetworks(ipv4, ipv6, onion, vNodeCount);

if (g_fluxnodeCache.mapFluxnodeList.count(Tier::STRATUS)) {
pindexNew->nStratus = vNodeCount[Tier::STRATUS - 1];
}
if (g_fluxnodeCache.mapFluxnodeList.count(Tier::NIMBUS)) {
pindexNew->nNimbus = vNodeCount[Tier::NIMBUS - 1];
}
if (g_fluxnodeCache.mapFluxnodeList.count(Tier::CUMULUS)) {
pindexNew->nCumulus = vNodeCount[Tier::CUMULUS - 1];
}
}

if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork)
pindexBestHeader = pindexNew;

Expand Down Expand Up @@ -5384,6 +5402,10 @@ bool static LoadBlockIndexDB()
pblocktree->ReadFlag("txindex", fTxIndex);
LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled");

// Check whether we have a fluxnodecount index
pblocktree->ReadFlag("fluxnodecount", fFluxNodeCountIndex);
LogPrintf("%s: fluxnodecount index %s\n", __func__, fFluxNodeCountIndex ? "enabled" : "disabled");

// insightexplorer
// Check whether block explorer features are enabled
pblocktree->ReadFlag("insightexplorer", fInsightExplorer);
Expand Down Expand Up @@ -5727,6 +5749,10 @@ bool InitBlockIndex(const CChainParams& chainparams)
fTxIndex = GetBoolArg("-txindex", false);
pblocktree->WriteFlag("txindex", fTxIndex);

// Use the provided setting for -fluxnodecount in the new database
fFluxNodeCountIndex = GetBoolArg("-fluxnodecount", false);
pblocktree->WriteFlag("fluxnodecount", fFluxNodeCountIndex);

// Use the provided setting for -insightexplorer in the new database
fInsightExplorer = GetBoolArg("-insightexplorer", false);
pblocktree->WriteFlag("insightexplorer", fInsightExplorer);
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ extern bool fImporting;
extern bool fReindex;
extern int nScriptCheckThreads;
extern bool fTxIndex;
extern bool fFluxNodeCountIndex;

extern bool fIsVerifying;

Expand Down
4 changes: 3 additions & 1 deletion src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "z_setmigration", 0},
{ "spork", 1},
{ "printsnapshot", 0},
{ "createp2shstarttx", 3}
{ "createp2shstarttx", 3},
{ "getfluxnodecount", 0},
{ "getfluxnodecount", 1}
};

class CRPCConvertTable
Expand Down
44 changes: 43 additions & 1 deletion src/rpc/fluxnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,11 +1133,15 @@ UniValue zelnodecurrentwinner (const UniValue& params, bool fHelp)

UniValue getfluxnodecount (const UniValue& params, bool fHelp, string cmdname)
{
if (fHelp || (params.size() > 0))
if (fHelp || (params.size() > 2))
throw runtime_error(
cmdname + "\n"
"\nGet fluxnode count values\n"

"\nArguments:\n"
"1. history (boolean, optional) Specifiy if you want all fluxnode counts from all blocks (-fluxnodecount=1 required)\n"
"2. timetable (number, optional) Default=360 How often you want the fluxnode count. 360 = 12 Hours, 720 = 1 Day. Range is (1, 99999999)\n"

"\nResult:\n"
"{\n"
" \"total\": n, (numeric) Total fluxnodes\n"
Expand All @@ -1151,6 +1155,44 @@ UniValue getfluxnodecount (const UniValue& params, bool fHelp, string cmdname)

UniValue obj(UniValue::VOBJ);

// Global Numbers
bool fAll = false;
uint32_t nSpread = 360; // 360 = 12 hours with 2 minute blocks. 720 blocks a day
if (params.size() >= 1) {
fAll = params[0].get_bool();
}

if (fAll && !fFluxNodeCountIndex) {
throw JSONRPCError(RPC_INVALID_REQUEST, "history was requested but fluxnodecount is not enabled. You must have fluxnodecount=1 in flux.conf");
}

// Get Global Data instead of current blocks count
if (fAll) {
if (params.size() == 2) {
nSpread = params[1].get_int();
}

if (nSpread <= 0 || nSpread >= 100000000) {
nSpread = 360;
}

LOCK(cs_main);
CBlockIndex *index = nullptr;
index = chainActive[Params().GetConsensus().vUpgrades[Consensus::UPGRADE_KAMATA].nActivationHeight];

while (index) {
UniValue amounts(UniValue::VOBJ);
amounts.pushKV("stratus", index->nStratus);
amounts.pushKV("nimbus", index->nNimbus);
amounts.pushKV("cumulus", index->nCumulus);
obj.pushKV(std::to_string(index->nHeight), amounts);

index = chainActive[index->nHeight + nSpread];
}

return obj;
}

int ipv4 = 0, ipv6 = 0, onion = 0, nTotal = 0;
std::vector<int> vNodeCount(GetNumberOfTiers());
{
Expand Down
4 changes: 4 additions & 0 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ bool CBlockTreeDB::LoadBlockIndexGuts(boost::function<CBlockIndex*(const uint256
pindexNew->nSproutValue = diskindex.nSproutValue;
pindexNew->nSaplingValue = diskindex.nSaplingValue;

pindexNew->nStratus = diskindex.nStratus;
pindexNew->nNimbus = diskindex.nNimbus;
pindexNew->nCumulus = diskindex.nCumulus;

// Consistency checks
auto header = pindexNew->GetBlockHeader();
if (header.GetHash() != pindexNew->GetBlockHash())
Expand Down