From 90955940d5bbe037d512699c1bfca2689018daea Mon Sep 17 00:00:00 2001 From: ptschip Date: Sat, 5 Dec 2015 09:02:02 -0800 Subject: [PATCH 01/14] Do not download transactions during inital sync Github-Pull: #7164 Rebased-From: 39a525c21fd1b34df63ab30868423b97b708ee49 --- qa/rpc-tests/listtransactions.py | 5 +++++ qa/rpc-tests/receivedby.py | 5 +++++ qa/rpc-tests/test_framework/util.py | 30 +++++++++++++++++++++++++---- src/main.cpp | 2 +- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/qa/rpc-tests/listtransactions.py b/qa/rpc-tests/listtransactions.py index 51a29b48e..4e5809f4a 100755 --- a/qa/rpc-tests/listtransactions.py +++ b/qa/rpc-tests/listtransactions.py @@ -18,6 +18,11 @@ def txFromHex(hexstring): class ListTransactionsTest(BitcoinTestFramework): + def setup_nodes(self): + #This test requires mocktime + enable_mocktime() + return start_nodes(4, self.options.tmpdir) + def run_test(self): # Simple send, 0 to 1: txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1) diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index 15ef71a58..7d8231f5e 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -27,6 +27,11 @@ def get_sub_array_from_array(object_array, to_match): class ReceivedByTest(BitcoinTestFramework): + def setup_nodes(self): + #This test requires mocktime + enable_mocktime() + return start_nodes(4, self.options.tmpdir) + def run_test(self): ''' listreceivedbyaddress Test diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 3d08fc7d7..50a649b01 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -26,6 +26,26 @@ from .authproxy import AuthServiceProxy, JSONRPCException COVERAGE_DIR = None +#Set Mocktime default to OFF. +#MOCKTIME is only needed for scripts that use the +#cached version of the blockchain. If the cached +#version of the blockchain is used without MOCKTIME +#then the mempools will not sync due to IBD. +MOCKTIME = 0 + +def enable_mocktime(): + #For backwared compatibility of the python scripts + #with previous versions of the cache, set MOCKTIME + #to Jan 1, 2014 + (201 * 10 * 60) + global MOCKTIME + MOCKTIME = 1388534400 + (201 * 10 * 60) + +def disable_mocktime(): + global MOCKTIME + MOCKTIME = 0 + +def get_mocktime(): + return MOCKTIME def enable_coverage(dirname): """Maintain a log of which RPC calls are made during testing.""" @@ -168,9 +188,10 @@ def initialize_chain(test_dir): # Create a 200-block-long chain; each of the 4 nodes # gets 25 mature blocks and 25 immature. - # blocks are created with timestamps 10 minutes apart, starting - # at 1 Jan 2014 - block_time = 1388534400 + # blocks are created with timestamps 10 minutes apart + # starting from 2010 minutes in the past + enable_mocktime() + block_time = get_mocktime() - (201 * 10 * 60) for i in range(2): for peer in range(4): for j in range(25): @@ -183,6 +204,7 @@ def initialize_chain(test_dir): # Shut them down, and clean up cache directories: stop_nodes(rpcs) wait_bitcoinds() + disable_mocktime() for i in range(4): os.remove(log_filename("cache", i, "debug.log")) os.remove(log_filename("cache", i, "db.log")) @@ -232,7 +254,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= if binary is None: binary = os.getenv("BITCOIND", "bitcoind") # RPC tests still depend on free transactions - args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-blockprioritysize=50000" ] + args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-blockprioritysize=50000", "-mocktime="+str(get_mocktime()) ] if extra_args is not None: args.extend(extra_args) bitcoind_processes[i] = subprocess.Popen(args) devnull = open(os.devnull, "w") diff --git a/src/main.cpp b/src/main.cpp index f85ac3317..7d3bb2a3c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4845,7 +4845,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { if (fBlocksOnly) LogPrint("net", "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), pfrom->id); - else if (!fAlreadyHave && !fImporting && !fReindex) + else if (!fAlreadyHave && !fImporting && !fReindex && !IsInitialBlockDownload()) pfrom->AskFor(inv); } From a9e73f71d4a622708a7f2f8b77e491adc74160e3 Mon Sep 17 00:00:00 2001 From: instagibbs Date: Fri, 12 Feb 2016 13:55:32 -0500 Subject: [PATCH 02/14] Fix and cleanup listreceivedbyX documentation Github-Pull: #7527 Rebased-From: c372572595b6b19a4dd88258401d8a0046ce4469 --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ba43b805a..921d5c1e2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1246,7 +1246,7 @@ UniValue listreceivedbyaddress(const UniValue& params, bool fHelp) "\nList balances by receiving address.\n" "\nArguments:\n" "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" - "2. includeempty (numeric, optional, default=false) Whether to include addresses that haven't received any payments.\n" + "2. includeempty (bool, optional, default=false) Whether to include addresses that haven't received any payments.\n" "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" "\nResult:\n" @@ -1284,7 +1284,7 @@ UniValue listreceivedbyaccount(const UniValue& params, bool fHelp) "\nDEPRECATED. List balances by account.\n" "\nArguments:\n" "1. minconf (numeric, optional, default=1) The minimum number of confirmations before payments are included.\n" - "2. includeempty (boolean, optional, default=false) Whether to include accounts that haven't received any payments.\n" + "2. includeempty (bool, optional, default=false) Whether to include accounts that haven't received any payments.\n" "3. includeWatchonly (bool, optional, default=false) Whether to include watchonly addresses (see 'importaddress').\n" "\nResult:\n" From 64fd0ce1d92f6dbd40f755edbbe8353a8ee3f353 Mon Sep 17 00:00:00 2001 From: jloughry Date: Fri, 12 Feb 2016 11:35:32 -0700 Subject: [PATCH 03/14] fix spelling of advertise in src and doc Github-Pull: #7526 Rebased-From: 37767fd46f673a06864df6e14d3030622b1cb2c9 --- doc/tor.md | 2 +- src/main.cpp | 8 ++++---- src/net.cpp | 4 ++-- src/net.h | 2 +- src/torcontrol.cpp | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/tor.md b/doc/tor.md index 1d35a658b..be4125544 100644 --- a/doc/tor.md +++ b/doc/tor.md @@ -52,7 +52,7 @@ your bitcoind's P2P listen port (8333 by default). this option, and this can be a .onion address. Given the above configuration, you can find your onion address in /var/lib/tor/bitcoin-service/hostname. Onion addresses are given - preference for your node to advertize itself with, for connections + preference for your node to advertise itself with, for connections coming from unroutable addresses (such as 127.0.0.1, where the Tor proxy typically runs). diff --git a/src/main.cpp b/src/main.cpp index 7d3bb2a3c..24d292454 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -391,7 +391,7 @@ void MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const Consensus::Pa mapBlocksInFlight[hash] = std::make_pair(nodeid, it); } -/** Check whether the last unknown block a peer advertized is not yet known. */ +/** Check whether the last unknown block a peer advertised is not yet known. */ void ProcessBlockAvailability(NodeId nodeid) { CNodeState *state = State(nodeid); assert(state != NULL); @@ -4639,11 +4639,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, CAddress addr = GetLocalAddress(&pfrom->addr); if (addr.IsRoutable()) { - LogPrintf("ProcessMessages: advertizing address %s\n", addr.ToString()); + LogPrintf("ProcessMessages: advertising address %s\n", addr.ToString()); pfrom->PushAddress(addr); } else if (IsPeerAddrLocalGood(pfrom)) { addr.SetIP(pfrom->addrLocal); - LogPrintf("ProcessMessages: advertizing address %s\n", addr.ToString()); + LogPrintf("ProcessMessages: advertising address %s\n", addr.ToString()); pfrom->PushAddress(addr); } } @@ -5652,7 +5652,7 @@ bool SendMessages(CNode* pto) // Address refresh broadcast int64_t nNow = GetTimeMicros(); if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) { - AdvertizeLocal(pto); + AdvertiseLocal(pto); pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL); } diff --git a/src/net.cpp b/src/net.cpp index 2f60cfa1c..1ad8f2476 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -203,7 +203,7 @@ bool IsPeerAddrLocalGood(CNode *pnode) } // pushes our own address to a peer -void AdvertizeLocal(CNode *pnode) +void AdvertiseLocal(CNode *pnode) { if (fListen && pnode->fSuccessfullyConnected) { @@ -218,7 +218,7 @@ void AdvertizeLocal(CNode *pnode) } if (addrLocal.IsRoutable()) { - LogPrintf("AdvertizeLocal: advertizing address %s\n", addrLocal.ToString()); + LogPrintf("AdvertiseLocal: advertising address %s\n", addrLocal.ToString()); pnode->PushAddress(addrLocal); } } diff --git a/src/net.h b/src/net.h index 07083341d..3fd267959 100644 --- a/src/net.h +++ b/src/net.h @@ -134,7 +134,7 @@ enum }; bool IsPeerAddrLocalGood(CNode *pnode); -void AdvertizeLocal(CNode *pnode); +void AdvertiseLocal(CNode *pnode); void SetLimited(enum Network net, bool fLimited = true); bool IsLimited(enum Network net); bool IsLimited(const CNetAddr& addr); diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 4ebcb9b66..6da1f5a98 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -430,7 +430,7 @@ void TorController::add_onion_cb(TorControlConnection& conn, const TorControlRep } service = CService(service_id+".onion", GetListenPort(), false); - LogPrintf("tor: Got service ID %s, advertizing service %s\n", service_id, service.ToString()); + LogPrintf("tor: Got service ID %s, advertising service %s\n", service_id, service.ToString()); if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) { LogPrint("tor", "tor: Cached service private key to %s\n", GetPrivateKeyFile()); } else { @@ -611,7 +611,7 @@ void TorController::connected_cb(TorControlConnection& conn) void TorController::disconnected_cb(TorControlConnection& conn) { - // Stop advertizing service when disconnected + // Stop advertising service when disconnected if (service.IsValid()) RemoveLocal(service); service = CService(); From 1c3d38bde7be181a87c7c73e26c079e285a6fe96 Mon Sep 17 00:00:00 2001 From: Chris Moore Date: Thu, 25 Feb 2016 19:15:17 -0800 Subject: [PATCH 04/14] Remove spurious dollar sign. Fixes #7189. Github-Pull: #7189 Rebased-From: 3d19193f14b9400f7c908a61375c330113571a38 --- build-aux/m4/bitcoin_qt.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-aux/m4/bitcoin_qt.m4 b/build-aux/m4/bitcoin_qt.m4 index 2480267dc..338016c83 100644 --- a/build-aux/m4/bitcoin_qt.m4 +++ b/build-aux/m4/bitcoin_qt.m4 @@ -384,7 +384,7 @@ AC_DEFUN([_BITCOIN_QT_FIND_LIBS_WITH_PKGCONFIG],[ dnl qt version is set to 'auto' and the preferred version wasn't found. Now try the other. if test x$have_qt = xno && test x$bitcoin_qt_want_version = xauto; then - if test x$auto_priority_version = x$qt5; then + if test x$auto_priority_version = xqt5; then PKG_CHECK_MODULES([QT], [$qt4_modules], [QT_INCLUDES="$QT_CFLAGS"; have_qt=yes; QT_LIB_PREFIX=Qt; bitcoin_qt_got_major_vers=4], [have_qt=no]) else PKG_CHECK_MODULES([QT], [$qt5_modules], [QT_INCLUDES="$QT_CFLAGS"; have_qt=yes; QT_LIB_PREFIX=Qt5; bitcoin_qt_got_major_vers=5], [have_qt=no]) From 66d54085598205de2182c04739cc418e2d15543c Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 3 Mar 2016 13:28:07 +0100 Subject: [PATCH 05/14] Fix memleak in TorController [rework] It looks like, TorController::disconnected_cb(TorControlConnection& conn) gets called multiple times which results in multiple event_new(). Avoid this by creating the event only once in the constructore, and deleting it only once in the destructor (thanks to Cory Fields for the idea). Replaces the fix by Jonas Schnelli in #7610, see discussion there. Github-Pull: #7637 Rebased-From: e2195037116f47b11b66452351dba4fe606423a2 --- src/torcontrol.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 6da1f5a98..1a57ad89c 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -394,6 +394,9 @@ TorController::TorController(struct event_base* base, const std::string& target) target(target), conn(base), reconnect(true), reconnect_ev(0), reconnect_timeout(RECONNECT_TIMEOUT_START) { + reconnect_ev = event_new(base, -1, 0, reconnect_cb, this); + if (!reconnect_ev) + LogPrintf("tor: Failed to create event for reconnection: out of memory?\n"); // Start connection attempts immediately if (!conn.Connect(target, boost::bind(&TorController::connected_cb, this, _1), boost::bind(&TorController::disconnected_cb, this, _1) )) { @@ -409,8 +412,10 @@ TorController::TorController(struct event_base* base, const std::string& target) TorController::~TorController() { - if (reconnect_ev) - event_del(reconnect_ev); + if (reconnect_ev) { + event_free(reconnect_ev); + reconnect_ev = 0; + } if (service.IsValid()) { RemoveLocal(service); } @@ -622,8 +627,8 @@ void TorController::disconnected_cb(TorControlConnection& conn) // Single-shot timer for reconnect. Use exponential backoff. struct timeval time = MillisToTimeval(int64_t(reconnect_timeout * 1000.0)); - reconnect_ev = event_new(base, -1, 0, reconnect_cb, this); - event_add(reconnect_ev, &time); + if (reconnect_ev) + event_add(reconnect_ev, &time); reconnect_timeout *= RECONNECT_TIMEOUT_EXP; } From 21b2f82eb743757f2971ce2e1fc97e8a6171e5c7 Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Thu, 11 Feb 2016 17:10:41 -0500 Subject: [PATCH 06/14] Don't resend wallet txs that aren't in our own mempool Github-Pull: #7521 Rebased-From: 5a2b1c0c8b49c5ae79946e71b9f989b33c9fcf5c --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 71f309148..177edbf2d 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1264,7 +1264,7 @@ bool CWalletTx::RelayWalletTransaction() assert(pwallet->GetBroadcastTransactions()); if (!IsCoinBase()) { - if (GetDepthInMainChain() == 0 && !isAbandoned()) { + if (GetDepthInMainChain() == 0 && !isAbandoned() && InMempool()) { LogPrintf("Relaying wtx %s\n", GetHash().ToString()); RelayTransaction((CTransaction)*this); return true; From 52c101158f31a0112837488f46e4a4fc09735e4e Mon Sep 17 00:00:00 2001 From: Matthew Zipkin Date: Tue, 16 Feb 2016 11:42:14 -0800 Subject: [PATCH 07/14] Clarify description of blockindex see issues: https://github.com/bitcoin-dot-org/bitcoin.org/issues/1237 https://github.com/bitcoin/bitcoin/issues/7532 Github-Pull: #7541 Rebased-From: 7eef1d0dad0c48e9faefdc4fe5cfb6182edc79ab --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 921d5c1e2..48aa7320f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1446,7 +1446,7 @@ UniValue listtransactions(const UniValue& params, bool fHelp) " \"trusted\": xxx (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n" " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive'\n" " category of transactions.\n" - " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive'\n" + " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive'\n" " category of transactions.\n" " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n" " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" @@ -1639,7 +1639,7 @@ UniValue listsinceblock(const UniValue& params, bool fHelp) " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions.\n" " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n" - " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive' category of transactions.\n" + " \"blockindex\": n, (numeric) The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions.\n" " \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n" " \"txid\": \"transactionid\", (string) The transaction id. Available for 'send' and 'receive' category of transactions.\n" " \"time\": xxx, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT).\n" @@ -1723,7 +1723,7 @@ UniValue gettransaction(const UniValue& params, bool fHelp) " \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n" " \"confirmations\" : n, (numeric) The number of confirmations\n" " \"blockhash\" : \"hash\", (string) The block hash\n" - " \"blockindex\" : xx, (numeric) The block index\n" + " \"blockindex\" : xx, (numeric) The index of the transaction in the block that includes it\n" " \"blocktime\" : ttt, (numeric) The time in seconds since epoch (1 Jan 1970 GMT)\n" " \"txid\" : \"transactionid\", (string) The transaction id.\n" " \"time\" : ttt, (numeric) The transaction time in seconds since epoch (1 Jan 1970 GMT)\n" From a5bc6a1bc4696ddda26a75f5ee1d6dc6817ca675 Mon Sep 17 00:00:00 2001 From: Patrick Strateman Date: Wed, 17 Feb 2016 22:44:32 -0800 Subject: [PATCH 08/14] Remove vfReachable and modify IsReachable to only use vfLimited. We do not know that a class of Network is reachable, only that it is not. Github-Pull: #7553 Rebased-From: 110b62f06992d0fb989153afff2dc3aea62a674f --- src/init.cpp | 7 ++++--- src/net.cpp | 12 +----------- src/net.h | 1 - src/torcontrol.cpp | 2 +- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 0b3234566..eda9105a7 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1175,6 +1175,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // -proxy sets a proxy for all outgoing network traffic // -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default std::string proxyArg = GetArg("-proxy", ""); + SetLimited(NET_TOR); if (proxyArg != "" && proxyArg != "0") { proxyType addrProxy = proxyType(CService(proxyArg, 9050), proxyRandomize); if (!addrProxy.IsValid()) @@ -1184,7 +1185,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) SetProxy(NET_IPV6, addrProxy); SetProxy(NET_TOR, addrProxy); SetNameProxy(addrProxy); - SetReachable(NET_TOR); // by default, -proxy sets onion as reachable, unless -noonion later + SetLimited(NET_TOR, false); // by default, -proxy sets onion as reachable, unless -noonion later } // -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses @@ -1193,13 +1194,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) std::string onionArg = GetArg("-onion", ""); if (onionArg != "") { if (onionArg == "0") { // Handle -noonion/-onion=0 - SetReachable(NET_TOR, false); // set onions as unreachable + SetLimited(NET_TOR); // set onions as unreachable } else { proxyType addrOnion = proxyType(CService(onionArg, 9050), proxyRandomize); if (!addrOnion.IsValid()) return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg)); SetProxy(NET_TOR, addrOnion); - SetReachable(NET_TOR); + SetLimited(NET_TOR, false); } } diff --git a/src/net.cpp b/src/net.cpp index 1ad8f2476..bb366685a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -77,7 +77,6 @@ bool fListen = true; uint64_t nLocalServices = NODE_NETWORK; CCriticalSection cs_mapLocalHost; map mapLocalHost; -static bool vfReachable[NET_MAX] = {}; static bool vfLimited[NET_MAX] = {}; static CNode* pnodeLocalHost = NULL; uint64_t nLocalHostNonce = 0; @@ -224,14 +223,6 @@ void AdvertiseLocal(CNode *pnode) } } -void SetReachable(enum Network net, bool fFlag) -{ - LOCK(cs_mapLocalHost); - vfReachable[net] = fFlag; - if (net == NET_IPV6 && fFlag) - vfReachable[NET_IPV4] = true; -} - // learn a new local address bool AddLocal(const CService& addr, int nScore) { @@ -254,7 +245,6 @@ bool AddLocal(const CService& addr, int nScore) info.nScore = nScore + (fAlready ? 1 : 0); info.nPort = addr.GetPort(); } - SetReachable(addr.GetNetwork()); } return true; @@ -317,7 +307,7 @@ bool IsLocal(const CService& addr) bool IsReachable(enum Network net) { LOCK(cs_mapLocalHost); - return vfReachable[net] && !vfLimited[net]; + return !vfLimited[net]; } /** check whether a given address is in a network we can probably connect to */ diff --git a/src/net.h b/src/net.h index 3fd267959..96ecec49c 100644 --- a/src/net.h +++ b/src/net.h @@ -146,7 +146,6 @@ bool IsLocal(const CService& addr); bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL); bool IsReachable(enum Network net); bool IsReachable(const CNetAddr &addr); -void SetReachable(enum Network net, bool fFlag = true); CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL); diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 1a57ad89c..0a68d2348 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -460,7 +460,7 @@ void TorController::auth_cb(TorControlConnection& conn, const TorControlReply& r if (GetArg("-onion", "") == "") { proxyType addrOnion = proxyType(CService("127.0.0.1", 9050), true); SetProxy(NET_TOR, addrOnion); - SetReachable(NET_TOR); + SetLimited(NET_TOR, false); } // Finally - now create the service From d3ead9bcb6d9c8dd59c299db914006d26382816d Mon Sep 17 00:00:00 2001 From: R E Broadley Date: Fri, 26 Jun 2015 22:38:07 +0300 Subject: [PATCH 09/14] Avoid "Unknown command" messages when receiving getaddr on outbound connections. Github-Pull: #7642 Rebased-From: d84ea1a59ce3704457a162f1fd8a7353047156de --- src/main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 24d292454..8a9dae03a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5247,13 +5247,18 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } - // This asymmetric behavior for inbound and outbound connections was introduced - // to prevent a fingerprinting attack: an attacker can send specific fake addresses - // to users' AddrMan and later request them by sending getaddr messages. - // Making nodes which are behind NAT and can only make outgoing connections ignore - // the getaddr message mitigates the attack. - else if ((strCommand == NetMsgType::GETADDR) && (pfrom->fInbound)) + else if (strCommand == NetMsgType::GETADDR) { + // This asymmetric behavior for inbound and outbound connections was introduced + // to prevent a fingerprinting attack: an attacker can send specific fake addresses + // to users' AddrMan and later request them by sending getaddr messages. + // Making nodes which are behind NAT and can only make outgoing connections ignore + // the getaddr message mitigates the attack. + if (!pfrom->fInbound) { + LogPrint("net", "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom->id); + return true; + } + pfrom->vAddrToSend.clear(); vector vAddr = addrman.GetAddr(); BOOST_FOREACH(const CAddress &addr, vAddr) From 5583a3d0a7ace48076a6675014172431b7356f22 Mon Sep 17 00:00:00 2001 From: BtcDrak Date: Wed, 9 Mar 2016 09:20:16 +0000 Subject: [PATCH 10/14] Add curl to Gitian setup instrustions curl is required to fetch dependencies Github-Pull: #7658 Rebased-From: ce41cf082c861cc8d333b811b3101d52d06f50ec --- doc/gitian-building.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/gitian-building.md b/doc/gitian-building.md index e3fb94438..6b10c4f95 100644 --- a/doc/gitian-building.md +++ b/doc/gitian-building.md @@ -252,7 +252,7 @@ First we need to log in as `root` to set up dependencies and make sure that our user can use the sudo command. Type/paste the following in the terminal: ```bash -apt-get install git ruby sudo apt-cacher-ng qemu-utils debootstrap lxc python-cheetah parted kpartx bridge-utils make ubuntu-archive-keyring +apt-get install git ruby sudo apt-cacher-ng qemu-utils debootstrap lxc python-cheetah parted kpartx bridge-utils make ubuntu-archive-keyring curl adduser debian sudo ``` From 7e71785c40a891c17a9ef912ef6007f0b83b3b2d Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Mon, 11 Apr 2016 12:52:29 -0400 Subject: [PATCH 11/14] Use txid as key in mapAlreadyAskedFor Previously we used the CInv that would be sent to the peer announcing the transaction as the key, but using the txid instead allows us to decouple the p2p layer from the application logic (which relies on this map to avoid duplicate tx requests). Github-Pull: #7862 Rebased-From: 7e91f632c70ff1848a152f24ee67a06796803943 --- src/main.cpp | 2 +- src/net.cpp | 6 +++--- src/net.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8a9dae03a..1ae202ea4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5001,7 +5001,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, CValidationState state; pfrom->setAskFor.erase(inv.hash); - mapAlreadyAskedFor.erase(inv); + mapAlreadyAskedFor.erase(inv.hash); if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) { diff --git a/src/net.cpp b/src/net.cpp index bb366685a..5386f6482 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -91,7 +91,7 @@ CCriticalSection cs_vNodes; map mapRelay; deque > vRelayExpiration; CCriticalSection cs_mapRelay; -limitedmap mapAlreadyAskedFor(MAX_INV_SZ); +limitedmap mapAlreadyAskedFor(MAX_INV_SZ); static deque vOneShots; CCriticalSection cs_vOneShots; @@ -2409,7 +2409,7 @@ void CNode::AskFor(const CInv& inv) // We're using mapAskFor as a priority queue, // the key is the earliest time the request can be sent int64_t nRequestTime; - limitedmap::const_iterator it = mapAlreadyAskedFor.find(inv); + limitedmap::const_iterator it = mapAlreadyAskedFor.find(inv.hash); if (it != mapAlreadyAskedFor.end()) nRequestTime = it->second; else @@ -2428,7 +2428,7 @@ void CNode::AskFor(const CInv& inv) if (it != mapAlreadyAskedFor.end()) mapAlreadyAskedFor.update(it, nRequestTime); else - mapAlreadyAskedFor.insert(std::make_pair(inv, nRequestTime)); + mapAlreadyAskedFor.insert(std::make_pair(inv.hash, nRequestTime)); mapAskFor.insert(std::make_pair(nRequestTime, inv)); } diff --git a/src/net.h b/src/net.h index 96ecec49c..a7deceb14 100644 --- a/src/net.h +++ b/src/net.h @@ -163,7 +163,7 @@ extern CCriticalSection cs_vNodes; extern std::map mapRelay; extern std::deque > vRelayExpiration; extern CCriticalSection cs_mapRelay; -extern limitedmap mapAlreadyAskedFor; +extern limitedmap mapAlreadyAskedFor; extern std::vector vAddedNodes; extern CCriticalSection cs_vAddedNodes; From 06c73a1751b346726f549c2780bc1b2a19035db9 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Sat, 9 Apr 2016 14:30:07 +0100 Subject: [PATCH 12/14] Removed call to `TryCreateDirectory` from `GetDefaultDataDir` in `src/util.cpp`. See https://github.com/bitcoin/bitcoin/issues/7845#issuecomment-207684728. Also refactored `GetDefaultDataDir` function to return path for Mac in one expression. Github-Pull: #7850 Rebased-From: 41dbc4849e0bf14eef98962b0f0bddcde0bb3014 --- src/util.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 019c912f5..afcff2f1c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -471,9 +471,7 @@ boost::filesystem::path GetDefaultDataDir() pathRet = fs::path(pszHome); #ifdef MAC_OSX // Mac - pathRet /= "Library/Application Support"; - TryCreateDirectory(pathRet); - return pathRet / "Bitcoin"; + return pathRet / "Library/Application Support/Bitcoin"; #else // Unix return pathRet / ".bitcoin"; From 43c14acf14ee191d946de070615bed93a0601dfa Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Wed, 20 Apr 2016 13:49:55 -0400 Subject: [PATCH 13/14] Fix headers announcements edge case Previously we would assert that if every block in vBlockHashesToAnnounce is in chainActive, then the blocks to be announced must connect. However, there are edge cases where this assumption could be violated (eg using invalidateblock / reconsiderblock), so just check for this case and revert to inv-announcement instead. Github-Pull: #7919 Rebased-From: 3a99fb2cb14955f5e029d315041a093e957e6c3e --- src/main.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 1ae202ea4..5187d543a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5770,7 +5770,21 @@ bool SendMessages(CNode* pto) fRevertToInv = true; break; } - assert(pBestIndex == NULL || pindex->pprev == pBestIndex); + if (pBestIndex != NULL && pindex->pprev != pBestIndex) { + // This means that the list of blocks to announce don't + // connect to each other. + // This shouldn't really be possible to hit during + // regular operation (because reorgs should take us to + // a chain that has some block not on the prior chain, + // which should be caught by the prior check), but one + // way this could happen is by using invalidateblock / + // reconsiderblock repeatedly on the tip, causing it to + // be added multiple times to vBlockHashesToAnnounce. + // Robustly deal with this rare situation by reverting + // to an inv. + fRevertToInv = true; + break; + } pBestIndex = pindex; if (fFoundStartingHeader) { // add this to the headers message From c3d1bc33b598c19c6dab4de032953b770991098b Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Mon, 18 Apr 2016 23:56:06 +0200 Subject: [PATCH 14/14] CBase58Data::SetString: cleanse the full vector SetString seems to be passing the length of the wrong variable to memory_cleanse, resulting in the last byte of the temporary buffer not being securely erased. Github-Pull: #7922 Rebased-From: 57704499be948c640c789c7fc11ed1abf8a681bd --- src/base58.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base58.cpp b/src/base58.cpp index 5e26cf8d4..d59d459e0 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -172,7 +172,7 @@ bool CBase58Data::SetString(const char* psz, unsigned int nVersionBytes) vchData.resize(vchTemp.size() - nVersionBytes); if (!vchData.empty()) memcpy(&vchData[0], &vchTemp[nVersionBytes], vchData.size()); - memory_cleanse(&vchTemp[0], vchData.size()); + memory_cleanse(&vchTemp[0], vchTemp.size()); return true; }