Advertisement
Guest User

BU code on Launchpad after second crash

a guest
Mar 22nd, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 53.23 KB | None | 0 0
  1. diff -Nru bitcoinunlimited-1.0.1.1/configure.ac bitcoinunlimited-1.0.1.2/configure.ac
  2. --- bitcoinunlimited-1.0.1.1/configure.ac 2017-03-14 22:18:47.000000000 +0000
  3. +++ bitcoinunlimited-1.0.1.2/configure.ac 2017-03-21 23:57:43.000000000 +0000
  4. @@ -12,7 +12,7 @@
  5. define(_CLIENT_VERSION_MAJOR, 1)
  6. define(_CLIENT_VERSION_MINOR, 0)
  7. define(_CLIENT_VERSION_REVISION, 1)
  8. -define(_CLIENT_VERSION_BUILD, 1)
  9. +define(_CLIENT_VERSION_BUILD, 2)
  10. define(_CLIENT_VERSION_IS_RELEASE, true)
  11. define(_COPYRIGHT_YEAR, 2017)
  12. AC_INIT([Bitcoin Unlimited],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[https://github.com/BitcoinUnlimited/BitcoinUnlimited/issues],[bitcoinUnlimited])
  13. diff -Nru bitcoinunlimited-1.0.1.1/contrib/gitian-descriptors/gitian-arm.yml bitcoinunlimited-1.0.1.2/contrib/gitian-descriptors/gitian-arm.yml
  14. --- bitcoinunlimited-1.0.1.1/contrib/gitian-descriptors/gitian-arm.yml 2017-03-14 22:18:47.000000000 +0000
  15. +++ bitcoinunlimited-1.0.1.2/contrib/gitian-descriptors/gitian-arm.yml 2017-03-21 23:57:43.000000000 +0000
  16. @@ -1,5 +1,5 @@
  17. ---
  18. -name: "BitcoinUnlimited-linux-0.12"
  19. +name: "BitcoinUnlimited-linux-1.0"
  20. enable_cache: true
  21. suites:
  22. - "trusty"
  23. diff -Nru bitcoinunlimited-1.0.1.1/contrib/gitian-descriptors/gitian-linux.yml bitcoinunlimited-1.0.1.2/contrib/gitian-descriptors/gitian-linux.yml
  24. --- bitcoinunlimited-1.0.1.1/contrib/gitian-descriptors/gitian-linux.yml 2017-03-14 22:18:47.000000000 +0000
  25. +++ bitcoinunlimited-1.0.1.2/contrib/gitian-descriptors/gitian-linux.yml 2017-03-21 23:57:43.000000000 +0000
  26. @@ -1,5 +1,5 @@
  27. ---
  28. -name: "BitcoinUnlimited-linux-0.12"
  29. +name: "BitcoinUnlimited-linux-1.0"
  30. enable_cache: true
  31. suites:
  32. - "trusty"
  33. diff -Nru bitcoinunlimited-1.0.1.1/contrib/gitian-descriptors/gitian-osx.yml bitcoinunlimited-1.0.1.2/contrib/gitian-descriptors/gitian-osx.yml
  34. --- bitcoinunlimited-1.0.1.1/contrib/gitian-descriptors/gitian-osx.yml 2017-03-14 22:18:47.000000000 +0000
  35. +++ bitcoinunlimited-1.0.1.2/contrib/gitian-descriptors/gitian-osx.yml 2017-03-21 23:57:43.000000000 +0000
  36. @@ -1,5 +1,5 @@
  37. ---
  38. -name: "BitcoinUnlimited-osx-0.12.1"
  39. +name: "BitcoinUnlimited-osx-1.0"
  40. enable_cache: true
  41. suites:
  42. - "trusty"
  43. diff -Nru bitcoinunlimited-1.0.1.1/contrib/gitian-descriptors/gitian-win.yml bitcoinunlimited-1.0.1.2/contrib/gitian-descriptors/gitian-win.yml
  44. --- bitcoinunlimited-1.0.1.1/contrib/gitian-descriptors/gitian-win.yml 2017-03-14 22:18:47.000000000 +0000
  45. +++ bitcoinunlimited-1.0.1.2/contrib/gitian-descriptors/gitian-win.yml 2017-03-21 23:57:43.000000000 +0000
  46. @@ -1,5 +1,5 @@
  47. ---
  48. -name: "BitcoinUnlimited-win-0.12"
  49. +name: "BitcoinUnlimited-win-1.0"
  50. enable_cache: true
  51. suites:
  52. - "trusty"
  53. diff -Nru bitcoinunlimited-1.0.1.1/debian/changelog bitcoinunlimited-1.0.1.2/debian/changelog
  54. --- bitcoinunlimited-1.0.1.1/debian/changelog 2017-03-14 22:31:00.000000000 +0000
  55. +++ bitcoinunlimited-1.0.1.2/debian/changelog 2017-03-22 00:08:57.000000000 +0000
  56. @@ -1,5 +1,5 @@
  57. -bitcoinunlimited (1.0.1.1-yakkety) yakkety; urgency=medium
  58. +bitcoinunlimited (1.0.1.2-yakkety) yakkety; urgency=medium
  59.  
  60. - * Bitcoin Unlimited 1.0.1.1 release
  61. + * Bitcoin Unlimited 1.0.1.2 release
  62.  
  63. - -- Andrea Suisani (sickpig) <sickpig@gmail.com> Fri, 14 Mar 2017 23:31:00 +0100
  64. + -- Andrea Suisani (sickpig) <sickpig@gmail.com> Fri, 22 Mar 2017 01:09:00 +0100
  65. diff -Nru bitcoinunlimited-1.0.1.1/debian/rules bitcoinunlimited-1.0.1.2/debian/rules
  66. --- bitcoinunlimited-1.0.1.1/debian/rules 2017-03-10 16:54:25.000000000 +0000
  67. +++ bitcoinunlimited-1.0.1.2/debian/rules 2017-03-21 23:59:55.000000000 +0000
  68. @@ -18,7 +18,7 @@
  69. # Yea, autogen should be run on the source archive, but I like doing git archive
  70. override_dh_auto_configure:
  71. ./autogen.sh
  72. - LIBS="-lboost_atomic" ./configure --without-miniupnpc --with-gui=qt4
  73. + LIBS="-lboost_atomic" ./configure --disable-tests --without-miniupnpc --with-gui=qt4
  74.  
  75. override_dh_auto_test:
  76. echo "no make check"
  77. diff -Nru bitcoinunlimited-1.0.1.1/doc/release-notes/release-notes-1.0.1.1.md bitcoinunlimited-1.0.1.2/doc/release-notes/release-notes-1.0.1.1.md
  78. --- bitcoinunlimited-1.0.1.1/doc/release-notes/release-notes-1.0.1.1.md 1970-01-01 00:00:00.000000000 +0000
  79. +++ bitcoinunlimited-1.0.1.2/doc/release-notes/release-notes-1.0.1.1.md 2017-03-21 23:57:43.000000000 +0000
  80. @@ -0,0 +1,36 @@
  81. +Release Notes for Bitcoin Unlimited v1.0.1.1
  82. +==========================================
  83. +
  84. +Bitcoin Unlimited version 1.0.1.1 is now available from:
  85. +
  86. + <https://bitcoinunlimited.info/download>
  87. +
  88. +Please report bugs using the issue tracker at github:
  89. +
  90. + <https://github.com/BitcoinUnlimited/BitcoinUnlimited/issues>
  91. +
  92. +This is an hotfix release.
  93. +
  94. +Upgrading
  95. +---------
  96. +
  97. +If you are running an older version, shut it down. Wait until it has completely
  98. +shut down (which might take a few minutes for older versions), then run the
  99. +installer (on Windows) or just copy over /Applications/Bitcoin-Qt (on Mac) or
  100. +bitcoind/bitcoin-qt (on Linux).
  101. +
  102. +Main Changes
  103. +------------
  104. +
  105. +Changes are as follows:
  106. +
  107. +- Fix unwanted assertion Sending an invalid GET_XTHIN is a serious misbehavior and any node doing so will be DOS100 banned immediately. Also sending a GET_XTHIN with an invalid message type will also cause the sendder to be banned. This bug cause the node to crash.
  108. +- Fix pruning when syncing a chain for the first time. iWhen syncing a chain with pruning enabled there are at times new blocks arriving which make the nLastHeight equal to the tip of the blockchain, however this prevents block files from being removed during pruning. By not downloading new blocks until the chain no longer in IsInitialDownload() the issue is prevented.
  109. +
  110. +Commit details
  111. +--------------
  112. +- `95c594a` version 1.0.1.1 (Andrew Stone)
  113. +- `eee6a2d` Fix potential unwanted assertion (Peter Tschipper)
  114. +- `db93b0c` Merge pull request #291 from ptschip/dev_prune (gandrewstone)
  115. +- `b200b0d` Bump client version (Justaphf)
  116. +- `da4619d` Merge pull request #300 from Justaphf/dev_2017 (gandrewstone)
  117. diff -Nru bitcoinunlimited-1.0.1.1/.git/config bitcoinunlimited-1.0.1.2/.git/config
  118. --- bitcoinunlimited-1.0.1.1/.git/config 2017-03-14 22:18:43.000000000 +0000
  119. +++ bitcoinunlimited-1.0.1.2/.git/config 2017-03-21 23:57:40.000000000 +0000
  120. @@ -4,5 +4,5 @@
  121. bare = false
  122. logallrefupdates = true
  123. [remote "origin"]
  124. - url = https://github.com/bitcoinUnlimited/BitcoinUnlimited.git
  125. - fetch = +refs/tags/1.0.1.1:refs/tags/1.0.1.1
  126. + url = git@github.com:BitcoinUnlimited/BUprivate.git
  127. + fetch = +refs/tags/1.0.1.2:refs/tags/1.0.1.2
  128. diff -Nru bitcoinunlimited-1.0.1.1/.git/HEAD bitcoinunlimited-1.0.1.2/.git/HEAD
  129. --- bitcoinunlimited-1.0.1.1/.git/HEAD 2017-03-14 22:18:47.000000000 +0000
  130. +++ bitcoinunlimited-1.0.1.2/.git/HEAD 2017-03-21 23:57:43.000000000 +0000
  131. @@ -1 +1 @@
  132. -95c594ade707e49639cda33845dbfaee9ba86acd
  133. +a73f2b336742b25af69c6030683f3dbd5438778a
  134. Binary files /tmp/tmpReIBYD/qrqmSo2qWE/bitcoinunlimited-1.0.1.1/.git/index and /tmp/tmpReIBYD/et8aYIiQbc/bitcoinunlimited-1.0.1.2/.git/index differ
  135. diff -Nru bitcoinunlimited-1.0.1.1/.git/logs/HEAD bitcoinunlimited-1.0.1.2/.git/logs/HEAD
  136. --- bitcoinunlimited-1.0.1.1/.git/logs/HEAD 2017-03-14 22:18:47.000000000 +0000
  137. +++ bitcoinunlimited-1.0.1.2/.git/logs/HEAD 2017-03-21 23:57:43.000000000 +0000
  138. @@ -1 +1 @@
  139. -0000000000000000000000000000000000000000 95c594ade707e49639cda33845dbfaee9ba86acd Andrea Suisani <sickpig@gmail.com> 1489529927 +0100 clone: from https://github.com/bitcoinUnlimited/BitcoinUnlimited.git
  140. +0000000000000000000000000000000000000000 a73f2b336742b25af69c6030683f3dbd5438778a Andrea Suisani <sickpig@gmail.com> 1490140663 +0100 clone: from git@github.com:BitcoinUnlimited/BUprivate.git
  141. Binary files /tmp/tmpReIBYD/qrqmSo2qWE/bitcoinunlimited-1.0.1.1/.git/objects/pack/pack-6789b15c8e3b7de4b2fda24e7e28d1e798091cf8.idx and /tmp/tmpReIBYD/et8aYIiQbc/bitcoinunlimited-1.0.1.2/.git/objects/pack/pack-6789b15c8e3b7de4b2fda24e7e28d1e798091cf8.idx differ
  142. Binary files /tmp/tmpReIBYD/qrqmSo2qWE/bitcoinunlimited-1.0.1.1/.git/objects/pack/pack-6789b15c8e3b7de4b2fda24e7e28d1e798091cf8.pack and /tmp/tmpReIBYD/et8aYIiQbc/bitcoinunlimited-1.0.1.2/.git/objects/pack/pack-6789b15c8e3b7de4b2fda24e7e28d1e798091cf8.pack differ
  143. Binary files /tmp/tmpReIBYD/qrqmSo2qWE/bitcoinunlimited-1.0.1.1/.git/objects/pack/pack-d3c99a09174070093781eafb7547ec30caf62ba5.idx and /tmp/tmpReIBYD/et8aYIiQbc/bitcoinunlimited-1.0.1.2/.git/objects/pack/pack-d3c99a09174070093781eafb7547ec30caf62ba5.idx differ
  144. Binary files /tmp/tmpReIBYD/qrqmSo2qWE/bitcoinunlimited-1.0.1.1/.git/objects/pack/pack-d3c99a09174070093781eafb7547ec30caf62ba5.pack and /tmp/tmpReIBYD/et8aYIiQbc/bitcoinunlimited-1.0.1.2/.git/objects/pack/pack-d3c99a09174070093781eafb7547ec30caf62ba5.pack differ
  145. diff -Nru bitcoinunlimited-1.0.1.1/.git/packed-refs bitcoinunlimited-1.0.1.2/.git/packed-refs
  146. --- bitcoinunlimited-1.0.1.1/.git/packed-refs 2017-03-14 22:18:47.000000000 +0000
  147. +++ bitcoinunlimited-1.0.1.2/.git/packed-refs 2017-03-21 23:57:43.000000000 +0000
  148. @@ -1,2 +1,2 @@
  149. # pack-refs with: peeled fully-peeled
  150. -95c594ade707e49639cda33845dbfaee9ba86acd refs/tags/1.0.1.1
  151. +a73f2b336742b25af69c6030683f3dbd5438778a refs/tags/1.0.1.2
  152. diff -Nru bitcoinunlimited-1.0.1.1/.git/shallow bitcoinunlimited-1.0.1.2/.git/shallow
  153. --- bitcoinunlimited-1.0.1.1/.git/shallow 2017-03-14 22:18:44.000000000 +0000
  154. +++ bitcoinunlimited-1.0.1.2/.git/shallow 2017-03-21 23:57:40.000000000 +0000
  155. @@ -1 +1 @@
  156. -95c594ade707e49639cda33845dbfaee9ba86acd
  157. +a73f2b336742b25af69c6030683f3dbd5438778a
  158. diff -Nru bitcoinunlimited-1.0.1.1/qa/rpc-tests/txn_clone.py bitcoinunlimited-1.0.1.2/qa/rpc-tests/txn_clone.py
  159. --- bitcoinunlimited-1.0.1.1/qa/rpc-tests/txn_clone.py 2017-03-14 22:18:47.000000000 +0000
  160. +++ bitcoinunlimited-1.0.1.2/qa/rpc-tests/txn_clone.py 2017-03-21 23:57:43.000000000 +0000
  161. @@ -25,6 +25,7 @@
  162. # All nodes should start with 1,250 BTC:
  163. starting_balance = 1250
  164. for i in range(4):
  165. + print("node ", i," balance ", self.nodes[i].getbalance())
  166. assert_equal(self.nodes[i].getbalance(), starting_balance)
  167. self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress!
  168.  
  169. diff -Nru bitcoinunlimited-1.0.1.1/qa/rpc-tests/txn_doublespend.py bitcoinunlimited-1.0.1.2/qa/rpc-tests/txn_doublespend.py
  170. --- bitcoinunlimited-1.0.1.1/qa/rpc-tests/txn_doublespend.py 2017-03-14 22:18:47.000000000 +0000
  171. +++ bitcoinunlimited-1.0.1.2/qa/rpc-tests/txn_doublespend.py 2017-03-21 23:57:43.000000000 +0000
  172. @@ -25,6 +25,7 @@
  173. # All nodes should start with 1,250 BTC:
  174. starting_balance = 1250
  175. for i in range(4):
  176. + print("node ", i," balance ", self.nodes[i].getbalance())
  177. assert_equal(self.nodes[i].getbalance(), starting_balance)
  178. self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress!
  179.  
  180. diff -Nru bitcoinunlimited-1.0.1.1/src/addrman.cpp bitcoinunlimited-1.0.1.2/src/addrman.cpp
  181. --- bitcoinunlimited-1.0.1.1/src/addrman.cpp 2017-03-14 22:18:47.000000000 +0000
  182. +++ bitcoinunlimited-1.0.1.2/src/addrman.cpp 2017-03-21 23:57:43.000000000 +0000
  183. @@ -118,7 +118,7 @@
  184.  
  185. void CAddrMan::Delete(int nId)
  186. {
  187. - assert(mapInfo.count(nId) != 0);
  188. + DbgAssert(mapInfo.count(nId) != 0, return); // already deleted so no-op
  189. CAddrInfo& info = mapInfo[nId];
  190. assert(!info.fInTried);
  191. assert(info.nRefCount == 0);
  192. diff -Nru bitcoinunlimited-1.0.1.1/src/chain.h bitcoinunlimited-1.0.1.2/src/chain.h
  193. --- bitcoinunlimited-1.0.1.1/src/chain.h 2017-03-14 22:18:47.000000000 +0000
  194. +++ bitcoinunlimited-1.0.1.2/src/chain.h 2017-03-21 23:57:43.000000000 +0000
  195. @@ -378,6 +378,7 @@
  196.  
  197. /** Efficiently check whether a block is present in this chain. */
  198. bool Contains(const CBlockIndex *pindex) const {
  199. + if (!pindex) return false; // null pointer isn't in this chain
  200. return (*this)[pindex->nHeight] == pindex;
  201. }
  202.  
  203. diff -Nru bitcoinunlimited-1.0.1.1/src/clientversion.cpp bitcoinunlimited-1.0.1.2/src/clientversion.cpp
  204. --- bitcoinunlimited-1.0.1.1/src/clientversion.cpp 2017-03-14 22:26:20.000000000 +0000
  205. +++ bitcoinunlimited-1.0.1.2/src/clientversion.cpp 2017-03-21 23:57:43.000000000 +0000
  206. @@ -105,7 +105,7 @@
  207.  
  208. std::string FormatFullVersion()
  209. {
  210. - return "1.0.1.1-95c594a";
  211. + return CLIENT_BUILD;
  212. }
  213.  
  214. /**
  215. diff -Nru bitcoinunlimited-1.0.1.1/src/clientversion.h bitcoinunlimited-1.0.1.2/src/clientversion.h
  216. --- bitcoinunlimited-1.0.1.1/src/clientversion.h 2017-03-14 22:18:47.000000000 +0000
  217. +++ bitcoinunlimited-1.0.1.2/src/clientversion.h 2017-03-21 23:57:43.000000000 +0000
  218. @@ -18,7 +18,7 @@
  219. #define CLIENT_VERSION_MAJOR 1
  220. #define CLIENT_VERSION_MINOR 0
  221. #define CLIENT_VERSION_REVISION 1
  222. -#define CLIENT_VERSION_BUILD 1
  223. +#define CLIENT_VERSION_BUILD 2
  224.  
  225. //! Set to true for release, false for prerelease or test build
  226. #define CLIENT_VERSION_IS_RELEASE true
  227. diff -Nru bitcoinunlimited-1.0.1.1/src/main.cpp bitcoinunlimited-1.0.1.2/src/main.cpp
  228. --- bitcoinunlimited-1.0.1.1/src/main.cpp 2017-03-14 22:18:47.000000000 +0000
  229. +++ bitcoinunlimited-1.0.1.2/src/main.cpp 2017-03-21 23:57:43.000000000 +0000
  230. @@ -365,15 +365,15 @@
  231. //EraseOrphansFor(nodeid); BUIP010 Xtreme Thinblocks - We do not want to delete orphans at any time. We handle them when we accept a block
  232. nPreferredDownload -= state->fPreferredDownload;
  233. nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0);
  234. - assert(nPeersWithValidatedDownloads >= 0);
  235. + DbgAssert(nPeersWithValidatedDownloads >= 0, nPeersWithValidatedDownloads=0);
  236.  
  237. mapNodeState.erase(nodeid);
  238.  
  239. if (mapNodeState.empty()) {
  240. - // Do a consistency check after the last peer is removed.
  241. - assert(mapBlocksInFlight.empty());
  242. - assert(nPreferredDownload == 0);
  243. - assert(nPeersWithValidatedDownloads == 0);
  244. + // Do a consistency check after the last peer is removed. Force consistent state if production code
  245. + DbgAssert(mapBlocksInFlight.empty(), mapBlocksInFlight.clear());
  246. + DbgAssert(nPreferredDownload == 0, nPreferredDownload = 0);
  247. + DbgAssert(nPeersWithValidatedDownloads == 0, nPeersWithValidatedDownloads = 0);
  248. }
  249. }
  250.  
  251. @@ -475,7 +475,7 @@
  252. /** Check whether the last unknown block a peer advertised is not yet known. */
  253. void ProcessBlockAvailability(NodeId nodeid) {
  254. CNodeState *state = State(nodeid);
  255. - assert(state != NULL);
  256. + DbgAssert(state != NULL, return); // node already destructed, nothing to do in production mode
  257.  
  258. if (!state->hashLastUnknownBlock.IsNull()) {
  259. BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock);
  260. @@ -490,7 +490,7 @@
  261. /** Update tracking information about which blocks a peer is assumed to have. */
  262. void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) {
  263. CNodeState *state = State(nodeid);
  264. - assert(state != NULL);
  265. + DbgAssert(state != NULL, return); // node already destructed, nothing to do in production mode
  266.  
  267. ProcessBlockAvailability(nodeid);
  268.  
  269. @@ -542,7 +542,7 @@
  270.  
  271. vBlocks.reserve(vBlocks.size() + count);
  272. CNodeState *state = State(nodeid);
  273. - assert(state != NULL);
  274. + DbgAssert(state != NULL, return);
  275.  
  276. // Make sure pindexBestKnownBlock is up to date, we'll need it.
  277. ProcessBlockAvailability(nodeid);
  278. @@ -622,8 +622,8 @@
  279.  
  280.  
  281.  
  282. -// Requires cs_main.
  283. void MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const Consensus::Params& consensusParams, CBlockIndex *pindex = NULL) {
  284. + AssertLockHeld(cs_main);
  285. CNodeState *state = State(nodeid);
  286. assert(state != NULL);
  287.  
  288. @@ -2026,8 +2026,18 @@
  289. int GetSpendHeight(const CCoinsViewCache& inputs)
  290. {
  291. LOCK(cs_main);
  292. - CBlockIndex* pindexPrev = mapBlockIndex.find(inputs.GetBestBlock())->second;
  293. - return pindexPrev->nHeight + 1;
  294. + BlockMap::iterator i = mapBlockIndex.find(inputs.GetBestBlock());
  295. + if (i != mapBlockIndex.end())
  296. + {
  297. + CBlockIndex* pindexPrev = i->second;
  298. + if (pindexPrev)
  299. + return pindexPrev->nHeight + 1;
  300. + else
  301. + {
  302. + throw runtime_error("GetSpendHeight(): mapBlockIndex contains null block");
  303. + }
  304. + }
  305. + throw runtime_error("GetSpendHeight(): best block does not exist");
  306. }
  307.  
  308. namespace Consensus {
  309. @@ -3704,10 +3714,10 @@
  310. AssertLockHeld(cs_main);
  311. // Check for duplicate
  312. uint256 hash = block.GetHash();
  313. - BlockMap::iterator miSelf = mapBlockIndex.find(hash);
  314. CBlockIndex *pindex = NULL;
  315. - if (hash != chainparams.GetConsensus().hashGenesisBlock) {
  316. -
  317. + if (hash != chainparams.GetConsensus().hashGenesisBlock)
  318. + {
  319. + BlockMap::iterator miSelf = mapBlockIndex.find(hash);
  320. if (miSelf != mapBlockIndex.end()) {
  321. // Block header is already known.
  322. pindex = miSelf->second;
  323. @@ -4769,7 +4779,7 @@
  324. {
  325. case MSG_TX:
  326. {
  327. - assert(recentRejects);
  328. + // remove assertions from P2P code, but this should hold: assert(recentRejects);
  329. if (chainActive.Tip()->GetBlockHash() != hashRecentRejectsChainTip)
  330. {
  331. // If the chain tip has changed previously rejected transactions
  332. @@ -4777,9 +4787,11 @@
  333. // or a double-spend. Reset the rejects filter and give those
  334. // txs a second chance.
  335. hashRecentRejectsChainTip = chainActive.Tip()->GetBlockHash();
  336. - recentRejects->reset();
  337. + if (recentRejects) recentRejects->reset();
  338. + else recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
  339. }
  340. - return recentRejects->contains(inv.hash) ||
  341. + bool rrc = recentRejects ? recentRejects->contains(inv.hash) : false;
  342. + return rrc ||
  343. mempool.exists(inv.hash) ||
  344. AlreadyHaveOrphan(inv.hash) ||
  345. pcoinsTip->HaveCoins(inv.hash);
  346. @@ -4850,61 +4862,68 @@
  347. // Pruned nodes may have deleted the block, so check whether
  348. // it's available before trying to send.
  349. if (send && (mi->second->nStatus & BLOCK_HAVE_DATA))
  350. - {
  351. + {
  352. // Send block from disk
  353. CBlock block;
  354. if (!ReadBlockFromDisk(block, (*mi).second, consensusParams))
  355. - assert(!"cannot load block from disk");
  356. - if (inv.type == MSG_BLOCK)
  357. - {
  358. - pfrom->blocksSent += 1;
  359. - pfrom->PushMessage(NetMsgType::BLOCK, block);
  360. - }
  361. -
  362. - // BUIP010 Xtreme Thinblocks: begin section
  363. - else if (inv.type == MSG_THINBLOCK || inv.type == MSG_XTHINBLOCK) {
  364. - LogPrint("thin", "Sending xthin by INV queue getdata message\n");
  365. - SendXThinBlock(block, pfrom, inv);
  366. - }
  367. - // BUIP010 Xtreme Thinblocks: end section
  368. -
  369. - else // MSG_FILTERED_BLOCK)
  370. - {
  371. - LOCK(pfrom->cs_filter);
  372. - if (pfrom->pfilter)
  373. - {
  374. - CMerkleBlock merkleBlock(block, *pfrom->pfilter);
  375. - pfrom->PushMessage(NetMsgType::MERKLEBLOCK, merkleBlock);
  376. + {
  377. + // its possible that I know about it but haven't stored it yet
  378. + LogPrint("thin", "unable to load block %s from disk\n", (*mi).second->phashBlock ? (*mi).second->phashBlock->ToString() : "");
  379. + // no response
  380. + }
  381. + else
  382. + {
  383. + if (inv.type == MSG_BLOCK)
  384. + {
  385. pfrom->blocksSent += 1;
  386. - // CMerkleBlock just contains hashes, so also push any transactions in the block the client did not see
  387. - // This avoids hurting performance by pointlessly requiring a round-trip
  388. - // Note that there is currently no way for a node to request any single transactions we didn't send here -
  389. - // they must either disconnect and retry or request the full block.
  390. - // Thus, the protocol spec specified allows for us to provide duplicate txn here,
  391. - // however we MUST always provide at least what the remote peer needs
  392. - typedef std::pair<unsigned int, uint256> PairType;
  393. - BOOST_FOREACH(PairType& pair, merkleBlock.vMatchedTxn)
  394. - {
  395. - pfrom->txsSent += 1;
  396. - pfrom->PushMessage(NetMsgType::TX, block.vtx[pair.first]);
  397. - }
  398. + pfrom->PushMessage(NetMsgType::BLOCK, block);
  399. + }
  400. +
  401. + // BUIP010 Xtreme Thinblocks: begin section
  402. + else if (inv.type == MSG_THINBLOCK || inv.type == MSG_XTHINBLOCK) {
  403. + LogPrint("thin", "Sending xthin by INV queue getdata message\n");
  404. + SendXThinBlock(block, pfrom, inv);
  405. }
  406. - // else
  407. + // BUIP010 Xtreme Thinblocks: end section
  408. +
  409. + else // MSG_FILTERED_BLOCK)
  410. + {
  411. + LOCK(pfrom->cs_filter);
  412. + if (pfrom->pfilter)
  413. + {
  414. + CMerkleBlock merkleBlock(block, *pfrom->pfilter);
  415. + pfrom->PushMessage(NetMsgType::MERKLEBLOCK, merkleBlock);
  416. + pfrom->blocksSent += 1;
  417. + // CMerkleBlock just contains hashes, so also push any transactions in the block the client did not see
  418. + // This avoids hurting performance by pointlessly requiring a round-trip
  419. + // Note that there is currently no way for a node to request any single transactions we didn't send here -
  420. + // they must either disconnect and retry or request the full block.
  421. + // Thus, the protocol spec specified allows for us to provide duplicate txn here,
  422. + // however we MUST always provide at least what the remote peer needs
  423. + typedef std::pair<unsigned int, uint256> PairType;
  424. + BOOST_FOREACH(PairType& pair, merkleBlock.vMatchedTxn)
  425. + {
  426. + pfrom->txsSent += 1;
  427. + pfrom->PushMessage(NetMsgType::TX, block.vtx[pair.first]);
  428. + }
  429. + }
  430. + // else
  431. // no response
  432. - }
  433. + }
  434.  
  435. - // Trigger the peer node to send a getblocks request for the next batch of inventory
  436. - if (inv.hash == pfrom->hashContinue)
  437. - {
  438. - // Bypass PushInventory, this must send even if redundant,
  439. - // and we want it right after the last block so they don't
  440. - // wait for other stuff first.
  441. - vector<CInv> vInv;
  442. - vInv.push_back(CInv(MSG_BLOCK, chainActive.Tip()->GetBlockHash()));
  443. - pfrom->PushMessage(NetMsgType::INV, vInv);
  444. - pfrom->hashContinue.SetNull();
  445. - }
  446. - }
  447. + // Trigger the peer node to send a getblocks request for the next batch of inventory
  448. + if (inv.hash == pfrom->hashContinue)
  449. + {
  450. + // Bypass PushInventory, this must send even if redundant,
  451. + // and we want it right after the last block so they don't
  452. + // wait for other stuff first.
  453. + vector<CInv> vInv;
  454. + vInv.push_back(CInv(MSG_BLOCK, chainActive.Tip()->GetBlockHash()));
  455. + pfrom->PushMessage(NetMsgType::INV, vInv);
  456. + pfrom->hashContinue.SetNull();
  457. + }
  458. + }
  459. + }
  460. }
  461. else if (inv.IsKnownType())
  462. {
  463. @@ -5238,12 +5257,23 @@
  464. {
  465. vector<CInv> vInv;
  466. vRecv >> vInv;
  467. - if (vInv.size() > MAX_INV_SZ)
  468. + if ((vInv.size() > MAX_INV_SZ)||(vInv.size() == 0)) // BU check size == 0 to be intolerant of an empty and useless request
  469. {
  470. Misbehaving(pfrom->GetId(), 20);
  471. return error("message inv size() = %u", vInv.size());
  472. }
  473. -
  474. +
  475. + for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) // Validate that INVs are a valid type
  476. + {
  477. + const CInv &inv = vInv[nInv];
  478. + if (!((inv.type == MSG_TX) || (inv.type == MSG_BLOCK)))
  479. + {
  480. + Misbehaving(pfrom->GetId(), 20);
  481. + return error("message inv invalid type = %u", inv.type);
  482. + }
  483. + // inv.hash does not need validation, since SHA2556 hash can be any value
  484. + }
  485. +
  486. bool fBlocksOnly = GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
  487.  
  488. // Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistrelay is true
  489. @@ -5252,7 +5282,7 @@
  490.  
  491. LOCK(cs_main);
  492.  
  493. - std::vector<CInv> vToFetch;
  494. + // BU remove, unused std::vector<CInv> vToFetch;
  495.  
  496. for (unsigned int nInv = 0; nInv < vInv.size(); nInv++)
  497. {
  498. @@ -5292,8 +5322,8 @@
  499. }
  500. }
  501.  
  502. - if (!vToFetch.empty())
  503. - pfrom->PushMessage(NetMsgType::GETDATA, vToFetch);
  504. + // BU remove, unused if (!vToFetch.empty())
  505. + // BU remove, unused pfrom->PushMessage(NetMsgType::GETDATA, vToFetch);
  506. }
  507.  
  508.  
  509. @@ -5301,11 +5331,22 @@
  510. {
  511. vector<CInv> vInv;
  512. vRecv >> vInv;
  513. - if (vInv.size() > MAX_INV_SZ)
  514. + if ((vInv.size() > MAX_INV_SZ)||(vInv.size() == 0)) // BU check size == 0 to be intolerant of an empty and useless request
  515. {
  516. Misbehaving(pfrom->GetId(), 20);
  517. return error("message getdata size() = %u", vInv.size());
  518. }
  519. + for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) // Validate that INVs are a valid type
  520. + {
  521. + const CInv &inv = vInv[nInv];
  522. + if (!((inv.type == MSG_TX) || (inv.type == MSG_BLOCK) || (inv.type == MSG_FILTERED_BLOCK) || (inv.type == MSG_THINBLOCK) || (inv.type == MSG_XTHINBLOCK)))
  523. + {
  524. + Misbehaving(pfrom->GetId(), 20);
  525. + return error("message inv invalid type = %u", inv.type);
  526. + }
  527. + // inv.hash does not need validation, since SHA2556 hash can be any value
  528. + }
  529. +
  530.  
  531. if (fDebug || (vInv.size() != 1))
  532. LogPrint("net", "received getdata (%u invsz) peer=%d\n", vInv.size(), pfrom->id);
  533. @@ -5441,7 +5482,6 @@
  534. // Check for recently rejected (and do other quick existence checks)
  535. if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))
  536. {
  537. -
  538. mempool.check(pcoinsTip);
  539. RelayTransaction(tx);
  540. vWorkQueue.push_back(inv.hash);
  541. @@ -5496,8 +5536,7 @@
  542. // Probably non-standard or insufficient fee/priority
  543. LogPrint("mempool", " removed orphan tx %s\n", orphanHash.ToString());
  544. vEraseQueue.push_back(orphanHash);
  545. - assert(recentRejects);
  546. - recentRejects->insert(orphanHash);
  547. + if (recentRejects) recentRejects->insert(orphanHash); // should always be true
  548. }
  549. mempool.check(pcoinsTip);
  550. }
  551. @@ -5519,8 +5558,7 @@
  552. if (nEvicted > 0)
  553. LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted);
  554. } else {
  555. - assert(recentRejects);
  556. - recentRejects->insert(tx.GetHash());
  557. + if (recentRejects) recentRejects->insert(tx.GetHash()); // should always be true
  558.  
  559. if (pfrom->fWhitelisted && GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
  560. // Always relay transactions received from whitelisted peers, even
  561. @@ -5611,7 +5649,7 @@
  562. CNodeState *nodestate = State(pfrom->GetId());
  563. // If this set of headers is valid and ends in a block with at least as
  564. // much work as our tip, download as much as possible.
  565. - if (fCanDirectFetch && pindexLast->IsValid(BLOCK_VALID_TREE) && chainActive.Tip()->nChainWork <= pindexLast->nChainWork) {
  566. + if (fCanDirectFetch && pindexLast && pindexLast->IsValid(BLOCK_VALID_TREE) && chainActive.Tip()->nChainWork <= pindexLast->nChainWork) {
  567. vector<CBlockIndex *> vToFetch;
  568. CBlockIndex *pindexWalk = pindexLast;
  569. // Calculate all the blocks we'd need to switch to pindexLast, up to a limit.
  570. @@ -5627,7 +5665,7 @@
  571. // very large reorg at a time we think we're close to caught up to
  572. // the main chain -- this shouldn't really happen. Bail out on the
  573. // direct fetch and rely on parallel download instead.
  574. - if (!chainActive.Contains(pindexWalk)) {
  575. + if (pindexWalk && !chainActive.Contains(pindexWalk)) {
  576. LogPrint("net", "Large reorg, won't direct fetch to %s (%d)\n",
  577. pindexLast->GetBlockHash().ToString(),
  578. pindexLast->nHeight);
  579. @@ -5640,6 +5678,7 @@
  580. // Can't download any more from this peer
  581. break;
  582. }
  583. + // pindex must be nonnull because we populated vToFetch a few lines above
  584. vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
  585. MarkBlockAsInFlight(pfrom->GetId(), pindex->GetBlockHash(), chainparams.GetConsensus(), pindex);
  586. LogPrint("net", "Requesting block %s from peer=%d\n",
  587. @@ -5689,13 +5728,20 @@
  588. CBloomFilter filterMemPool;
  589. CInv inv;
  590. vRecv >> inv >> filterMemPool;
  591. + if (!((inv.type == MSG_XTHINBLOCK)||(inv.type == MSG_THINBLOCK)))
  592. + {
  593. + Misbehaving(pfrom->GetId(), 20);
  594. + return error("message inv invalid type = %u", inv.type);
  595. + }
  596. +
  597.  
  598. - LoadFilter(pfrom, &filterMemPool);
  599. + LoadFilter(pfrom, &filterMemPool); // Validates that the filter is reasonably sized.
  600.  
  601. {
  602. LOCK(cs_main);
  603. BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
  604. - if (mi == mapBlockIndex.end()) {
  605. + if (mi == mapBlockIndex.end()) { // This block does not even exist
  606. + LogPrint("thin", "Peer %s (%d) requested nonexistent block %s\n", pfrom->addrName.c_str(), pfrom->id, inv.hash.ToString());
  607. Misbehaving(pfrom->GetId(), 100);
  608. return false;
  609. }
  610. @@ -5703,9 +5749,15 @@
  611. CBlock block;
  612. const Consensus::Params& consensusParams = Params().GetConsensus();
  613. if (!ReadBlockFromDisk(block, (*mi).second, consensusParams))
  614. - assert(!"cannot load block from disk");
  615. -
  616. - SendXThinBlock(block, pfrom, inv);
  617. + {
  618. + // We don't have the block yet, although we know about it.
  619. + LogPrint("thin", "Peer %s (%d) requested not-yet-received block %s\n", pfrom->addrName.c_str(), pfrom->id, inv.hash.ToString());
  620. + return false;
  621. + }
  622. + else
  623. + {
  624. + SendXThinBlock(block, pfrom, inv);
  625. + }
  626. }
  627. }
  628. else if (strCommand == NetMsgType::XPEDITEDREQUEST) // BU
  629. @@ -5714,7 +5766,12 @@
  630. }
  631. else if (strCommand == NetMsgType::XPEDITEDBLK) // BU
  632. {
  633. - HandleExpeditedBlock(vRecv,pfrom);
  634. + if (!HandleExpeditedBlock(vRecv,pfrom))
  635. + {
  636. + LOCK(cs_main);
  637. + Misbehaving(pfrom->GetId(), 5);
  638. + return false;
  639. + }
  640. }
  641. // BU - used to pass BU specific version information similar to NetMsgType::VERSION
  642. else if (strCommand == NetMsgType::BUVERSION)
  643. @@ -5743,18 +5800,17 @@
  644. {
  645. CXThinBlock thinBlock;
  646. vRecv >> thinBlock;
  647. -
  648. + CInv inv(MSG_BLOCK, thinBlock.header.GetHash());
  649. // Send expedited ASAP
  650. CValidationState state;
  651. if (!CheckBlockHeader(thinBlock.header, state, true)) { // block header is bad
  652. - LogPrint("thin", "Thinblock %s received with bad header from peer %s (%d)\n", thinBlock.header.GetHash().ToString(), pfrom->addrName.c_str(), pfrom->id);
  653. + LogPrint("thin", "Thinblock %s received with bad header from peer %s (%d)\n", inv.hash.ToString(), pfrom->addrName.c_str(), pfrom->id);
  654. Misbehaving(pfrom->GetId(), 20);
  655. return false;
  656. }
  657. - else if (!IsRecentlyExpeditedAndStore(thinBlock.header.GetHash()))
  658. + else if (!IsRecentlyExpeditedAndStore(inv.hash))
  659. SendExpeditedBlock(thinBlock, 0, pfrom);
  660.  
  661. - CInv inv(MSG_BLOCK, thinBlock.header.GetHash());
  662. int nSizeThinBlock = ::GetSerializeSize(thinBlock, SER_NETWORK, PROTOCOL_VERSION);
  663. LogPrint("thin", "Received thinblock %s from peer %s (%d). Size %d bytes.\n", inv.hash.ToString(), pfrom->addrName.c_str(), pfrom->id, nSizeThinBlock);
  664.  
  665. @@ -5829,6 +5885,15 @@
  666. else if (inMissingTx)
  667. tx = mapMissingTx[hash];
  668. }
  669. + else
  670. + {
  671. + // Set misbehaving and abort if the thin block has a tx with a null hash.
  672. + LogPrintf("Misbehaving - thin block with a NULL hash\n");
  673. + LOCK(cs_main);
  674. + Misbehaving(pfrom->GetId(), 100);
  675. + return false;
  676. + }
  677. +
  678. if (tx.IsNull())
  679. missingCount++;
  680. // This will push an empty/invalid transaction if we don't have it yet
  681. @@ -5863,7 +5928,7 @@
  682. // This marks the end of the transactions we've received. If we get this and we have NOT been able to
  683. // finish reassembling the block, we need to re-request the full regular block:
  684. vector<CInv> vGetData;
  685. - vGetData.push_back(CInv(MSG_BLOCK, thinBlock.header.GetHash()));
  686. + vGetData.push_back(inv);
  687. pfrom->PushMessage("getdata", vGetData);
  688. setPreVerifiedTxHash.clear(); // Xpress Validation - clear the set since we do not do XVal on regular blocks
  689. LogPrint("thin", "Missing %d Thinblock transactions, re-requesting a regular block\n",
  690. @@ -5894,6 +5959,13 @@
  691.  
  692. int count=0;
  693. size_t i;
  694. + if (pfrom->xThinBlockHashes.size() != pfrom->thinBlock.vtx.size()) // Because the next loop assumes this
  695. + {
  696. + LogPrint("thin", "Inconsistent thin block data. Aborting the thin block\n");
  697. + // TODO clear out the thin block
  698. + return true;
  699. + }
  700. +
  701. for (i = 0; i < pfrom->thinBlock.vtx.size(); i++) {
  702. if (pfrom->thinBlock.vtx[i].IsNull()) {
  703. std::map<uint64_t, CTransaction>::iterator val = mapMissingTx.find(pfrom->xThinBlockHashes[i]);
  704. @@ -6205,14 +6277,22 @@
  705. vRecv >> filter;
  706.  
  707. if (!filter.IsWithinSizeConstraints())
  708. + {
  709. // There is no excuse for sending a too-large filter
  710. Misbehaving(pfrom->GetId(), 100);
  711. + return false;
  712. + }
  713. else
  714. {
  715. LOCK(pfrom->cs_filter);
  716. delete pfrom->pfilter;
  717. pfrom->pfilter = new CBloomFilter(filter);
  718. - pfrom->pfilter->UpdateEmptyFull();
  719. + if (!pfrom->pfilter)
  720. + {
  721. + LogPrintf("Unable to allocate new bloom filter -- out of memory");
  722. + return false;
  723. + }
  724. + else pfrom->pfilter->UpdateEmptyFull();
  725. }
  726. pfrom->fRelayTxes = true;
  727. }
  728. @@ -6306,9 +6386,9 @@
  729. }
  730.  
  731.  
  732. -// requires LOCK(cs_vRecvMsg)
  733. bool ProcessMessages(CNode* pfrom)
  734. {
  735. + AssertLockHeld(pfrom->cs_vRecvMsg);
  736. const CChainParams& chainparams = Params();
  737. //if (fDebug)
  738. // LogPrintf("%s(%u messages)\n", __func__, pfrom->vRecvMsg.size());
  739. @@ -6591,7 +6671,7 @@
  740. // headers that aren't on chainActive, give up.
  741. BOOST_FOREACH(const uint256 &hash, pto->vBlockHashesToAnnounce) {
  742. BlockMap::iterator mi = mapBlockIndex.find(hash);
  743. - assert(mi != mapBlockIndex.end());
  744. + if (mi == mapBlockIndex.end()) continue; // BU skip blocks that we don't know about. was: assert(mi != mapBlockIndex.end());
  745. CBlockIndex *pindex = mi->second;
  746. if (chainActive[pindex->nHeight] != pindex) {
  747. // Bail out if we reorged away from this block
  748. @@ -6639,25 +6719,27 @@
  749. if (!pto->vBlockHashesToAnnounce.empty()) {
  750. const uint256 &hashToAnnounce = pto->vBlockHashesToAnnounce.back();
  751. BlockMap::iterator mi = mapBlockIndex.find(hashToAnnounce);
  752. - assert(mi != mapBlockIndex.end());
  753. - CBlockIndex *pindex = mi->second;
  754. -
  755. - // Warn if we're announcing a block that is not on the main chain.
  756. - // This should be very rare and could be optimized out.
  757. - // Just log for now.
  758. - if (chainActive[pindex->nHeight] != pindex) {
  759. - LogPrint("net", "Announcing block %s not on main chain (tip=%s)\n",
  760. - hashToAnnounce.ToString(), chainActive.Tip()->GetBlockHash().ToString());
  761. - }
  762. + if (mi != mapBlockIndex.end()) // was assert(mi != mapBlockIndex.end());
  763. + {
  764. + CBlockIndex *pindex = mi->second;
  765. +
  766. + // Warn if we're announcing a block that is not on the main chain.
  767. + // This should be very rare and could be optimized out.
  768. + // Just log for now.
  769. + if (chainActive[pindex->nHeight] != pindex) {
  770. + LogPrint("net", "Announcing block %s not on main chain (tip=%s)\n",
  771. + hashToAnnounce.ToString(), chainActive.Tip()->GetBlockHash().ToString());
  772. + }
  773.  
  774. - // If the peer announced this block to us, don't inv it back.
  775. - // (Since block announcements may not be via inv's, we can't solely rely on
  776. - // setInventoryKnown to track this.)
  777. - if (!PeerHasHeader(&state, pindex)) {
  778. - pto->PushInventory(CInv(MSG_BLOCK, hashToAnnounce));
  779. - LogPrint("net", "%s: sending inv peer=%d hash=%s\n", __func__,
  780. - pto->id, hashToAnnounce.ToString());
  781. - }
  782. + // If the peer announced this block to us, don't inv it back.
  783. + // (Since block announcements may not be via inv's, we can't solely rely on
  784. + // setInventoryKnown to track this.)
  785. + if (!PeerHasHeader(&state, pindex)) {
  786. + pto->PushInventory(CInv(MSG_BLOCK, hashToAnnounce));
  787. + LogPrint("net", "%s: sending inv peer=%d hash=%s\n", __func__,
  788. + pto->id, hashToAnnounce.ToString());
  789. + }
  790. + }
  791. }
  792. } else if (!vHeaders.empty()) {
  793. if (vHeaders.size() > 1) {
  794. @@ -6752,19 +6834,9 @@
  795. // to unreasonably increase our timeout.
  796. if (!pto->fDisconnect && state.vBlocksInFlight.size() > 0) {
  797. QueuedBlock &queuedBlock = state.vBlocksInFlight.front();
  798. -#if 0 // TODO: original 12.0
  799. - int64_t nTimeoutIfRequestedNow = GetBlockTimeout(nNow, nQueuedValidatedHeaders - state.nBlocksInFlightValidHeaders, consensusParams);
  800. - if (queuedBlock.nTimeDisconnect > nTimeoutIfRequestedNow) {
  801. - LogPrint("net", "Reducing block download timeout for peer=%s (%d) block=%s, orig=%d new=%d\n", pto->addrName.c_str(), pto->id, queuedBlock.hash.ToString(), queuedBlock.nTimeDisconnect, nTimeoutIfRequestedNow);
  802. - queuedBlock.nTimeDisconnect = nTimeoutIfRequestedNow;
  803. - }
  804. - if (queuedBlock.nTimeDisconnect < nNow) {
  805. - LogPrintf("Timeout downloading block %s from peer %s (%d), disconnecting\n", queuedBlock.hash.ToString(), pto->addrName.c_str(), pto->id);
  806. -#else // new 12.1
  807. int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - (state.nBlocksInFlightValidHeaders > 0);
  808. if (nNow > state.nDownloadingSince + consensusParams.nPowTargetSpacing * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
  809. LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", queuedBlock.hash.ToString(), pto->id);
  810. -#endif
  811. pto->fDisconnect = true;
  812. }
  813. }
  814. diff -Nru bitcoinunlimited-1.0.1.1/src/net.cpp bitcoinunlimited-1.0.1.2/src/net.cpp
  815. --- bitcoinunlimited-1.0.1.1/src/net.cpp 2017-03-14 22:18:47.000000000 +0000
  816. +++ bitcoinunlimited-1.0.1.2/src/net.cpp 2017-03-21 23:57:43.000000000 +0000
  817. @@ -1278,7 +1278,8 @@
  818. }
  819. if (fDelete) {
  820. vNodesDisconnected.remove(pnode);
  821. - assert(std::find(vNodes.begin(),vNodes.end(), pnode) == vNodes.end()); // make sure it has been removed
  822. + // no need to remove from vNodes. we know pnode has already been removed from vNodes since that
  823. + // occurred prior to insertion into vNodesDisconnected
  824. delete pnode;
  825. }
  826. }
  827. diff -Nru bitcoinunlimited-1.0.1.1/src/protocol.h bitcoinunlimited-1.0.1.2/src/protocol.h
  828. --- bitcoinunlimited-1.0.1.1/src/protocol.h 2017-03-14 22:18:47.000000000 +0000
  829. +++ bitcoinunlimited-1.0.1.2/src/protocol.h 2017-03-21 23:57:43.000000000 +0000
  830. @@ -363,7 +363,7 @@
  831.  
  832. friend bool operator<(const CInv& a, const CInv& b);
  833.  
  834. - bool IsKnownType() const;
  835. + bool IsKnownType() const; // all types ever used (includes type 3 = "filtered block")
  836. const char* GetCommand() const;
  837. std::string ToString() const;
  838.  
  839. diff -Nru bitcoinunlimited-1.0.1.1/src/rpcserver.cpp bitcoinunlimited-1.0.1.2/src/rpcserver.cpp
  840. --- bitcoinunlimited-1.0.1.1/src/rpcserver.cpp 2017-03-14 22:18:47.000000000 +0000
  841. +++ bitcoinunlimited-1.0.1.2/src/rpcserver.cpp 2017-03-21 23:57:43.000000000 +0000
  842. @@ -577,7 +577,7 @@
  843. void RPCUnregisterTimerInterface(RPCTimerInterface *iface)
  844. {
  845. std::vector<RPCTimerInterface*>::iterator i = std::find(timerInterfaces.begin(), timerInterfaces.end(), iface);
  846. - assert(i != timerInterfaces.end());
  847. + DbgAssert(i != timerInterfaces.end(), return); // already removed, so ignore the problem in production
  848. timerInterfaces.erase(i);
  849. }
  850.  
  851. diff -Nru bitcoinunlimited-1.0.1.1/src/script/script.h bitcoinunlimited-1.0.1.2/src/script/script.h
  852. --- bitcoinunlimited-1.0.1.1/src/script/script.h 2017-03-14 22:18:47.000000000 +0000
  853. +++ bitcoinunlimited-1.0.1.2/src/script/script.h 2017-03-21 23:57:43.000000000 +0000
  854. @@ -461,7 +461,7 @@
  855. insert(end(), b.begin(), b.end());
  856. return *this;
  857. }
  858. -
  859. +#if 0
  860. CScript& operator<<(const CScript& b)
  861. {
  862. // I'm not sure if this should push the script or concatenate scripts.
  863. @@ -469,7 +469,7 @@
  864. assert(!"Warning: Pushing a CScript onto a CScript with << is probably not intended, use + to concatenate!");
  865. return *this;
  866. }
  867. -
  868. +#endif
  869.  
  870. bool GetOp(iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet)
  871. {
  872. diff -Nru bitcoinunlimited-1.0.1.1/src/txdb.cpp bitcoinunlimited-1.0.1.2/src/txdb.cpp
  873. --- bitcoinunlimited-1.0.1.1/src/txdb.cpp 2017-03-14 22:18:47.000000000 +0000
  874. +++ bitcoinunlimited-1.0.1.2/src/txdb.cpp 2017-03-21 23:57:43.000000000 +0000
  875. @@ -103,7 +103,12 @@
  876. pcursor->Seek(DB_COINS);
  877.  
  878. CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
  879. - stats.hashBlock = GetBestBlock();
  880. +
  881. + {
  882. + LOCK(cs_main);
  883. + stats.hashBlock = GetBestBlock();
  884. + stats.nHeight = mapBlockIndex.find(stats.hashBlock)->second->nHeight;
  885. + }
  886. ss << stats.hashBlock;
  887. CAmount nTotalAmount = 0;
  888. while (pcursor->Valid()) {
  889. @@ -132,10 +137,6 @@
  890. }
  891. pcursor->Next();
  892. }
  893. - {
  894. - LOCK(cs_main);
  895. - stats.nHeight = mapBlockIndex.find(stats.hashBlock)->second->nHeight;
  896. - }
  897. stats.hashSerialized = ss.GetHash();
  898. stats.nTotalAmount = nTotalAmount;
  899. return true;
  900. diff -Nru bitcoinunlimited-1.0.1.1/src/unlimited.cpp bitcoinunlimited-1.0.1.2/src/unlimited.cpp
  901. --- bitcoinunlimited-1.0.1.1/src/unlimited.cpp 2017-03-14 22:18:47.000000000 +0000
  902. +++ bitcoinunlimited-1.0.1.2/src/unlimited.cpp 2017-03-21 23:57:43.000000000 +0000
  903. @@ -185,7 +185,6 @@
  904.  
  905. void HandleExpeditedRequest(CDataStream& vRecv,CNode* pfrom)
  906. {
  907. - // TODO locks
  908. uint64_t options;
  909. vRecv >> options;
  910. bool stop = ((options & EXPEDITED_STOP) != 0); // Are we starting or stopping expedited service?
  911. @@ -210,12 +209,12 @@
  912. if (xpeditedBlk.size() < maxExpedited )
  913. {
  914. LogPrint("blk", "Starting expedited blocks to peer %s (%d).\n", pfrom->addrName.c_str(),pfrom->id);
  915. - std::vector<CNode*>::iterator it = std::find(xpeditedBlk.begin(), xpeditedBlk.end(),((CNode*)NULL));
  916. + std::vector<CNode*>::iterator it = std::find(xpeditedBlk.begin(), xpeditedBlk.end(),(CNode*)NULL); // find an empty array location
  917. if (it != xpeditedBlk.end())
  918. *it = pfrom;
  919. else
  920. xpeditedBlk.push_back(pfrom);
  921. - pfrom->AddRef();
  922. + pfrom->AddRef(); // add a reference because we have added this pointer into the expedited array
  923. }
  924. else
  925. {
  926. @@ -271,7 +270,7 @@
  927. return false;
  928. }
  929.  
  930. -void HandleExpeditedBlock(CDataStream& vRecv,CNode* pfrom)
  931. +bool HandleExpeditedBlock(CDataStream& vRecv,CNode* pfrom)
  932. {
  933. unsigned char hops;
  934. unsigned char msgType;
  935. @@ -281,35 +280,35 @@
  936. {
  937. CXThinBlock thinBlock;
  938. vRecv >> thinBlock;
  939. + uint256 blkHash = thinBlock.header.GetHash();
  940. + CInv inv(MSG_BLOCK, blkHash);
  941.  
  942. - CInv inv(MSG_BLOCK, thinBlock.header.GetHash());
  943. -
  944. - BlockMap::iterator mapEntry = mapBlockIndex.find(thinBlock.header.GetHash());
  945. + BlockMap::iterator mapEntry = mapBlockIndex.find(blkHash);
  946. CBlockIndex *blkidx = NULL;
  947. unsigned int status = 0;
  948. if (mapEntry != mapBlockIndex.end())
  949. {
  950. blkidx = mapEntry->second;
  951. - status = blkidx->nStatus;
  952. + if (blkidx) status = blkidx->nStatus;
  953. }
  954. bool newBlock = ((blkidx == NULL) || (!(blkidx->nStatus & BLOCK_HAVE_DATA))); // If I have never seen the block or just seen an INV, treat the block as new
  955. int nSizeThinBlock = ::GetSerializeSize(thinBlock, SER_NETWORK, PROTOCOL_VERSION); // TODO replace with size of vRecv for efficiency
  956. LogPrint("thin", "Received %s expedited thinblock %s from peer %s (%d). Hop %d. Size %d bytes. (status %d,0x%x)\n", newBlock ? "new":"repeated", inv.hash.ToString(), pfrom->addrName.c_str(),pfrom->id, hops, nSizeThinBlock,status,status);
  957.  
  958. // Skip if we've already seen this block
  959. - // TODO move thes above the print, once we ensure no unexpected dups.
  960. - if (IsRecentlyExpeditedAndStore(thinBlock.header.GetHash())) return;
  961. + // TODO move this above the print, once we ensure no unexpected dups.
  962. + if (IsRecentlyExpeditedAndStore(blkHash)) return true;
  963. if (!newBlock)
  964. {
  965. // TODO determine if we have the block or just have an INV to it.
  966. - return;
  967. + return true;
  968. }
  969.  
  970. CValidationState state;
  971. if (!CheckBlockHeader(thinBlock.header, state, true)) // block header is bad
  972. {
  973. - // demerit the sender
  974. - return;
  975. + // demerit the sender, it should have checked the header before expedited relay
  976. + return false;
  977. }
  978. // TODO: Start headers-only mining now
  979.  
  980. @@ -319,7 +318,9 @@
  981. else
  982. {
  983. LogPrint("thin", "Received unknown (0x%x) expedited message from peer %s (%d). Hop %d.\n", msgType, pfrom->addrName.c_str(),pfrom->id, hops);
  984. + return false;
  985. }
  986. + return true;
  987. }
  988.  
  989. void SendExpeditedBlock(CXThinBlock& thinBlock,unsigned char hops,const CNode* skip)
  990. @@ -494,7 +495,7 @@
  991. std::vector<CNode*>::iterator elem = std::find(xpeditedBlkUp.begin(), xpeditedBlkUp.end(),node);
  992. if ((flags & EXPEDITED_BLOCKS)&&(flags & EXPEDITED_STOP))
  993. {
  994. - if (elem == xpeditedBlkUp.end()) xpeditedBlkUp.erase(elem);
  995. + if (elem != xpeditedBlkUp.end()) xpeditedBlkUp.erase(elem);
  996. }
  997. else if (flags & EXPEDITED_BLOCKS)
  998. {
  999. @@ -1212,23 +1213,27 @@
  1000. {
  1001. BOOST_FOREACH(string& strAddr, mapMultiArgs["-expeditedblock"])
  1002. {
  1003. - // Add the peer's listening port if it is empty
  1004. - int pos1 = strAddr.rfind(":");
  1005. - int pos2 = strAddr.rfind("]:");
  1006. - if (pos1 <= 0 && pos2 <= 0)
  1007. - strAddr += ':' + boost::lexical_cast<std::string>(pfrom->addrFromPort);
  1008. -
  1009. string strListeningPeerIP;
  1010. string strPeerIP = pfrom->addr.ToString();
  1011. - pos1 = strPeerIP.rfind(":");
  1012. - pos2 = strPeerIP.rfind("]:");
  1013. - // Handle both ipv4 and ipv6 cases
  1014. - if (pos1 <= 0 && pos2 <= 0)
  1015. - strListeningPeerIP = strPeerIP + ':' + boost::lexical_cast<std::string>(pfrom->addrFromPort);
  1016. - else if (pos1 > 0)
  1017. - strListeningPeerIP = strPeerIP.substr(0, pos1) + ':' + boost::lexical_cast<std::string>(pfrom->addrFromPort);
  1018. - else
  1019. - strListeningPeerIP = strPeerIP.substr(0, pos2) + ':' + boost::lexical_cast<std::string>(pfrom->addrFromPort);
  1020. + // Add the peer's listening port if it was provided (only misbehaving clients do not provide it)
  1021. + if (pfrom->addrFromPort != 0)
  1022. + {
  1023. + int pos1 = strAddr.rfind(":");
  1024. + int pos2 = strAddr.rfind("]:");
  1025. + if (pos1 <= 0 && pos2 <= 0)
  1026. + strAddr += ':' + boost::lexical_cast<std::string>(pfrom->addrFromPort);
  1027. +
  1028. + pos1 = strPeerIP.rfind(":");
  1029. + pos2 = strPeerIP.rfind("]:");
  1030. + // Handle both ipv4 and ipv6 cases
  1031. + if (pos1 <= 0 && pos2 <= 0)
  1032. + strListeningPeerIP = strPeerIP + ':' + boost::lexical_cast<std::string>(pfrom->addrFromPort);
  1033. + else if (pos1 > 0)
  1034. + strListeningPeerIP = strPeerIP.substr(0, pos1) + ':' + boost::lexical_cast<std::string>(pfrom->addrFromPort);
  1035. + else
  1036. + strListeningPeerIP = strPeerIP.substr(0, pos2) + ':' + boost::lexical_cast<std::string>(pfrom->addrFromPort);
  1037. + }
  1038. + else strListeningPeerIP = strPeerIP;
  1039.  
  1040. if(strAddr == strListeningPeerIP)
  1041. {
  1042. diff -Nru bitcoinunlimited-1.0.1.1/src/unlimited.h bitcoinunlimited-1.0.1.2/src/unlimited.h
  1043. --- bitcoinunlimited-1.0.1.1/src/unlimited.h 2017-03-14 22:18:47.000000000 +0000
  1044. +++ bitcoinunlimited-1.0.1.2/src/unlimited.h 2017-03-21 23:57:43.000000000 +0000
  1045. @@ -72,7 +72,7 @@
  1046. CNode* FindLikelyNode(const std::string& addrName);
  1047.  
  1048. // process incoming unsolicited block
  1049. -void HandleExpeditedBlock(CDataStream& vRecv,CNode* pfrom);
  1050. +bool HandleExpeditedBlock(CDataStream& vRecv,CNode* pfrom);
  1051.  
  1052. // Convert the BUComments to the string client's "subversion" string
  1053. extern void settingsToUserAgentString();
  1054. diff -Nru bitcoinunlimited-1.0.1.1/src/util.h bitcoinunlimited-1.0.1.2/src/util.h
  1055. --- bitcoinunlimited-1.0.1.1/src/util.h 2017-03-14 22:18:47.000000000 +0000
  1056. +++ bitcoinunlimited-1.0.1.2/src/util.h 2017-03-21 23:57:43.000000000 +0000
  1057. @@ -29,6 +29,15 @@
  1058. #include <boost/signals2/signal.hpp>
  1059. #include <boost/thread/exceptions.hpp>
  1060.  
  1061. +#ifdef DEBUG_ASSERTION
  1062. +/// If DEBUG_ASSERTION is enabled this asserts when the predicate is false.
  1063. +// If DEBUG_ASSERTION is disabled and the predicate is false, it executes the execInRelease statements.
  1064. +// Typically, the programmer will error out -- return false, raise an exception, etc in the execInRelease code.
  1065. +#define DbgAssert(pred, execInRelease) do { assert(pred); } while(0)
  1066. +#else
  1067. +#define DbgAssert(pred, execInRelease) do { if (!(pred)) { execInRelease; }} while(0)
  1068. +#endif
  1069. +
  1070. static const bool DEFAULT_LOGTIMEMICROS = false;
  1071. static const bool DEFAULT_LOGIPS = true;
  1072. static const bool DEFAULT_LOGTIMESTAMPS = true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement