Merge branch 'duke' of https://github.com/MyHush/hush3 into duke

This commit is contained in:
Duke Leto
2019-12-21 00:02:30 -05:00
14 changed files with 485 additions and 37 deletions

View File

@@ -1874,24 +1874,69 @@ inline CBlockIndex* LookupBlockIndex(const uint256& hash)
return it == mapBlockIndex.end() ? nullptr : it->second;
}
// given a transaction count X, subtract out coinbase and dpow transactions
// to give an "organic count". We return 0 instead of negative values
#define ORG(X) ( (X - blockcount - nNotarizationsDiff) > 0 ? (X - blockcount - nNotarizationsDiff) : 0 )
//TODO: Allow custom error message in this macro
#define THROW_IF_SYNCING(INSYNC) if (INSYNC == 0) { throw runtime_error(strprintf("%s: Chain still syncing at height %d, aborting to prevent garbage data. Please wait until the chain is synced to run this RPC",__FUNCTION__,chainActive.Tip()->GetHeight())); }
UniValue getchaintxstats(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
THROW_IF_SYNCING(KOMODO_INSYNC);
if (fHelp || params.size() > 2)
throw runtime_error(
"getchaintxstats\n"
"\nCompute statistics about the total number and rate of transactions in the chain.\n"
"\nThis RPC will return a large amount of additional data if the shielded index (zindex) is enabled.\n"
"\nArguments:\n"
"1. nblocks (numeric, optional) Number of blocks in averaging window.\n"
"2. blockhash (string, optional) The hash of the block which ends the window.\n"
"\nResult:\n"
"{\n"
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
" \"shielded_txcount\": xxxxx, (numeric) The total number of shielded (containing a zaddr) transactions in the chain up to that point.\n"
" \"shielding_txcount\": xxxxx, (numeric) The total number of shielding (containing a zaddr output) transactions in the chain up to that point.\n"
" \"deshielding_txcount\": xxxxx, (numeric) The total number of deshielding (containing a zaddr input) transactions in the chain up to that point.\n"
" \"fully_shielded_txcount\": xxxxx, (numeric) The total number of z2z, AKA fully-shielded (containing only zaddr inputs+outputs) transactions in the chain up to that point.\n"
" \"payments\": xxxxx, (numeric) The total number of payments in the chain up to that point.\n"
" \"shielded_payments\": xxxxx, (numeric) The total number of shielded (containing a zaddr) payments in the chain up to that point.\n"
" \"shielding_payments\": xxxxx, (numeric) The total number of shielding (containing a zaddr output) payments in the chain up to that point.\n"
" \"deshielding_payments\": xxxxx, (numeric) The total number of deshielding (containing a zaddr input) payments in the chain up to that point.\n"
" \"fully_shielded_payments\": xxxxx, (numeric) The total number of z2z, AKA fully-shielded (containing only zaddr inputs+outputs) payments in the chain up to that point.\n"
" \"notarizations\": xxxxx, (numeric) The total number of notarization transactions in the chain up to that point.\n"
" \"window_final_block_hash\": \"...\", (string) The hash of the final block in the window.\n"
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n"
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n"
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
" \"txrate\": x.xx, (numeric) The average rate of transactions per second in the window. Only returned if \"window_interval\" is > 0.\n"
" \"window_final_block_height\": xxxxx, (numeric) Block height of final block in window.\n"
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n"
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n"
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
" \"window_shielded_txcount\": xxxxx, (numeric) The total number of shielded (containing a zaddr) transactions in the chain up to that point.\n"
" \"window_shielding_txcount\": xxxxx, (numeric) The total number of shielding (containing a zaddr output) transactions in the chain up to that point.\n"
" \"window_deshielding_txcount\": xxxxx, (numeric) The total number of deshielding (containing a zaddr input) transactions in the chain up to that point.\n"
" \"window_fully_shielded_txcount\": xxxxx, (numeric) The total number of z2z, AKA fully-shielded (containing only zaddr inputs+outputs) transactions in the chain up to that point.\n"
" \"window_shielded_payments\": xxxxx, (numeric) The total number of shielded (containing a zaddr) payments in the chain up to that point.\n"
" \"window_shielding_payments\": xxxxx, (numeric) The total number of shielding (containing a zaddr output) payments in the chain up to that point.\n"
" \"window_deshielding_payments\": xxxxx, (numeric) The total number of deshielding (containing a zaddr input) payments in the chain up to that point.\n"
" \"window_fully_shielded_payments\": xxxxx, (numeric) The total number of z2z, AKA fully-shielded (containing only zaddr inputs+outputs) payments in the chain up to that point.\n"
" \"txrate\": x.xx, (numeric) The average rate of transactions per second in the window. Only returned if \"window_interval\" is > 0.\n"
" \"shielded\": { (string) The set of stats specific to only shieled transactions. \n"
" \"fully_shielded_tx_percent\": (numeric) The percentage of fully shielded transactions.\n"
" \"shielding_tx_percent\": (numeric) The percentage of shielding transactions.\n"
" \"deshielding_tx_percent\": (numeric) The percentage of deshielding transactions.\n"
" \"fully_shielded_payments_percent\": (numeric) The percentage of fully shielded payments.\n"
" \"shielding_payments_percent\": (numeric) The percentage of shielding payments.\n"
" \"deshielding_payments_percent\": (numeric) The percentage of deshielding payments.\n"
" },\n"
" \"organic\": { (string) The set of stats about organic transactions, i.e. those that are not coinbase and not notarizations\n"
" \"fully_shielded_tx_percent\": (numeric) The percentage of fully shielded organic transactions.\n"
" \"shielding_tx_percent\": (numeric) The percentage of shielding organic transactions.\n"
" \"deshielding_tx_percent\": (numeric) The percentage of deshielding organic transactions.\n"
" \"fully_shielded_payments_percent\": (numeric) The percentage of fully shielded organic payments.\n"
" \"shielding_payments_percent\": (numeric) The percentage of shielding organic payments.\n"
" \"deshielding_payments_percent\": (numeric) The percentage of deshielding organic payments.\n"
" }\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getchaintxstats", "")
@@ -1929,20 +1974,120 @@ UniValue getchaintxstats(const UniValue& params, bool fHelp, const CPubKey& mypk
}
const CBlockIndex* pindexPast = pindex->GetAncestor(pindex->GetHeight() - blockcount);
int nTimeDiff = pindex->GetMedianTimePast() - pindexPast->GetMedianTimePast();
int nTxDiff = pindex->nChainTx - pindexPast->nChainTx;
int nTimeDiff = pindex->GetMedianTimePast() - pindexPast->GetMedianTimePast();
int nTxDiff = pindex->nChainTx - pindexPast->nChainTx;
UniValue ret(UniValue::VOBJ);
ret.pushKV("time", (int64_t)pindex->nTime);
ret.pushKV("txcount", (int64_t)pindex->nChainTx);
ret.pushKV("window_final_block_hash", pindex->GetBlockHash().GetHex());
ret.pushKV("window_final_block_height", pindex->GetHeight());
ret.pushKV("window_block_count", blockcount);
if (fZindex) {
ret.pushKV("notarizations", (int64_t)pindex->nChainNotarizations);
ret.pushKV("shielded_txcount", (int64_t)pindex->nChainShieldedTx);
ret.pushKV("fully_shielded_txcount", (int64_t)pindex->nChainFullyShieldedTx);
ret.pushKV("deshielding_txcount", (int64_t)pindex->nChainDeshieldingTx);
ret.pushKV("shielding_txcount", (int64_t)pindex->nChainShieldingTx);
ret.pushKV("shielded_payments", (int64_t)pindex->nChainShieldedPayments);
ret.pushKV("fully_shielded_payments", (int64_t)pindex->nChainFullyShieldedPayments);
ret.pushKV("deshielding_payments", (int64_t)pindex->nChainDeshieldingPayments);
ret.pushKV("shielding_payments", (int64_t)pindex->nChainShieldingPayments);
}
if (blockcount > 0) {
ret.pushKV("window_tx_count", nTxDiff);
ret.pushKV("window_interval", nTimeDiff);
int64_t nPaymentsDiff = pindex->nChainPayments - pindexPast->nChainPayments;
int64_t nShieldedTxDiff = pindex->nChainShieldedTx - pindexPast->nChainShieldedTx;
int64_t nShieldingTxDiff = pindex->nChainShieldingTx - pindexPast->nChainShieldingTx;
int64_t nDeshieldingTxDiff = pindex->nChainDeshieldingTx - pindexPast->nChainDeshieldingTx;
int64_t nFullyShieldedTxDiff = pindex->nChainFullyShieldedTx - pindexPast->nChainFullyShieldedTx;
int64_t nShieldedPaymentsDiff = pindex->nChainShieldedPayments - pindexPast->nChainShieldedPayments;
int64_t nShieldingPaymentsDiff = pindex->nChainShieldingPayments - pindexPast->nChainShieldingPayments;
int64_t nDeshieldingPaymentsDiff = pindex->nChainDeshieldingPayments - pindexPast->nChainDeshieldingPayments;
int64_t nFullyShieldedPaymentsDiff = pindex->nChainFullyShieldedPayments - pindexPast->nChainFullyShieldedPayments;
int64_t nNotarizationsDiff = pindex->nChainNotarizations - pindexPast->nChainNotarizations;
if (nTimeDiff > 0) {
ret.pushKV("txrate", ((double)nTxDiff) / nTimeDiff);
ret.pushKV("txrate", ((double)nTxDiff) / nTimeDiff);
if (fZindex) {
ret.pushKV("notarization_txrate", ((double)nNotarizationsDiff) / nTimeDiff);
ret.pushKV("shielded_txrate", ((double)nShieldedTxDiff) / nTimeDiff);
ret.pushKV("fully_shielded_txrate", ((double)nFullyShieldedTxDiff) / nTimeDiff);
ret.pushKV("paymentrate", ((double)nPaymentsDiff) / nTimeDiff);
ret.pushKV("shielded_paymentrate", ((double)nShieldedPaymentsDiff) / nTimeDiff);
ret.pushKV("fully_shielded_paymentrate", ((double)nFullyShieldedPaymentsDiff) / nTimeDiff);
}
}
if (fZindex) {
ret.pushKV("window_payments", (int) nPaymentsDiff);
ret.pushKV("window_notarizations", (int) nNotarizationsDiff);
ret.pushKV("window_fully_shielded_txcount", nFullyShieldedTxDiff);
ret.pushKV("window_deshielding_txcount", nDeshieldingTxDiff);
ret.pushKV("window_shielding_txcount", nShieldingTxDiff);
ret.pushKV("window_shielded_txcount", nShieldedTxDiff);
ret.pushKV("window_fully_shielded_payments", nFullyShieldedPaymentsDiff);
ret.pushKV("window_shielded_payments", nShieldedPaymentsDiff);
ret.pushKV("window_shielding_payments", nShieldingPaymentsDiff);
ret.pushKV("window_deshielding_payments", nDeshieldingPaymentsDiff);
if (nTxDiff > 0) {
ret.pushKV("shielded_tx_percent", ((double)nShieldedTxDiff) / nTxDiff);
ret.pushKV("fully_shielded_tx_percent", ((double)nFullyShieldedTxDiff) / nTxDiff);
ret.pushKV("shielding_tx_percent", ((double)nShieldingTxDiff) / nTxDiff);
ret.pushKV("deshielding_tx_percent", ((double)nDeshieldingTxDiff) / nTxDiff);
}
if (nPaymentsDiff > 0) {
ret.pushKV("shielded_payments_percent", ((double)nShieldedPaymentsDiff) / nPaymentsDiff);
ret.pushKV("fully_shielded_payments_percent", ((double)nFullyShieldedPaymentsDiff) / nPaymentsDiff);
ret.pushKV("shielding_payments_percent", ((double)nShieldingPaymentsDiff) / nPaymentsDiff);
ret.pushKV("deshielding_payments_percent", ((double)nDeshieldingPaymentsDiff) / nPaymentsDiff);
}
// Statistics considering only zxtns
UniValue shielded(UniValue::VOBJ);
if (nShieldedTxDiff > 0) {
shielded.pushKV("fully_shielded_tx_percent", ((double)nFullyShieldedTxDiff) / nShieldedTxDiff );
shielded.pushKV("shielding_tx_percent", ((double)nShieldingTxDiff) / nShieldedTxDiff );
shielded.pushKV("deshielding_tx_percent", ((double)nDeshieldingTxDiff) / nShieldedTxDiff );
}
if (nShieldedPaymentsDiff > 0) {
shielded.pushKV("fully_shielded_payments_percent", ((double)nFullyShieldedPaymentsDiff) / nShieldedPaymentsDiff );
shielded.pushKV("shielding_payments_percent", ((double)nShieldingPaymentsDiff) / nShieldedPaymentsDiff );
shielded.pushKV("deshielding_payments_percent", ((double)nDeshieldingPaymentsDiff) / nShieldedPaymentsDiff );
}
if(nShieldedTxDiff+nShieldedPaymentsDiff > 0)
ret.pushKV("shielded", shielded);
// Organic tx stats = Raw - Coinbase - DPoW
if (nTxDiff > 0) {
UniValue organic(UniValue::VOBJ);
if(ORG(nTxDiff) > 0) {
organic.pushKV("shielded_tx_percent", ((double)nShieldedTxDiff) / ORG(nTxDiff));
organic.pushKV("fully_shielded_tx_percent", ((double)nFullyShieldedTxDiff) / ORG(nTxDiff));
organic.pushKV("shielding_tx_percent", ((double)nShieldingTxDiff) / ORG(nTxDiff));
organic.pushKV("deshielding_tx_percent", ((double)nDeshieldingTxDiff) / ORG(nTxDiff));
}
if(ORG(nPaymentsDiff) > 0) {
organic.pushKV("shielded_payments_percent", ((double)nShieldedPaymentsDiff) / ORG(nPaymentsDiff));
organic.pushKV("fully_shielded_payments_percent", ((double)nFullyShieldedPaymentsDiff) / ORG(nPaymentsDiff));
organic.pushKV("shielding_payments_percent", ((double)nShieldingPaymentsDiff) / ORG(nPaymentsDiff));
organic.pushKV("deshielding_payments_percent", ((double)nDeshieldingPaymentsDiff) / ORG(nPaymentsDiff));
}
if (nTimeDiff > 0) {
organic.pushKV("paymentrate", ((double)ORG(nPaymentsDiff)) / nTimeDiff);
organic.pushKV("txrate", ((double)ORG(nTxDiff)) / nTimeDiff);
}
organic.pushKV("txcount", (int) ORG(nTxDiff));
organic.pushKV("payments", (int) ORG(nPaymentsDiff));
ret.pushKV("organic", organic);
}
}
}
return ret;

View File

@@ -83,7 +83,7 @@ extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
extern uint32_t ASSETCHAINS_CC;
extern uint32_t ASSETCHAINS_MAGIC,ASSETCHAINS_ALGO;
extern uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY;
extern int32_t ASSETCHAINS_LWMAPOS,ASSETCHAINS_SAPLING,ASSETCHAINS_STAKED;
extern int32_t ASSETCHAINS_SAPLING;
extern uint64_t ASSETCHAINS_ENDSUBSIDY[],ASSETCHAINS_REWARD[],ASSETCHAINS_HALVING[],ASSETCHAINS_DECAY[],ASSETCHAINS_NOTARY_PAY[];
extern std::string NOTARY_PUBKEY,NOTARY_ADDRESS; extern uint8_t NOTARY_PUBKEY33[];
@@ -348,10 +348,6 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
if ( ASSETCHAINS_COMMISSION != 0 )
obj.push_back(Pair("commission", ASSETCHAINS_COMMISSION));
if ( ASSETCHAINS_STAKED != 0 )
obj.push_back(Pair("staked", ASSETCHAINS_STAKED));
if ( ASSETCHAINS_LWMAPOS != 0 )
obj.push_back(Pair("lwmapos", ASSETCHAINS_LWMAPOS));
if ( ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH )
obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]));
}