From 6950bb6200cb71d0a1932e80c3aa563391fe6627 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Tue, 20 Dec 2011 23:16:33 -0500 Subject: [PATCH 1/2] Add new "getmininginfo" JSON-RPC method, with mining-only fields moved out of "getinfo" --- src/bitcoinrpc.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index ce298401..57deed9a 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -347,10 +347,7 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (fUseProxy ? addrProxy.ToStringIPPort() : string()))); - obj.push_back(Pair("generate", (bool)fGenerateBitcoins)); - obj.push_back(Pair("genproclimit", (int)(fLimitProcessors ? nLimitProcessors : -1))); obj.push_back(Pair("difficulty", (double)GetDifficulty())); - obj.push_back(Pair("hashespersec", gethashespersec(params, false))); obj.push_back(Pair("testnet", fTestNet)); obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize())); @@ -362,6 +359,25 @@ Value getinfo(const Array& params, bool fHelp) } +Value getmininginfo(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getmininginfo\n" + "Returns an object containing mining-related information."); + + Object obj; + obj.push_back(Pair("blocks", (int)nBestHeight)); + obj.push_back(Pair("difficulty", (double)GetDifficulty())); + obj.push_back(Pair("errors", GetWarnings("statusbar"))); + obj.push_back(Pair("generate", (bool)fGenerateBitcoins)); + obj.push_back(Pair("genproclimit", (int)(fLimitProcessors ? nLimitProcessors : -1))); + obj.push_back(Pair("hashespersec", gethashespersec(params, false))); + obj.push_back(Pair("testnet", fTestNet)); + return obj; +} + + Value getnewaddress(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) @@ -1986,6 +2002,7 @@ pair pCallTable[] = make_pair("setgenerate", &setgenerate), make_pair("gethashespersec", &gethashespersec), make_pair("getinfo", &getinfo), + make_pair("getmininginfo", &getmininginfo), make_pair("getnewaddress", &getnewaddress), make_pair("getaccountaddress", &getaccountaddress), make_pair("setaccount", &setaccount), @@ -2036,6 +2053,7 @@ string pAllowInSafeMode[] = "setgenerate", "gethashespersec", "getinfo", + "getmininginfo", "getnewaddress", "getaccountaddress", "getaccount", From 340f0876eabcabefa77588585f7c8f29954dcb48 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 27 May 2011 00:02:51 -0400 Subject: [PATCH 2/2] collect more info on tx pooling and block finding for getmininginfo --- src/bitcoinrpc.cpp | 3 +++ src/main.cpp | 15 +++++++++++++++ src/main.h | 3 +++ 3 files changed, 21 insertions(+) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 57deed9a..19aaf35d 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -368,11 +368,14 @@ Value getmininginfo(const Array& params, bool fHelp) Object obj; obj.push_back(Pair("blocks", (int)nBestHeight)); + obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize)); + obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx)); obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("generate", (bool)fGenerateBitcoins)); obj.push_back(Pair("genproclimit", (int)(fLimitProcessors ? nLimitProcessors : -1))); obj.push_back(Pair("hashespersec", gethashespersec(params, false))); + obj.push_back(Pair("pooledtx", (uint64_t)nPooledTx)); obj.push_back(Pair("testnet", fTestNet)); return obj; } diff --git a/src/main.cpp b/src/main.cpp index 2d5e9a18..bf7dbe80 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -559,8 +559,11 @@ bool CTransaction::AcceptToMemoryPool(bool fCheckInputs, bool* pfMissingInputs) return AcceptToMemoryPool(txdb, fCheckInputs, pfMissingInputs); } +uint64 nPooledTx = 0; + bool CTransaction::AddToMemoryPoolUnchecked() { + printf("AcceptToMemoryPoolUnchecked(): size %lu\n", mapTransactions.size()); // Add to memory pool without checking anything. Don't call this directly, // call AcceptToMemoryPool to properly check the transaction first. CRITICAL_BLOCK(cs_mapTransactions) @@ -570,6 +573,7 @@ bool CTransaction::AddToMemoryPoolUnchecked() for (int i = 0; i < vin.size(); i++) mapNextTx[vin[i].prevout] = CInPoint(&mapTransactions[hash], i); nTransactionsUpdated++; + ++nPooledTx; } return true; } @@ -584,6 +588,7 @@ bool CTransaction::RemoveFromMemoryPool() mapNextTx.erase(txin.prevout); mapTransactions.erase(GetHash()); nTransactionsUpdated++; + --nPooledTx; } return true; } @@ -2887,6 +2892,9 @@ public: }; +uint64 nLastBlockTx = 0; +uint64 nLastBlockSize = 0; + CBlock* CreateNewBlock(CReserveKey& reservekey) { CBlockIndex* pindexPrev = pindexBest; @@ -2974,6 +2982,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) // Collect transactions into block map mapTestPool; uint64 nBlockSize = 1000; + uint64 nBlockTx = 0; int nBlockSigOps = 100; while (!mapPriority.empty()) { @@ -3008,6 +3017,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) pblock->vtx.push_back(tx); nBlockSize += nTxSize; nBlockSigOps += nTxSigOps; + ++nBlockTx; // Add transactions that depend on this one to the priority queue uint256 hash = tx.GetHash(); @@ -3024,6 +3034,11 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) } } } + + nLastBlockTx = nBlockTx; + nLastBlockSize = nBlockSize; + printf("CreateNewBlock(): total size %lu\n", nBlockSize); + } pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees); diff --git a/src/main.h b/src/main.h index a7c16828..30f3cc3e 100644 --- a/src/main.h +++ b/src/main.h @@ -62,7 +62,10 @@ extern CBigNum bnBestChainWork; extern CBigNum bnBestInvalidWork; extern uint256 hashBestChain; extern CBlockIndex* pindexBest; +extern uint64 nPooledTx; extern unsigned int nTransactionsUpdated; +extern uint64 nLastBlockTx; +extern uint64 nLastBlockSize; extern double dHashesPerSec; extern int64 nHPSTimerStart; extern int64 nTimeBestReceived;