aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qa/rpc-tests/util.py4
-rw-r--r--src/chainparamsbase.cpp4
-rw-r--r--src/chainparamsbase.h6
-rw-r--r--src/coins.cpp15
-rw-r--r--src/coins.h15
-rw-r--r--src/init.cpp14
-rw-r--r--src/main.cpp2
-rw-r--r--src/qt/bitcoin.cpp31
-rw-r--r--src/rpcnet.cpp2
-rw-r--r--src/uint256.cpp43
-rw-r--r--src/uint256.h4
-rw-r--r--src/util.cpp2
12 files changed, 115 insertions, 27 deletions
diff --git a/qa/rpc-tests/util.py b/qa/rpc-tests/util.py
index fc7ae85776..da2b6df197 100644
--- a/qa/rpc-tests/util.py
+++ b/qa/rpc-tests/util.py
@@ -85,7 +85,7 @@ def initialize_chain(test_dir):
# Create cache directories, run bitcoinds:
for i in range(4):
datadir=initialize_datadir("cache", i)
- args = [ "bitcoind", "-keypool=1", "-datadir="+datadir ]
+ args = [ "bitcoind", "-keypool=1", "-datadir="+datadir, "-discover=0" ]
if i > 0:
args.append("-connect=127.0.0.1:"+str(p2p_port(0)))
bitcoind_processes[i] = subprocess.Popen(args)
@@ -147,7 +147,7 @@ def start_node(i, dir, extra_args=None, rpchost=None):
Start a bitcoind and return RPC connection to it
"""
datadir = os.path.join(dir, "node"+str(i))
- args = [ "bitcoind", "-datadir="+datadir, "-keypool=1" ]
+ args = [ "bitcoind", "-datadir="+datadir, "-keypool=1", "-discover=0" ]
if extra_args is not None: args.extend(extra_args)
bitcoind_processes[i] = subprocess.Popen(args)
devnull = open("/dev/null", "w+")
diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp
index 19a9e72cc9..720e24c4a8 100644
--- a/src/chainparamsbase.cpp
+++ b/src/chainparamsbase.cpp
@@ -91,3 +91,7 @@ bool SelectBaseParamsFromCommandLine() {
}
return true;
}
+
+bool AreBaseParamsConfigured() {
+ return pCurrentBaseParams != NULL;
+}
diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h
index 4a3b268909..4398f69548 100644
--- a/src/chainparamsbase.h
+++ b/src/chainparamsbase.h
@@ -49,4 +49,10 @@ void SelectBaseParams(CBaseChainParams::Network network);
*/
bool SelectBaseParamsFromCommandLine();
+/**
+ * Return true if SelectBaseParamsFromCommandLine() has been called to select
+ * a network.
+ */
+bool AreBaseParamsConfigured();
+
#endif
diff --git a/src/coins.cpp b/src/coins.cpp
index 13a4ea95cd..fe40911db7 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -4,6 +4,8 @@
#include "coins.h"
+#include "random.h"
+
#include <assert.h>
// calculate number of bytes for the bitmask, and its number of non-zero bytes
@@ -69,6 +71,8 @@ void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
bool CCoinsViewBacked::BatchWrite(const CCoinsMap &mapCoins, const uint256 &hashBlock) { return base->BatchWrite(mapCoins, hashBlock); }
bool CCoinsViewBacked::GetStats(CCoinsStats &stats) { return base->GetStats(stats); }
+CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {}
+
CCoinsViewCache::CCoinsViewCache(CCoinsView &baseIn, bool fDummy) : CCoinsViewBacked(baseIn), hashBlock(0) { }
bool CCoinsViewCache::GetCoins(const uint256 &txid, CCoins &coins) {
@@ -84,8 +88,8 @@ bool CCoinsViewCache::GetCoins(const uint256 &txid, CCoins &coins) {
}
CCoinsMap::iterator CCoinsViewCache::FetchCoins(const uint256 &txid) {
- CCoinsMap::iterator it = cacheCoins.lower_bound(txid);
- if (it != cacheCoins.end() && it->first == txid)
+ CCoinsMap::iterator it = cacheCoins.find(txid);
+ if (it != cacheCoins.end())
return it;
CCoins tmp;
if (!base->GetCoins(txid,tmp))
@@ -107,7 +111,12 @@ bool CCoinsViewCache::SetCoins(const uint256 &txid, const CCoins &coins) {
}
bool CCoinsViewCache::HaveCoins(const uint256 &txid) {
- return FetchCoins(txid) != cacheCoins.end();
+ CCoinsMap::iterator it = FetchCoins(txid);
+ // We're using vtx.empty() instead of IsPruned here for performance reasons,
+ // as we only care about the case where an transaction was replaced entirely
+ // in a reorganization (which wipes vout entirely, as opposed to spending
+ // which just cleans individual outputs).
+ return (it != cacheCoins.end() && !it->second.vout.empty());
}
uint256 CCoinsViewCache::GetBestBlock() {
diff --git a/src/coins.h b/src/coins.h
index c57a5ec722..9f90fe6bd0 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -13,6 +13,7 @@
#include <stdint.h>
#include <boost/foreach.hpp>
+#include <boost/unordered_map.hpp>
/** pruned version of CTransaction: only retains metadata and unspent transaction outputs
*
@@ -239,7 +240,19 @@ public:
}
};
-typedef std::map<uint256,CCoins> CCoinsMap;
+class CCoinsKeyHasher
+{
+private:
+ uint256 salt;
+
+public:
+ CCoinsKeyHasher();
+ uint64_t operator()(const uint256& key) const {
+ return key.GetHash(salt);
+ }
+};
+
+typedef boost::unordered_map<uint256, CCoins, CCoinsKeyHasher> CCoinsMap;
struct CCoinsStats
{
diff --git a/src/init.cpp b/src/init.cpp
index 07960ee37b..b80d718f01 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -127,12 +127,14 @@ void Shutdown()
StopNode();
UnregisterNodeSignals(GetNodeSignals());
- boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
- CAutoFile est_fileout = CAutoFile(fopen(est_path.string().c_str(), "wb"), SER_DISK, CLIENT_VERSION);
- if (est_fileout)
- mempool.WriteFeeEstimates(est_fileout);
- else
- LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string());
+ {
+ boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
+ CAutoFile est_fileout(fopen(est_path.string().c_str(), "wb"), SER_DISK, CLIENT_VERSION);
+ if (est_fileout)
+ mempool.WriteFeeEstimates(est_fileout);
+ else
+ LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string());
+ }
{
LOCK(cs_main);
diff --git a/src/main.cpp b/src/main.cpp
index 830bcb5489..766f0970f0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1918,7 +1918,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
// Update the on-disk chain state.
bool static WriteChainState(CValidationState &state) {
static int64_t nLastWrite = 0;
- if (!IsInitialBlockDownload() || pcoinsTip->GetCacheSize() > nCoinCacheSize || GetTimeMicros() > nLastWrite + 600*1000000) {
+ if (pcoinsTip->GetCacheSize() > nCoinCacheSize || (!IsInitialBlockDownload() && GetTimeMicros() > nLastWrite + 600*1000000)) {
// Typical CCoins structures on disk are around 100 bytes in size.
// Pushing a new one to the database can cause it to be written
// twice (once in the log, and once in the tables). This is already
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 7c4af25edf..43466663fa 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -34,6 +34,7 @@
#include <boost/filesystem/operations.hpp>
#include <QApplication>
+#include <QDebug>
#include <QLibraryInfo>
#include <QLocale>
#include <QMessageBox>
@@ -237,7 +238,7 @@ void BitcoinCore::initialize()
{
try
{
- LogPrintf("Running AppInit2 in thread\n");
+ qDebug() << __func__ << ": Running AppInit2 in thread";
int rv = AppInit2(threadGroup);
if(rv)
{
@@ -258,11 +259,11 @@ void BitcoinCore::shutdown()
{
try
{
- LogPrintf("Running Shutdown in thread\n");
+ qDebug() << __func__ << ": Running Shutdown in thread";
threadGroup.interrupt_all();
threadGroup.join_all();
Shutdown();
- LogPrintf("Shutdown finished\n");
+ qDebug() << __func__ << ": Shutdown finished";
emit shutdownResult(1);
} catch (std::exception& e) {
handleRunawayException(&e);
@@ -285,15 +286,17 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv):
returnValue(0)
{
setQuitOnLastWindowClosed(false);
- startThread();
}
BitcoinApplication::~BitcoinApplication()
{
- LogPrintf("Stopping thread\n");
- emit stopThread();
- coreThread->wait();
- LogPrintf("Stopped thread\n");
+ if(coreThread)
+ {
+ qDebug() << __func__ << ": Stopping thread";
+ emit stopThread();
+ coreThread->wait();
+ qDebug() << __func__ << ": Stopped thread";
+ }
delete window;
window = 0;
@@ -336,6 +339,8 @@ void BitcoinApplication::createSplashScreen(bool isaTestNet)
void BitcoinApplication::startThread()
{
+ if(coreThread)
+ return;
coreThread = new QThread(this);
BitcoinCore *executor = new BitcoinCore();
executor->moveToThread(coreThread);
@@ -355,13 +360,15 @@ void BitcoinApplication::startThread()
void BitcoinApplication::requestInitialize()
{
- LogPrintf("Requesting initialize\n");
+ qDebug() << __func__ << ": Requesting initialize";
+ startThread();
emit requestedInitialize();
}
void BitcoinApplication::requestShutdown()
{
- LogPrintf("Requesting shutdown\n");
+ qDebug() << __func__ << ": Requesting shutdown";
+ startThread();
window->hide();
window->setClientModel(0);
pollShutdownTimer->stop();
@@ -383,7 +390,7 @@ void BitcoinApplication::requestShutdown()
void BitcoinApplication::initializeResult(int retval)
{
- LogPrintf("Initialization result: %i\n", retval);
+ qDebug() << __func__ << ": Initialization result: " << retval;
// Set exit result: 0 if successful, 1 if failure
returnValue = retval ? 0 : 1;
if(retval)
@@ -438,7 +445,7 @@ void BitcoinApplication::initializeResult(int retval)
void BitcoinApplication::shutdownResult(int retval)
{
- LogPrintf("Shutdown result: %i\n", retval);
+ qDebug() << __func__ << ": Shutdown result: " << retval;
quit(); // Exit main loop after shutdown finished
}
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp
index 680717930b..bd3609b0c9 100644
--- a/src/rpcnet.cpp
+++ b/src/rpcnet.cpp
@@ -79,6 +79,7 @@ Value getpeerinfo(const Array& params, bool fHelp)
"\nbResult:\n"
"[\n"
" {\n"
+ " \"id\": n, (numeric) Peer index\n"
" \"addr\":\"host:port\", (string) The ip address and port of the peer\n"
" \"addrlocal\":\"ip:port\", (string) local address\n"
" \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n"
@@ -113,6 +114,7 @@ Value getpeerinfo(const Array& params, bool fHelp)
Object obj;
CNodeStateStats statestats;
bool fStateStats = GetNodeStateStats(stats.nodeid, statestats);
+ obj.push_back(Pair("id", stats.nodeid));
obj.push_back(Pair("addr", stats.addrName));
if (!(stats.addrLocal.empty()))
obj.push_back(Pair("addrlocal", stats.addrLocal));
diff --git a/src/uint256.cpp b/src/uint256.cpp
index 3392f1e9bc..08c05594fd 100644
--- a/src/uint256.cpp
+++ b/src/uint256.cpp
@@ -290,3 +290,46 @@ uint32_t uint256::GetCompact(bool fNegative) const
nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
return nCompact;
}
+
+static void inline HashMix(uint32_t& a, uint32_t& b, uint32_t& c)
+{
+ // Taken from lookup3, by Bob Jenkins.
+ a -= c; a ^= ((c << 4) | (c >> 28)); c += b;
+ b -= a; b ^= ((a << 6) | (a >> 26)); a += c;
+ c -= b; c ^= ((b << 8) | (b >> 24)); b += a;
+ a -= c; a ^= ((c << 16) | (c >> 16)); c += b;
+ b -= a; b ^= ((a << 19) | (a >> 13)); a += c;
+ c -= b; c ^= ((b << 4) | (b >> 28)); b += a;
+}
+
+static void inline HashFinal(uint32_t& a, uint32_t& b, uint32_t& c)
+{
+ // Taken from lookup3, by Bob Jenkins.
+ c ^= b; c -= ((b << 14) | (b >> 18));
+ a ^= c; a -= ((c << 11) | (c >> 21));
+ b ^= a; b -= ((a << 25) | (a >> 7));
+ c ^= b; c -= ((b << 16) | (b >> 16));
+ a ^= c; a -= ((c << 4) | (c >> 28));
+ b ^= a; b -= ((a << 14) | (a >> 18));
+ c ^= b; c -= ((b << 24) | (b >> 8));
+}
+
+uint64_t uint256::GetHash(const uint256 &salt) const
+{
+ uint32_t a, b, c;
+ a = b = c = 0xdeadbeef + (WIDTH << 2);
+
+ a += pn[0] ^ salt.pn[0];
+ b += pn[1] ^ salt.pn[1];
+ c += pn[2] ^ salt.pn[2];
+ HashMix(a, b, c);
+ a += pn[3] ^ salt.pn[3];
+ b += pn[4] ^ salt.pn[4];
+ c += pn[5] ^ salt.pn[5];
+ HashMix(a, b, c);
+ a += pn[6] ^ salt.pn[6];
+ b += pn[7] ^ salt.pn[7];
+ HashFinal(a, b, c);
+
+ return ((((uint64_t)b) << 32) | c);
+}
diff --git a/src/uint256.h b/src/uint256.h
index 82db7758c9..ad0a56f447 100644
--- a/src/uint256.h
+++ b/src/uint256.h
@@ -21,7 +21,7 @@ public:
template<unsigned int BITS>
class base_uint
{
-private:
+protected:
enum { WIDTH=BITS/32 };
uint32_t pn[WIDTH];
public:
@@ -322,6 +322,8 @@ public:
// implementation accident.
uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL);
uint32_t GetCompact(bool fNegative = false) const;
+
+ uint64_t GetHash(const uint256& salt) const;
};
#endif
diff --git a/src/util.cpp b/src/util.cpp
index ce31619eca..d3fa5182f3 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -205,7 +205,7 @@ int LogPrintStr(const std::string &str)
// print to console
ret = fwrite(str.data(), 1, str.size(), stdout);
}
- else if (fPrintToDebugLog)
+ else if (fPrintToDebugLog && AreBaseParamsConfigured())
{
static bool fStartedNewLine = true;
boost::call_once(&DebugPrintInit, debugPrintInitFlag);