@neuraiproject/neurai-rpc 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1787) hide show
  1. package/Neurai/.gitattributes +1 -0
  2. package/Neurai/.github/ISSUE_TEMPLATE.md +37 -0
  3. package/Neurai/.github/scripts/00-install-deps.sh +133 -0
  4. package/Neurai/.github/scripts/02-copy-build-dependencies.sh +36 -0
  5. package/Neurai/.github/scripts/03-export-path.sh +26 -0
  6. package/Neurai/.github/scripts/04-configure-build.sh +39 -0
  7. package/Neurai/.github/scripts/05-binary-checks.sh +41 -0
  8. package/Neurai/.github/scripts/06-package.sh +256 -0
  9. package/Neurai/.github/workflows/build-neurai.yml +112 -0
  10. package/Neurai/.pydevproject +5 -0
  11. package/Neurai/.travis.yml +80 -0
  12. package/Neurai/.tx/config +10 -0
  13. package/Neurai/CONTRIBUTING.md +286 -0
  14. package/Neurai/COPYING +22 -0
  15. package/Neurai/INSTALL.md +5 -0
  16. package/Neurai/Makefile.am +313 -0
  17. package/Neurai/README.md +110 -0
  18. package/Neurai/about +35 -0
  19. package/Neurai/assets/asset_metadata_spec.md +99 -0
  20. package/Neurai/assets/tools/README.md +53 -0
  21. package/Neurai/assets/tools/asset_audit.py +179 -0
  22. package/Neurai/assets/tools/blockfacts.py +45 -0
  23. package/Neurai/assets/tools/ipfs_pinner.py +448 -0
  24. package/Neurai/assets/tools/issuebulk.py +162 -0
  25. package/Neurai/assets/tools/signed_promises.py +197 -0
  26. package/Neurai/assets/tools/txfacts.py +120 -0
  27. package/Neurai/autogen.sh +17 -0
  28. package/Neurai/build-aux/m4/ax_boost_base.m4 +291 -0
  29. package/Neurai/build-aux/m4/ax_boost_chrono.m4 +119 -0
  30. package/Neurai/build-aux/m4/ax_boost_filesystem.m4 +119 -0
  31. package/Neurai/build-aux/m4/ax_boost_program_options.m4 +108 -0
  32. package/Neurai/build-aux/m4/ax_boost_system.m4 +122 -0
  33. package/Neurai/build-aux/m4/ax_boost_thread.m4 +150 -0
  34. package/Neurai/build-aux/m4/ax_boost_unit_test_framework.m4 +138 -0
  35. package/Neurai/build-aux/m4/ax_check_compile_flag.m4 +74 -0
  36. package/Neurai/build-aux/m4/ax_check_link_flag.m4 +74 -0
  37. package/Neurai/build-aux/m4/ax_check_preproc_flag.m4 +74 -0
  38. package/Neurai/build-aux/m4/ax_cxx_compile_stdcxx.m4 +951 -0
  39. package/Neurai/build-aux/m4/ax_gcc_func_attribute.m4 +223 -0
  40. package/Neurai/build-aux/m4/ax_pthread.m4 +485 -0
  41. package/Neurai/build-aux/m4/l_atomic.m4 +46 -0
  42. package/Neurai/build-aux/m4/neurai_find_bdb48.m4 +80 -0
  43. package/Neurai/build-aux/m4/neurai_qt.m4 +387 -0
  44. package/Neurai/build-aux/m4/neurai_subdir_to_include.m4 +20 -0
  45. package/Neurai/configure.ac +1359 -0
  46. package/Neurai/contrib/Dockerfile +60 -0
  47. package/Neurai/contrib/README.md +50 -0
  48. package/Neurai/contrib/debian/README.md +21 -0
  49. package/Neurai/contrib/debian/changelog +578 -0
  50. package/Neurai/contrib/debian/compat +1 -0
  51. package/Neurai/contrib/debian/control +70 -0
  52. package/Neurai/contrib/debian/copyright +137 -0
  53. package/Neurai/contrib/debian/examples/neurai.conf +147 -0
  54. package/Neurai/contrib/debian/gbp.conf +5 -0
  55. package/Neurai/contrib/debian/neurai-qt.desktop +13 -0
  56. package/Neurai/contrib/debian/neurai-qt.install +6 -0
  57. package/Neurai/contrib/debian/neurai-qt.lintian-overrides +2 -0
  58. package/Neurai/contrib/debian/neurai-qt.manpages +1 -0
  59. package/Neurai/contrib/debian/neurai-qt.protocol +11 -0
  60. package/Neurai/contrib/debian/neurai-tx.bash-completion +1 -0
  61. package/Neurai/contrib/debian/neurai-tx.install +1 -0
  62. package/Neurai/contrib/debian/neurai-tx.manpages +1 -0
  63. package/Neurai/contrib/debian/neuraid.bash-completion +2 -0
  64. package/Neurai/contrib/debian/neuraid.examples +1 -0
  65. package/Neurai/contrib/debian/neuraid.install +2 -0
  66. package/Neurai/contrib/debian/neuraid.lintian-overrides +2 -0
  67. package/Neurai/contrib/debian/neuraid.manpages +2 -0
  68. package/Neurai/contrib/debian/patches/README +3 -0
  69. package/Neurai/contrib/debian/patches/series +1 -0
  70. package/Neurai/contrib/debian/rules +23 -0
  71. package/Neurai/contrib/debian/source/format +1 -0
  72. package/Neurai/contrib/debian/watch +5 -0
  73. package/Neurai/contrib/devtools/README.md +188 -0
  74. package/Neurai/contrib/devtools/check-doc.py +47 -0
  75. package/Neurai/contrib/devtools/check-rpc-mappings.py +159 -0
  76. package/Neurai/contrib/devtools/clang-format-diff.py +164 -0
  77. package/Neurai/contrib/devtools/commit-script-check.sh +48 -0
  78. package/Neurai/contrib/devtools/copyright_header.py +617 -0
  79. package/Neurai/contrib/devtools/gen-manpages.sh +29 -0
  80. package/Neurai/contrib/devtools/git-subtree-check.sh +79 -0
  81. package/Neurai/contrib/devtools/github-merge.py +330 -0
  82. package/Neurai/contrib/devtools/lint-all.sh +24 -0
  83. package/Neurai/contrib/devtools/lint-whitespace.sh +90 -0
  84. package/Neurai/contrib/devtools/optimize-pngs.py +79 -0
  85. package/Neurai/contrib/devtools/security-check.py +217 -0
  86. package/Neurai/contrib/devtools/split-debug.sh.in +10 -0
  87. package/Neurai/contrib/devtools/symbol-check.py +162 -0
  88. package/Neurai/contrib/devtools/test-security-check.py +63 -0
  89. package/Neurai/contrib/devtools/update-translations.py +208 -0
  90. package/Neurai/contrib/filter-lcov.py +25 -0
  91. package/Neurai/contrib/init/README.md +12 -0
  92. package/Neurai/contrib/init/neuraid.conf +65 -0
  93. package/Neurai/contrib/init/neuraid.init +67 -0
  94. package/Neurai/contrib/init/neuraid.openrc +92 -0
  95. package/Neurai/contrib/init/neuraid.openrcconf +33 -0
  96. package/Neurai/contrib/init/neuraid.service +22 -0
  97. package/Neurai/contrib/init/org.neurai.neuraid.plist +14 -0
  98. package/Neurai/contrib/install_cli.sh +13 -0
  99. package/Neurai/contrib/install_db4.sh +251 -0
  100. package/Neurai/contrib/linearize/README.md +55 -0
  101. package/Neurai/contrib/linearize/example-linearize.cfg +50 -0
  102. package/Neurai/contrib/linearize/linearize-data.py +310 -0
  103. package/Neurai/contrib/linearize/linearize-hashes.py +158 -0
  104. package/Neurai/contrib/macdeploy/LICENSE +674 -0
  105. package/Neurai/contrib/macdeploy/README.md +15 -0
  106. package/Neurai/contrib/macdeploy/background.svg +35 -0
  107. package/Neurai/contrib/macdeploy/custom_dsstore.py +61 -0
  108. package/Neurai/contrib/macdeploy/detached-sig-apply.sh +58 -0
  109. package/Neurai/contrib/macdeploy/detached-sig-create.sh +53 -0
  110. package/Neurai/contrib/macdeploy/extract-osx-sdk.sh +35 -0
  111. package/Neurai/contrib/macdeploy/fancy.plist +32 -0
  112. package/Neurai/contrib/macdeploy/macdeployqtplus +872 -0
  113. package/Neurai/contrib/neurai-cli.bash-completion +156 -0
  114. package/Neurai/contrib/neurai-tx.bash-completion +59 -0
  115. package/Neurai/contrib/neuraid.bash-completion +58 -0
  116. package/Neurai/contrib/qos/README.md +5 -0
  117. package/Neurai/contrib/qos/tc.sh +61 -0
  118. package/Neurai/contrib/rpm/README.md +185 -0
  119. package/Neurai/contrib/rpm/neurai.fc +8 -0
  120. package/Neurai/contrib/rpm/neurai.if +157 -0
  121. package/Neurai/contrib/rpm/neurai.spec +442 -0
  122. package/Neurai/contrib/rpm/neurai.te +81 -0
  123. package/Neurai/contrib/seeds/README.md +19 -0
  124. package/Neurai/contrib/seeds/generate-seeds.py +138 -0
  125. package/Neurai/contrib/seeds/makeseeds.py +173 -0
  126. package/Neurai/contrib/seeds/nodes_main.txt +1 -0
  127. package/Neurai/contrib/seeds/nodes_test.txt +6 -0
  128. package/Neurai/contrib/static-builds/README.md +219 -0
  129. package/Neurai/contrib/static-builds/script.sh +323 -0
  130. package/Neurai/contrib/static-builds/staticbuild.md +483 -0
  131. package/Neurai/contrib/testgen/README.md +8 -0
  132. package/Neurai/contrib/testgen/base58.py +107 -0
  133. package/Neurai/contrib/testgen/gen_base58_test_vectors.py +129 -0
  134. package/Neurai/contrib/tidy_datadir.sh +64 -0
  135. package/Neurai/contrib/verifybinaries/README.md +3 -0
  136. package/Neurai/contrib/verifybinaries/verify.sh +3 -0
  137. package/Neurai/contrib/windeploy/detached-sig-create.sh +36 -0
  138. package/Neurai/contrib/windeploy/win-codesign.cert +99 -0
  139. package/Neurai/contrib/zmq/zmq_sub.py +90 -0
  140. package/Neurai/contrib/zmq/zmq_sub3.4.py +90 -0
  141. package/Neurai/contrib/zmq/zmq_test.py +75 -0
  142. package/Neurai/depends/README.md +84 -0
  143. package/Neurai/depends/builders/darwin.mk +22 -0
  144. package/Neurai/depends/builders/default.mk +20 -0
  145. package/Neurai/depends/builders/linux.mk +2 -0
  146. package/Neurai/depends/config.guess +1466 -0
  147. package/Neurai/depends/config.site.in +119 -0
  148. package/Neurai/depends/config.sub +1836 -0
  149. package/Neurai/depends/description.md +53 -0
  150. package/Neurai/depends/funcs.mk +262 -0
  151. package/Neurai/depends/hosts/darwin.mk +126 -0
  152. package/Neurai/depends/hosts/default.mk +39 -0
  153. package/Neurai/depends/hosts/linux.mk +32 -0
  154. package/Neurai/depends/hosts/mingw32.mk +12 -0
  155. package/Neurai/depends/packages/bdb.mk +31 -0
  156. package/Neurai/depends/packages/boost.mk +45 -0
  157. package/Neurai/depends/packages/dbus.mk +23 -0
  158. package/Neurai/depends/packages/expat.mk +21 -0
  159. package/Neurai/depends/packages/fontconfig.mk +28 -0
  160. package/Neurai/depends/packages/freetype.mk +22 -0
  161. package/Neurai/depends/packages/libICE.mk +23 -0
  162. package/Neurai/depends/packages/libSM.mk +23 -0
  163. package/Neurai/depends/packages/libX11.mk +23 -0
  164. package/Neurai/depends/packages/libXau.mk +23 -0
  165. package/Neurai/depends/packages/libXext.mk +22 -0
  166. package/Neurai/depends/packages/libevent.mk +33 -0
  167. package/Neurai/depends/packages/libxcb.mk +35 -0
  168. package/Neurai/depends/packages/libxkbcommon.mk +32 -0
  169. package/Neurai/depends/packages/miniupnpc.mk +28 -0
  170. package/Neurai/depends/packages/native_b2.mk +20 -0
  171. package/Neurai/depends/packages/native_biplist.mk +20 -0
  172. package/Neurai/depends/packages/native_capnp.mk +18 -0
  173. package/Neurai/depends/packages/native_ccache.mk +25 -0
  174. package/Neurai/depends/packages/native_cctools.mk +38 -0
  175. package/Neurai/depends/packages/native_cdrkit.mk +26 -0
  176. package/Neurai/depends/packages/native_clang.mk +27 -0
  177. package/Neurai/depends/packages/native_ds_store.mk +15 -0
  178. package/Neurai/depends/packages/native_libdmg-hfsplus.mk +24 -0
  179. package/Neurai/depends/packages/native_libtapi.mk +20 -0
  180. package/Neurai/depends/packages/native_mac_alias.mk +18 -0
  181. package/Neurai/depends/packages/native_protobuf.mk +25 -0
  182. package/Neurai/depends/packages/openssl.mk +80 -0
  183. package/Neurai/depends/packages/packages.mk +23 -0
  184. package/Neurai/depends/packages/protobuf.mk +29 -0
  185. package/Neurai/depends/packages/qrencode.mk +22 -0
  186. package/Neurai/depends/packages/qt.mk +285 -0
  187. package/Neurai/depends/packages/xcb_proto.mk +27 -0
  188. package/Neurai/depends/packages/xextproto.mk +21 -0
  189. package/Neurai/depends/packages/xproto.mk +21 -0
  190. package/Neurai/depends/packages/xtrans.mk +22 -0
  191. package/Neurai/depends/packages/zeromq.mk +37 -0
  192. package/Neurai/depends/packages/zlib.mk +27 -0
  193. package/Neurai/depends/packages.md +194 -0
  194. package/Neurai/depends/patches/qt/mac-qmake.conf +26 -0
  195. package/Neurai/doc/Doxyfile.in +2460 -0
  196. package/Neurai/doc/JSON-RPC-interface.md +129 -0
  197. package/Neurai/doc/README.md +594 -0
  198. package/Neurai/doc/README_osx.md +97 -0
  199. package/Neurai/doc/README_windows.txt +23 -0
  200. package/Neurai/doc/REST-interface.md +112 -0
  201. package/Neurai/doc/adr/0001-record-architecture-decisions.md +19 -0
  202. package/Neurai/doc/assets-attribution.md +1 -0
  203. package/Neurai/doc/atomicswaps.md +125 -0
  204. package/Neurai/doc/benchmarking.md +30 -0
  205. package/Neurai/doc/bips.md +35 -0
  206. package/Neurai/doc/bitcoin_logo_doxygen.png +0 -0
  207. package/Neurai/doc/build-docker.md +110 -0
  208. package/Neurai/doc/build-freebsd.md +85 -0
  209. package/Neurai/doc/build-openbsd.md +190 -0
  210. package/Neurai/doc/build-osx.md +136 -0
  211. package/Neurai/doc/build-rasberrypi.md +44 -0
  212. package/Neurai/doc/build-ubuntu.md +287 -0
  213. package/Neurai/doc/build-unix.md +248 -0
  214. package/Neurai/doc/build-windows.md +119 -0
  215. package/Neurai/doc/dependencies.md +43 -0
  216. package/Neurai/doc/developer-notes.md +708 -0
  217. package/Neurai/doc/dnsseed-policy.md +54 -0
  218. package/Neurai/doc/docker/Dockerfile-Linux64-bin +41 -0
  219. package/Neurai/doc/docker/Dockerfile-Node-Linux +53 -0
  220. package/Neurai/doc/docker/Dockerfile-Win64-bin +41 -0
  221. package/Neurai/doc/docker/README.md +5 -0
  222. package/Neurai/doc/files.md +18 -0
  223. package/Neurai/doc/fuzzing.md +72 -0
  224. package/Neurai/doc/init.md +141 -0
  225. package/Neurai/doc/man/Makefile.am +17 -0
  226. package/Neurai/doc/man/neurai-cli.1 +104 -0
  227. package/Neurai/doc/man/neurai-qt.1 +558 -0
  228. package/Neurai/doc/man/neurai-tx.1 +128 -0
  229. package/Neurai/doc/man/neuraid.1 +537 -0
  230. package/Neurai/doc/neurai-conf.md +61 -0
  231. package/Neurai/doc/neurai_logo_doxygen.png +0 -0
  232. package/Neurai/doc/reduce-memory.md +50 -0
  233. package/Neurai/doc/reduce-traffic.md +54 -0
  234. package/Neurai/doc/release-notes/release-notes-0.15.0.1.md +87 -0
  235. package/Neurai/doc/release-notes/release-notes-0.15.0.md +878 -0
  236. package/Neurai/doc/release-notes/release-notes-1.0.0.md +80 -0
  237. package/Neurai/doc/release-notes/release-notes-1.0.2.md +80 -0
  238. package/Neurai/doc/release-notes/release-notes-2.0.4.md +87 -0
  239. package/Neurai/doc/release-notes/release-notes-2.1.0.md +94 -0
  240. package/Neurai/doc/release-notes/release-notes-2.2.2.md +98 -0
  241. package/Neurai/doc/release-notes/release-notes-2.4.0.md +80 -0
  242. package/Neurai/doc/release-notes.md +95 -0
  243. package/Neurai/doc/release-process.md +113 -0
  244. package/Neurai/doc/release_checklist.md +30 -0
  245. package/Neurai/doc/shared-libraries.md +49 -0
  246. package/Neurai/doc/tor.md +125 -0
  247. package/Neurai/doc/translation_process.md +109 -0
  248. package/Neurai/doc/translation_strings_policy.md +109 -0
  249. package/Neurai/doc/zmq.md +114 -0
  250. package/Neurai/img/neurai-title.jpg +0 -0
  251. package/Neurai/libneuraiconsensus.pc.in +11 -0
  252. package/Neurai/scripts/00-install-deps.sh +130 -0
  253. package/Neurai/scripts/02-copy-build-dependencies.sh +68 -0
  254. package/Neurai/scripts/03-export-path.sh +26 -0
  255. package/Neurai/scripts/04-configure-build.sh +39 -0
  256. package/Neurai/scripts/05-binary-checks.sh +41 -0
  257. package/Neurai/scripts/06-package.sh +256 -0
  258. package/Neurai/share/genbuild.sh +54 -0
  259. package/Neurai/share/pixmaps/neurai.BMP +0 -0
  260. package/Neurai/share/pixmaps/neurai.ico +0 -0
  261. package/Neurai/share/pixmaps/neurai.svg +107 -0
  262. package/Neurai/share/pixmaps/neurai128.png +0 -0
  263. package/Neurai/share/pixmaps/neurai128.xpm +818 -0
  264. package/Neurai/share/pixmaps/neurai16.png +0 -0
  265. package/Neurai/share/pixmaps/neurai16.xpm +100 -0
  266. package/Neurai/share/pixmaps/neurai256.png +0 -0
  267. package/Neurai/share/pixmaps/neurai256.xpm +1584 -0
  268. package/Neurai/share/pixmaps/neurai32.png +0 -0
  269. package/Neurai/share/pixmaps/neurai32.xpm +200 -0
  270. package/Neurai/share/pixmaps/neurai64.png +0 -0
  271. package/Neurai/share/pixmaps/neurai64.xpm +301 -0
  272. package/Neurai/share/pixmaps/nsis-header.bmp +0 -0
  273. package/Neurai/share/pixmaps/nsis-wizard.bmp +0 -0
  274. package/Neurai/share/qt/Info.plist.in +109 -0
  275. package/Neurai/share/qt/extract_strings_qt.py +90 -0
  276. package/Neurai/share/rpcuser/README.md +10 -0
  277. package/Neurai/share/rpcuser/rpcuser.py +42 -0
  278. package/Neurai/share/setup.nsi.in +177 -0
  279. package/Neurai/src/.clang-format +51 -0
  280. package/Neurai/src/LibBoolEE.cpp +177 -0
  281. package/Neurai/src/LibBoolEE.h +70 -0
  282. package/Neurai/src/Makefile.am +651 -0
  283. package/Neurai/src/Makefile.bench.include +83 -0
  284. package/Neurai/src/Makefile.leveldb.include +151 -0
  285. package/Neurai/src/Makefile.qt.include +579 -0
  286. package/Neurai/src/Makefile.qttest.include +79 -0
  287. package/Neurai/src/Makefile.test.include +198 -0
  288. package/Neurai/src/addrdb.cpp +148 -0
  289. package/Neurai/src/addrdb.h +104 -0
  290. package/Neurai/src/addressindex.h +409 -0
  291. package/Neurai/src/addrman.cpp +532 -0
  292. package/Neurai/src/addrman.h +607 -0
  293. package/Neurai/src/algo/Lyra2RE.c +110 -0
  294. package/Neurai/src/algo/Lyra2RE.h +15 -0
  295. package/Neurai/src/algo/aes_helper.c +392 -0
  296. package/Neurai/src/algo/blake.c +1120 -0
  297. package/Neurai/src/algo/bmw.c +965 -0
  298. package/Neurai/src/algo/cubehash.c +723 -0
  299. package/Neurai/src/algo/echo.c +1031 -0
  300. package/Neurai/src/algo/extra.c +35 -0
  301. package/Neurai/src/algo/extra.h +4 -0
  302. package/Neurai/src/algo/fugue.c +1208 -0
  303. package/Neurai/src/algo/gost_streebog.c +1023 -0
  304. package/Neurai/src/algo/gost_streebog.h +185 -0
  305. package/Neurai/src/algo/groestl.c +3119 -0
  306. package/Neurai/src/algo/hamsi.c +867 -0
  307. package/Neurai/src/algo/hamsi_helper.c +39648 -0
  308. package/Neurai/src/algo/haval.c +983 -0
  309. package/Neurai/src/algo/haval_helper.c +190 -0
  310. package/Neurai/src/algo/jh.c +1116 -0
  311. package/Neurai/src/algo/keccak.c +1824 -0
  312. package/Neurai/src/algo/luffa.c +1436 -0
  313. package/Neurai/src/algo/lyra2.cpp +382 -0
  314. package/Neurai/src/algo/lyra2.h +44 -0
  315. package/Neurai/src/algo/md_helper.c +347 -0
  316. package/Neurai/src/algo/sha2.c +550 -0
  317. package/Neurai/src/algo/shabal.c +806 -0
  318. package/Neurai/src/algo/shavite.c +1764 -0
  319. package/Neurai/src/algo/simd.c +1799 -0
  320. package/Neurai/src/algo/skein.c +1254 -0
  321. package/Neurai/src/algo/sph_blake.h +327 -0
  322. package/Neurai/src/algo/sph_bmw.h +328 -0
  323. package/Neurai/src/algo/sph_cubehash.h +292 -0
  324. package/Neurai/src/algo/sph_echo.h +320 -0
  325. package/Neurai/src/algo/sph_fugue.h +81 -0
  326. package/Neurai/src/algo/sph_groestl.h +329 -0
  327. package/Neurai/src/algo/sph_hamsi.h +321 -0
  328. package/Neurai/src/algo/sph_haval.h +976 -0
  329. package/Neurai/src/algo/sph_jh.h +298 -0
  330. package/Neurai/src/algo/sph_keccak.h +293 -0
  331. package/Neurai/src/algo/sph_luffa.h +296 -0
  332. package/Neurai/src/algo/sph_md_helper.c +352 -0
  333. package/Neurai/src/algo/sph_sha2.c +690 -0
  334. package/Neurai/src/algo/sph_sha2.h +379 -0
  335. package/Neurai/src/algo/sph_sha2big.c +255 -0
  336. package/Neurai/src/algo/sph_shabal.h +344 -0
  337. package/Neurai/src/algo/sph_shavite.h +314 -0
  338. package/Neurai/src/algo/sph_simd.h +309 -0
  339. package/Neurai/src/algo/sph_skein.h +298 -0
  340. package/Neurai/src/algo/sph_tiger.h +191 -0
  341. package/Neurai/src/algo/sph_types.h +1976 -0
  342. package/Neurai/src/algo/sph_whirlpool.h +218 -0
  343. package/Neurai/src/algo/sponge.cpp +745 -0
  344. package/Neurai/src/algo/sponge.h +108 -0
  345. package/Neurai/src/algo/tiger.cpp +697 -0
  346. package/Neurai/src/algo/whirlpool.c +3480 -0
  347. package/Neurai/src/amount.h +31 -0
  348. package/Neurai/src/arith_uint256.cpp +264 -0
  349. package/Neurai/src/arith_uint256.h +298 -0
  350. package/Neurai/src/assets/assetdb.cpp +395 -0
  351. package/Neurai/src/assets/assetdb.h +99 -0
  352. package/Neurai/src/assets/assets.cpp +5938 -0
  353. package/Neurai/src/assets/assets.h +620 -0
  354. package/Neurai/src/assets/assetsnapshotdb.cpp +151 -0
  355. package/Neurai/src/assets/assetsnapshotdb.h +78 -0
  356. package/Neurai/src/assets/assettypes.cpp +31 -0
  357. package/Neurai/src/assets/assettypes.h +689 -0
  358. package/Neurai/src/assets/messages.cpp +346 -0
  359. package/Neurai/src/assets/messages.h +143 -0
  360. package/Neurai/src/assets/myassetsdb.cpp +344 -0
  361. package/Neurai/src/assets/myassetsdb.h +82 -0
  362. package/Neurai/src/assets/restricteddb.cpp +257 -0
  363. package/Neurai/src/assets/restricteddb.h +64 -0
  364. package/Neurai/src/assets/rewards.cpp +395 -0
  365. package/Neurai/src/assets/rewards.h +171 -0
  366. package/Neurai/src/assets/snapshotrequestdb.cpp +236 -0
  367. package/Neurai/src/assets/snapshotrequestdb.h +117 -0
  368. package/Neurai/src/base58.cpp +347 -0
  369. package/Neurai/src/base58.h +174 -0
  370. package/Neurai/src/bench/Examples.cpp +36 -0
  371. package/Neurai/src/bench/base58.cpp +61 -0
  372. package/Neurai/src/bench/bench.cpp +106 -0
  373. package/Neurai/src/bench/bench.h +82 -0
  374. package/Neurai/src/bench/bench_neurai.cpp +29 -0
  375. package/Neurai/src/bench/ccoins_caching.cpp +88 -0
  376. package/Neurai/src/bench/checkblock.cpp +59 -0
  377. package/Neurai/src/bench/checkqueue.cpp +105 -0
  378. package/Neurai/src/bench/coin_selection.cpp +60 -0
  379. package/Neurai/src/bench/crypto_hash.cpp +105 -0
  380. package/Neurai/src/bench/data/block566553.raw +0 -0
  381. package/Neurai/src/bench/lockedpool.cpp +49 -0
  382. package/Neurai/src/bench/mempool_eviction.cpp +116 -0
  383. package/Neurai/src/bench/perf.cpp +55 -0
  384. package/Neurai/src/bench/perf.h +39 -0
  385. package/Neurai/src/bench/prevector_destructor.cpp +38 -0
  386. package/Neurai/src/bench/rollingbloom.cpp +45 -0
  387. package/Neurai/src/bench/verify_script.cpp +110 -0
  388. package/Neurai/src/blockencodings.cpp +231 -0
  389. package/Neurai/src/blockencodings.h +239 -0
  390. package/Neurai/src/bloom.cpp +313 -0
  391. package/Neurai/src/bloom.h +145 -0
  392. package/Neurai/src/chain.cpp +171 -0
  393. package/Neurai/src/chain.h +524 -0
  394. package/Neurai/src/chainparams.cpp +635 -0
  395. package/Neurai/src/chainparams.h +241 -0
  396. package/Neurai/src/chainparamsbase.cpp +104 -0
  397. package/Neurai/src/chainparamsbase.h +65 -0
  398. package/Neurai/src/chainparamsseeds.h +15 -0
  399. package/Neurai/src/checkpoints.cpp +34 -0
  400. package/Neurai/src/checkpoints.h +29 -0
  401. package/Neurai/src/checkqueue.h +219 -0
  402. package/Neurai/src/clientversion.cpp +104 -0
  403. package/Neurai/src/clientversion.h +55 -0
  404. package/Neurai/src/coins.cpp +539 -0
  405. package/Neurai/src/coins.h +322 -0
  406. package/Neurai/src/compat/byteswap.h +68 -0
  407. package/Neurai/src/compat/endian.h +198 -0
  408. package/Neurai/src/compat/glibc_compat.cpp +76 -0
  409. package/Neurai/src/compat/glibc_sanity.cpp +70 -0
  410. package/Neurai/src/compat/glibcxx_sanity.cpp +63 -0
  411. package/Neurai/src/compat/sanity.h +13 -0
  412. package/Neurai/src/compat/strnlen.cpp +20 -0
  413. package/Neurai/src/compat.h +105 -0
  414. package/Neurai/src/compressor.cpp +187 -0
  415. package/Neurai/src/compressor.h +123 -0
  416. package/Neurai/src/config/.empty +0 -0
  417. package/Neurai/src/consensus/consensus.cpp +29 -0
  418. package/Neurai/src/consensus/consensus.h +55 -0
  419. package/Neurai/src/consensus/merkle.cpp +189 -0
  420. package/Neurai/src/consensus/merkle.h +40 -0
  421. package/Neurai/src/consensus/params.h +84 -0
  422. package/Neurai/src/consensus/tx_verify.cpp +900 -0
  423. package/Neurai/src/consensus/tx_verify.h +93 -0
  424. package/Neurai/src/consensus/validation.h +121 -0
  425. package/Neurai/src/core_io.h +40 -0
  426. package/Neurai/src/core_memusage.h +73 -0
  427. package/Neurai/src/core_read.cpp +191 -0
  428. package/Neurai/src/core_write.cpp +331 -0
  429. package/Neurai/src/crypto/aes.cpp +218 -0
  430. package/Neurai/src/crypto/aes.h +120 -0
  431. package/Neurai/src/crypto/aes_helper.c +392 -0
  432. package/Neurai/src/crypto/blake.c +1120 -0
  433. package/Neurai/src/crypto/bmw.c +965 -0
  434. package/Neurai/src/crypto/chacha20.cpp +182 -0
  435. package/Neurai/src/crypto/chacha20.h +28 -0
  436. package/Neurai/src/crypto/common.h +105 -0
  437. package/Neurai/src/crypto/ctaes/COPYING +21 -0
  438. package/Neurai/src/crypto/ctaes/README.md +41 -0
  439. package/Neurai/src/crypto/ctaes/bench.c +170 -0
  440. package/Neurai/src/crypto/ctaes/ctaes.c +556 -0
  441. package/Neurai/src/crypto/ctaes/ctaes.h +41 -0
  442. package/Neurai/src/crypto/ctaes/test.c +110 -0
  443. package/Neurai/src/crypto/cubehash.c +723 -0
  444. package/Neurai/src/crypto/echo.c +1031 -0
  445. package/Neurai/src/crypto/ethash/helpers.hpp +54 -0
  446. package/Neurai/src/crypto/ethash/include/ethash/ethash.h +131 -0
  447. package/Neurai/src/crypto/ethash/include/ethash/ethash.hpp +172 -0
  448. package/Neurai/src/crypto/ethash/include/ethash/hash_types.h +50 -0
  449. package/Neurai/src/crypto/ethash/include/ethash/hash_types.hpp +15 -0
  450. package/Neurai/src/crypto/ethash/include/ethash/keccak.h +49 -0
  451. package/Neurai/src/crypto/ethash/include/ethash/keccak.hpp +35 -0
  452. package/Neurai/src/crypto/ethash/include/ethash/progpow.hpp +49 -0
  453. package/Neurai/src/crypto/ethash/include/ethash/version.h +18 -0
  454. package/Neurai/src/crypto/ethash/lib/ethash/bit_manipulation.h +81 -0
  455. package/Neurai/src/crypto/ethash/lib/ethash/builtins.h +43 -0
  456. package/Neurai/src/crypto/ethash/lib/ethash/endianness.hpp +106 -0
  457. package/Neurai/src/crypto/ethash/lib/ethash/ethash-internal.hpp +68 -0
  458. package/Neurai/src/crypto/ethash/lib/ethash/ethash.cpp +442 -0
  459. package/Neurai/src/crypto/ethash/lib/ethash/kiss99.hpp +64 -0
  460. package/Neurai/src/crypto/ethash/lib/ethash/managed.cpp +100 -0
  461. package/Neurai/src/crypto/ethash/lib/ethash/primes.c +43 -0
  462. package/Neurai/src/crypto/ethash/lib/ethash/primes.h +25 -0
  463. package/Neurai/src/crypto/ethash/lib/ethash/progpow.cpp +581 -0
  464. package/Neurai/src/crypto/ethash/lib/keccak/keccak.c +129 -0
  465. package/Neurai/src/crypto/ethash/lib/keccak/keccakf1600.c +255 -0
  466. package/Neurai/src/crypto/ethash/lib/keccak/keccakf800.c +253 -0
  467. package/Neurai/src/crypto/ethash/lib/support/attributes.h +33 -0
  468. package/Neurai/src/crypto/ethash/progpow_test_vectors.hpp +64 -0
  469. package/Neurai/src/crypto/groestl.c +3123 -0
  470. package/Neurai/src/crypto/hmac_sha256.cpp +36 -0
  471. package/Neurai/src/crypto/hmac_sha256.h +34 -0
  472. package/Neurai/src/crypto/hmac_sha512.cpp +36 -0
  473. package/Neurai/src/crypto/hmac_sha512.h +34 -0
  474. package/Neurai/src/crypto/jh.c +1116 -0
  475. package/Neurai/src/crypto/keccak.c +1824 -0
  476. package/Neurai/src/crypto/luffa.c +1426 -0
  477. package/Neurai/src/crypto/md_helper.c +346 -0
  478. package/Neurai/src/crypto/ripemd160.cpp +294 -0
  479. package/Neurai/src/crypto/ripemd160.h +30 -0
  480. package/Neurai/src/crypto/sha1.cpp +201 -0
  481. package/Neurai/src/crypto/sha1.h +30 -0
  482. package/Neurai/src/crypto/sha2.c +646 -0
  483. package/Neurai/src/crypto/sha256.cpp +251 -0
  484. package/Neurai/src/crypto/sha256.h +36 -0
  485. package/Neurai/src/crypto/sha256_sse4.cpp +1508 -0
  486. package/Neurai/src/crypto/sha512.cpp +209 -0
  487. package/Neurai/src/crypto/sha512.h +30 -0
  488. package/Neurai/src/crypto/shavite.c +1764 -0
  489. package/Neurai/src/crypto/simd.c +1799 -0
  490. package/Neurai/src/crypto/skein.c +1254 -0
  491. package/Neurai/src/crypto/sph_blake.h +327 -0
  492. package/Neurai/src/crypto/sph_bmw.h +328 -0
  493. package/Neurai/src/crypto/sph_cubehash.h +292 -0
  494. package/Neurai/src/crypto/sph_echo.h +320 -0
  495. package/Neurai/src/crypto/sph_fugue.c +1208 -0
  496. package/Neurai/src/crypto/sph_fugue.h +81 -0
  497. package/Neurai/src/crypto/sph_groestl.h +329 -0
  498. package/Neurai/src/crypto/sph_hamsi.c +867 -0
  499. package/Neurai/src/crypto/sph_hamsi.h +321 -0
  500. package/Neurai/src/crypto/sph_hamsi_helper.c +39648 -0
  501. package/Neurai/src/crypto/sph_jh.h +298 -0
  502. package/Neurai/src/crypto/sph_keccak.h +293 -0
  503. package/Neurai/src/crypto/sph_luffa.h +296 -0
  504. package/Neurai/src/crypto/sph_sha2.c +701 -0
  505. package/Neurai/src/crypto/sph_sha2.h +378 -0
  506. package/Neurai/src/crypto/sph_sha512.c +247 -0
  507. package/Neurai/src/crypto/sph_shabal.c +808 -0
  508. package/Neurai/src/crypto/sph_shabal.h +343 -0
  509. package/Neurai/src/crypto/sph_shavite.h +314 -0
  510. package/Neurai/src/crypto/sph_simd.h +309 -0
  511. package/Neurai/src/crypto/sph_skein.h +298 -0
  512. package/Neurai/src/crypto/sph_types.h +1976 -0
  513. package/Neurai/src/crypto/sph_whirlpool.c +3481 -0
  514. package/Neurai/src/crypto/sph_whirlpool.h +217 -0
  515. package/Neurai/src/crypto/whirlpool.c +104 -0
  516. package/Neurai/src/crypto/whirlpoolx.c +69 -0
  517. package/Neurai/src/cuckoocache.h +481 -0
  518. package/Neurai/src/dbwrapper.cpp +246 -0
  519. package/Neurai/src/dbwrapper.h +345 -0
  520. package/Neurai/src/depinecies.cpp +406 -0
  521. package/Neurai/src/depinecies.h +162 -0
  522. package/Neurai/src/depinmcpclient.cpp +380 -0
  523. package/Neurai/src/depinmcpclient.h +101 -0
  524. package/Neurai/src/depinmcpworker.cpp +654 -0
  525. package/Neurai/src/depinmcpworker.h +205 -0
  526. package/Neurai/src/depinmsgpool.cpp +908 -0
  527. package/Neurai/src/depinmsgpool.h +182 -0
  528. package/Neurai/src/depinmsgpoolnet.cpp +1149 -0
  529. package/Neurai/src/depinmsgpoolnet.h +148 -0
  530. package/Neurai/src/fs.cpp +15 -0
  531. package/Neurai/src/fs.h +29 -0
  532. package/Neurai/src/hash.cpp +294 -0
  533. package/Neurai/src/hash.h +613 -0
  534. package/Neurai/src/httprpc.cpp +262 -0
  535. package/Neurai/src/httprpc.h +37 -0
  536. package/Neurai/src/httpserver.cpp +685 -0
  537. package/Neurai/src/httpserver.h +155 -0
  538. package/Neurai/src/indirectmap.h +58 -0
  539. package/Neurai/src/init.cpp +2122 -0
  540. package/Neurai/src/init.h +85 -0
  541. package/Neurai/src/key.cpp +317 -0
  542. package/Neurai/src/key.h +188 -0
  543. package/Neurai/src/keystore.cpp +146 -0
  544. package/Neurai/src/keystore.h +120 -0
  545. package/Neurai/src/leveldb/.travis.yml +13 -0
  546. package/Neurai/src/leveldb/AUTHORS +12 -0
  547. package/Neurai/src/leveldb/CONTRIBUTING.md +36 -0
  548. package/Neurai/src/leveldb/LICENSE +27 -0
  549. package/Neurai/src/leveldb/Makefile +424 -0
  550. package/Neurai/src/leveldb/NEWS +17 -0
  551. package/Neurai/src/leveldb/README.md +174 -0
  552. package/Neurai/src/leveldb/TODO +14 -0
  553. package/Neurai/src/leveldb/WINDOWS.md +39 -0
  554. package/Neurai/src/leveldb/build_detect_platform +259 -0
  555. package/Neurai/src/leveldb/db/autocompact_test.cc +118 -0
  556. package/Neurai/src/leveldb/db/builder.cc +88 -0
  557. package/Neurai/src/leveldb/db/builder.h +34 -0
  558. package/Neurai/src/leveldb/db/c.cc +595 -0
  559. package/Neurai/src/leveldb/db/c_test.c +390 -0
  560. package/Neurai/src/leveldb/db/corruption_test.cc +374 -0
  561. package/Neurai/src/leveldb/db/db_bench.cc +1020 -0
  562. package/Neurai/src/leveldb/db/db_impl.cc +1568 -0
  563. package/Neurai/src/leveldb/db/db_impl.h +211 -0
  564. package/Neurai/src/leveldb/db/db_iter.cc +317 -0
  565. package/Neurai/src/leveldb/db/db_iter.h +28 -0
  566. package/Neurai/src/leveldb/db/db_test.cc +2158 -0
  567. package/Neurai/src/leveldb/db/dbformat.cc +140 -0
  568. package/Neurai/src/leveldb/db/dbformat.h +230 -0
  569. package/Neurai/src/leveldb/db/dbformat_test.cc +112 -0
  570. package/Neurai/src/leveldb/db/dumpfile.cc +225 -0
  571. package/Neurai/src/leveldb/db/fault_injection_test.cc +554 -0
  572. package/Neurai/src/leveldb/db/filename.cc +144 -0
  573. package/Neurai/src/leveldb/db/filename.h +85 -0
  574. package/Neurai/src/leveldb/db/filename_test.cc +123 -0
  575. package/Neurai/src/leveldb/db/leveldbutil.cc +64 -0
  576. package/Neurai/src/leveldb/db/log_format.h +35 -0
  577. package/Neurai/src/leveldb/db/log_reader.cc +284 -0
  578. package/Neurai/src/leveldb/db/log_reader.h +113 -0
  579. package/Neurai/src/leveldb/db/log_test.cc +591 -0
  580. package/Neurai/src/leveldb/db/log_writer.cc +112 -0
  581. package/Neurai/src/leveldb/db/log_writer.h +54 -0
  582. package/Neurai/src/leveldb/db/memtable.cc +145 -0
  583. package/Neurai/src/leveldb/db/memtable.h +88 -0
  584. package/Neurai/src/leveldb/db/recovery_test.cc +324 -0
  585. package/Neurai/src/leveldb/db/repair.cc +461 -0
  586. package/Neurai/src/leveldb/db/skiplist.h +384 -0
  587. package/Neurai/src/leveldb/db/skiplist_test.cc +378 -0
  588. package/Neurai/src/leveldb/db/snapshot.h +67 -0
  589. package/Neurai/src/leveldb/db/table_cache.cc +127 -0
  590. package/Neurai/src/leveldb/db/table_cache.h +61 -0
  591. package/Neurai/src/leveldb/db/version_edit.cc +266 -0
  592. package/Neurai/src/leveldb/db/version_edit.h +107 -0
  593. package/Neurai/src/leveldb/db/version_edit_test.cc +46 -0
  594. package/Neurai/src/leveldb/db/version_set.cc +1535 -0
  595. package/Neurai/src/leveldb/db/version_set.h +398 -0
  596. package/Neurai/src/leveldb/db/version_set_test.cc +179 -0
  597. package/Neurai/src/leveldb/db/write_batch.cc +147 -0
  598. package/Neurai/src/leveldb/db/write_batch_internal.h +50 -0
  599. package/Neurai/src/leveldb/db/write_batch_test.cc +120 -0
  600. package/Neurai/src/leveldb/doc/bench/db_bench_sqlite3.cc +718 -0
  601. package/Neurai/src/leveldb/doc/bench/db_bench_tree_db.cc +528 -0
  602. package/Neurai/src/leveldb/doc/benchmark.html +459 -0
  603. package/Neurai/src/leveldb/doc/impl.md +170 -0
  604. package/Neurai/src/leveldb/doc/index.md +523 -0
  605. package/Neurai/src/leveldb/doc/log_format.md +75 -0
  606. package/Neurai/src/leveldb/doc/table_format.md +107 -0
  607. package/Neurai/src/leveldb/helpers/memenv/memenv.cc +398 -0
  608. package/Neurai/src/leveldb/helpers/memenv/memenv.h +20 -0
  609. package/Neurai/src/leveldb/helpers/memenv/memenv_test.cc +241 -0
  610. package/Neurai/src/leveldb/include/leveldb/c.h +290 -0
  611. package/Neurai/src/leveldb/include/leveldb/cache.h +110 -0
  612. package/Neurai/src/leveldb/include/leveldb/comparator.h +63 -0
  613. package/Neurai/src/leveldb/include/leveldb/db.h +163 -0
  614. package/Neurai/src/leveldb/include/leveldb/dumpfile.h +25 -0
  615. package/Neurai/src/leveldb/include/leveldb/env.h +351 -0
  616. package/Neurai/src/leveldb/include/leveldb/filter_policy.h +70 -0
  617. package/Neurai/src/leveldb/include/leveldb/iterator.h +100 -0
  618. package/Neurai/src/leveldb/include/leveldb/options.h +213 -0
  619. package/Neurai/src/leveldb/include/leveldb/slice.h +109 -0
  620. package/Neurai/src/leveldb/include/leveldb/status.h +112 -0
  621. package/Neurai/src/leveldb/include/leveldb/table.h +85 -0
  622. package/Neurai/src/leveldb/include/leveldb/table_builder.h +92 -0
  623. package/Neurai/src/leveldb/include/leveldb/write_batch.h +64 -0
  624. package/Neurai/src/leveldb/issues/issue178_test.cc +92 -0
  625. package/Neurai/src/leveldb/issues/issue200_test.cc +59 -0
  626. package/Neurai/src/leveldb/port/README +10 -0
  627. package/Neurai/src/leveldb/port/atomic_pointer.h +245 -0
  628. package/Neurai/src/leveldb/port/port.h +21 -0
  629. package/Neurai/src/leveldb/port/port_example.h +145 -0
  630. package/Neurai/src/leveldb/port/port_posix.cc +68 -0
  631. package/Neurai/src/leveldb/port/port_posix.h +161 -0
  632. package/Neurai/src/leveldb/port/port_posix_sse.cc +110 -0
  633. package/Neurai/src/leveldb/port/port_win.cc +158 -0
  634. package/Neurai/src/leveldb/port/port_win.h +177 -0
  635. package/Neurai/src/leveldb/port/thread_annotations.h +60 -0
  636. package/Neurai/src/leveldb/port/win/stdint.h +24 -0
  637. package/Neurai/src/leveldb/table/block.cc +268 -0
  638. package/Neurai/src/leveldb/table/block.h +44 -0
  639. package/Neurai/src/leveldb/table/block_builder.cc +109 -0
  640. package/Neurai/src/leveldb/table/block_builder.h +57 -0
  641. package/Neurai/src/leveldb/table/filter_block.cc +111 -0
  642. package/Neurai/src/leveldb/table/filter_block.h +68 -0
  643. package/Neurai/src/leveldb/table/filter_block_test.cc +128 -0
  644. package/Neurai/src/leveldb/table/format.cc +144 -0
  645. package/Neurai/src/leveldb/table/format.h +108 -0
  646. package/Neurai/src/leveldb/table/iterator.cc +67 -0
  647. package/Neurai/src/leveldb/table/iterator_wrapper.h +66 -0
  648. package/Neurai/src/leveldb/table/merger.cc +197 -0
  649. package/Neurai/src/leveldb/table/merger.h +26 -0
  650. package/Neurai/src/leveldb/table/table.cc +285 -0
  651. package/Neurai/src/leveldb/table/table_builder.cc +270 -0
  652. package/Neurai/src/leveldb/table/table_test.cc +876 -0
  653. package/Neurai/src/leveldb/table/two_level_iterator.cc +182 -0
  654. package/Neurai/src/leveldb/table/two_level_iterator.h +34 -0
  655. package/Neurai/src/leveldb/util/arena.cc +68 -0
  656. package/Neurai/src/leveldb/util/arena.h +68 -0
  657. package/Neurai/src/leveldb/util/arena_test.cc +68 -0
  658. package/Neurai/src/leveldb/util/bloom.cc +95 -0
  659. package/Neurai/src/leveldb/util/bloom_test.cc +162 -0
  660. package/Neurai/src/leveldb/util/cache.cc +405 -0
  661. package/Neurai/src/leveldb/util/cache_test.cc +226 -0
  662. package/Neurai/src/leveldb/util/coding.cc +194 -0
  663. package/Neurai/src/leveldb/util/coding.h +104 -0
  664. package/Neurai/src/leveldb/util/coding_test.cc +196 -0
  665. package/Neurai/src/leveldb/util/comparator.cc +81 -0
  666. package/Neurai/src/leveldb/util/crc32c.cc +354 -0
  667. package/Neurai/src/leveldb/util/crc32c.h +45 -0
  668. package/Neurai/src/leveldb/util/crc32c_test.cc +72 -0
  669. package/Neurai/src/leveldb/util/env.cc +100 -0
  670. package/Neurai/src/leveldb/util/env_posix.cc +698 -0
  671. package/Neurai/src/leveldb/util/env_posix_test.cc +66 -0
  672. package/Neurai/src/leveldb/util/env_posix_test_helper.h +28 -0
  673. package/Neurai/src/leveldb/util/env_test.cc +106 -0
  674. package/Neurai/src/leveldb/util/env_win.cc +898 -0
  675. package/Neurai/src/leveldb/util/filter_policy.cc +11 -0
  676. package/Neurai/src/leveldb/util/hash.cc +52 -0
  677. package/Neurai/src/leveldb/util/hash.h +19 -0
  678. package/Neurai/src/leveldb/util/hash_test.cc +54 -0
  679. package/Neurai/src/leveldb/util/histogram.cc +139 -0
  680. package/Neurai/src/leveldb/util/histogram.h +42 -0
  681. package/Neurai/src/leveldb/util/logging.cc +72 -0
  682. package/Neurai/src/leveldb/util/logging.h +43 -0
  683. package/Neurai/src/leveldb/util/mutexlock.h +41 -0
  684. package/Neurai/src/leveldb/util/options.cc +30 -0
  685. package/Neurai/src/leveldb/util/posix_logger.h +98 -0
  686. package/Neurai/src/leveldb/util/random.h +64 -0
  687. package/Neurai/src/leveldb/util/status.cc +75 -0
  688. package/Neurai/src/leveldb/util/testharness.cc +77 -0
  689. package/Neurai/src/leveldb/util/testharness.h +138 -0
  690. package/Neurai/src/leveldb/util/testutil.cc +51 -0
  691. package/Neurai/src/leveldb/util/testutil.h +63 -0
  692. package/Neurai/src/limitedmap.h +102 -0
  693. package/Neurai/src/memusage.h +171 -0
  694. package/Neurai/src/merkleblock.cpp +166 -0
  695. package/Neurai/src/merkleblock.h +169 -0
  696. package/Neurai/src/miner.cpp +731 -0
  697. package/Neurai/src/miner.h +211 -0
  698. package/Neurai/src/net.cpp +2944 -0
  699. package/Neurai/src/net.h +888 -0
  700. package/Neurai/src/net_processing.cpp +3803 -0
  701. package/Neurai/src/net_processing.h +86 -0
  702. package/Neurai/src/netaddress.cpp +740 -0
  703. package/Neurai/src/netaddress.h +179 -0
  704. package/Neurai/src/netbase.cpp +738 -0
  705. package/Neurai/src/netbase.h +72 -0
  706. package/Neurai/src/netmessagemaker.h +38 -0
  707. package/Neurai/src/neurai-cli-res.rc +35 -0
  708. package/Neurai/src/neurai-cli.cpp +518 -0
  709. package/Neurai/src/neurai-tx-res.rc +35 -0
  710. package/Neurai/src/neurai-tx.cpp +875 -0
  711. package/Neurai/src/neuraid-res.rc +35 -0
  712. package/Neurai/src/neuraid.cpp +204 -0
  713. package/Neurai/src/noui.cpp +60 -0
  714. package/Neurai/src/noui.h +12 -0
  715. package/Neurai/src/policy/feerate.cpp +45 -0
  716. package/Neurai/src/policy/feerate.h +61 -0
  717. package/Neurai/src/policy/fees.cpp +1074 -0
  718. package/Neurai/src/policy/fees.h +305 -0
  719. package/Neurai/src/policy/policy.cpp +274 -0
  720. package/Neurai/src/policy/policy.h +108 -0
  721. package/Neurai/src/policy/rbf.cpp +49 -0
  722. package/Neurai/src/policy/rbf.h +30 -0
  723. package/Neurai/src/pow.cpp +199 -0
  724. package/Neurai/src/pow.h +25 -0
  725. package/Neurai/src/prevector.h +519 -0
  726. package/Neurai/src/primitives/block.cpp +161 -0
  727. package/Neurai/src/primitives/block.h +235 -0
  728. package/Neurai/src/primitives/transaction.cpp +134 -0
  729. package/Neurai/src/primitives/transaction.h +440 -0
  730. package/Neurai/src/protocol.cpp +216 -0
  731. package/Neurai/src/protocol.h +446 -0
  732. package/Neurai/src/pubkey.cpp +301 -0
  733. package/Neurai/src/pubkey.h +252 -0
  734. package/Neurai/src/pubkeyindex.h +76 -0
  735. package/Neurai/src/qt/addressbookpage.cpp +315 -0
  736. package/Neurai/src/qt/addressbookpage.h +88 -0
  737. package/Neurai/src/qt/addresstablemodel.cpp +443 -0
  738. package/Neurai/src/qt/addresstablemodel.h +97 -0
  739. package/Neurai/src/qt/askpassphrasedialog.cpp +277 -0
  740. package/Neurai/src/qt/askpassphrasedialog.h +54 -0
  741. package/Neurai/src/qt/assetcontroldialog.cpp +827 -0
  742. package/Neurai/src/qt/assetcontroldialog.h +129 -0
  743. package/Neurai/src/qt/assetcontroltreewidget.cpp +36 -0
  744. package/Neurai/src/qt/assetcontroltreewidget.h +24 -0
  745. package/Neurai/src/qt/assetfilterproxy.cpp +43 -0
  746. package/Neurai/src/qt/assetfilterproxy.h +30 -0
  747. package/Neurai/src/qt/assetrecord.h +56 -0
  748. package/Neurai/src/qt/assetsdialog.cpp +1068 -0
  749. package/Neurai/src/qt/assetsdialog.h +122 -0
  750. package/Neurai/src/qt/assettablemodel.cpp +274 -0
  751. package/Neurai/src/qt/assettablemodel.h +73 -0
  752. package/Neurai/src/qt/bantablemodel.cpp +184 -0
  753. package/Neurai/src/qt/bantablemodel.h +75 -0
  754. package/Neurai/src/qt/callback.h +30 -0
  755. package/Neurai/src/qt/clientmodel.cpp +342 -0
  756. package/Neurai/src/qt/clientmodel.h +121 -0
  757. package/Neurai/src/qt/coincontroldialog.cpp +738 -0
  758. package/Neurai/src/qt/coincontroldialog.h +114 -0
  759. package/Neurai/src/qt/coincontroltreewidget.cpp +36 -0
  760. package/Neurai/src/qt/coincontroltreewidget.h +24 -0
  761. package/Neurai/src/qt/createassetdialog.cpp +1600 -0
  762. package/Neurai/src/qt/createassetdialog.h +158 -0
  763. package/Neurai/src/qt/csvmodelwriter.cpp +93 -0
  764. package/Neurai/src/qt/csvmodelwriter.h +48 -0
  765. package/Neurai/src/qt/currencyunits.h +33 -0
  766. package/Neurai/src/qt/darkstyle.cpp +90 -0
  767. package/Neurai/src/qt/darkstyle.h +40 -0
  768. package/Neurai/src/qt/editaddressdialog.cpp +146 -0
  769. package/Neurai/src/qt/editaddressdialog.h +59 -0
  770. package/Neurai/src/qt/forms/addressbookpage.ui +159 -0
  771. package/Neurai/src/qt/forms/askpassphrasedialog.ui +160 -0
  772. package/Neurai/src/qt/forms/assetcontroldialog.ui +517 -0
  773. package/Neurai/src/qt/forms/assetsdialog.ui +1305 -0
  774. package/Neurai/src/qt/forms/coincontroldialog.ui +495 -0
  775. package/Neurai/src/qt/forms/createassetdialog.ui +1466 -0
  776. package/Neurai/src/qt/forms/debugwindow.ui +1598 -0
  777. package/Neurai/src/qt/forms/editaddressdialog.ui +112 -0
  778. package/Neurai/src/qt/forms/helpmessagedialog.ui +189 -0
  779. package/Neurai/src/qt/forms/intro.ui +293 -0
  780. package/Neurai/src/qt/forms/mnemonicdialog1.ui +156 -0
  781. package/Neurai/src/qt/forms/mnemonicdialog2.ui +353 -0
  782. package/Neurai/src/qt/forms/mnemonicdialog3.ui +376 -0
  783. package/Neurai/src/qt/forms/modaloverlay.ui +383 -0
  784. package/Neurai/src/qt/forms/openuridialog.ui +118 -0
  785. package/Neurai/src/qt/forms/optionsdialog.ui +923 -0
  786. package/Neurai/src/qt/forms/overviewpage.ui +845 -0
  787. package/Neurai/src/qt/forms/receivecoinsdialog.ui +344 -0
  788. package/Neurai/src/qt/forms/receiverequestdialog.ui +168 -0
  789. package/Neurai/src/qt/forms/reissueassetdialog.ui +1747 -0
  790. package/Neurai/src/qt/forms/restrictedassetsdialog.ui +299 -0
  791. package/Neurai/src/qt/forms/restrictedassignqualifier.ui +165 -0
  792. package/Neurai/src/qt/forms/restrictedfreezeaddress.ui +232 -0
  793. package/Neurai/src/qt/forms/sendassetsentry.ui +1344 -0
  794. package/Neurai/src/qt/forms/sendcoinsdialog.ui +1305 -0
  795. package/Neurai/src/qt/forms/sendcoinsentry.ui +1269 -0
  796. package/Neurai/src/qt/forms/signverifymessagedialog.ui +390 -0
  797. package/Neurai/src/qt/forms/transactiondescdialog.ui +74 -0
  798. package/Neurai/src/qt/guiconstants.h +130 -0
  799. package/Neurai/src/qt/guiutil.cpp +1072 -0
  800. package/Neurai/src/qt/guiutil.h +273 -0
  801. package/Neurai/src/qt/intro.cpp +332 -0
  802. package/Neurai/src/qt/intro.h +80 -0
  803. package/Neurai/src/qt/locale/neurai_af.ts +1072 -0
  804. package/Neurai/src/qt/locale/neurai_af_ZA.ts +840 -0
  805. package/Neurai/src/qt/locale/neurai_ar.ts +2036 -0
  806. package/Neurai/src/qt/locale/neurai_be_BY.ts +1406 -0
  807. package/Neurai/src/qt/locale/neurai_bg.ts +3104 -0
  808. package/Neurai/src/qt/locale/neurai_bg_BG.ts +472 -0
  809. package/Neurai/src/qt/locale/neurai_ca.ts +3218 -0
  810. package/Neurai/src/qt/locale/neurai_ca@valencia.ts +2942 -0
  811. package/Neurai/src/qt/locale/neurai_ca_ES.ts +3242 -0
  812. package/Neurai/src/qt/locale/neurai_cs.ts +3726 -0
  813. package/Neurai/src/qt/locale/neurai_cy.ts +540 -0
  814. package/Neurai/src/qt/locale/neurai_da.ts +3731 -0
  815. package/Neurai/src/qt/locale/neurai_de.ts +5452 -0
  816. package/Neurai/src/qt/locale/neurai_el.ts +256 -0
  817. package/Neurai/src/qt/locale/neurai_el_GR.ts +2099 -0
  818. package/Neurai/src/qt/locale/neurai_en.ts +8344 -0
  819. package/Neurai/src/qt/locale/neurai_en_GB.ts +2522 -0
  820. package/Neurai/src/qt/locale/neurai_eo.ts +1482 -0
  821. package/Neurai/src/qt/locale/neurai_es.ts +4196 -0
  822. package/Neurai/src/qt/locale/neurai_es_AR.ts +220 -0
  823. package/Neurai/src/qt/locale/neurai_es_CL.ts +855 -0
  824. package/Neurai/src/qt/locale/neurai_es_CO.ts +356 -0
  825. package/Neurai/src/qt/locale/neurai_es_DO.ts +1285 -0
  826. package/Neurai/src/qt/locale/neurai_es_ES.ts +3579 -0
  827. package/Neurai/src/qt/locale/neurai_es_MX.ts +668 -0
  828. package/Neurai/src/qt/locale/neurai_es_UY.ts +487 -0
  829. package/Neurai/src/qt/locale/neurai_es_VE.ts +684 -0
  830. package/Neurai/src/qt/locale/neurai_et.ts +1874 -0
  831. package/Neurai/src/qt/locale/neurai_et_EE.ts +812 -0
  832. package/Neurai/src/qt/locale/neurai_eu_ES.ts +860 -0
  833. package/Neurai/src/qt/locale/neurai_fa.ts +1834 -0
  834. package/Neurai/src/qt/locale/neurai_fa_IR.ts +984 -0
  835. package/Neurai/src/qt/locale/neurai_fi.ts +2906 -0
  836. package/Neurai/src/qt/locale/neurai_fr.ts +4062 -0
  837. package/Neurai/src/qt/locale/neurai_fr_CA.ts +204 -0
  838. package/Neurai/src/qt/locale/neurai_fr_FR.ts +1819 -0
  839. package/Neurai/src/qt/locale/neurai_gl.ts +1180 -0
  840. package/Neurai/src/qt/locale/neurai_he.ts +3022 -0
  841. package/Neurai/src/qt/locale/neurai_hi_IN.ts +491 -0
  842. package/Neurai/src/qt/locale/neurai_hr.ts +1110 -0
  843. package/Neurai/src/qt/locale/neurai_hu.ts +1578 -0
  844. package/Neurai/src/qt/locale/neurai_id_ID.ts +2160 -0
  845. package/Neurai/src/qt/locale/neurai_it.ts +3519 -0
  846. package/Neurai/src/qt/locale/neurai_it_IT.ts +252 -0
  847. package/Neurai/src/qt/locale/neurai_ja.ts +3731 -0
  848. package/Neurai/src/qt/locale/neurai_ka.ts +1492 -0
  849. package/Neurai/src/qt/locale/neurai_kk_KZ.ts +368 -0
  850. package/Neurai/src/qt/locale/neurai_ko_KR.ts +5040 -0
  851. package/Neurai/src/qt/locale/neurai_ku_IQ.ts +428 -0
  852. package/Neurai/src/qt/locale/neurai_ky.ts +396 -0
  853. package/Neurai/src/qt/locale/neurai_la.ts +920 -0
  854. package/Neurai/src/qt/locale/neurai_lt.ts +1000 -0
  855. package/Neurai/src/qt/locale/neurai_lv_LV.ts +1232 -0
  856. package/Neurai/src/qt/locale/neurai_mk_MK.ts +614 -0
  857. package/Neurai/src/qt/locale/neurai_mn.ts +616 -0
  858. package/Neurai/src/qt/locale/neurai_ms_MY.ts +550 -0
  859. package/Neurai/src/qt/locale/neurai_nb.ts +4448 -0
  860. package/Neurai/src/qt/locale/neurai_ne.ts +644 -0
  861. package/Neurai/src/qt/locale/neurai_nl.ts +4264 -0
  862. package/Neurai/src/qt/locale/neurai_pl.ts +4802 -0
  863. package/Neurai/src/qt/locale/neurai_pt_BR.ts +4038 -0
  864. package/Neurai/src/qt/locale/neurai_pt_PT.ts +3507 -0
  865. package/Neurai/src/qt/locale/neurai_ro.ts +920 -0
  866. package/Neurai/src/qt/locale/neurai_ro_RO.ts +2414 -0
  867. package/Neurai/src/qt/locale/neurai_ru.ts +3726 -0
  868. package/Neurai/src/qt/locale/neurai_ru_RU.ts +852 -0
  869. package/Neurai/src/qt/locale/neurai_sk.ts +3539 -0
  870. package/Neurai/src/qt/locale/neurai_sl_SI.ts +1914 -0
  871. package/Neurai/src/qt/locale/neurai_sq.ts +832 -0
  872. package/Neurai/src/qt/locale/neurai_sr.ts +745 -0
  873. package/Neurai/src/qt/locale/neurai_sr@latin.ts +482 -0
  874. package/Neurai/src/qt/locale/neurai_sv.ts +3655 -0
  875. package/Neurai/src/qt/locale/neurai_ta.ts +744 -0
  876. package/Neurai/src/qt/locale/neurai_th_TH.ts +922 -0
  877. package/Neurai/src/qt/locale/neurai_tr.ts +6074 -0
  878. package/Neurai/src/qt/locale/neurai_tr_TR.ts +220 -0
  879. package/Neurai/src/qt/locale/neurai_uk.ts +3182 -0
  880. package/Neurai/src/qt/locale/neurai_ur_PK.ts +296 -0
  881. package/Neurai/src/qt/locale/neurai_uz@Cyrl.ts +1228 -0
  882. package/Neurai/src/qt/locale/neurai_vi.ts +212 -0
  883. package/Neurai/src/qt/locale/neurai_vi_VN.ts +1058 -0
  884. package/Neurai/src/qt/locale/neurai_zh.ts +244 -0
  885. package/Neurai/src/qt/locale/neurai_zh_CN.ts +3510 -0
  886. package/Neurai/src/qt/locale/neurai_zh_HK.ts +690 -0
  887. package/Neurai/src/qt/locale/neurai_zh_TW.ts +3731 -0
  888. package/Neurai/src/qt/macdockiconhandler.h +46 -0
  889. package/Neurai/src/qt/macdockiconhandler.mm +136 -0
  890. package/Neurai/src/qt/macnotificationhandler.h +29 -0
  891. package/Neurai/src/qt/macnotificationhandler.mm +79 -0
  892. package/Neurai/src/qt/mnemonicdialog.cpp +253 -0
  893. package/Neurai/src/qt/mnemonicdialog.h +105 -0
  894. package/Neurai/src/qt/modaloverlay.cpp +178 -0
  895. package/Neurai/src/qt/modaloverlay.h +52 -0
  896. package/Neurai/src/qt/myrestrictedassetrecord.cpp +85 -0
  897. package/Neurai/src/qt/myrestrictedassetrecord.h +79 -0
  898. package/Neurai/src/qt/myrestrictedassettablemodel.cpp +551 -0
  899. package/Neurai/src/qt/myrestrictedassettablemodel.h +99 -0
  900. package/Neurai/src/qt/networkstyle.cpp +99 -0
  901. package/Neurai/src/qt/networkstyle.h +37 -0
  902. package/Neurai/src/qt/neurai-qt.config +2 -0
  903. package/Neurai/src/qt/neurai-qt.creator +1 -0
  904. package/Neurai/src/qt/neurai-qt.creator.user +198 -0
  905. package/Neurai/src/qt/neurai-qt.files +118 -0
  906. package/Neurai/src/qt/neurai-qt.includes +2 -0
  907. package/Neurai/src/qt/neurai.cpp +785 -0
  908. package/Neurai/src/qt/neurai.qrc +156 -0
  909. package/Neurai/src/qt/neurai_locale.qrc +89 -0
  910. package/Neurai/src/qt/neuraiaddressvalidator.cpp +99 -0
  911. package/Neurai/src/qt/neuraiaddressvalidator.h +37 -0
  912. package/Neurai/src/qt/neuraiamountfield.cpp +431 -0
  913. package/Neurai/src/qt/neuraiamountfield.h +130 -0
  914. package/Neurai/src/qt/neuraigui.cpp +1958 -0
  915. package/Neurai/src/qt/neuraigui.h +364 -0
  916. package/Neurai/src/qt/neuraistrings.cpp +569 -0
  917. package/Neurai/src/qt/neuraiunits.cpp +288 -0
  918. package/Neurai/src/qt/neuraiunits.h +140 -0
  919. package/Neurai/src/qt/notificator.cpp +262 -0
  920. package/Neurai/src/qt/notificator.h +79 -0
  921. package/Neurai/src/qt/openuridialog.cpp +54 -0
  922. package/Neurai/src/qt/openuridialog.h +36 -0
  923. package/Neurai/src/qt/optionsdialog.cpp +373 -0
  924. package/Neurai/src/qt/optionsdialog.h +76 -0
  925. package/Neurai/src/qt/optionsmodel.cpp +558 -0
  926. package/Neurai/src/qt/optionsmodel.h +120 -0
  927. package/Neurai/src/qt/overviewpage.cpp +730 -0
  928. package/Neurai/src/qt/overviewpage.h +97 -0
  929. package/Neurai/src/qt/paymentrequest.proto +48 -0
  930. package/Neurai/src/qt/paymentrequestplus.cpp +219 -0
  931. package/Neurai/src/qt/paymentrequestplus.h +53 -0
  932. package/Neurai/src/qt/paymentserver.cpp +812 -0
  933. package/Neurai/src/qt/paymentserver.h +150 -0
  934. package/Neurai/src/qt/peertablemodel.cpp +254 -0
  935. package/Neurai/src/qt/peertablemodel.h +87 -0
  936. package/Neurai/src/qt/platformstyle.cpp +288 -0
  937. package/Neurai/src/qt/platformstyle.h +84 -0
  938. package/Neurai/src/qt/qvalidatedlineedit.cpp +129 -0
  939. package/Neurai/src/qt/qvalidatedlineedit.h +45 -0
  940. package/Neurai/src/qt/qvaluecombobox.cpp +33 -0
  941. package/Neurai/src/qt/qvaluecombobox.h +39 -0
  942. package/Neurai/src/qt/receivecoinsdialog.cpp +345 -0
  943. package/Neurai/src/qt/receivecoinsdialog.h +81 -0
  944. package/Neurai/src/qt/receiverequestdialog.cpp +215 -0
  945. package/Neurai/src/qt/receiverequestdialog.h +73 -0
  946. package/Neurai/src/qt/recentrequeststablemodel.cpp +242 -0
  947. package/Neurai/src/qt/recentrequeststablemodel.h +109 -0
  948. package/Neurai/src/qt/reissueassetdialog.cpp +1494 -0
  949. package/Neurai/src/qt/reissueassetdialog.h +145 -0
  950. package/Neurai/src/qt/res/darkstyle/darkstyle.qss +343 -0
  951. package/Neurai/src/qt/res/darkstyle/icon_branch_closed.png +0 -0
  952. package/Neurai/src/qt/res/darkstyle/icon_branch_end.png +0 -0
  953. package/Neurai/src/qt/res/darkstyle/icon_branch_more.png +0 -0
  954. package/Neurai/src/qt/res/darkstyle/icon_branch_open.png +0 -0
  955. package/Neurai/src/qt/res/darkstyle/icon_checkbox_checked.png +0 -0
  956. package/Neurai/src/qt/res/darkstyle/icon_checkbox_checked_disabled.png +0 -0
  957. package/Neurai/src/qt/res/darkstyle/icon_checkbox_checked_pressed.png +0 -0
  958. package/Neurai/src/qt/res/darkstyle/icon_checkbox_indeterminate.png +0 -0
  959. package/Neurai/src/qt/res/darkstyle/icon_checkbox_indeterminate_disabled.png +0 -0
  960. package/Neurai/src/qt/res/darkstyle/icon_checkbox_indeterminate_pressed.png +0 -0
  961. package/Neurai/src/qt/res/darkstyle/icon_checkbox_unchecked.png +0 -0
  962. package/Neurai/src/qt/res/darkstyle/icon_checkbox_unchecked_disabled.png +0 -0
  963. package/Neurai/src/qt/res/darkstyle/icon_checkbox_unchecked_pressed.png +0 -0
  964. package/Neurai/src/qt/res/darkstyle/icon_close.png +0 -0
  965. package/Neurai/src/qt/res/darkstyle/icon_radiobutton_checked.png +0 -0
  966. package/Neurai/src/qt/res/darkstyle/icon_radiobutton_checked_disabled.png +0 -0
  967. package/Neurai/src/qt/res/darkstyle/icon_radiobutton_checked_pressed.png +0 -0
  968. package/Neurai/src/qt/res/darkstyle/icon_radiobutton_unchecked.png +0 -0
  969. package/Neurai/src/qt/res/darkstyle/icon_radiobutton_unchecked_disabled.png +0 -0
  970. package/Neurai/src/qt/res/darkstyle/icon_radiobutton_unchecked_pressed.png +0 -0
  971. package/Neurai/src/qt/res/darkstyle/icon_restore.png +0 -0
  972. package/Neurai/src/qt/res/darkstyle/icon_undock.png +0 -0
  973. package/Neurai/src/qt/res/darkstyle/icon_vline.png +0 -0
  974. package/Neurai/src/qt/res/fonts/OpenSans-Bold.ttf +0 -0
  975. package/Neurai/src/qt/res/fonts/OpenSans-BoldItalic.ttf +0 -0
  976. package/Neurai/src/qt/res/fonts/OpenSans-ExtraBold.ttf +0 -0
  977. package/Neurai/src/qt/res/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
  978. package/Neurai/src/qt/res/fonts/OpenSans-Italic.ttf +0 -0
  979. package/Neurai/src/qt/res/fonts/OpenSans-Light.ttf +0 -0
  980. package/Neurai/src/qt/res/fonts/OpenSans-LightItalic.ttf +0 -0
  981. package/Neurai/src/qt/res/fonts/OpenSans-Regular.ttf +0 -0
  982. package/Neurai/src/qt/res/fonts/OpenSans-SemiBold.ttf +0 -0
  983. package/Neurai/src/qt/res/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
  984. package/Neurai/src/qt/res/icons/about.png +0 -0
  985. package/Neurai/src/qt/res/icons/about_qt.png +0 -0
  986. package/Neurai/src/qt/res/icons/add.png +0 -0
  987. package/Neurai/src/qt/res/icons/address-book.png +0 -0
  988. package/Neurai/src/qt/res/icons/asset_administrator.png +0 -0
  989. package/Neurai/src/qt/res/icons/asset_administrator_dark.png +0 -0
  990. package/Neurai/src/qt/res/icons/asset_create.png +0 -0
  991. package/Neurai/src/qt/res/icons/asset_create_selected.png +0 -0
  992. package/Neurai/src/qt/res/icons/asset_manage.png +0 -0
  993. package/Neurai/src/qt/res/icons/asset_manage_selected.png +0 -0
  994. package/Neurai/src/qt/res/icons/asset_transfer.png +0 -0
  995. package/Neurai/src/qt/res/icons/asset_transfer_selected.png +0 -0
  996. package/Neurai/src/qt/res/icons/chevron.png +0 -0
  997. package/Neurai/src/qt/res/icons/clock1.png +0 -0
  998. package/Neurai/src/qt/res/icons/clock2.png +0 -0
  999. package/Neurai/src/qt/res/icons/clock3.png +0 -0
  1000. package/Neurai/src/qt/res/icons/clock4.png +0 -0
  1001. package/Neurai/src/qt/res/icons/clock5.png +0 -0
  1002. package/Neurai/src/qt/res/icons/configure.png +0 -0
  1003. package/Neurai/src/qt/res/icons/connect0.png +0 -0
  1004. package/Neurai/src/qt/res/icons/connect1.png +0 -0
  1005. package/Neurai/src/qt/res/icons/connect2.png +0 -0
  1006. package/Neurai/src/qt/res/icons/connect3.png +0 -0
  1007. package/Neurai/src/qt/res/icons/connect4.png +0 -0
  1008. package/Neurai/src/qt/res/icons/debugwindow.png +0 -0
  1009. package/Neurai/src/qt/res/icons/edit.png +0 -0
  1010. package/Neurai/src/qt/res/icons/editcopy.png +0 -0
  1011. package/Neurai/src/qt/res/icons/editpaste.png +0 -0
  1012. package/Neurai/src/qt/res/icons/export.png +0 -0
  1013. package/Neurai/src/qt/res/icons/external_link.png +0 -0
  1014. package/Neurai/src/qt/res/icons/external_link_dark.png +0 -0
  1015. package/Neurai/src/qt/res/icons/eye.png +0 -0
  1016. package/Neurai/src/qt/res/icons/eye_minus.png +0 -0
  1017. package/Neurai/src/qt/res/icons/eye_plus.png +0 -0
  1018. package/Neurai/src/qt/res/icons/filesave.png +0 -0
  1019. package/Neurai/src/qt/res/icons/fontbigger.png +0 -0
  1020. package/Neurai/src/qt/res/icons/fontsmaller.png +0 -0
  1021. package/Neurai/src/qt/res/icons/hd_disabled.png +0 -0
  1022. package/Neurai/src/qt/res/icons/hd_enabled.png +0 -0
  1023. package/Neurai/src/qt/res/icons/hd_enabled_44.png +0 -0
  1024. package/Neurai/src/qt/res/icons/history.png +0 -0
  1025. package/Neurai/src/qt/res/icons/history_selected.png +0 -0
  1026. package/Neurai/src/qt/res/icons/info.png +0 -0
  1027. package/Neurai/src/qt/res/icons/key.png +0 -0
  1028. package/Neurai/src/qt/res/icons/lock_closed.png +0 -0
  1029. package/Neurai/src/qt/res/icons/lock_open.png +0 -0
  1030. package/Neurai/src/qt/res/icons/network_disabled.png +0 -0
  1031. package/Neurai/src/qt/res/icons/neurai.icns +0 -0
  1032. package/Neurai/src/qt/res/icons/neurai.ico +0 -0
  1033. package/Neurai/src/qt/res/icons/neurai.png +0 -0
  1034. package/Neurai/src/qt/res/icons/neurai_testnet.ico +0 -0
  1035. package/Neurai/src/qt/res/icons/neuraitext.png +0 -0
  1036. package/Neurai/src/qt/res/icons/open.png +0 -0
  1037. package/Neurai/src/qt/res/icons/overview.png +0 -0
  1038. package/Neurai/src/qt/res/icons/overview_selected.png +0 -0
  1039. package/Neurai/src/qt/res/icons/quit.png +0 -0
  1040. package/Neurai/src/qt/res/icons/receive.png +0 -0
  1041. package/Neurai/src/qt/res/icons/receive_selected.png +0 -0
  1042. package/Neurai/src/qt/res/icons/refresh.png +0 -0
  1043. package/Neurai/src/qt/res/icons/remove.png +0 -0
  1044. package/Neurai/src/qt/res/icons/restricted_asset.png +0 -0
  1045. package/Neurai/src/qt/res/icons/restricted_asset_selected.png +0 -0
  1046. package/Neurai/src/qt/res/icons/send.png +0 -0
  1047. package/Neurai/src/qt/res/icons/send_selected.png +0 -0
  1048. package/Neurai/src/qt/res/icons/synced.png +0 -0
  1049. package/Neurai/src/qt/res/icons/transaction0.png +0 -0
  1050. package/Neurai/src/qt/res/icons/transaction2.png +0 -0
  1051. package/Neurai/src/qt/res/icons/transaction_abandoned.png +0 -0
  1052. package/Neurai/src/qt/res/icons/transaction_conflicted.png +0 -0
  1053. package/Neurai/src/qt/res/icons/tx_asset_input.png +0 -0
  1054. package/Neurai/src/qt/res/icons/tx_asset_output.png +0 -0
  1055. package/Neurai/src/qt/res/icons/tx_atomic_swap.png +0 -0
  1056. package/Neurai/src/qt/res/icons/tx_inout.png +0 -0
  1057. package/Neurai/src/qt/res/icons/tx_input.png +0 -0
  1058. package/Neurai/src/qt/res/icons/tx_mined.png +0 -0
  1059. package/Neurai/src/qt/res/icons/tx_output.png +0 -0
  1060. package/Neurai/src/qt/res/icons/verify.png +0 -0
  1061. package/Neurai/src/qt/res/icons/warning.png +0 -0
  1062. package/Neurai/src/qt/res/icons/xnatext.png +0 -0
  1063. package/Neurai/src/qt/res/movies/makespinner.sh +13 -0
  1064. package/Neurai/src/qt/res/movies/spinner-000.png +0 -0
  1065. package/Neurai/src/qt/res/movies/spinner-001.png +0 -0
  1066. package/Neurai/src/qt/res/movies/spinner-002.png +0 -0
  1067. package/Neurai/src/qt/res/movies/spinner-003.png +0 -0
  1068. package/Neurai/src/qt/res/movies/spinner-004.png +0 -0
  1069. package/Neurai/src/qt/res/movies/spinner-005.png +0 -0
  1070. package/Neurai/src/qt/res/movies/spinner-006.png +0 -0
  1071. package/Neurai/src/qt/res/movies/spinner-007.png +0 -0
  1072. package/Neurai/src/qt/res/movies/spinner-008.png +0 -0
  1073. package/Neurai/src/qt/res/movies/spinner-009.png +0 -0
  1074. package/Neurai/src/qt/res/movies/spinner-010.png +0 -0
  1075. package/Neurai/src/qt/res/movies/spinner-011.png +0 -0
  1076. package/Neurai/src/qt/res/movies/spinner-012.png +0 -0
  1077. package/Neurai/src/qt/res/movies/spinner-013.png +0 -0
  1078. package/Neurai/src/qt/res/movies/spinner-014.png +0 -0
  1079. package/Neurai/src/qt/res/movies/spinner-015.png +0 -0
  1080. package/Neurai/src/qt/res/movies/spinner-016.png +0 -0
  1081. package/Neurai/src/qt/res/movies/spinner-017.png +0 -0
  1082. package/Neurai/src/qt/res/movies/spinner-018.png +0 -0
  1083. package/Neurai/src/qt/res/movies/spinner-019.png +0 -0
  1084. package/Neurai/src/qt/res/movies/spinner-020.png +0 -0
  1085. package/Neurai/src/qt/res/movies/spinner-021.png +0 -0
  1086. package/Neurai/src/qt/res/movies/spinner-022.png +0 -0
  1087. package/Neurai/src/qt/res/movies/spinner-023.png +0 -0
  1088. package/Neurai/src/qt/res/movies/spinner-024.png +0 -0
  1089. package/Neurai/src/qt/res/movies/spinner-025.png +0 -0
  1090. package/Neurai/src/qt/res/movies/spinner-026.png +0 -0
  1091. package/Neurai/src/qt/res/movies/spinner-027.png +0 -0
  1092. package/Neurai/src/qt/res/movies/spinner-028.png +0 -0
  1093. package/Neurai/src/qt/res/movies/spinner-029.png +0 -0
  1094. package/Neurai/src/qt/res/movies/spinner-030.png +0 -0
  1095. package/Neurai/src/qt/res/movies/spinner-031.png +0 -0
  1096. package/Neurai/src/qt/res/movies/spinner-032.png +0 -0
  1097. package/Neurai/src/qt/res/movies/spinner-033.png +0 -0
  1098. package/Neurai/src/qt/res/movies/spinner-034.png +0 -0
  1099. package/Neurai/src/qt/res/movies/spinner-035.png +0 -0
  1100. package/Neurai/src/qt/res/neurai-qt-res.rc +38 -0
  1101. package/Neurai/src/qt/res/src/clock_0.svg +14 -0
  1102. package/Neurai/src/qt/res/src/clock_1.svg +15 -0
  1103. package/Neurai/src/qt/res/src/clock_2.svg +13 -0
  1104. package/Neurai/src/qt/res/src/clock_3.svg +15 -0
  1105. package/Neurai/src/qt/res/src/clock_4.svg +23 -0
  1106. package/Neurai/src/qt/res/src/connect-0.svg +66 -0
  1107. package/Neurai/src/qt/res/src/connect-1.svg +69 -0
  1108. package/Neurai/src/qt/res/src/connect-2.svg +59 -0
  1109. package/Neurai/src/qt/res/src/connect-3.svg +72 -0
  1110. package/Neurai/src/qt/res/src/connect-4.svg +65 -0
  1111. package/Neurai/src/qt/res/src/hd_disabled.svg +26 -0
  1112. package/Neurai/src/qt/res/src/hd_enabled.svg +13 -0
  1113. package/Neurai/src/qt/res/src/mine.svg +12 -0
  1114. package/Neurai/src/qt/res/src/network_disabled.svg +49 -0
  1115. package/Neurai/src/qt/res/src/neurai.svg +37 -0
  1116. package/Neurai/src/qt/res/src/qt.svg +26 -0
  1117. package/Neurai/src/qt/res/src/spinner.png +0 -0
  1118. package/Neurai/src/qt/res/src/transaction0.svg +35 -0
  1119. package/Neurai/src/qt/res/src/tx_in.svg +9 -0
  1120. package/Neurai/src/qt/res/src/tx_inout.svg +11 -0
  1121. package/Neurai/src/qt/res/src/verify.svg +14 -0
  1122. package/Neurai/src/qt/restrictedassetsdialog.cpp +468 -0
  1123. package/Neurai/src/qt/restrictedassetsdialog.h +77 -0
  1124. package/Neurai/src/qt/restrictedassignqualifier.cpp +221 -0
  1125. package/Neurai/src/qt/restrictedassignqualifier.h +67 -0
  1126. package/Neurai/src/qt/restrictedfreezeaddress.cpp +240 -0
  1127. package/Neurai/src/qt/restrictedfreezeaddress.h +68 -0
  1128. package/Neurai/src/qt/rpcconsole.cpp +1287 -0
  1129. package/Neurai/src/qt/rpcconsole.h +174 -0
  1130. package/Neurai/src/qt/sendassetsentry.cpp +571 -0
  1131. package/Neurai/src/qt/sendassetsentry.h +96 -0
  1132. package/Neurai/src/qt/sendcoinsdialog.cpp +1015 -0
  1133. package/Neurai/src/qt/sendcoinsdialog.h +128 -0
  1134. package/Neurai/src/qt/sendcoinsentry.cpp +293 -0
  1135. package/Neurai/src/qt/sendcoinsentry.h +75 -0
  1136. package/Neurai/src/qt/signverifymessagedialog.cpp +280 -0
  1137. package/Neurai/src/qt/signverifymessagedialog.h +55 -0
  1138. package/Neurai/src/qt/splashscreen.cpp +258 -0
  1139. package/Neurai/src/qt/splashscreen.h +59 -0
  1140. package/Neurai/src/qt/test/compattests.cpp +25 -0
  1141. package/Neurai/src/qt/test/compattests.h +21 -0
  1142. package/Neurai/src/qt/test/paymentrequestdata.h +462 -0
  1143. package/Neurai/src/qt/test/paymentservertests.cpp +213 -0
  1144. package/Neurai/src/qt/test/paymentservertests.h +37 -0
  1145. package/Neurai/src/qt/test/rpcnestedtests.cpp +135 -0
  1146. package/Neurai/src/qt/test/rpcnestedtests.h +27 -0
  1147. package/Neurai/src/qt/test/test_main.cpp +116 -0
  1148. package/Neurai/src/qt/test/uritests.cpp +68 -0
  1149. package/Neurai/src/qt/test/uritests.h +21 -0
  1150. package/Neurai/src/qt/test/wallettests.cpp +265 -0
  1151. package/Neurai/src/qt/test/wallettests.h +15 -0
  1152. package/Neurai/src/qt/trafficgraphwidget.cpp +178 -0
  1153. package/Neurai/src/qt/trafficgraphwidget.h +50 -0
  1154. package/Neurai/src/qt/transactiondesc.cpp +478 -0
  1155. package/Neurai/src/qt/transactiondesc.h +35 -0
  1156. package/Neurai/src/qt/transactiondescdialog.cpp +30 -0
  1157. package/Neurai/src/qt/transactiondescdialog.h +33 -0
  1158. package/Neurai/src/qt/transactionfilterproxy.cpp +126 -0
  1159. package/Neurai/src/qt/transactionfilterproxy.h +71 -0
  1160. package/Neurai/src/qt/transactionrecord.cpp +543 -0
  1161. package/Neurai/src/qt/transactionrecord.h +151 -0
  1162. package/Neurai/src/qt/transactiontablemodel.cpp +857 -0
  1163. package/Neurai/src/qt/transactiontablemodel.h +125 -0
  1164. package/Neurai/src/qt/transactionview.cpp +690 -0
  1165. package/Neurai/src/qt/transactionview.h +126 -0
  1166. package/Neurai/src/qt/utilitydialog.cpp +201 -0
  1167. package/Neurai/src/qt/utilitydialog.h +53 -0
  1168. package/Neurai/src/qt/walletframe.cpp +243 -0
  1169. package/Neurai/src/qt/walletframe.h +109 -0
  1170. package/Neurai/src/qt/walletmodel.cpp +924 -0
  1171. package/Neurai/src/qt/walletmodel.h +372 -0
  1172. package/Neurai/src/qt/walletmodeltransaction.cpp +100 -0
  1173. package/Neurai/src/qt/walletmodeltransaction.h +50 -0
  1174. package/Neurai/src/qt/walletview.cpp +454 -0
  1175. package/Neurai/src/qt/walletview.h +160 -0
  1176. package/Neurai/src/qt/winshutdownmonitor.cpp +72 -0
  1177. package/Neurai/src/qt/winshutdownmonitor.h +31 -0
  1178. package/Neurai/src/random.cpp +469 -0
  1179. package/Neurai/src/random.h +170 -0
  1180. package/Neurai/src/rest.cpp +597 -0
  1181. package/Neurai/src/reverse_iterator.h +39 -0
  1182. package/Neurai/src/reverselock.h +36 -0
  1183. package/Neurai/src/rpc/assets.cpp +3404 -0
  1184. package/Neurai/src/rpc/blockchain.cpp +1938 -0
  1185. package/Neurai/src/rpc/blockchain.h +45 -0
  1186. package/Neurai/src/rpc/client.cpp +307 -0
  1187. package/Neurai/src/rpc/client.h +24 -0
  1188. package/Neurai/src/rpc/messages.cpp +1653 -0
  1189. package/Neurai/src/rpc/mining.cpp +1299 -0
  1190. package/Neurai/src/rpc/mining.h +25 -0
  1191. package/Neurai/src/rpc/misc.cpp +1414 -0
  1192. package/Neurai/src/rpc/net.cpp +674 -0
  1193. package/Neurai/src/rpc/protocol.cpp +158 -0
  1194. package/Neurai/src/rpc/protocol.h +106 -0
  1195. package/Neurai/src/rpc/rawtransaction.cpp +2220 -0
  1196. package/Neurai/src/rpc/register.h +43 -0
  1197. package/Neurai/src/rpc/rewards.cpp +503 -0
  1198. package/Neurai/src/rpc/safemode.cpp +14 -0
  1199. package/Neurai/src/rpc/safemode.h +14 -0
  1200. package/Neurai/src/rpc/server.cpp +674 -0
  1201. package/Neurai/src/rpc/server.h +205 -0
  1202. package/Neurai/src/rpc/test.json +45 -0
  1203. package/Neurai/src/scheduler.cpp +211 -0
  1204. package/Neurai/src/scheduler.h +115 -0
  1205. package/Neurai/src/script/interpreter.cpp +1756 -0
  1206. package/Neurai/src/script/interpreter.h +193 -0
  1207. package/Neurai/src/script/ismine.cpp +205 -0
  1208. package/Neurai/src/script/ismine.h +43 -0
  1209. package/Neurai/src/script/neuraiconsensus.cpp +131 -0
  1210. package/Neurai/src/script/neuraiconsensus.h +85 -0
  1211. package/Neurai/src/script/script.cpp +601 -0
  1212. package/Neurai/src/script/script.h +742 -0
  1213. package/Neurai/src/script/script_error.cpp +99 -0
  1214. package/Neurai/src/script/script_error.h +76 -0
  1215. package/Neurai/src/script/sigcache.cpp +96 -0
  1216. package/Neurai/src/script/sigcache.h +58 -0
  1217. package/Neurai/src/script/sign.cpp +482 -0
  1218. package/Neurai/src/script/sign.h +86 -0
  1219. package/Neurai/src/script/standard.cpp +414 -0
  1220. package/Neurai/src/script/standard.h +162 -0
  1221. package/Neurai/src/secp256k1/.travis.yml +108 -0
  1222. package/Neurai/src/secp256k1/COPYING +19 -0
  1223. package/Neurai/src/secp256k1/Makefile.am +164 -0
  1224. package/Neurai/src/secp256k1/README.md +104 -0
  1225. package/Neurai/src/secp256k1/SECURITY.md +15 -0
  1226. package/Neurai/src/secp256k1/autogen.sh +3 -0
  1227. package/Neurai/src/secp256k1/build-aux/compile +351 -0
  1228. package/Neurai/src/secp256k1/build-aux/config.guess +1815 -0
  1229. package/Neurai/src/secp256k1/build-aux/config.sub +2354 -0
  1230. package/Neurai/src/secp256k1/build-aux/depcomp +792 -0
  1231. package/Neurai/src/secp256k1/build-aux/install-sh +541 -0
  1232. package/Neurai/src/secp256k1/build-aux/ltmain.sh +11523 -0
  1233. package/Neurai/src/secp256k1/build-aux/m4/ax_prog_cc_for_build.m4 +125 -0
  1234. package/Neurai/src/secp256k1/build-aux/m4/bitcoin_secp.m4 +89 -0
  1235. package/Neurai/src/secp256k1/build-aux/m4/libtool.m4 +8513 -0
  1236. package/Neurai/src/secp256k1/build-aux/m4/ltoptions.m4 +467 -0
  1237. package/Neurai/src/secp256k1/build-aux/m4/ltsugar.m4 +124 -0
  1238. package/Neurai/src/secp256k1/build-aux/m4/ltversion.m4 +24 -0
  1239. package/Neurai/src/secp256k1/build-aux/m4/lt~obsolete.m4 +99 -0
  1240. package/Neurai/src/secp256k1/build-aux/missing +236 -0
  1241. package/Neurai/src/secp256k1/build-aux/test-driver +160 -0
  1242. package/Neurai/src/secp256k1/configure.ac +529 -0
  1243. package/Neurai/src/secp256k1/contrib/lax_der_parsing.c +149 -0
  1244. package/Neurai/src/secp256k1/contrib/lax_der_parsing.h +91 -0
  1245. package/Neurai/src/secp256k1/contrib/lax_der_privatekey_parsing.c +113 -0
  1246. package/Neurai/src/secp256k1/contrib/lax_der_privatekey_parsing.h +90 -0
  1247. package/Neurai/src/secp256k1/contrib/travis.sh +68 -0
  1248. package/Neurai/src/secp256k1/include/secp256k1.h +764 -0
  1249. package/Neurai/src/secp256k1/include/secp256k1_ecdh.h +62 -0
  1250. package/Neurai/src/secp256k1/include/secp256k1_extrakeys.h +236 -0
  1251. package/Neurai/src/secp256k1/include/secp256k1_preallocated.h +128 -0
  1252. package/Neurai/src/secp256k1/include/secp256k1_recovery.h +110 -0
  1253. package/Neurai/src/secp256k1/include/secp256k1_schnorrsig.h +111 -0
  1254. package/Neurai/src/secp256k1/libsecp256k1.pc.in +13 -0
  1255. package/Neurai/src/secp256k1/sage/gen_exhaustive_groups.sage +129 -0
  1256. package/Neurai/src/secp256k1/sage/group_prover.sage +322 -0
  1257. package/Neurai/src/secp256k1/sage/secp256k1.sage +306 -0
  1258. package/Neurai/src/secp256k1/sage/weierstrass_prover.sage +264 -0
  1259. package/Neurai/src/secp256k1/src/asm/field_10x26_arm.s +913 -0
  1260. package/Neurai/src/secp256k1/src/assumptions.h +80 -0
  1261. package/Neurai/src/secp256k1/src/basic-config.h +34 -0
  1262. package/Neurai/src/secp256k1/src/bench.h +133 -0
  1263. package/Neurai/src/secp256k1/src/bench_ecdh.c +59 -0
  1264. package/Neurai/src/secp256k1/src/bench_ecmult.c +214 -0
  1265. package/Neurai/src/secp256k1/src/bench_internal.c +431 -0
  1266. package/Neurai/src/secp256k1/src/bench_recover.c +62 -0
  1267. package/Neurai/src/secp256k1/src/bench_schnorrsig.c +102 -0
  1268. package/Neurai/src/secp256k1/src/bench_sign.c +58 -0
  1269. package/Neurai/src/secp256k1/src/bench_verify.c +115 -0
  1270. package/Neurai/src/secp256k1/src/ecdsa.h +21 -0
  1271. package/Neurai/src/secp256k1/src/ecdsa_impl.h +315 -0
  1272. package/Neurai/src/secp256k1/src/eckey.h +25 -0
  1273. package/Neurai/src/secp256k1/src/eckey_impl.h +96 -0
  1274. package/Neurai/src/secp256k1/src/ecmult.h +46 -0
  1275. package/Neurai/src/secp256k1/src/ecmult_const.h +20 -0
  1276. package/Neurai/src/secp256k1/src/ecmult_const_impl.h +254 -0
  1277. package/Neurai/src/secp256k1/src/ecmult_gen.h +50 -0
  1278. package/Neurai/src/secp256k1/src/ecmult_gen_impl.h +208 -0
  1279. package/Neurai/src/secp256k1/src/ecmult_impl.h +1083 -0
  1280. package/Neurai/src/secp256k1/src/field.h +134 -0
  1281. package/Neurai/src/secp256k1/src/field_10x26.h +50 -0
  1282. package/Neurai/src/secp256k1/src/field_10x26_impl.h +1167 -0
  1283. package/Neurai/src/secp256k1/src/field_5x52.h +55 -0
  1284. package/Neurai/src/secp256k1/src/field_5x52_asm_impl.h +502 -0
  1285. package/Neurai/src/secp256k1/src/field_5x52_impl.h +501 -0
  1286. package/Neurai/src/secp256k1/src/field_5x52_int128_impl.h +279 -0
  1287. package/Neurai/src/secp256k1/src/field_impl.h +320 -0
  1288. package/Neurai/src/secp256k1/src/gen_context.c +88 -0
  1289. package/Neurai/src/secp256k1/src/group.h +151 -0
  1290. package/Neurai/src/secp256k1/src/group_impl.h +693 -0
  1291. package/Neurai/src/secp256k1/src/hash.h +41 -0
  1292. package/Neurai/src/secp256k1/src/hash_impl.h +297 -0
  1293. package/Neurai/src/secp256k1/src/libsecp256k1-config.h.in +139 -0
  1294. package/Neurai/src/secp256k1/src/modules/ecdh/Makefile.am.include +8 -0
  1295. package/Neurai/src/secp256k1/src/modules/ecdh/main_impl.h +71 -0
  1296. package/Neurai/src/secp256k1/src/modules/ecdh/tests_impl.h +132 -0
  1297. package/Neurai/src/secp256k1/src/modules/extrakeys/Makefile.am.include +4 -0
  1298. package/Neurai/src/secp256k1/src/modules/extrakeys/main_impl.h +251 -0
  1299. package/Neurai/src/secp256k1/src/modules/extrakeys/tests_exhaustive_impl.h +68 -0
  1300. package/Neurai/src/secp256k1/src/modules/extrakeys/tests_impl.h +524 -0
  1301. package/Neurai/src/secp256k1/src/modules/recovery/Makefile.am.include +9 -0
  1302. package/Neurai/src/secp256k1/src/modules/recovery/main_impl.h +160 -0
  1303. package/Neurai/src/secp256k1/src/modules/recovery/tests_exhaustive_impl.h +149 -0
  1304. package/Neurai/src/secp256k1/src/modules/recovery/tests_impl.h +393 -0
  1305. package/Neurai/src/secp256k1/src/modules/schnorrsig/Makefile.am.include +9 -0
  1306. package/Neurai/src/secp256k1/src/modules/schnorrsig/main_impl.h +239 -0
  1307. package/Neurai/src/secp256k1/src/modules/schnorrsig/tests_exhaustive_impl.h +206 -0
  1308. package/Neurai/src/secp256k1/src/modules/schnorrsig/tests_impl.h +806 -0
  1309. package/Neurai/src/secp256k1/src/num.h +74 -0
  1310. package/Neurai/src/secp256k1/src/num_gmp.h +20 -0
  1311. package/Neurai/src/secp256k1/src/num_gmp_impl.h +288 -0
  1312. package/Neurai/src/secp256k1/src/num_impl.h +24 -0
  1313. package/Neurai/src/secp256k1/src/scalar.h +117 -0
  1314. package/Neurai/src/secp256k1/src/scalar_4x64.h +19 -0
  1315. package/Neurai/src/secp256k1/src/scalar_4x64_impl.h +958 -0
  1316. package/Neurai/src/secp256k1/src/scalar_8x32.h +19 -0
  1317. package/Neurai/src/secp256k1/src/scalar_8x32_impl.h +734 -0
  1318. package/Neurai/src/secp256k1/src/scalar_impl.h +516 -0
  1319. package/Neurai/src/secp256k1/src/scalar_low.h +17 -0
  1320. package/Neurai/src/secp256k1/src/scalar_low_impl.h +128 -0
  1321. package/Neurai/src/secp256k1/src/scratch.h +42 -0
  1322. package/Neurai/src/secp256k1/src/scratch_impl.h +99 -0
  1323. package/Neurai/src/secp256k1/src/secp256k1.c +774 -0
  1324. package/Neurai/src/secp256k1/src/selftest.h +32 -0
  1325. package/Neurai/src/secp256k1/src/testrand.h +47 -0
  1326. package/Neurai/src/secp256k1/src/testrand_impl.h +158 -0
  1327. package/Neurai/src/secp256k1/src/tests.c +5737 -0
  1328. package/Neurai/src/secp256k1/src/tests_exhaustive.c +454 -0
  1329. package/Neurai/src/secp256k1/src/util.h +273 -0
  1330. package/Neurai/src/secp256k1/src/valgrind_ctime_test.c +157 -0
  1331. package/Neurai/src/serialize.h +979 -0
  1332. package/Neurai/src/spentindex.h +98 -0
  1333. package/Neurai/src/streams.h +711 -0
  1334. package/Neurai/src/support/allocators/secure.h +61 -0
  1335. package/Neurai/src/support/allocators/zeroafterfree.h +50 -0
  1336. package/Neurai/src/support/cleanse.cpp +41 -0
  1337. package/Neurai/src/support/cleanse.h +16 -0
  1338. package/Neurai/src/support/events.h +58 -0
  1339. package/Neurai/src/support/lockedpool.cpp +392 -0
  1340. package/Neurai/src/support/lockedpool.h +233 -0
  1341. package/Neurai/src/sync.cpp +182 -0
  1342. package/Neurai/src/sync.h +291 -0
  1343. package/Neurai/src/test/DoS_tests.cpp +286 -0
  1344. package/Neurai/src/test/README.md +84 -0
  1345. package/Neurai/src/test/addrman_tests.cpp +560 -0
  1346. package/Neurai/src/test/allocator_tests.cpp +255 -0
  1347. package/Neurai/src/test/amount_tests.cpp +118 -0
  1348. package/Neurai/src/test/arith_uint256_tests.cpp +629 -0
  1349. package/Neurai/src/test/assets/asset_reissue_tests.cpp +207 -0
  1350. package/Neurai/src/test/assets/asset_tests.cpp +735 -0
  1351. package/Neurai/src/test/assets/asset_tx_tests.cpp +610 -0
  1352. package/Neurai/src/test/assets/cache_tests.cpp +41 -0
  1353. package/Neurai/src/test/assets/messaging_tests.cpp +82 -0
  1354. package/Neurai/src/test/assets/null_asset_data_tests.cpp +77 -0
  1355. package/Neurai/src/test/assets/qualifier_tests.cpp +122 -0
  1356. package/Neurai/src/test/assets/restricted_tests.cpp +188 -0
  1357. package/Neurai/src/test/assets/serialization_tests.cpp +179 -0
  1358. package/Neurai/src/test/assets/unique_tests.cpp +65 -0
  1359. package/Neurai/src/test/assets/verifier_string_tests.cpp +371 -0
  1360. package/Neurai/src/test/base32_tests.cpp +29 -0
  1361. package/Neurai/src/test/base58_tests.cpp +282 -0
  1362. package/Neurai/src/test/base64_tests.cpp +29 -0
  1363. package/Neurai/src/test/bech32_tests.cpp +75 -0
  1364. package/Neurai/src/test/bip32_tests.cpp +179 -0
  1365. package/Neurai/src/test/bip39_tests.cpp +67 -0
  1366. package/Neurai/src/test/blockencodings_tests.cpp +360 -0
  1367. package/Neurai/src/test/bloom_tests.cpp +574 -0
  1368. package/Neurai/src/test/bswap_tests.cpp +30 -0
  1369. package/Neurai/src/test/checkqueue_tests.cpp +554 -0
  1370. package/Neurai/src/test/coins_tests.cpp +949 -0
  1371. package/Neurai/src/test/compress_tests.cpp +72 -0
  1372. package/Neurai/src/test/crypto_tests.cpp +599 -0
  1373. package/Neurai/src/test/cuckoocache_tests.cpp +406 -0
  1374. package/Neurai/src/test/data/README.md +12 -0
  1375. package/Neurai/src/test/data/base58_encode_decode.json +14 -0
  1376. package/Neurai/src/test/data/base58_keys_invalid.json +152 -0
  1377. package/Neurai/src/test/data/base58_keys_valid.json +452 -0
  1378. package/Neurai/src/test/data/bip39_vectors.json +146 -0
  1379. package/Neurai/src/test/data/script_tests.json +2607 -0
  1380. package/Neurai/src/test/data/sighash.json +503 -0
  1381. package/Neurai/src/test/data/tx_invalid.json +344 -0
  1382. package/Neurai/src/test/data/tx_valid.json +514 -0
  1383. package/Neurai/src/test/dbwrapper_tests.cpp +365 -0
  1384. package/Neurai/src/test/getarg_tests.cpp +173 -0
  1385. package/Neurai/src/test/hash_tests.cpp +185 -0
  1386. package/Neurai/src/test/kawpow_tests.cpp +142 -0
  1387. package/Neurai/src/test/key_tests.cpp +169 -0
  1388. package/Neurai/src/test/limitedmap_tests.cpp +112 -0
  1389. package/Neurai/src/test/main_tests.cpp +91 -0
  1390. package/Neurai/src/test/mempool_tests.cpp +601 -0
  1391. package/Neurai/src/test/merkle_tests.cpp +152 -0
  1392. package/Neurai/src/test/merkleblock_tests.cpp +84 -0
  1393. package/Neurai/src/test/miner_tests.cpp +661 -0
  1394. package/Neurai/src/test/multisig_tests.cpp +240 -0
  1395. package/Neurai/src/test/net_tests.cpp +202 -0
  1396. package/Neurai/src/test/netbase_tests.cpp +318 -0
  1397. package/Neurai/src/test/pmt_tests.cpp +139 -0
  1398. package/Neurai/src/test/policyestimator_tests.cpp +209 -0
  1399. package/Neurai/src/test/pow_tests.cpp +100 -0
  1400. package/Neurai/src/test/prevector_tests.cpp +321 -0
  1401. package/Neurai/src/test/raii_event_tests.cpp +102 -0
  1402. package/Neurai/src/test/random_tests.cpp +98 -0
  1403. package/Neurai/src/test/reverselock_tests.cpp +68 -0
  1404. package/Neurai/src/test/rpc_tests.cpp +393 -0
  1405. package/Neurai/src/test/sanity_tests.cpp +24 -0
  1406. package/Neurai/src/test/scheduler_tests.cpp +127 -0
  1407. package/Neurai/src/test/script_P2PKH_tests.cpp +65 -0
  1408. package/Neurai/src/test/script_P2PK_tests.cpp +52 -0
  1409. package/Neurai/src/test/script_P2SH_tests.cpp +392 -0
  1410. package/Neurai/src/test/script_standard_tests.cpp +802 -0
  1411. package/Neurai/src/test/script_tests.cpp +1650 -0
  1412. package/Neurai/src/test/scriptnum10.h +222 -0
  1413. package/Neurai/src/test/scriptnum_tests.cpp +207 -0
  1414. package/Neurai/src/test/serialize_tests.cpp +439 -0
  1415. package/Neurai/src/test/sighash_tests.cpp +225 -0
  1416. package/Neurai/src/test/sigopcount_tests.cpp +242 -0
  1417. package/Neurai/src/test/skiplist_tests.cpp +207 -0
  1418. package/Neurai/src/test/streams_tests.cpp +129 -0
  1419. package/Neurai/src/test/test_neurai.cpp +183 -0
  1420. package/Neurai/src/test/test_neurai.h +164 -0
  1421. package/Neurai/src/test/test_neurai_fuzzy.cpp +339 -0
  1422. package/Neurai/src/test/test_neurai_hash.cpp +39 -0
  1423. package/Neurai/src/test/test_neurai_main.cpp +28 -0
  1424. package/Neurai/src/test/timedata_tests.cpp +41 -0
  1425. package/Neurai/src/test/torcontrol_tests.cpp +204 -0
  1426. package/Neurai/src/test/transaction_tests.cpp +867 -0
  1427. package/Neurai/src/test/txvalidationcache_tests.cpp +398 -0
  1428. package/Neurai/src/test/uint256_tests.cpp +279 -0
  1429. package/Neurai/src/test/univalue_tests.cpp +347 -0
  1430. package/Neurai/src/test/util_tests.cpp +674 -0
  1431. package/Neurai/src/test/versionbits_tests.cpp +392 -0
  1432. package/Neurai/src/threadinterrupt.cpp +43 -0
  1433. package/Neurai/src/threadinterrupt.h +36 -0
  1434. package/Neurai/src/threadsafety.h +57 -0
  1435. package/Neurai/src/timedata.cpp +122 -0
  1436. package/Neurai/src/timedata.h +80 -0
  1437. package/Neurai/src/timestampindex.h +131 -0
  1438. package/Neurai/src/tinyformat.h +1056 -0
  1439. package/Neurai/src/torcontrol.cpp +779 -0
  1440. package/Neurai/src/torcontrol.h +22 -0
  1441. package/Neurai/src/txdb.cpp +654 -0
  1442. package/Neurai/src/txdb.h +158 -0
  1443. package/Neurai/src/txmempool.cpp +1520 -0
  1444. package/Neurai/src/txmempool.h +850 -0
  1445. package/Neurai/src/ui_interface.cpp +31 -0
  1446. package/Neurai/src/ui_interface.h +130 -0
  1447. package/Neurai/src/uint256.cpp +81 -0
  1448. package/Neurai/src/uint256.h +180 -0
  1449. package/Neurai/src/undo.h +124 -0
  1450. package/Neurai/src/univalue/.travis.yml +52 -0
  1451. package/Neurai/src/univalue/COPYING +19 -0
  1452. package/Neurai/src/univalue/Makefile.am +116 -0
  1453. package/Neurai/src/univalue/README.md +32 -0
  1454. package/Neurai/src/univalue/TODO +10 -0
  1455. package/Neurai/src/univalue/autogen.sh +9 -0
  1456. package/Neurai/src/univalue/build-aux/compile +351 -0
  1457. package/Neurai/src/univalue/build-aux/config.guess +1815 -0
  1458. package/Neurai/src/univalue/build-aux/config.sub +2354 -0
  1459. package/Neurai/src/univalue/build-aux/depcomp +792 -0
  1460. package/Neurai/src/univalue/build-aux/install-sh +541 -0
  1461. package/Neurai/src/univalue/build-aux/ltmain.sh +11523 -0
  1462. package/Neurai/src/univalue/build-aux/m4/libtool.m4 +8513 -0
  1463. package/Neurai/src/univalue/build-aux/m4/ltoptions.m4 +467 -0
  1464. package/Neurai/src/univalue/build-aux/m4/ltsugar.m4 +124 -0
  1465. package/Neurai/src/univalue/build-aux/m4/ltversion.m4 +24 -0
  1466. package/Neurai/src/univalue/build-aux/m4/lt~obsolete.m4 +99 -0
  1467. package/Neurai/src/univalue/build-aux/missing +236 -0
  1468. package/Neurai/src/univalue/build-aux/test-driver +160 -0
  1469. package/Neurai/src/univalue/configure.ac +69 -0
  1470. package/Neurai/src/univalue/gen/gen.cpp +85 -0
  1471. package/Neurai/src/univalue/include/univalue.h +305 -0
  1472. package/Neurai/src/univalue/lib/univalue.cpp +244 -0
  1473. package/Neurai/src/univalue/lib/univalue_escapes.h +262 -0
  1474. package/Neurai/src/univalue/lib/univalue_get.cpp +198 -0
  1475. package/Neurai/src/univalue/lib/univalue_read.cpp +451 -0
  1476. package/Neurai/src/univalue/lib/univalue_utffilter.h +119 -0
  1477. package/Neurai/src/univalue/lib/univalue_write.cpp +115 -0
  1478. package/Neurai/src/univalue/pc/libunivalue-uninstalled.pc.in +9 -0
  1479. package/Neurai/src/univalue/pc/libunivalue.pc.in +10 -0
  1480. package/Neurai/src/univalue/test/fail1.json +1 -0
  1481. package/Neurai/src/univalue/test/fail10.json +1 -0
  1482. package/Neurai/src/univalue/test/fail11.json +1 -0
  1483. package/Neurai/src/univalue/test/fail12.json +1 -0
  1484. package/Neurai/src/univalue/test/fail13.json +1 -0
  1485. package/Neurai/src/univalue/test/fail14.json +1 -0
  1486. package/Neurai/src/univalue/test/fail15.json +1 -0
  1487. package/Neurai/src/univalue/test/fail16.json +1 -0
  1488. package/Neurai/src/univalue/test/fail17.json +1 -0
  1489. package/Neurai/src/univalue/test/fail18.json +1 -0
  1490. package/Neurai/src/univalue/test/fail19.json +1 -0
  1491. package/Neurai/src/univalue/test/fail2.json +1 -0
  1492. package/Neurai/src/univalue/test/fail20.json +1 -0
  1493. package/Neurai/src/univalue/test/fail21.json +1 -0
  1494. package/Neurai/src/univalue/test/fail22.json +1 -0
  1495. package/Neurai/src/univalue/test/fail23.json +1 -0
  1496. package/Neurai/src/univalue/test/fail24.json +1 -0
  1497. package/Neurai/src/univalue/test/fail25.json +1 -0
  1498. package/Neurai/src/univalue/test/fail26.json +1 -0
  1499. package/Neurai/src/univalue/test/fail27.json +2 -0
  1500. package/Neurai/src/univalue/test/fail28.json +2 -0
  1501. package/Neurai/src/univalue/test/fail29.json +1 -0
  1502. package/Neurai/src/univalue/test/fail3.json +1 -0
  1503. package/Neurai/src/univalue/test/fail30.json +1 -0
  1504. package/Neurai/src/univalue/test/fail31.json +1 -0
  1505. package/Neurai/src/univalue/test/fail32.json +1 -0
  1506. package/Neurai/src/univalue/test/fail33.json +1 -0
  1507. package/Neurai/src/univalue/test/fail34.json +1 -0
  1508. package/Neurai/src/univalue/test/fail35.json +1 -0
  1509. package/Neurai/src/univalue/test/fail36.json +1 -0
  1510. package/Neurai/src/univalue/test/fail37.json +1 -0
  1511. package/Neurai/src/univalue/test/fail38.json +1 -0
  1512. package/Neurai/src/univalue/test/fail39.json +1 -0
  1513. package/Neurai/src/univalue/test/fail4.json +1 -0
  1514. package/Neurai/src/univalue/test/fail40.json +1 -0
  1515. package/Neurai/src/univalue/test/fail41.json +1 -0
  1516. package/Neurai/src/univalue/test/fail42.json +0 -0
  1517. package/Neurai/src/univalue/test/fail44.json +1 -0
  1518. package/Neurai/src/univalue/test/fail5.json +1 -0
  1519. package/Neurai/src/univalue/test/fail6.json +1 -0
  1520. package/Neurai/src/univalue/test/fail7.json +1 -0
  1521. package/Neurai/src/univalue/test/fail8.json +1 -0
  1522. package/Neurai/src/univalue/test/fail9.json +1 -0
  1523. package/Neurai/src/univalue/test/no_nul.cpp +8 -0
  1524. package/Neurai/src/univalue/test/object.cpp +397 -0
  1525. package/Neurai/src/univalue/test/pass1.json +58 -0
  1526. package/Neurai/src/univalue/test/pass2.json +1 -0
  1527. package/Neurai/src/univalue/test/pass3.json +6 -0
  1528. package/Neurai/src/univalue/test/round1.json +1 -0
  1529. package/Neurai/src/univalue/test/round2.json +1 -0
  1530. package/Neurai/src/univalue/test/round3.json +1 -0
  1531. package/Neurai/src/univalue/test/round4.json +1 -0
  1532. package/Neurai/src/univalue/test/round5.json +1 -0
  1533. package/Neurai/src/univalue/test/round6.json +1 -0
  1534. package/Neurai/src/univalue/test/round7.json +1 -0
  1535. package/Neurai/src/univalue/test/test_json.cpp +24 -0
  1536. package/Neurai/src/univalue/test/unitester.cpp +170 -0
  1537. package/Neurai/src/univalue/univalue-config.h.in +63 -0
  1538. package/Neurai/src/util.cpp +955 -0
  1539. package/Neurai/src/util.h +366 -0
  1540. package/Neurai/src/utilmoneystr.cpp +79 -0
  1541. package/Neurai/src/utilmoneystr.h +26 -0
  1542. package/Neurai/src/utilstrencodings.cpp +736 -0
  1543. package/Neurai/src/utilstrencodings.h +160 -0
  1544. package/Neurai/src/utiltime.cpp +89 -0
  1545. package/Neurai/src/utiltime.h +34 -0
  1546. package/Neurai/src/validation.cpp +5949 -0
  1547. package/Neurai/src/validation.h +620 -0
  1548. package/Neurai/src/validationinterface.cpp +146 -0
  1549. package/Neurai/src/validationinterface.h +115 -0
  1550. package/Neurai/src/version.h +64 -0
  1551. package/Neurai/src/versionbits.cpp +244 -0
  1552. package/Neurai/src/versionbits.h +84 -0
  1553. package/Neurai/src/wallet/bip39.cpp +236 -0
  1554. package/Neurai/src/wallet/bip39.h +67 -0
  1555. package/Neurai/src/wallet/bip39_chinese_simplified.h +2074 -0
  1556. package/Neurai/src/wallet/bip39_chinese_traditional.h +2074 -0
  1557. package/Neurai/src/wallet/bip39_english.h +2074 -0
  1558. package/Neurai/src/wallet/bip39_french.h +2074 -0
  1559. package/Neurai/src/wallet/bip39_italian.h +2074 -0
  1560. package/Neurai/src/wallet/bip39_japanese.h +2074 -0
  1561. package/Neurai/src/wallet/bip39_korean.h +2074 -0
  1562. package/Neurai/src/wallet/bip39_spanish.h +2074 -0
  1563. package/Neurai/src/wallet/coincontrol.h +134 -0
  1564. package/Neurai/src/wallet/crypter.cpp +413 -0
  1565. package/Neurai/src/wallet/crypter.h +208 -0
  1566. package/Neurai/src/wallet/db.cpp +728 -0
  1567. package/Neurai/src/wallet/db.h +373 -0
  1568. package/Neurai/src/wallet/feebumper.cpp +292 -0
  1569. package/Neurai/src/wallet/feebumper.h +63 -0
  1570. package/Neurai/src/wallet/fees.cpp +91 -0
  1571. package/Neurai/src/wallet/fees.h +36 -0
  1572. package/Neurai/src/wallet/init.cpp +288 -0
  1573. package/Neurai/src/wallet/init.h +45 -0
  1574. package/Neurai/src/wallet/rpcdump.cpp +1363 -0
  1575. package/Neurai/src/wallet/rpcwallet.cpp +3589 -0
  1576. package/Neurai/src/wallet/rpcwallet.h +30 -0
  1577. package/Neurai/src/wallet/test/accounting_tests.cpp +142 -0
  1578. package/Neurai/src/wallet/test/crypto_tests.cpp +136 -0
  1579. package/Neurai/src/wallet/test/wallet_test_fixture.cpp +37 -0
  1580. package/Neurai/src/wallet/test/wallet_test_fixture.h +22 -0
  1581. package/Neurai/src/wallet/test/wallet_tests.cpp +720 -0
  1582. package/Neurai/src/wallet/wallet.cpp +4998 -0
  1583. package/Neurai/src/wallet/wallet.h +1307 -0
  1584. package/Neurai/src/wallet/walletdb.cpp +1049 -0
  1585. package/Neurai/src/wallet/walletdb.h +292 -0
  1586. package/Neurai/src/warnings.cpp +85 -0
  1587. package/Neurai/src/warnings.h +29 -0
  1588. package/Neurai/src/zmq/zmqabstractnotifier.cpp +29 -0
  1589. package/Neurai/src/zmq/zmqabstractnotifier.h +48 -0
  1590. package/Neurai/src/zmq/zmqconfig.h +26 -0
  1591. package/Neurai/src/zmq/zmqnotificationinterface.cpp +202 -0
  1592. package/Neurai/src/zmq/zmqnotificationinterface.h +43 -0
  1593. package/Neurai/src/zmq/zmqpublishnotifier.cpp +209 -0
  1594. package/Neurai/src/zmq/zmqpublishnotifier.h +64 -0
  1595. package/Neurai/test/README.md +187 -0
  1596. package/Neurai/test/config.ini.in +20 -0
  1597. package/Neurai/test/functional/README.md +102 -0
  1598. package/Neurai/test/functional/combine_logs.py +123 -0
  1599. package/Neurai/test/functional/combined_log_template.html +40 -0
  1600. package/Neurai/test/functional/create_cache.py +30 -0
  1601. package/Neurai/test/functional/example_test.py +194 -0
  1602. package/Neurai/test/functional/feature_assets.py +365 -0
  1603. package/Neurai/test/functional/feature_assets_mempool.py +153 -0
  1604. package/Neurai/test/functional/feature_assets_reorg.py +154 -0
  1605. package/Neurai/test/functional/feature_assumevalid.py +199 -0
  1606. package/Neurai/test/functional/feature_bip68_sequence.py +387 -0
  1607. package/Neurai/test/functional/feature_cltv.py +164 -0
  1608. package/Neurai/test/functional/feature_dbcrash.py +284 -0
  1609. package/Neurai/test/functional/feature_dersig.py +155 -0
  1610. package/Neurai/test/functional/feature_fee_estimation.py +265 -0
  1611. package/Neurai/test/functional/feature_listmyassets.py +56 -0
  1612. package/Neurai/test/functional/feature_loadblock.py +89 -0
  1613. package/Neurai/test/functional/feature_maxreorgdepth.py +138 -0
  1614. package/Neurai/test/functional/feature_maxuploadtarget.py +183 -0
  1615. package/Neurai/test/functional/feature_messaging.py +139 -0
  1616. package/Neurai/test/functional/feature_minchainwork.py +91 -0
  1617. package/Neurai/test/functional/feature_notifications.py +90 -0
  1618. package/Neurai/test/functional/feature_nulldummy.py +137 -0
  1619. package/Neurai/test/functional/feature_proxy.py +200 -0
  1620. package/Neurai/test/functional/feature_pruning.py +457 -0
  1621. package/Neurai/test/functional/feature_raw_restricted_assets.py +568 -0
  1622. package/Neurai/test/functional/feature_rawassettransactions.py +1845 -0
  1623. package/Neurai/test/functional/feature_rbf.py +571 -0
  1624. package/Neurai/test/functional/feature_reindex.py +43 -0
  1625. package/Neurai/test/functional/feature_restricted_assets.py +591 -0
  1626. package/Neurai/test/functional/feature_rewards.py +1270 -0
  1627. package/Neurai/test/functional/feature_segwit.py +642 -0
  1628. package/Neurai/test/functional/feature_shutdown.py +36 -0
  1629. package/Neurai/test/functional/feature_uacomment.py +37 -0
  1630. package/Neurai/test/functional/feature_unique_assets.py +144 -0
  1631. package/Neurai/test/functional/feature_versionbits_warning.py +131 -0
  1632. package/Neurai/test/functional/interface_http.py +110 -0
  1633. package/Neurai/test/functional/interface_neurai_cli.py +59 -0
  1634. package/Neurai/test/functional/interface_rest.py +329 -0
  1635. package/Neurai/test/functional/interface_rpc.py +77 -0
  1636. package/Neurai/test/functional/interface_zmq.py +125 -0
  1637. package/Neurai/test/functional/mempool_limit.py +68 -0
  1638. package/Neurai/test/functional/mempool_packages.py +245 -0
  1639. package/Neurai/test/functional/mempool_persist.py +112 -0
  1640. package/Neurai/test/functional/mempool_reorg.py +98 -0
  1641. package/Neurai/test/functional/mempool_resurrect.py +70 -0
  1642. package/Neurai/test/functional/mempool_spend_coinbase.py +54 -0
  1643. package/Neurai/test/functional/mining_basic.py +136 -0
  1644. package/Neurai/test/functional/mining_getblocktemplate_longpoll.py +72 -0
  1645. package/Neurai/test/functional/mining_prioritisetransaction.py +130 -0
  1646. package/Neurai/test/functional/p2p_compactblocks.py +939 -0
  1647. package/Neurai/test/functional/p2p_disconnect_ban.py +104 -0
  1648. package/Neurai/test/functional/p2p_feefilter.py +103 -0
  1649. package/Neurai/test/functional/p2p_fingerprint.py +151 -0
  1650. package/Neurai/test/functional/p2p_leak.py +149 -0
  1651. package/Neurai/test/functional/p2p_leak_tx.py +58 -0
  1652. package/Neurai/test/functional/p2p_mempool.py +40 -0
  1653. package/Neurai/test/functional/p2p_segwit.py +1988 -0
  1654. package/Neurai/test/functional/p2p_sendheaders.py +554 -0
  1655. package/Neurai/test/functional/p2p_timeouts.py +85 -0
  1656. package/Neurai/test/functional/p2p_unrequested_blocks.py +250 -0
  1657. package/Neurai/test/functional/rpc_addressindex.py +349 -0
  1658. package/Neurai/test/functional/rpc_assettransfer.py +138 -0
  1659. package/Neurai/test/functional/rpc_bind.py +108 -0
  1660. package/Neurai/test/functional/rpc_blockchain.py +220 -0
  1661. package/Neurai/test/functional/rpc_decodescript.py +210 -0
  1662. package/Neurai/test/functional/rpc_deprecated.py +26 -0
  1663. package/Neurai/test/functional/rpc_fundrawtransaction.py +716 -0
  1664. package/Neurai/test/functional/rpc_getchaintips.py +66 -0
  1665. package/Neurai/test/functional/rpc_invalidateblock.py +67 -0
  1666. package/Neurai/test/functional/rpc_misc.py +57 -0
  1667. package/Neurai/test/functional/rpc_named_arguments.py +35 -0
  1668. package/Neurai/test/functional/rpc_net.py +95 -0
  1669. package/Neurai/test/functional/rpc_preciousblock.py +113 -0
  1670. package/Neurai/test/functional/rpc_rawtransaction.py +225 -0
  1671. package/Neurai/test/functional/rpc_setban.py +50 -0
  1672. package/Neurai/test/functional/rpc_signmessage.py +40 -0
  1673. package/Neurai/test/functional/rpc_signrawtransaction.py +144 -0
  1674. package/Neurai/test/functional/rpc_spentindex.py +141 -0
  1675. package/Neurai/test/functional/rpc_timestampindex.py +60 -0
  1676. package/Neurai/test/functional/rpc_txindex.py +73 -0
  1677. package/Neurai/test/functional/rpc_txoutproof.py +85 -0
  1678. package/Neurai/test/functional/rpc_uptime.py +31 -0
  1679. package/Neurai/test/functional/rpc_users.py +154 -0
  1680. package/Neurai/test/functional/test_framework/__init__.py +0 -0
  1681. package/Neurai/test/functional/test_framework/address.py +81 -0
  1682. package/Neurai/test/functional/test_framework/authproxy.py +201 -0
  1683. package/Neurai/test/functional/test_framework/bignum.py +58 -0
  1684. package/Neurai/test/functional/test_framework/blocktools.py +116 -0
  1685. package/Neurai/test/functional/test_framework/coverage.py +113 -0
  1686. package/Neurai/test/functional/test_framework/key.py +389 -0
  1687. package/Neurai/test/functional/test_framework/messages.py +1648 -0
  1688. package/Neurai/test/functional/test_framework/mininode.py +481 -0
  1689. package/Neurai/test/functional/test_framework/netutil.py +167 -0
  1690. package/Neurai/test/functional/test_framework/script.py +707 -0
  1691. package/Neurai/test/functional/test_framework/siphash.py +64 -0
  1692. package/Neurai/test/functional/test_framework/socks5.py +161 -0
  1693. package/Neurai/test/functional/test_framework/test_framework.py +448 -0
  1694. package/Neurai/test/functional/test_framework/test_node.py +231 -0
  1695. package/Neurai/test/functional/test_framework/util.py +737 -0
  1696. package/Neurai/test/functional/test_framework/wallet_util.py +3563 -0
  1697. package/Neurai/test/functional/test_runner.py +733 -0
  1698. package/Neurai/test/functional/wallet_abandonconflict.py +153 -0
  1699. package/Neurai/test/functional/wallet_backup.py +198 -0
  1700. package/Neurai/test/functional/wallet_basic.py +426 -0
  1701. package/Neurai/test/functional/wallet_bip44.py +148 -0
  1702. package/Neurai/test/functional/wallet_bip44_multilanguage.py +195 -0
  1703. package/Neurai/test/functional/wallet_bumpfee.py +302 -0
  1704. package/Neurai/test/functional/wallet_coinbase_category.py +56 -0
  1705. package/Neurai/test/functional/wallet_create_tx.py +76 -0
  1706. package/Neurai/test/functional/wallet_disable.py +37 -0
  1707. package/Neurai/test/functional/wallet_dump.py +110 -0
  1708. package/Neurai/test/functional/wallet_encryption.py +59 -0
  1709. package/Neurai/test/functional/wallet_groups.py +89 -0
  1710. package/Neurai/test/functional/wallet_hd.py +122 -0
  1711. package/Neurai/test/functional/wallet_import_rescan.py +193 -0
  1712. package/Neurai/test/functional/wallet_import_with_label.py +86 -0
  1713. package/Neurai/test/functional/wallet_importmulti.py +453 -0
  1714. package/Neurai/test/functional/wallet_importprunedfunds.py +118 -0
  1715. package/Neurai/test/functional/wallet_keypool.py +86 -0
  1716. package/Neurai/test/functional/wallet_keypool_topup.py +75 -0
  1717. package/Neurai/test/functional/wallet_labels.py +135 -0
  1718. package/Neurai/test/functional/wallet_listreceivedby.py +146 -0
  1719. package/Neurai/test/functional/wallet_listsinceblock.py +250 -0
  1720. package/Neurai/test/functional/wallet_listtransactions.py +207 -0
  1721. package/Neurai/test/functional/wallet_multiwallet.py +91 -0
  1722. package/Neurai/test/functional/wallet_reorgsrestore.py +97 -0
  1723. package/Neurai/test/functional/wallet_resendtransactions.py +31 -0
  1724. package/Neurai/test/functional/wallet_txn_clone.py +159 -0
  1725. package/Neurai/test/functional/wallet_txn_doublespend.py +140 -0
  1726. package/Neurai/test/functional/wallet_zapwallettxes.py +78 -0
  1727. package/Neurai/test/util/data/blanktxv1.hex +1 -0
  1728. package/Neurai/test/util/data/blanktxv1.json +13 -0
  1729. package/Neurai/test/util/data/blanktxv2.hex +1 -0
  1730. package/Neurai/test/util/data/blanktxv2.json +13 -0
  1731. package/Neurai/test/util/data/neurai-util-test.json +410 -0
  1732. package/Neurai/test/util/data/tt-delin1-out.hex +1 -0
  1733. package/Neurai/test/util/data/tt-delin1-out.json +219 -0
  1734. package/Neurai/test/util/data/tt-delout1-out.hex +1 -0
  1735. package/Neurai/test/util/data/tt-delout1-out.json +215 -0
  1736. package/Neurai/test/util/data/tt-locktime317000-out.hex +1 -0
  1737. package/Neurai/test/util/data/tt-locktime317000-out.json +228 -0
  1738. package/Neurai/test/util/data/tx394b54bb.hex +1 -0
  1739. package/Neurai/test/util/data/txcreate1.hex +1 -0
  1740. package/Neurai/test/util/data/txcreate1.json +66 -0
  1741. package/Neurai/test/util/data/txcreate2.hex +1 -0
  1742. package/Neurai/test/util/data/txcreate2.json +22 -0
  1743. package/Neurai/test/util/data/txcreatedata1.hex +1 -0
  1744. package/Neurai/test/util/data/txcreatedata1.json +44 -0
  1745. package/Neurai/test/util/data/txcreatedata2.hex +1 -0
  1746. package/Neurai/test/util/data/txcreatedata2.json +44 -0
  1747. package/Neurai/test/util/data/txcreatedata_seq0.hex +1 -0
  1748. package/Neurai/test/util/data/txcreatedata_seq0.json +35 -0
  1749. package/Neurai/test/util/data/txcreatedata_seq1.hex +1 -0
  1750. package/Neurai/test/util/data/txcreatedata_seq1.json +44 -0
  1751. package/Neurai/test/util/data/txcreatemultisig1.hex +1 -0
  1752. package/Neurai/test/util/data/txcreatemultisig1.json +28 -0
  1753. package/Neurai/test/util/data/txcreatemultisig2.hex +1 -0
  1754. package/Neurai/test/util/data/txcreatemultisig2.json +26 -0
  1755. package/Neurai/test/util/data/txcreatemultisig3.hex +1 -0
  1756. package/Neurai/test/util/data/txcreatemultisig3.json +22 -0
  1757. package/Neurai/test/util/data/txcreatemultisig4.hex +1 -0
  1758. package/Neurai/test/util/data/txcreatemultisig4.json +26 -0
  1759. package/Neurai/test/util/data/txcreatemultisig5.json +26 -0
  1760. package/Neurai/test/util/data/txcreateoutpubkey1.hex +1 -0
  1761. package/Neurai/test/util/data/txcreateoutpubkey1.json +26 -0
  1762. package/Neurai/test/util/data/txcreateoutpubkey2.hex +1 -0
  1763. package/Neurai/test/util/data/txcreateoutpubkey2.json +22 -0
  1764. package/Neurai/test/util/data/txcreateoutpubkey3.hex +1 -0
  1765. package/Neurai/test/util/data/txcreateoutpubkey3.json +26 -0
  1766. package/Neurai/test/util/data/txcreatescript1.hex +1 -0
  1767. package/Neurai/test/util/data/txcreatescript1.json +22 -0
  1768. package/Neurai/test/util/data/txcreatescript2.hex +1 -0
  1769. package/Neurai/test/util/data/txcreatescript2.json +26 -0
  1770. package/Neurai/test/util/data/txcreatescript3.hex +1 -0
  1771. package/Neurai/test/util/data/txcreatescript3.json +22 -0
  1772. package/Neurai/test/util/data/txcreatescript4.hex +1 -0
  1773. package/Neurai/test/util/data/txcreatescript4.json +26 -0
  1774. package/Neurai/test/util/data/txcreatesignv1.hex +1 -0
  1775. package/Neurai/test/util/data/txcreatesignv1.json +35 -0
  1776. package/Neurai/test/util/data/txcreatesignv2.hex +1 -0
  1777. package/Neurai/test/util/neurai-util-test.py +186 -0
  1778. package/dist/index.cjs +308 -0
  1779. package/dist/index.cjs.map +1 -1
  1780. package/dist/index.mjs +308 -0
  1781. package/dist/index.mjs.map +1 -1
  1782. package/dist/types.d.ts +13 -0
  1783. package/dist/types.d.ts.map +1 -1
  1784. package/docs.json +13 -0
  1785. package/docs.ts +399 -0
  1786. package/neurai_methods.md +4936 -0
  1787. package/package.json +4 -4
@@ -0,0 +1,3803 @@
1
+ // Copyright (c) 2009-2010 Satoshi Nakamoto
2
+ // Copyright (c) 2009-2016 The Bitcoin Core developers
3
+ // Copyright (c) 2017-2021 The Neurai developers
4
+ // Distributed under the MIT software license, see the accompanying
5
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6
+
7
+ #include "net_processing.h"
8
+
9
+ #include "addrman.h"
10
+ #include "arith_uint256.h"
11
+ #include "blockencodings.h"
12
+ #include "chainparams.h"
13
+ #include "consensus/validation.h"
14
+ #include "hash.h"
15
+ #include "init.h"
16
+ #include "validation.h"
17
+ #include "merkleblock.h"
18
+ #include "net.h"
19
+ #include "netmessagemaker.h"
20
+ #include "netbase.h"
21
+ #include "policy/fees.h"
22
+ #include "policy/policy.h"
23
+ #include "primitives/block.h"
24
+ #include "primitives/transaction.h"
25
+ #include "random.h"
26
+ #include "reverse_iterator.h"
27
+ #include "scheduler.h"
28
+ #include "tinyformat.h"
29
+ #include "txmempool.h"
30
+ #include "ui_interface.h"
31
+ #include "util.h"
32
+ #include "utilmoneystr.h"
33
+ #include "utilstrencodings.h"
34
+ #include "validationinterface.h"
35
+
36
+ #if defined(NDEBUG)
37
+ # error "Neurai cannot be compiled without assertions."
38
+ #endif
39
+
40
+ std::atomic<int64_t> nTimeBestReceived(0); // Used only to inform the wallet of when we last received a block
41
+
42
+ struct IteratorComparator
43
+ {
44
+ template<typename I>
45
+ bool operator()(const I& a, const I& b) const
46
+ {
47
+ return &(*a) < &(*b);
48
+ }
49
+ };
50
+
51
+ struct COrphanTx {
52
+ // When modifying, adapt the copy of this definition in tests/DoS_tests.
53
+ CTransactionRef tx;
54
+ NodeId fromPeer;
55
+ int64_t nTimeExpire;
56
+ };
57
+ std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(cs_main);
58
+ std::map<COutPoint, std::set<std::map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(cs_main);
59
+ void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
60
+
61
+ static size_t vExtraTxnForCompactIt = 0;
62
+ static std::vector<std::pair<uint256, CTransactionRef>> vExtraTxnForCompact GUARDED_BY(cs_main);
63
+
64
+ static const uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL; // SHA256("main address relay")[0:8]
65
+
66
+ /// Age after which a stale block will no longer be served if requested as
67
+ /// protection against fingerprinting. Set to one month, denominated in seconds.
68
+ static const int STALE_RELAY_AGE_LIMIT = 30 * 24 * 60 * 60;
69
+
70
+ /// Age after which a block is considered historical for purposes of rate
71
+ /// limiting block relay. Set to one week, denominated in seconds.
72
+ static const int HISTORICAL_BLOCK_AGE = 7 * 24 * 60 * 60;
73
+
74
+ // Internal stuff
75
+ namespace {
76
+ /** Number of nodes with fSyncStarted. */
77
+ int nSyncStarted = 0;
78
+
79
+ /**
80
+ * Sources of received blocks, saved to be able to send them reject
81
+ * messages or ban them when processing happens afterwards. Protected by
82
+ * cs_main.
83
+ * Set mapBlockSource[hash].second to false if the node should not be
84
+ * punished if the block is invalid.
85
+ */
86
+ std::map<uint256, std::pair<NodeId, bool>> mapBlockSource;
87
+
88
+ /**
89
+ * Filter for transactions that were recently rejected by
90
+ * AcceptToMemoryPool. These are not rerequested until the chain tip
91
+ * changes, at which point the entire filter is reset. Protected by
92
+ * cs_main.
93
+ *
94
+ * Without this filter we'd be re-requesting txs from each of our peers,
95
+ * increasing bandwidth consumption considerably. For instance, with 100
96
+ * peers, half of which relay a tx we don't accept, that might be a 50x
97
+ * bandwidth increase. A flooding attacker attempting to roll-over the
98
+ * filter using minimum-sized, 60byte, transactions might manage to send
99
+ * 1000/sec if we have fast peers, so we pick 120,000 to give our peers a
100
+ * two minute window to send invs to us.
101
+ *
102
+ * Decreasing the false positive rate is fairly cheap, so we pick one in a
103
+ * million to make it highly unlikely for users to have issues with this
104
+ * filter.
105
+ *
106
+ * Memory used: 1.3 MB
107
+ */
108
+ std::unique_ptr<CRollingBloomFilter> recentRejects;
109
+ uint256 hashRecentRejectsChainTip;
110
+
111
+ /** Blocks that are in flight, and that are in the queue to be downloaded. Protected by cs_main. */
112
+ struct QueuedBlock {
113
+ uint256 hash;
114
+ const CBlockIndex* pindex; //!< Optional.
115
+ bool fValidatedHeaders; //!< Whether this block has validated headers at the time of request.
116
+ std::unique_ptr<PartiallyDownloadedBlock> partialBlock; //!< Optional, used for CMPCTBLOCK downloads
117
+ };
118
+ std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> > mapBlocksInFlight;
119
+
120
+ /** Stack of nodes which we have set to announce using compact blocks */
121
+ std::list<NodeId> lNodesAnnouncingHeaderAndIDs;
122
+
123
+ /** Number of preferable block download peers. */
124
+ int nPreferredDownload = 0;
125
+
126
+ /** Number of peers from which we're downloading blocks. */
127
+ int nPeersWithValidatedDownloads = 0;
128
+
129
+ /** Number of outbound peers with m_chain_sync.m_protect. */
130
+ int g_outbound_peers_with_protect_from_disconnect = 0;
131
+
132
+ /** When our tip was last updated. */
133
+ int64_t g_last_tip_update = 0;
134
+
135
+ /** Relay map, protected by cs_main. */
136
+ typedef std::map<uint256, CTransactionRef> MapRelay;
137
+ MapRelay mapRelay;
138
+ /** Expiration-time ordered list of (expire time, relay map entry) pairs, protected by cs_main). */
139
+ std::deque<std::pair<int64_t, MapRelay::iterator>> vRelayExpiration;
140
+ } // namespace
141
+
142
+ namespace {
143
+
144
+ struct CBlockReject {
145
+ unsigned char chRejectCode;
146
+ std::string strRejectReason;
147
+ uint256 hashBlock;
148
+ };
149
+
150
+ /**
151
+ * Maintain validation-specific state about nodes, protected by cs_main, instead
152
+ * by CNode's own locks. This simplifies asynchronous operation, where
153
+ * processing of incoming data is done after the ProcessMessage call returns,
154
+ * and we're no longer holding the node's locks.
155
+ */
156
+ struct CNodeState {
157
+ //! The peer's address
158
+ const CService address;
159
+ //! Whether we have a fully established connection.
160
+ bool fCurrentlyConnected{false};
161
+ //! Accumulated misbehaviour score for this peer.
162
+ int nMisbehavior{0};
163
+ //! Whether this peer should be disconnected and banned (unless whitelisted).
164
+ bool fShouldBan{false};
165
+ //! String name of this peer (debugging/logging purposes).
166
+ const std::string name;
167
+ //! List of asynchronously-determined block rejections to notify this peer about.
168
+ std::vector<CBlockReject> rejects;
169
+ //! The best known block we know this peer has announced.
170
+ const CBlockIndex* pindexBestKnownBlock{nullptr};
171
+ //! The hash of the last unknown block this peer has announced.
172
+ uint256 hashLastUnknownBlock{};
173
+ //! The last full block we both have.
174
+ const CBlockIndex* pindexLastCommonBlock{nullptr};
175
+ //! The best header we have sent our peer.
176
+ const CBlockIndex* pindexBestHeaderSent{nullptr};
177
+ //! Length of current-streak of unconnecting headers announcements
178
+ int nUnconnectingHeaders{0};
179
+ //! Whether we've started headers synchronization with this peer.
180
+ bool fSyncStarted{false};
181
+ //! When to potentially disconnect peer for stalling headers download
182
+ int64_t nHeadersSyncTimeout{0};
183
+ //! Since when we're stalling block download progress (in microseconds), or 0.
184
+ int64_t nStallingSince{0};
185
+ std::list<QueuedBlock> vBlocksInFlight;
186
+ //! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty.
187
+ int64_t nDownloadingSince{0};
188
+ int nBlocksInFlight{0};
189
+ int nBlocksInFlightValidHeaders{0};
190
+ //! Whether we consider this a preferred download peer.
191
+ bool fPreferredDownload{false};
192
+ //! Whether this peer wants invs or headers (when possible) for block announcements.
193
+ bool fPreferHeaders{false};
194
+ //! Whether this peer wants invs or cmpctblocks (when possible) for block announcements.
195
+ bool fPreferHeaderAndIDs{false};
196
+ /**
197
+ * Whether this peer will send us cmpctblocks if we request them.
198
+ * This is not used to gate request logic, as we really only care about fSupportsDesiredCmpctVersion,
199
+ * but is used as a flag to "lock in" the version of compact blocks (fWantsCmpctWitness) we send.
200
+ */
201
+ bool fProvidesHeaderAndIDs{false};
202
+ //! Whether this peer can give us witnesses
203
+ bool fHaveWitness{false};
204
+ //! Whether this peer wants witnesses in cmpctblocks/blocktxns
205
+ bool fWantsCmpctWitness{false};
206
+ /**
207
+ * If we've announced NODE_WITNESS to this peer: whether the peer sends witnesses in cmpctblocks/blocktxns,
208
+ * otherwise: whether this peer sends non-witnesses in cmpctblocks/blocktxns.
209
+ */
210
+ bool fSupportsDesiredCmpctVersion{false};
211
+
212
+ /** State used to enforce CHAIN_SYNC_TIMEOUT
213
+ * Only in effect for outbound, non-manual connections, with
214
+ * m_protect == false
215
+ * Algorithm: if a peer's best known block has less work than our tip,
216
+ * set a timeout CHAIN_SYNC_TIMEOUT seconds in the future:
217
+ * - If at timeout their best known block now has more work than our tip
218
+ * when the timeout was set, then either reset the timeout or clear it
219
+ * (after comparing against our current tip's work)
220
+ * - If at timeout their best known block still has less work than our
221
+ * tip did when the timeout was set, then send a getheaders message,
222
+ * and set a shorter timeout, HEADERS_RESPONSE_TIME seconds in future.
223
+ * If their best known block is still behind when that new timeout is
224
+ * reached, disconnect.
225
+ */
226
+ struct ChainSyncTimeoutState {
227
+ //! A timeout used for checking whether our peer has sufficiently synced
228
+ int64_t m_timeout;
229
+ //! A header with the work we require on our peer's chain
230
+ const CBlockIndex * m_work_header;
231
+ //! After timeout is reached, set to true after sending getheaders
232
+ bool m_sent_getheaders;
233
+ //! Whether this peer is protected from disconnection due to a bad/slow chain
234
+ bool m_protect;
235
+ };
236
+
237
+ ChainSyncTimeoutState m_chain_sync{0, nullptr, false, false};
238
+
239
+ //! Time of last new block announcement
240
+ int64_t m_last_block_announcement{0};
241
+
242
+ CNodeState(CAddress addrIn, std::string addrNameIn) : address(addrIn), name(addrNameIn) {
243
+ m_chain_sync = { 0, nullptr, false, false };
244
+ m_last_block_announcement = 0;
245
+ }
246
+ };
247
+
248
+ /** Map maintaining per-node state. Requires cs_main. */
249
+ std::map<NodeId, CNodeState> mapNodeState;
250
+
251
+ // Requires cs_main.
252
+ CNodeState *State(NodeId pnode) {
253
+ std::map<NodeId, CNodeState>::iterator it = mapNodeState.find(pnode);
254
+ if (it == mapNodeState.end())
255
+ return nullptr;
256
+ return &it->second;
257
+ }
258
+
259
+ void UpdatePreferredDownload(CNode* node, CNodeState* state)
260
+ {
261
+ nPreferredDownload -= state->fPreferredDownload;
262
+
263
+ // Whether this node should be marked as a preferred download node.
264
+ state->fPreferredDownload = (!node->fInbound || node->fWhitelisted) && !node->fOneShot && !node->fClient;
265
+
266
+ nPreferredDownload += state->fPreferredDownload;
267
+ }
268
+
269
+ void PushNodeVersion(CNode *pnode, CConnman* connman, int64_t nTime)
270
+ {
271
+ ServiceFlags nLocalNodeServices = pnode->GetLocalServices();
272
+ uint64_t nonce = pnode->GetLocalNonce();
273
+ int nNodeStartingHeight = pnode->GetMyStartingHeight();
274
+ NodeId nodeid = pnode->GetId();
275
+ CAddress addr = pnode->addr;
276
+
277
+ CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService(), addr.nServices));
278
+ CAddress addrMe = CAddress(CService(), nLocalNodeServices);
279
+
280
+ connman->PushMessage(pnode, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERSION, PROTOCOL_VERSION, (uint64_t)nLocalNodeServices, nTime, addrYou, addrMe,
281
+ nonce, strSubVersion, nNodeStartingHeight, ::fRelayTxes));
282
+
283
+ if (fLogIPs) {
284
+ LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString(), addrYou.ToString(), nodeid);
285
+ } else {
286
+ LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString(), nodeid);
287
+ }
288
+ }
289
+
290
+ // Requires cs_main.
291
+ // Returns a bool indicating whether we requested this block.
292
+ // Also used if a block was /not/ received and timed out or started with another peer
293
+ bool MarkBlockAsReceived(const uint256& hash) {
294
+ std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash);
295
+ if (itInFlight != mapBlocksInFlight.end()) {
296
+ CNodeState *state = State(itInFlight->second.first);
297
+ assert(state != nullptr);
298
+ state->nBlocksInFlightValidHeaders -= itInFlight->second.second->fValidatedHeaders;
299
+ if (state->nBlocksInFlightValidHeaders == 0 && itInFlight->second.second->fValidatedHeaders) {
300
+ // Last validated block on the queue was received.
301
+ nPeersWithValidatedDownloads--;
302
+ }
303
+ if (state->vBlocksInFlight.begin() == itInFlight->second.second) {
304
+ // First block on the queue was received, update the start download time for the next one
305
+ state->nDownloadingSince = std::max(state->nDownloadingSince, GetTimeMicros());
306
+ }
307
+ state->vBlocksInFlight.erase(itInFlight->second.second);
308
+ state->nBlocksInFlight--;
309
+ state->nStallingSince = 0;
310
+ mapBlocksInFlight.erase(itInFlight);
311
+ return true;
312
+ }
313
+ return false;
314
+ }
315
+
316
+ // Requires cs_main.
317
+ // returns false, still setting pit, if the block was already in flight from the same peer
318
+ // pit will only be valid as long as the same cs_main lock is being held
319
+ bool MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* pindex = nullptr, std::list<QueuedBlock>::iterator** pit = nullptr) {
320
+ CNodeState *state = State(nodeid);
321
+ assert(state != nullptr);
322
+
323
+ // Short-circuit most stuff in case its from the same node
324
+ std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash);
325
+ if (itInFlight != mapBlocksInFlight.end() && itInFlight->second.first == nodeid) {
326
+ if (pit) {
327
+ *pit = &itInFlight->second.second;
328
+ }
329
+ return false;
330
+ }
331
+
332
+ // Make sure it's not listed somewhere already.
333
+ MarkBlockAsReceived(hash);
334
+
335
+ std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
336
+ {hash, pindex, pindex != nullptr, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&mempool) : nullptr)});
337
+ state->nBlocksInFlight++;
338
+ state->nBlocksInFlightValidHeaders += it->fValidatedHeaders;
339
+ if (state->nBlocksInFlight == 1) {
340
+ // We're starting a block download (batch) from this peer.
341
+ state->nDownloadingSince = GetTimeMicros();
342
+ }
343
+ if (state->nBlocksInFlightValidHeaders == 1 && pindex != nullptr) {
344
+ nPeersWithValidatedDownloads++;
345
+ }
346
+ itInFlight = mapBlocksInFlight.insert(std::make_pair(hash, std::make_pair(nodeid, it))).first;
347
+ if (pit)
348
+ *pit = &itInFlight->second.second;
349
+ return true;
350
+ }
351
+
352
+ /** Check whether the last unknown block a peer advertised is not yet known. */
353
+ void ProcessBlockAvailability(NodeId nodeid) {
354
+ CNodeState *state = State(nodeid);
355
+ assert(state != nullptr);
356
+
357
+ if (!state->hashLastUnknownBlock.IsNull()) {
358
+ BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock);
359
+ if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) {
360
+ if (state->pindexBestKnownBlock == nullptr || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork)
361
+ state->pindexBestKnownBlock = itOld->second;
362
+ state->hashLastUnknownBlock.SetNull();
363
+ }
364
+ }
365
+ }
366
+
367
+ /** Update tracking information about which blocks a peer is assumed to have. */
368
+ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) {
369
+ CNodeState *state = State(nodeid);
370
+ assert(state != nullptr);
371
+
372
+ ProcessBlockAvailability(nodeid);
373
+
374
+ BlockMap::iterator it = mapBlockIndex.find(hash);
375
+ if (it != mapBlockIndex.end() && it->second->nChainWork > 0) {
376
+ // An actually better block was announced.
377
+ if (state->pindexBestKnownBlock == nullptr || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork)
378
+ state->pindexBestKnownBlock = it->second;
379
+ } else {
380
+ // An unknown block was announced; just assume that the latest one is the best one.
381
+ state->hashLastUnknownBlock = hash;
382
+ }
383
+ }
384
+
385
+ void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connman) {
386
+ AssertLockHeld(cs_main);
387
+ CNodeState* nodestate = State(nodeid);
388
+ if (!nodestate || !nodestate->fSupportsDesiredCmpctVersion) {
389
+ // Never ask from peers who can't provide witnesses.
390
+ return;
391
+ }
392
+ if (nodestate->fProvidesHeaderAndIDs) {
393
+ for (std::list<NodeId>::iterator it = lNodesAnnouncingHeaderAndIDs.begin(); it != lNodesAnnouncingHeaderAndIDs.end(); it++) {
394
+ if (*it == nodeid) {
395
+ lNodesAnnouncingHeaderAndIDs.erase(it);
396
+ lNodesAnnouncingHeaderAndIDs.push_back(nodeid);
397
+ return;
398
+ }
399
+ }
400
+ connman->ForNode(nodeid, [connman](CNode* pfrom){
401
+ uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices() & NODE_WITNESS) ? 2 : 1;
402
+ if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
403
+ // As per BIP152, we only get 3 of our peers to announce
404
+ // blocks using compact encodings.
405
+ connman->ForNode(lNodesAnnouncingHeaderAndIDs.front(), [connman, nCMPCTBLOCKVersion](CNode* pnodeStop){
406
+ connman->PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion));
407
+ return true;
408
+ });
409
+ lNodesAnnouncingHeaderAndIDs.pop_front();
410
+ }
411
+ connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/true, nCMPCTBLOCKVersion));
412
+ lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
413
+ return true;
414
+ });
415
+ }
416
+ }
417
+
418
+ bool TipMayBeStale(const Consensus::Params &consensusParams)
419
+ {
420
+ AssertLockHeld(cs_main);
421
+ if (g_last_tip_update == 0) {
422
+ g_last_tip_update = GetTime();
423
+ }
424
+ return g_last_tip_update < GetTime() - consensusParams.nPowTargetSpacing * 3 && mapBlocksInFlight.empty();
425
+ }
426
+
427
+ // Requires cs_main
428
+ bool CanDirectFetch(const Consensus::Params &consensusParams)
429
+ {
430
+ return chainActive.Tip()->GetBlockTime() > GetAdjustedTime() - consensusParams.nPowTargetSpacing * 20;
431
+ }
432
+
433
+ // Requires cs_main
434
+ bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex)
435
+ {
436
+ if (state->pindexBestKnownBlock && pindex == state->pindexBestKnownBlock->GetAncestor(pindex->nHeight))
437
+ return true;
438
+ if (state->pindexBestHeaderSent && pindex == state->pindexBestHeaderSent->GetAncestor(pindex->nHeight))
439
+ return true;
440
+ return false;
441
+ }
442
+
443
+ /** Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has
444
+ * at most count entries. */
445
+ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<const CBlockIndex*>& vBlocks, NodeId& nodeStaller, const Consensus::Params& consensusParams) {
446
+ if (count == 0)
447
+ return;
448
+
449
+ vBlocks.reserve(vBlocks.size() + count);
450
+ CNodeState *state = State(nodeid);
451
+ assert(state != nullptr);
452
+
453
+ // Make sure pindexBestKnownBlock is up to date, we'll need it.
454
+ ProcessBlockAvailability(nodeid);
455
+
456
+ if (state->pindexBestKnownBlock == nullptr || state->pindexBestKnownBlock->nChainWork < chainActive.Tip()->nChainWork || state->pindexBestKnownBlock->nChainWork < nMinimumChainWork) {
457
+ // This peer has nothing interesting.
458
+ return;
459
+ }
460
+
461
+ if (state->pindexLastCommonBlock == nullptr) {
462
+ // Bootstrap quickly by guessing a parent of our best tip is the forking point.
463
+ // Guessing wrong in either direction is not a problem.
464
+ state->pindexLastCommonBlock = chainActive[std::min(state->pindexBestKnownBlock->nHeight, chainActive.Height())];
465
+ }
466
+
467
+ // If the peer reorganized, our previous pindexLastCommonBlock may not be an ancestor
468
+ // of its current tip anymore. Go back enough to fix that.
469
+ state->pindexLastCommonBlock = LastCommonAncestor(state->pindexLastCommonBlock, state->pindexBestKnownBlock);
470
+ if (state->pindexLastCommonBlock == state->pindexBestKnownBlock)
471
+ return;
472
+
473
+ std::vector<const CBlockIndex*> vToFetch;
474
+ const CBlockIndex *pindexWalk = state->pindexLastCommonBlock;
475
+ // Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond the last
476
+ // linked block we have in common with this peer. The +1 is so we can detect stalling, namely if we would be able to
477
+ // download that next block if the window were 1 larger.
478
+ int nWindowEnd = state->pindexLastCommonBlock->nHeight + BLOCK_DOWNLOAD_WINDOW;
479
+ int nMaxHeight = std::min<int>(state->pindexBestKnownBlock->nHeight, nWindowEnd + 1);
480
+ NodeId waitingfor = -1;
481
+ while (pindexWalk->nHeight < nMaxHeight) {
482
+ // Read up to 128 (or more, if more blocks than that are needed) successors of pindexWalk (towards
483
+ // pindexBestKnownBlock) into vToFetch. We fetch 128, because CBlockIndex::GetAncestor may be as expensive
484
+ // as iterating over ~100 CBlockIndex* entries anyway.
485
+ int nToFetch = std::min(nMaxHeight - pindexWalk->nHeight, std::max<int>(count - vBlocks.size(), 128));
486
+ vToFetch.resize(nToFetch);
487
+ pindexWalk = state->pindexBestKnownBlock->GetAncestor(pindexWalk->nHeight + nToFetch);
488
+ vToFetch[nToFetch - 1] = pindexWalk;
489
+ for (unsigned int i = nToFetch - 1; i > 0; i--) {
490
+ vToFetch[i - 1] = vToFetch[i]->pprev;
491
+ }
492
+
493
+ // Iterate over those blocks in vToFetch (in forward direction), adding the ones that
494
+ // are not yet downloaded and not in flight to vBlocks. In the mean time, update
495
+ // pindexLastCommonBlock as long as all ancestors are already downloaded, or if it's
496
+ // already part of our chain (and therefore don't need it even if pruned).
497
+ for (const CBlockIndex* pindex : vToFetch) {
498
+ if (!pindex->IsValid(BLOCK_VALID_TREE)) {
499
+ // We consider the chain that this peer is on invalid.
500
+ return;
501
+ }
502
+ if (!State(nodeid)->fHaveWitness && IsWitnessEnabled(pindex->pprev, consensusParams)) {
503
+ // We wouldn't download this block or its descendants from this peer.
504
+ return;
505
+ }
506
+ if (pindex->nStatus & BLOCK_HAVE_DATA || chainActive.Contains(pindex)) {
507
+ if (pindex->nChainTx)
508
+ state->pindexLastCommonBlock = pindex;
509
+ } else if (mapBlocksInFlight.count(pindex->GetBlockHash()) == 0) {
510
+ // The block is not already downloaded, and not yet in flight.
511
+ if (pindex->nHeight > nWindowEnd) {
512
+ // We reached the end of the window.
513
+ if (vBlocks.size() == 0 && waitingfor != nodeid) {
514
+ // We aren't able to fetch anything, but we would be if the download window was one larger.
515
+ nodeStaller = waitingfor;
516
+ }
517
+ return;
518
+ }
519
+ vBlocks.push_back(pindex);
520
+ if (vBlocks.size() == count) {
521
+ return;
522
+ }
523
+ } else if (waitingfor == -1) {
524
+ // This is the first already-in-flight block.
525
+ waitingfor = mapBlocksInFlight[pindex->GetBlockHash()].first;
526
+ }
527
+ }
528
+ }
529
+ }
530
+
531
+ } // namespace
532
+
533
+ // Returns true for outbound peers, excluding manual connections, feelers, and
534
+ // one-shots
535
+ bool IsOutboundDisconnectionCandidate(const CNode *node)
536
+ {
537
+ return !(node->fInbound || node->m_manual_connection || node->fFeeler || node->fOneShot);
538
+ }
539
+
540
+ void PeerLogicValidation::InitializeNode(CNode *pnode) {
541
+ CAddress addr = pnode->addr;
542
+ std::string addrName = pnode->GetAddrName();
543
+ NodeId nodeid = pnode->GetId();
544
+ {
545
+ LOCK(cs_main);
546
+ mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName)));
547
+ }
548
+ if(!pnode->fInbound)
549
+ PushNodeVersion(pnode, connman, GetTime());
550
+ }
551
+
552
+ void PeerLogicValidation::FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) {
553
+ fUpdateConnectionTime = false;
554
+ LOCK(cs_main);
555
+ CNodeState *state = State(nodeid);
556
+ assert(state != nullptr);
557
+
558
+ if (state->fSyncStarted)
559
+ nSyncStarted--;
560
+
561
+ if (state->nMisbehavior == 0 && state->fCurrentlyConnected) {
562
+ fUpdateConnectionTime = true;
563
+ }
564
+
565
+ for (const QueuedBlock& entry : state->vBlocksInFlight) {
566
+ mapBlocksInFlight.erase(entry.hash);
567
+ }
568
+ EraseOrphansFor(nodeid);
569
+ nPreferredDownload -= state->fPreferredDownload;
570
+ nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0);
571
+ assert(nPeersWithValidatedDownloads >= 0);
572
+ g_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync.m_protect;
573
+ assert(g_outbound_peers_with_protect_from_disconnect >= 0);
574
+
575
+ mapNodeState.erase(nodeid);
576
+
577
+ if (mapNodeState.empty()) {
578
+ // Do a consistency check after the last peer is removed.
579
+ assert(mapBlocksInFlight.empty());
580
+ assert(nPreferredDownload == 0);
581
+ assert(nPeersWithValidatedDownloads == 0);
582
+ assert(g_outbound_peers_with_protect_from_disconnect == 0);
583
+ }
584
+ LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid);
585
+ }
586
+
587
+ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
588
+ LOCK(cs_main);
589
+ CNodeState *state = State(nodeid);
590
+ if (state == nullptr)
591
+ return false;
592
+ stats.nMisbehavior = state->nMisbehavior;
593
+ stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
594
+ stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1;
595
+ for (const QueuedBlock& queue : state->vBlocksInFlight) {
596
+ if (queue.pindex)
597
+ stats.vHeightInFlight.push_back(queue.pindex->nHeight);
598
+ }
599
+ return true;
600
+ }
601
+
602
+ //////////////////////////////////////////////////////////////////////////////
603
+ //
604
+ // mapOrphanTransactions
605
+ //
606
+
607
+ void AddToCompactExtraTransactions(const CTransactionRef& tx)
608
+ {
609
+ size_t max_extra_txn = gArgs.GetArg("-blockreconstructionextratxn", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN);
610
+ if (max_extra_txn <= 0)
611
+ return;
612
+ if (!vExtraTxnForCompact.size())
613
+ vExtraTxnForCompact.resize(max_extra_txn);
614
+ vExtraTxnForCompact[vExtraTxnForCompactIt] = std::make_pair(tx->GetWitnessHash(), tx);
615
+ vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % max_extra_txn;
616
+ }
617
+
618
+ bool AddOrphanTx(const CTransactionRef& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
619
+ {
620
+ const uint256& hash = tx->GetHash();
621
+ if (mapOrphanTransactions.count(hash))
622
+ return false;
623
+
624
+ // Ignore big transactions, to avoid a
625
+ // send-big-orphans memory exhaustion attack. If a peer has a legitimate
626
+ // large transaction with a missing parent then we assume
627
+ // it will rebroadcast it later, after the parent transaction(s)
628
+ // have been mined or received.
629
+ // 100 orphans, each of which is at most 99,999 bytes big is
630
+ // at most 10 megabytes of orphans and somewhat more byprev index (in the worst case):
631
+ unsigned int sz = GetTransactionWeight(*tx);
632
+ if (sz >= MAX_STANDARD_TX_WEIGHT)
633
+ {
634
+ LogPrint(BCLog::MEMPOOL, "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString());
635
+ return false;
636
+ }
637
+
638
+ auto ret = mapOrphanTransactions.emplace(hash, COrphanTx{tx, peer, GetTime() + ORPHAN_TX_EXPIRE_TIME});
639
+ assert(ret.second);
640
+ for (const CTxIn& txin : tx->vin)
641
+ {
642
+ mapOrphanTransactionsByPrev[txin.prevout].insert(ret.first);
643
+ }
644
+
645
+ AddToCompactExtraTransactions(tx);
646
+
647
+ LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (mapsz %u outsz %u)\n", hash.ToString(),
648
+ mapOrphanTransactions.size(), mapOrphanTransactionsByPrev.size());
649
+ return true;
650
+ }
651
+
652
+ int static EraseOrphanTx(uint256 hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
653
+ {
654
+ std::map<uint256, COrphanTx>::iterator it = mapOrphanTransactions.find(hash);
655
+ if (it == mapOrphanTransactions.end())
656
+ return 0;
657
+ for (const CTxIn& txin : it->second.tx->vin)
658
+ {
659
+ auto itPrev = mapOrphanTransactionsByPrev.find(txin.prevout);
660
+ if (itPrev == mapOrphanTransactionsByPrev.end())
661
+ continue;
662
+ itPrev->second.erase(it);
663
+ if (itPrev->second.empty())
664
+ mapOrphanTransactionsByPrev.erase(itPrev);
665
+ }
666
+ mapOrphanTransactions.erase(it);
667
+ return 1;
668
+ }
669
+
670
+ void EraseOrphansFor(NodeId peer)
671
+ {
672
+ int nErased = 0;
673
+ std::map<uint256, COrphanTx>::iterator iter = mapOrphanTransactions.begin();
674
+ while (iter != mapOrphanTransactions.end())
675
+ {
676
+ std::map<uint256, COrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
677
+ if (maybeErase->second.fromPeer == peer)
678
+ {
679
+ nErased += EraseOrphanTx(maybeErase->second.tx->GetHash());
680
+ }
681
+ }
682
+ if (nErased > 0) LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx from peer=%d\n", nErased, peer);
683
+ }
684
+
685
+
686
+ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
687
+ {
688
+ unsigned int nEvicted = 0;
689
+ static int64_t nNextSweep;
690
+ int64_t nNow = GetTime();
691
+ if (nNextSweep <= nNow) {
692
+ // Sweep out expired orphan pool entries:
693
+ int nErased = 0;
694
+ int64_t nMinExpTime = nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL;
695
+ std::map<uint256, COrphanTx>::iterator iter = mapOrphanTransactions.begin();
696
+ while (iter != mapOrphanTransactions.end())
697
+ {
698
+ std::map<uint256, COrphanTx>::iterator maybeErase = iter++;
699
+ if (maybeErase->second.nTimeExpire <= nNow) {
700
+ nErased += EraseOrphanTx(maybeErase->second.tx->GetHash());
701
+ } else {
702
+ nMinExpTime = std::min(maybeErase->second.nTimeExpire, nMinExpTime);
703
+ }
704
+ }
705
+ // Sweep again 5 minutes after the next entry that expires in order to batch the linear scan.
706
+ nNextSweep = nMinExpTime + ORPHAN_TX_EXPIRE_INTERVAL;
707
+ if (nErased > 0) LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx due to expiration\n", nErased);
708
+ }
709
+ while (mapOrphanTransactions.size() > nMaxOrphans)
710
+ {
711
+ // Evict a random orphan:
712
+ uint256 randomhash = GetRandHash();
713
+ std::map<uint256, COrphanTx>::iterator it = mapOrphanTransactions.lower_bound(randomhash);
714
+ if (it == mapOrphanTransactions.end())
715
+ it = mapOrphanTransactions.begin();
716
+ EraseOrphanTx(it->first);
717
+ ++nEvicted;
718
+ }
719
+ return nEvicted;
720
+ }
721
+
722
+ // Requires cs_main.
723
+ void Misbehaving(NodeId pnode, int howmuch)
724
+ {
725
+ if (howmuch == 0)
726
+ return;
727
+
728
+ CNodeState *state = State(pnode);
729
+ if (state == nullptr)
730
+ return;
731
+
732
+ state->nMisbehavior += howmuch;
733
+ int banscore = gArgs.GetArg("-banscore", DEFAULT_BANSCORE_THRESHOLD);
734
+ if (state->nMisbehavior >= banscore && state->nMisbehavior - howmuch < banscore)
735
+ {
736
+ LogPrintf("%s: %s peer=%d (%d -> %d) BAN THRESHOLD EXCEEDED\n", __func__, state->name, pnode, state->nMisbehavior-howmuch, state->nMisbehavior);
737
+ state->fShouldBan = true;
738
+ } else
739
+ LogPrintf("%s: %s peer=%d (%d -> %d)\n", __func__, state->name, pnode, state->nMisbehavior-howmuch, state->nMisbehavior);
740
+ }
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+ //////////////////////////////////////////////////////////////////////////////
750
+ //
751
+ // blockchain -> download logic notification
752
+ //
753
+
754
+ // To prevent fingerprinting attacks, only send blocks/headers outside of the
755
+ // active chain if they are no more than a month older (both in time, and in
756
+ // best equivalent proof of work) than the best header chain we know about.
757
+ static bool StaleBlockRequestAllowed(const CBlockIndex* pindex, const Consensus::Params& consensusParams)
758
+ {
759
+ AssertLockHeld(cs_main);
760
+ return (pindexBestHeader != nullptr) &&
761
+ (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() < STALE_RELAY_AGE_LIMIT) &&
762
+ (GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, *pindexBestHeader, consensusParams) < STALE_RELAY_AGE_LIMIT);
763
+ }
764
+
765
+ PeerLogicValidation::PeerLogicValidation(CConnman* connmanIn, CScheduler &scheduler) : connman(connmanIn), m_stale_tip_check_time(0) {
766
+ // Initialize global variables that cannot be constructed at startup.
767
+ recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
768
+
769
+ const Consensus::Params& consensusParams = GetParams().GetConsensus();
770
+ // Stale tip checking and peer eviction are on two different timers, but we
771
+ // don't want them to get out of sync due to drift in the scheduler, so we
772
+ // combine them in one function and schedule at the quicker (peer-eviction)
773
+ // timer.
774
+ static_assert(EXTRA_PEER_CHECK_INTERVAL < STALE_CHECK_INTERVAL, "peer eviction timer should be less than stale tip check timer");
775
+ scheduler.scheduleEvery(std::bind(&PeerLogicValidation::CheckForStaleTipAndEvictPeers, this, consensusParams), EXTRA_PEER_CHECK_INTERVAL * 1000);
776
+ }
777
+
778
+ void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex, const std::vector<CTransactionRef>& vtxConflicted) {
779
+ LOCK(cs_main);
780
+
781
+ std::vector<uint256> vOrphanErase;
782
+
783
+ for (const CTransactionRef& ptx : pblock->vtx) {
784
+ const CTransaction& tx = *ptx;
785
+
786
+ // Which orphan pool entries must we evict?
787
+ for (const auto& txin : tx.vin) {
788
+ auto itByPrev = mapOrphanTransactionsByPrev.find(txin.prevout);
789
+ if (itByPrev == mapOrphanTransactionsByPrev.end()) continue;
790
+ for (auto mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) {
791
+ const CTransaction& orphanTx = *(*mi)->second.tx;
792
+ const uint256& orphanHash = orphanTx.GetHash();
793
+ vOrphanErase.push_back(orphanHash);
794
+ }
795
+ }
796
+ }
797
+
798
+ // Erase orphan transactions include or precluded by this block
799
+ if (vOrphanErase.size()) {
800
+ int nErased = 0;
801
+ for (uint256 &orphanHash : vOrphanErase) {
802
+ nErased += EraseOrphanTx(orphanHash);
803
+ }
804
+ LogPrint(BCLog::MEMPOOL, "Erased %d orphan tx included or conflicted by block\n", nErased);
805
+ }
806
+
807
+ g_last_tip_update = GetTime();
808
+ }
809
+
810
+ // All of the following cache a recent block, and are protected by cs_most_recent_block
811
+ static CCriticalSection cs_most_recent_block;
812
+ static std::shared_ptr<const CBlock> most_recent_block;
813
+ static std::shared_ptr<const CBlockHeaderAndShortTxIDs> most_recent_compact_block;
814
+ static uint256 most_recent_block_hash;
815
+ static bool fWitnessesPresentInMostRecentCompactBlock;
816
+
817
+ void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) {
818
+ std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true);
819
+ const CNetMsgMaker msgMaker(PROTOCOL_VERSION);
820
+
821
+ LOCK(cs_main);
822
+
823
+ static int nHighestFastAnnounce = 0;
824
+ if (pindex->nHeight <= nHighestFastAnnounce)
825
+ return;
826
+ nHighestFastAnnounce = pindex->nHeight;
827
+
828
+ bool fWitnessEnabled = IsWitnessEnabled(pindex->pprev, GetParams().GetConsensus());
829
+ uint256 hashBlock(pblock->GetHash());
830
+
831
+ {
832
+ LOCK(cs_most_recent_block);
833
+ most_recent_block_hash = hashBlock;
834
+ most_recent_block = pblock;
835
+ most_recent_compact_block = pcmpctblock;
836
+ fWitnessesPresentInMostRecentCompactBlock = fWitnessEnabled;
837
+ }
838
+
839
+ connman->ForEachNode([this, &pcmpctblock, pindex, &msgMaker, fWitnessEnabled, &hashBlock](CNode* pnode) {
840
+ // TODO: Avoid the repeated-serialization here
841
+ if (pnode->nVersion < INVALID_CB_NO_BAN_VERSION || pnode->fDisconnect)
842
+ return;
843
+ ProcessBlockAvailability(pnode->GetId());
844
+ CNodeState &state = *State(pnode->GetId());
845
+ // If the peer has, or we announced to them the previous block already,
846
+ // but we don't think they have this one, go ahead and announce it
847
+ if (state.fPreferHeaderAndIDs && (!fWitnessEnabled || state.fWantsCmpctWitness) &&
848
+ !PeerHasHeader(&state, pindex) && PeerHasHeader(&state, pindex->pprev)) {
849
+
850
+ LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", "PeerLogicValidation::NewPoWValidBlock",
851
+ hashBlock.ToString(), pnode->GetId());
852
+ connman->PushMessage(pnode, msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock));
853
+ state.pindexBestHeaderSent = pindex;
854
+ }
855
+ });
856
+ }
857
+
858
+ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
859
+ const int nNewHeight = pindexNew->nHeight;
860
+ connman->SetBestHeight(nNewHeight);
861
+
862
+ if (!fInitialDownload) {
863
+ // Find the hashes of all blocks that weren't previously in the best chain.
864
+ std::vector<uint256> vHashes;
865
+ const CBlockIndex *pindexToAnnounce = pindexNew;
866
+ while (pindexToAnnounce != pindexFork) {
867
+ vHashes.push_back(pindexToAnnounce->GetBlockHash());
868
+ pindexToAnnounce = pindexToAnnounce->pprev;
869
+ if (vHashes.size() == MAX_BLOCKS_TO_ANNOUNCE) {
870
+ // Limit announcements in case of a huge reorganization.
871
+ // Rely on the peer's synchronization mechanism in that case.
872
+ break;
873
+ }
874
+ }
875
+ // Relay inventory, but don't relay old inventory during initial block download.
876
+ connman->ForEachNode([nNewHeight, &vHashes](CNode* pnode) {
877
+ if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0)) {
878
+ for (const uint256& hash : reverse_iterate(vHashes)) {
879
+ pnode->PushBlockHash(hash);
880
+ }
881
+ }
882
+ });
883
+ connman->WakeMessageHandler();
884
+ }
885
+
886
+ nTimeBestReceived = GetTime();
887
+ }
888
+
889
+ void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationState& state) {
890
+ LOCK(cs_main);
891
+
892
+ const uint256 hash(block.GetHash());
893
+ std::map<uint256, std::pair<NodeId, bool>>::iterator it = mapBlockSource.find(hash);
894
+
895
+ int nDoS = 0;
896
+ if (state.IsInvalid(nDoS)) {
897
+ // Don't send reject message with code 0 or an internal reject code.
898
+ if (it != mapBlockSource.end() && State(it->second.first) && state.GetRejectCode() > 0 && state.GetRejectCode() < REJECT_INTERNAL) {
899
+ CBlockReject reject = {(unsigned char)state.GetRejectCode(), state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), hash};
900
+ State(it->second.first)->rejects.push_back(reject);
901
+ if (nDoS > 0 && it->second.second)
902
+ Misbehaving(it->second.first, nDoS);
903
+ }
904
+ }
905
+ // Check that:
906
+ // 1. The block is valid
907
+ // 2. We're not in initial block download
908
+ // 3. This is currently the best block we're aware of. We haven't updated
909
+ // the tip yet so we have no way to check this directly here. Instead we
910
+ // just check that there are currently no other blocks in flight.
911
+ else if (state.IsValid() &&
912
+ !IsInitialBlockDownload() &&
913
+ mapBlocksInFlight.count(hash) == mapBlocksInFlight.size()) {
914
+ if (it != mapBlockSource.end()) {
915
+ MaybeSetPeerAsAnnouncingHeaderAndIDs(it->second.first, connman);
916
+ }
917
+ }
918
+ if (it != mapBlockSource.end())
919
+ mapBlockSource.erase(it);
920
+ }
921
+
922
+ //////////////////////////////////////////////////////////////////////////////
923
+ //
924
+ // Messages
925
+ //
926
+
927
+
928
+ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
929
+ {
930
+ switch (inv.type)
931
+ {
932
+ case MSG_TX:
933
+ case MSG_WITNESS_TX:
934
+ {
935
+ assert(recentRejects);
936
+ if (chainActive.Tip()->GetBlockHash() != hashRecentRejectsChainTip)
937
+ {
938
+ // If the chain tip has changed previously rejected transactions
939
+ // might be now valid, e.g. due to a nLockTime'd tx becoming valid,
940
+ // or a double-spend. Reset the rejects filter and give those
941
+ // txs a second chance.
942
+ hashRecentRejectsChainTip = chainActive.Tip()->GetBlockHash();
943
+ recentRejects->reset();
944
+ }
945
+
946
+ return recentRejects->contains(inv.hash) ||
947
+ mempool.exists(inv.hash) ||
948
+ mapOrphanTransactions.count(inv.hash) ||
949
+ pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 0)) || // Best effort: only try output 0 and 1
950
+ pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 1));
951
+ }
952
+ case MSG_BLOCK:
953
+ case MSG_WITNESS_BLOCK:
954
+ return mapBlockIndex.count(inv.hash);
955
+ }
956
+ // Don't know what it is, just say we already got one
957
+ return true;
958
+ }
959
+
960
+ static void RelayTransaction(const CTransaction& tx, CConnman* connman)
961
+ {
962
+ CInv inv(MSG_TX, tx.GetHash());
963
+ connman->ForEachNode([&inv](CNode* pnode)
964
+ {
965
+ pnode->PushInventory(inv);
966
+ });
967
+ }
968
+
969
+ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman* connman)
970
+ {
971
+ unsigned int nRelayNodes = fReachable ? 2 : 1; // limited relaying of addresses outside our network(s)
972
+
973
+ // Relay to a limited number of other nodes
974
+ // Use deterministic randomness to send to the same nodes for 24 hours
975
+ // at a time so the addrKnowns of the chosen nodes prevent repeats
976
+ uint64_t hashAddr = addr.GetHash();
977
+ const CSipHasher hasher = connman->GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY).Write(hashAddr << 32).Write((GetTime() + hashAddr) / (24*60*60));
978
+ FastRandomContext insecure_rand;
979
+
980
+ std::array<std::pair<uint64_t, CNode*>,2> best{{{0, nullptr}, {0, nullptr}}};
981
+ assert(nRelayNodes <= best.size());
982
+
983
+ auto sortfunc = [&best, &hasher, nRelayNodes](CNode* pnode) {
984
+ if (pnode->nVersion >= CADDR_TIME_VERSION) {
985
+ uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize();
986
+ for (unsigned int i = 0; i < nRelayNodes; i++) {
987
+ if (hashKey > best[i].first) {
988
+ std::copy(best.begin() + i, best.begin() + nRelayNodes - 1, best.begin() + i + 1);
989
+ best[i] = std::make_pair(hashKey, pnode);
990
+ break;
991
+ }
992
+ }
993
+ }
994
+ };
995
+
996
+ auto pushfunc = [&addr, &best, nRelayNodes, &insecure_rand] {
997
+ for (unsigned int i = 0; i < nRelayNodes && best[i].first != 0; i++) {
998
+ best[i].second->PushAddress(addr, insecure_rand);
999
+ }
1000
+ };
1001
+
1002
+ connman->ForEachNodeThen(std::move(sortfunc), std::move(pushfunc));
1003
+ }
1004
+
1005
+ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParams, CConnman* connman, const std::atomic<bool>& interruptMsgProc)
1006
+ {
1007
+ std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin();
1008
+ std::vector<CInv> vNotFound;
1009
+ const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
1010
+ LOCK(cs_main);
1011
+
1012
+ while (it != pfrom->vRecvGetData.end()) {
1013
+ // Don't bother if send buffer is too full to respond anyway
1014
+ if (pfrom->fPauseSend)
1015
+ break;
1016
+
1017
+ const CInv &inv = *it;
1018
+ {
1019
+ if (interruptMsgProc)
1020
+ return;
1021
+
1022
+ it++;
1023
+
1024
+ if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK || inv.type == MSG_WITNESS_BLOCK)
1025
+ {
1026
+ bool send = false;
1027
+ BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
1028
+ std::shared_ptr<const CBlock> a_recent_block;
1029
+ std::shared_ptr<const CBlockHeaderAndShortTxIDs> a_recent_compact_block;
1030
+ bool fWitnessesPresentInARecentCompactBlock;
1031
+ {
1032
+ LOCK(cs_most_recent_block);
1033
+ a_recent_block = most_recent_block;
1034
+ a_recent_compact_block = most_recent_compact_block;
1035
+ fWitnessesPresentInARecentCompactBlock = fWitnessesPresentInMostRecentCompactBlock;
1036
+ }
1037
+ if (mi != mapBlockIndex.end())
1038
+ {
1039
+ if (mi->second->nChainTx && !mi->second->IsValid(BLOCK_VALID_SCRIPTS) &&
1040
+ mi->second->IsValid(BLOCK_VALID_TREE)) {
1041
+ // If we have the block and all of its parents, but have not yet validated it,
1042
+ // we might be in the middle of connecting it (ie in the unlock of cs_main
1043
+ // before ActivateBestChain but after AcceptBlock).
1044
+ // In this case, we need to run ActivateBestChain prior to checking the relay
1045
+ // conditions below.
1046
+ CValidationState dummy;
1047
+ ActivateBestChain(dummy, GetParams(), a_recent_block);
1048
+ }
1049
+ if (chainActive.Contains(mi->second)) {
1050
+ send = true;
1051
+ } else {
1052
+ // To prevent fingerprinting attacks, only send blocks outside of the active
1053
+ // chain if they are valid, and no more than a max reorg depth than the best header
1054
+ // chain we know about.
1055
+ send = mi->second->IsValid(BLOCK_VALID_SCRIPTS) &&
1056
+ StaleBlockRequestAllowed(mi->second, consensusParams) && (chainActive.Height() - (mi->second->nHeight-1) <
1057
+ GetParams().MaxReorganizationDepth());
1058
+ if (!send) {
1059
+ LogPrintf("%s: ignoring request from peer=%i for old block that isn't in the main chain\n", __func__, pfrom->GetId());
1060
+ }
1061
+ }
1062
+ }
1063
+ // disconnect node in case we have reached the outbound limit for serving historical blocks
1064
+ // never disconnect whitelisted nodes
1065
+ if (send && connman->OutboundTargetReached(true) && ( ((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - mi->second->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.type == MSG_FILTERED_BLOCK) && !pfrom->fWhitelisted)
1066
+ {
1067
+ LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom->GetId());
1068
+
1069
+ //disconnect node
1070
+ pfrom->fDisconnect = true;
1071
+ send = false;
1072
+ }
1073
+ // Pruned nodes may have deleted the block, so check whether
1074
+ // it's available before trying to send.
1075
+ if (send && (mi->second->nStatus & BLOCK_HAVE_DATA))
1076
+ {
1077
+ std::shared_ptr<const CBlock> pblock;
1078
+ if (a_recent_block && a_recent_block->GetHash() == (*mi).second->GetBlockHash()) {
1079
+ pblock = a_recent_block;
1080
+ } else {
1081
+ // Send block from disk
1082
+ std::shared_ptr<CBlock> pblockRead = std::make_shared<CBlock>();
1083
+ if (!ReadBlockFromDisk(*pblockRead, (*mi).second, consensusParams))
1084
+ assert(!"cannot load block from disk");
1085
+ pblock = pblockRead;
1086
+ }
1087
+ if (inv.type == MSG_BLOCK)
1088
+ connman->PushMessage(pfrom, msgMaker.Make(SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::BLOCK, *pblock));
1089
+ else if (inv.type == MSG_WITNESS_BLOCK)
1090
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::BLOCK, *pblock));
1091
+ else if (inv.type == MSG_FILTERED_BLOCK)
1092
+ {
1093
+ bool sendMerkleBlock = false;
1094
+ CMerkleBlock merkleBlock;
1095
+ {
1096
+ LOCK(pfrom->cs_filter);
1097
+ if (pfrom->pfilter) {
1098
+ sendMerkleBlock = true;
1099
+ merkleBlock = CMerkleBlock(*pblock, *pfrom->pfilter);
1100
+ }
1101
+ }
1102
+ if (sendMerkleBlock) {
1103
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::MERKLEBLOCK, merkleBlock));
1104
+ // CMerkleBlock just contains hashes, so also push any transactions in the block the client did not see
1105
+ // This avoids hurting performance by pointlessly requiring a round-trip
1106
+ // Note that there is currently no way for a node to request any single transactions we didn't send here -
1107
+ // they must either disconnect and retry or request the full block.
1108
+ // Thus, the protocol spec specified allows for us to provide duplicate txn here,
1109
+ // however we MUST always provide at least what the remote peer needs
1110
+ typedef std::pair<unsigned int, uint256> PairType;
1111
+ for (PairType& pair : merkleBlock.vMatchedTxn)
1112
+ connman->PushMessage(pfrom, msgMaker.Make(SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::TX, *pblock->vtx[pair.first]));
1113
+ }
1114
+ // else
1115
+ // no response
1116
+ }
1117
+ else if (inv.type == MSG_CMPCT_BLOCK)
1118
+ {
1119
+ // If a peer is asking for old blocks, we're almost guaranteed
1120
+ // they won't have a useful mempool to match against a compact block,
1121
+ // and we don't feel like constructing the object for them, so
1122
+ // instead we respond with the full, non-compact block.
1123
+ bool fPeerWantsWitness = State(pfrom->GetId())->fWantsCmpctWitness;
1124
+ int nSendFlags = fPeerWantsWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
1125
+ if (CanDirectFetch(consensusParams) && mi->second->nHeight >= chainActive.Height() - MAX_CMPCTBLOCK_DEPTH) {
1126
+ if ((fPeerWantsWitness || !fWitnessesPresentInARecentCompactBlock) && a_recent_compact_block &&
1127
+ a_recent_compact_block->header.GetHash() == mi->second->GetBlockHash()) {
1128
+ connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *a_recent_compact_block));
1129
+ } else {
1130
+ CBlockHeaderAndShortTxIDs cmpctblock(*pblock, fPeerWantsWitness);
1131
+ connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
1132
+ }
1133
+ } else {
1134
+ connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::BLOCK, *pblock));
1135
+ }
1136
+ }
1137
+
1138
+ // Trigger the peer node to send a getblocks request for the next batch of inventory
1139
+ if (inv.hash == pfrom->hashContinue)
1140
+ {
1141
+ // Bypass PushInventory, this must send even if redundant,
1142
+ // and we want it right after the last block so they don't
1143
+ // wait for other stuff first.
1144
+ std::vector<CInv> vInv;
1145
+ vInv.push_back(CInv(MSG_BLOCK, chainActive.Tip()->GetBlockHash()));
1146
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::INV, vInv));
1147
+ pfrom->hashContinue.SetNull();
1148
+ }
1149
+ }
1150
+ }
1151
+ else if (inv.type == MSG_TX || inv.type == MSG_WITNESS_TX)
1152
+ {
1153
+ // Send stream from relay memory
1154
+ bool push = false;
1155
+ auto mi = mapRelay.find(inv.hash);
1156
+ int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
1157
+ if (mi != mapRelay.end()) {
1158
+ connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
1159
+ push = true;
1160
+ } else if (pfrom->timeLastMempoolReq) {
1161
+ auto txinfo = mempool.info(inv.hash);
1162
+ // To protect privacy, do not answer getdata using the mempool when
1163
+ // that TX couldn't have been INVed in reply to a MEMPOOL request.
1164
+ if (txinfo.tx && txinfo.nTime <= pfrom->timeLastMempoolReq) {
1165
+ connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
1166
+ push = true;
1167
+ }
1168
+ }
1169
+ if (!push) {
1170
+ vNotFound.push_back(inv);
1171
+ }
1172
+ }
1173
+
1174
+ if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK || inv.type == MSG_WITNESS_BLOCK)
1175
+ break;
1176
+ }
1177
+ }
1178
+
1179
+ pfrom->vRecvGetData.erase(pfrom->vRecvGetData.begin(), it);
1180
+
1181
+ if (!vNotFound.empty()) {
1182
+ // Let the peer know that we didn't find what it asked for, so it doesn't
1183
+ // have to wait around forever. Currently only SPV clients actually care
1184
+ // about this message: it's needed when they are recursively walking the
1185
+ // dependencies of relevant unconfirmed transactions. SPV clients want to
1186
+ // do that because they want to know about (and store and rebroadcast and
1187
+ // risk analyze) the dependencies of transactions relevant to them, without
1188
+ // having to download the entire memory pool.
1189
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::NOTFOUND, vNotFound));
1190
+ }
1191
+ }
1192
+
1193
+ void static ProcessAssetGetData(CNode* pfrom, const Consensus::Params& consensusParams, CConnman* connman, const std::atomic<bool>& interruptMsgProc)
1194
+ {
1195
+ std::deque<CInvAsset>::iterator it = pfrom->vRecvAssetGetData.begin();
1196
+ std::vector<CInvAsset> vNotFound;
1197
+ const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
1198
+ LOCK(cs_main);
1199
+
1200
+ while (it != pfrom->vRecvAssetGetData.end()) {
1201
+ // Don't bother if send buffer is too full to respond anyway
1202
+ if (pfrom->fPauseSend)
1203
+ break;
1204
+
1205
+ const CInvAsset &inv = *it;
1206
+ {
1207
+ if (interruptMsgProc)
1208
+ return;
1209
+
1210
+ it++;
1211
+
1212
+ if (!IsAssetNameValid(inv.name)) {
1213
+ vNotFound.push_back(inv);
1214
+ continue;
1215
+ }
1216
+
1217
+ UNUSED_VAR bool push = false;
1218
+ auto currentActiveAssetCache = GetCurrentAssetCache();
1219
+ if (currentActiveAssetCache) {
1220
+ CNewAsset asset;
1221
+ int height;
1222
+ uint256 hash;
1223
+ if (currentActiveAssetCache->GetAssetMetaDataIfExists(inv.name, asset, height, hash)) {
1224
+ auto data = CDatabasedAssetData(asset, height, hash);
1225
+ passetsCache->Put(inv.name, data);
1226
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::ASSETDATA, SerializedAssetData(data)));
1227
+ push = true;
1228
+ } else {
1229
+ CDatabasedAssetData data;
1230
+ data.asset.strName = "_NF"; // Return _NF for NOT Found
1231
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::ASSETDATA, SerializedAssetData(data)));
1232
+ }
1233
+ }
1234
+
1235
+ // if (!push) {
1236
+ // vNotFound.push_back(inv);
1237
+ // }
1238
+ }
1239
+ }
1240
+
1241
+ pfrom->vRecvAssetGetData.erase(pfrom->vRecvAssetGetData.begin(), it);
1242
+
1243
+ // if (!vNotFound.empty()) {
1244
+ // // Let the peer know that we didn't find what it asked for, so it doesn't
1245
+ // // have to wait around forever. Currently only SPV clients actually care
1246
+ // // about this message: it's needed when they are recursively walking the
1247
+ // // dependencies of relevant unconfirmed transactions. SPV clients want to
1248
+ // // do that because they want to know about (and store and rebroadcast and
1249
+ // // risk analyze) the dependencies of transactions relevant to them, without
1250
+ // // having to download the entire memory pool.
1251
+ // for (auto assetinv : vNotFound) {
1252
+ // CDatabasedAssetData data;
1253
+ // data.asset.strName = "_NF"; // Return _NF for NOT Found
1254
+ // connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::ASSETDATA, SerializedAssetData(data)));
1255
+ // }
1256
+ // }
1257
+ }
1258
+
1259
+ uint32_t GetFetchFlags(CNode* pfrom) {
1260
+ uint32_t nFetchFlags = 0;
1261
+ if ((pfrom->GetLocalServices() & NODE_WITNESS) && State(pfrom->GetId())->fHaveWitness) {
1262
+ nFetchFlags |= MSG_WITNESS_FLAG;
1263
+ }
1264
+ return nFetchFlags;
1265
+ }
1266
+
1267
+ inline void static SendBlockTransactions(const CBlock& block, const BlockTransactionsRequest& req, CNode* pfrom, CConnman* connman) {
1268
+ BlockTransactions resp(req);
1269
+ for (size_t i = 0; i < req.indexes.size(); i++) {
1270
+ if (req.indexes[i] >= block.vtx.size()) {
1271
+ LOCK(cs_main);
1272
+ Misbehaving(pfrom->GetId(), 100);
1273
+ LogPrintf("Peer %d sent us a getblocktxn with out-of-bounds tx indices", pfrom->GetId());
1274
+ return;
1275
+ }
1276
+ resp.txn[i] = block.vtx[req.indexes[i]];
1277
+ }
1278
+ LOCK(cs_main);
1279
+ const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
1280
+ int nSendFlags = State(pfrom->GetId())->fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
1281
+ connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp));
1282
+ }
1283
+
1284
+ bool static ProcessHeadersMessage(CNode *pfrom, CConnman *connman, const std::vector<CBlockHeader>& headers, const CChainParams& chainparams, bool punish_duplicate_invalid)
1285
+ {
1286
+ const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
1287
+ size_t nCount = headers.size();
1288
+
1289
+ if (nCount == 0) {
1290
+ // Nothing interesting. Stop asking this peers for more headers.
1291
+ return true;
1292
+ }
1293
+
1294
+ bool received_new_header = false;
1295
+ const CBlockIndex *pindexLast = nullptr;
1296
+ {
1297
+ LOCK(cs_main);
1298
+ CNodeState *nodestate = State(pfrom->GetId());
1299
+
1300
+ // If this looks like it could be a block announcement (nCount <
1301
+ // MAX_BLOCKS_TO_ANNOUNCE), use special logic for handling headers that
1302
+ // don't connect:
1303
+ // - Send a getheaders message in response to try to connect the chain.
1304
+ // - The peer can send up to MAX_UNCONNECTING_HEADERS in a row that
1305
+ // don't connect before giving DoS points
1306
+ // - Once a headers message is received that is valid and does connect,
1307
+ // nUnconnectingHeaders gets reset back to 0.
1308
+ if (mapBlockIndex.find(headers[0].hashPrevBlock) == mapBlockIndex.end() && nCount < MAX_BLOCKS_TO_ANNOUNCE) {
1309
+ nodestate->nUnconnectingHeaders++;
1310
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), uint256()));
1311
+ LogPrint(BCLog::NET, "received header %s: missing prev block %s, sending getheaders (%d) to end (peer=%d, nUnconnectingHeaders=%d)\n",
1312
+ headers[0].GetHash().ToString(),
1313
+ headers[0].hashPrevBlock.ToString(),
1314
+ pindexBestHeader->nHeight,
1315
+ pfrom->GetId(), nodestate->nUnconnectingHeaders);
1316
+ // Set hashLastUnknownBlock for this peer, so that if we
1317
+ // eventually get the headers - even from a different peer -
1318
+ // we can use this peer to download.
1319
+ UpdateBlockAvailability(pfrom->GetId(), headers.back().GetHash());
1320
+
1321
+ if (nodestate->nUnconnectingHeaders % MAX_UNCONNECTING_HEADERS == 0) {
1322
+ Misbehaving(pfrom->GetId(), 20);
1323
+ }
1324
+ return true;
1325
+ }
1326
+
1327
+ uint256 hashLastBlock;
1328
+ for (const CBlockHeader& header : headers) {
1329
+ if (!hashLastBlock.IsNull() && header.hashPrevBlock != hashLastBlock) {
1330
+ Misbehaving(pfrom->GetId(), 20);
1331
+ return error("non-continuous headers sequence");
1332
+ }
1333
+ hashLastBlock = header.GetHash();
1334
+ }
1335
+
1336
+ // If we don't have the last header, then they'll have given us
1337
+ // something new (if these headers are valid).
1338
+ if (mapBlockIndex.find(hashLastBlock) == mapBlockIndex.end()) {
1339
+ received_new_header = true;
1340
+ }
1341
+ }
1342
+
1343
+ CValidationState state;
1344
+ CBlockHeader first_invalid_header;
1345
+ if (!ProcessNewBlockHeaders(headers, state, chainparams, &pindexLast, &first_invalid_header)) {
1346
+ int nDoS;
1347
+ if (state.IsInvalid(nDoS)) {
1348
+ LOCK(cs_main);
1349
+ if (nDoS > 0) {
1350
+ Misbehaving(pfrom->GetId(), nDoS);
1351
+ }
1352
+ if (punish_duplicate_invalid && mapBlockIndex.find(first_invalid_header.GetHash()) != mapBlockIndex.end()) {
1353
+ // Goal: don't allow outbound peers to use up our outbound
1354
+ // connection slots if they are on incompatible chains.
1355
+ //
1356
+ // We ask the caller to set punish_invalid appropriately based
1357
+ // on the peer and the method of header delivery (compact
1358
+ // blocks are allowed to be invalid in some circumstances,
1359
+ // under BIP 152).
1360
+ // Here, we try to detect the narrow situation that we have a
1361
+ // valid block header (ie it was valid at the time the header
1362
+ // was received, and hence stored in mapBlockIndex) but know the
1363
+ // block is invalid, and that a peer has announced that same
1364
+ // block as being on its active chain.
1365
+ // Disconnect the peer in such a situation.
1366
+ //
1367
+ // Note: if the header that is invalid was not accepted to our
1368
+ // mapBlockIndex at all, that may also be grounds for
1369
+ // disconnecting the peer, as the chain they are on is likely
1370
+ // to be incompatible. However, there is a circumstance where
1371
+ // that does not hold: if the header's timestamp is more than
1372
+ // 2 hours ahead of our current time. In that case, the header
1373
+ // may become valid in the future, and we don't want to
1374
+ // disconnect a peer merely for serving us one too-far-ahead
1375
+ // block header, to prevent an attacker from splitting the
1376
+ // network by mining a block right at the 2 hour boundary.
1377
+ //
1378
+ // TODO: update the DoS logic (or, rather, rewrite the
1379
+ // DoS-interface between validation and net_processing) so that
1380
+ // the interface is cleaner, and so that we disconnect on all the
1381
+ // reasons that a peer's headers chain is incompatible
1382
+ // with ours (eg block->nVersion softforks, MTP violations,
1383
+ // etc), and not just the duplicate-invalid case.
1384
+ pfrom->fDisconnect = true;
1385
+ }
1386
+ return error("invalid header received");
1387
+ }
1388
+ }
1389
+
1390
+ {
1391
+ LOCK(cs_main);
1392
+ CNodeState *nodestate = State(pfrom->GetId());
1393
+ if (nodestate->nUnconnectingHeaders > 0) {
1394
+ LogPrint(BCLog::NET, "peer=%d: resetting nUnconnectingHeaders (%d -> 0)\n", pfrom->GetId(), nodestate->nUnconnectingHeaders);
1395
+ }
1396
+ nodestate->nUnconnectingHeaders = 0;
1397
+
1398
+ assert(pindexLast);
1399
+ UpdateBlockAvailability(pfrom->GetId(), pindexLast->GetBlockHash());
1400
+
1401
+ // From here, pindexBestKnownBlock should be guaranteed to be non-null,
1402
+ // because it is set in UpdateBlockAvailability. Some nullptr checks
1403
+ // are still present, however, as belt-and-suspenders.
1404
+
1405
+ if (received_new_header && pindexLast->nChainWork > chainActive.Tip()->nChainWork) {
1406
+ nodestate->m_last_block_announcement = GetTime();
1407
+ }
1408
+
1409
+ if (nCount == MAX_HEADERS_RESULTS) {
1410
+ // Headers message had its maximum size; the peer may have more headers.
1411
+ // TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue
1412
+ // from there instead.
1413
+ LogPrint(BCLog::NET, "more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->GetId(), pfrom->nStartingHeight);
1414
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexLast), uint256()));
1415
+ }
1416
+
1417
+ bool fCanDirectFetch = CanDirectFetch(chainparams.GetConsensus());
1418
+ // If this set of headers is valid and ends in a block with at least as
1419
+ // much work as our tip, download as much as possible.
1420
+ if (fCanDirectFetch && pindexLast->IsValid(BLOCK_VALID_TREE) && chainActive.Tip()->nChainWork <= pindexLast->nChainWork) {
1421
+ std::vector<const CBlockIndex*> vToFetch;
1422
+ const CBlockIndex *pindexWalk = pindexLast;
1423
+ // Calculate all the blocks we'd need to switch to pindexLast, up to a limit.
1424
+ while (pindexWalk && !chainActive.Contains(pindexWalk) && vToFetch.size() <= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
1425
+ if (!(pindexWalk->nStatus & BLOCK_HAVE_DATA) &&
1426
+ !mapBlocksInFlight.count(pindexWalk->GetBlockHash()) &&
1427
+ (!IsWitnessEnabled(pindexWalk->pprev, chainparams.GetConsensus()) || State(pfrom->GetId())->fHaveWitness)) {
1428
+ // We don't have this block, and it's not yet in flight.
1429
+ vToFetch.push_back(pindexWalk);
1430
+ }
1431
+ pindexWalk = pindexWalk->pprev;
1432
+ }
1433
+ // If pindexWalk still isn't on our main chain, we're looking at a
1434
+ // very large reorg at a time we think we're close to caught up to
1435
+ // the main chain -- this shouldn't really happen. Bail out on the
1436
+ // direct fetch and rely on parallel download instead.
1437
+ if (!chainActive.Contains(pindexWalk)) {
1438
+ LogPrint(BCLog::NET, "Large reorg, won't direct fetch to %s (%d)\n",
1439
+ pindexLast->GetBlockHash().ToString(),
1440
+ pindexLast->nHeight);
1441
+ } else {
1442
+ std::vector<CInv> vGetData;
1443
+ // Download as much as possible, from earliest to latest.
1444
+ for (const CBlockIndex *pindex : reverse_iterate(vToFetch)) {
1445
+ if (nodestate->nBlocksInFlight >= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
1446
+ // Can't download any more from this peer
1447
+ break;
1448
+ }
1449
+ uint32_t nFetchFlags = GetFetchFlags(pfrom);
1450
+ vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
1451
+ MarkBlockAsInFlight(pfrom->GetId(), pindex->GetBlockHash(), pindex);
1452
+ LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n",
1453
+ pindex->GetBlockHash().ToString(), pfrom->GetId());
1454
+ }
1455
+ if (vGetData.size() > 1) {
1456
+ LogPrint(BCLog::NET, "Downloading blocks toward %s (%d) via headers direct fetch\n",
1457
+ pindexLast->GetBlockHash().ToString(), pindexLast->nHeight);
1458
+ }
1459
+ if (vGetData.size() > 0) {
1460
+ if (nodestate->fSupportsDesiredCmpctVersion && vGetData.size() == 1 && mapBlocksInFlight.size() == 1 && pindexLast->pprev->IsValid(BLOCK_VALID_CHAIN)) {
1461
+ // In any case, we want to download using a compact block, not a regular one
1462
+ vGetData[0] = CInv(MSG_CMPCT_BLOCK, vGetData[0].hash);
1463
+ }
1464
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETDATA, vGetData));
1465
+ }
1466
+ }
1467
+ }
1468
+ // If we're in IBD, we want outbound peers that will serve us a useful
1469
+ // chain. Disconnect peers that are on chains with insufficient work.
1470
+ if (IsInitialBlockDownload() && nCount != MAX_HEADERS_RESULTS) {
1471
+ // When nCount < MAX_HEADERS_RESULTS, we know we have no more
1472
+ // headers to fetch from this peer.
1473
+ if (nodestate->pindexBestKnownBlock && nodestate->pindexBestKnownBlock->nChainWork < nMinimumChainWork) {
1474
+ // This peer has too little work on their headers chain to help
1475
+ // us sync -- disconnect if using an outbound slot (unless
1476
+ // whitelisted or addnode).
1477
+ // Note: We compare their tip to nMinimumChainWork (rather than
1478
+ // chainActive.Tip()) because we won't start block download
1479
+ // until we have a headers chain that has at least
1480
+ // nMinimumChainWork, even if a peer has a chain past our tip,
1481
+ // as an anti-DoS measure.
1482
+ if (IsOutboundDisconnectionCandidate(pfrom)) {
1483
+ LogPrintf("Disconnecting outbound peer %d -- headers chain has insufficient work\n", pfrom->GetId());
1484
+ pfrom->fDisconnect = true;
1485
+ }
1486
+ }
1487
+ }
1488
+
1489
+ if (!pfrom->fDisconnect && IsOutboundDisconnectionCandidate(pfrom) && nodestate->pindexBestKnownBlock != nullptr) {
1490
+ // If this is an outbound peer, check to see if we should protect
1491
+ // it from the bad/lagging chain logic.
1492
+ if (g_outbound_peers_with_protect_from_disconnect < MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT && nodestate->pindexBestKnownBlock->nChainWork >= chainActive.Tip()->nChainWork && !nodestate->m_chain_sync.m_protect) {
1493
+ LogPrint(BCLog::NET, "Protecting outbound peer=%d from eviction\n", pfrom->GetId());
1494
+ nodestate->m_chain_sync.m_protect = true;
1495
+ ++g_outbound_peers_with_protect_from_disconnect;
1496
+ }
1497
+ }
1498
+ }
1499
+
1500
+ return true;
1501
+ }
1502
+
1503
+ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman* connman, const std::atomic<bool>& interruptMsgProc)
1504
+ {
1505
+ LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->GetId());
1506
+ if (gArgs.IsArgSet("-dropmessagestest") && GetRand(gArgs.GetArg("-dropmessagestest", 0)) == 0)
1507
+ {
1508
+ LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");
1509
+ return true;
1510
+ }
1511
+
1512
+
1513
+ if (!(pfrom->GetLocalServices() & NODE_BLOOM) &&
1514
+ (strCommand == NetMsgType::FILTERLOAD ||
1515
+ strCommand == NetMsgType::FILTERADD))
1516
+ {
1517
+ if (pfrom->nVersion >= NO_BLOOM_VERSION) {
1518
+ LOCK(cs_main);
1519
+ Misbehaving(pfrom->GetId(), 100);
1520
+ return false;
1521
+ } else {
1522
+ pfrom->fDisconnect = true;
1523
+ return false;
1524
+ }
1525
+ }
1526
+
1527
+ if (strCommand == NetMsgType::REJECT)
1528
+ {
1529
+ if (LogAcceptCategory(BCLog::NET)) {
1530
+ try {
1531
+ std::string strMsg; unsigned char ccode; std::string strReason;
1532
+ vRecv >> LIMITED_STRING(strMsg, CMessageHeader::COMMAND_SIZE) >> ccode >> LIMITED_STRING(strReason, MAX_REJECT_MESSAGE_LENGTH);
1533
+
1534
+ std::ostringstream ss;
1535
+ ss << strMsg << " code " << itostr(ccode) << ": " << strReason;
1536
+
1537
+ if (strMsg == NetMsgType::BLOCK || strMsg == NetMsgType::TX)
1538
+ {
1539
+ uint256 hash;
1540
+ vRecv >> hash;
1541
+ ss << ": hash " << hash.ToString();
1542
+ }
1543
+ LogPrint(BCLog::NET, "Reject %s\n", SanitizeString(ss.str()));
1544
+ } catch (const std::ios_base::failure&) {
1545
+ // Avoid feedback loops by preventing reject messages from triggering a new reject message.
1546
+ LogPrint(BCLog::NET, "Unparseable reject message received\n");
1547
+ }
1548
+ }
1549
+ }
1550
+
1551
+ else if (strCommand == NetMsgType::VERSION)
1552
+ {
1553
+ // Each connection can only send one version message
1554
+ if (pfrom->nVersion != 0)
1555
+ {
1556
+ connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_DUPLICATE, std::string("Duplicate version message")));
1557
+ LOCK(cs_main);
1558
+ Misbehaving(pfrom->GetId(), 1);
1559
+ return false;
1560
+ }
1561
+
1562
+ int64_t nTime;
1563
+ CAddress addrMe;
1564
+ CAddress addrFrom;
1565
+ uint64_t nNonce = 1;
1566
+ uint64_t nServiceInt;
1567
+ ServiceFlags nServices;
1568
+ int nVersion;
1569
+ int nSendVersion;
1570
+ std::string strSubVer;
1571
+ std::string cleanSubVer;
1572
+ int nStartingHeight = -1;
1573
+ bool fRelay = true;
1574
+
1575
+ vRecv >> nVersion >> nServiceInt >> nTime >> addrMe;
1576
+ nSendVersion = std::min(nVersion, PROTOCOL_VERSION);
1577
+ nServices = ServiceFlags(nServiceInt);
1578
+ if (!pfrom->fInbound)
1579
+ {
1580
+ connman->SetServices(pfrom->addr, nServices);
1581
+ }
1582
+ if (!pfrom->fInbound && !pfrom->fFeeler && !pfrom->m_manual_connection && !HasAllDesirableServiceFlags(nServices))
1583
+ {
1584
+ LogPrint(BCLog::NET, "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom->GetId(), nServices, GetDesirableServiceFlags(nServices));
1585
+ connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_NONSTANDARD,
1586
+ strprintf("Expected to offer services %08x", GetDesirableServiceFlags(nServices))));
1587
+ pfrom->fDisconnect = true;
1588
+ return false;
1589
+ }
1590
+
1591
+ if (nServices & ((1 << 7) | (1 << 5))) {
1592
+ if (GetTime() < 1533096000) {
1593
+ // Immediately disconnect peers that use service bits 6 or 8 until August 1st, 2018
1594
+ // These bits have been used as a flag to indicate that a node is running incompatible
1595
+ // consensus rules instead of changing the network magic, so we're stuck disconnecting
1596
+ // based on these service bits, at least for a while.
1597
+ pfrom->fDisconnect = true;
1598
+ return false;
1599
+ }
1600
+ }
1601
+
1602
+ if (nVersion < MIN_PEER_PROTO_VERSION)
1603
+ {
1604
+ // disconnect from peers older than this proto version
1605
+ LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->GetId(), nVersion);
1606
+ connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
1607
+ strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION)));
1608
+ pfrom->fDisconnect = true;
1609
+ return false;
1610
+ }
1611
+
1612
+ if (IsRip5Active() && nVersion < MESSAGING_RESTRICTED_ASSETS_VERSION) {
1613
+ LogPrintf("peer=%d using obsolete version %i; disconnecting because peer isn't signalling protocol version for restricted and messaging assets\n", pfrom->GetId(), nVersion);
1614
+ connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
1615
+ strprintf("Version must be %d or greater", MESSAGING_RESTRICTED_ASSETS_VERSION)));
1616
+ pfrom->fDisconnect = true;
1617
+ return false;
1618
+ }
1619
+
1620
+ if (AreTransferScriptsSizeDeployed() && nVersion < KAWPOW_VERSION) {
1621
+ LogPrintf("peer=%d using obsolete version %i; disconnecting because peer isn't signalling protocol version for kawpow support\n", pfrom->GetId(), nVersion);
1622
+ connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
1623
+ strprintf("Version must be %d or greater or equal to", KAWPOW_VERSION)));
1624
+ pfrom->fDisconnect = true;
1625
+ return false;
1626
+ }
1627
+
1628
+ if (nVersion == 10300)
1629
+ nVersion = 300;
1630
+ if (!vRecv.empty())
1631
+ vRecv >> addrFrom >> nNonce;
1632
+ if (!vRecv.empty()) {
1633
+ vRecv >> LIMITED_STRING(strSubVer, MAX_SUBVERSION_LENGTH);
1634
+ cleanSubVer = SanitizeString(strSubVer);
1635
+ }
1636
+ if (!vRecv.empty()) {
1637
+ vRecv >> nStartingHeight;
1638
+ }
1639
+ if (!vRecv.empty())
1640
+ vRecv >> fRelay;
1641
+ // Disconnect if we connected to ourself
1642
+ if (pfrom->fInbound && !connman->CheckIncomingNonce(nNonce))
1643
+ {
1644
+ LogPrintf("connected to self at %s, disconnecting\n", pfrom->addr.ToString());
1645
+ pfrom->fDisconnect = true;
1646
+ return true;
1647
+ }
1648
+
1649
+ if (pfrom->fInbound && addrMe.IsRoutable())
1650
+ {
1651
+ SeenLocal(addrMe);
1652
+ }
1653
+
1654
+ // Be shy and don't send version until we hear
1655
+ if (pfrom->fInbound)
1656
+ PushNodeVersion(pfrom, connman, GetAdjustedTime());
1657
+
1658
+ connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERACK));
1659
+
1660
+ pfrom->nServices = nServices;
1661
+ pfrom->SetAddrLocal(addrMe);
1662
+ {
1663
+ LOCK(pfrom->cs_SubVer);
1664
+ pfrom->strSubVer = strSubVer;
1665
+ pfrom->cleanSubVer = cleanSubVer;
1666
+ }
1667
+ pfrom->nStartingHeight = nStartingHeight;
1668
+ pfrom->fClient = !(nServices & NODE_NETWORK);
1669
+ {
1670
+ LOCK(pfrom->cs_filter);
1671
+ pfrom->fRelayTxes = fRelay; // set to true after we get the first filter* message
1672
+ }
1673
+
1674
+ // Change version
1675
+ pfrom->SetSendVersion(nSendVersion);
1676
+ pfrom->nVersion = nVersion;
1677
+
1678
+ if((nServices & NODE_WITNESS))
1679
+ {
1680
+ LOCK(cs_main);
1681
+ State(pfrom->GetId())->fHaveWitness = true;
1682
+ }
1683
+
1684
+ // Potentially mark this peer as a preferred download peer.
1685
+ {
1686
+ LOCK(cs_main);
1687
+ UpdatePreferredDownload(pfrom, State(pfrom->GetId()));
1688
+ }
1689
+
1690
+ if (!pfrom->fInbound)
1691
+ {
1692
+ // Advertise our address
1693
+ if (fListen && !IsInitialBlockDownload())
1694
+ {
1695
+ CAddress addr = GetLocalAddress(&pfrom->addr, pfrom->GetLocalServices());
1696
+ FastRandomContext insecure_rand;
1697
+ if (addr.IsRoutable())
1698
+ {
1699
+ LogPrint(BCLog::NET, "ProcessMessages: advertising address %s\n", addr.ToString());
1700
+ pfrom->PushAddress(addr, insecure_rand);
1701
+ } else if (IsPeerAddrLocalGood(pfrom)) {
1702
+ addr.SetIP(addrMe);
1703
+ LogPrint(BCLog::NET, "ProcessMessages: advertising address %s\n", addr.ToString());
1704
+ pfrom->PushAddress(addr, insecure_rand);
1705
+ }
1706
+ }
1707
+
1708
+ // Get recent addresses
1709
+ if (pfrom->fOneShot || pfrom->nVersion >= CADDR_TIME_VERSION || connman->GetAddressCount() < 1000)
1710
+ {
1711
+ connman->PushMessage(pfrom, CNetMsgMaker(nSendVersion).Make(NetMsgType::GETADDR));
1712
+ pfrom->fGetAddr = true;
1713
+ }
1714
+ connman->MarkAddressGood(pfrom->addr);
1715
+ }
1716
+
1717
+ std::string remoteAddr;
1718
+ if (fLogIPs)
1719
+ remoteAddr = ", peeraddr=" + pfrom->addr.ToString();
1720
+
1721
+ LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, peer=%d%s\n",
1722
+ cleanSubVer, pfrom->nVersion,
1723
+ pfrom->nStartingHeight, addrMe.ToString(), pfrom->GetId(),
1724
+ remoteAddr);
1725
+
1726
+ int64_t nTimeOffset = nTime - GetTime();
1727
+ pfrom->nTimeOffset = nTimeOffset;
1728
+ AddTimeData(pfrom->addr, nTimeOffset);
1729
+
1730
+ // If the peer is old enough to have the old alert system, send it the final alert.
1731
+ if (pfrom->nVersion <= 70012) {
1732
+ CDataStream finalAlert(ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50"), SER_NETWORK, PROTOCOL_VERSION);
1733
+ connman->PushMessage(pfrom, CNetMsgMaker(nSendVersion).Make("alert", finalAlert));
1734
+ }
1735
+
1736
+ // Feeler connections exist only to verify if address is online.
1737
+ if (pfrom->fFeeler) {
1738
+ assert(pfrom->fInbound == false);
1739
+ pfrom->fDisconnect = true;
1740
+ }
1741
+ return true;
1742
+ }
1743
+
1744
+
1745
+ else if (pfrom->nVersion == 0)
1746
+ {
1747
+ // Must have a version message before anything else
1748
+ LOCK(cs_main);
1749
+ Misbehaving(pfrom->GetId(), 1);
1750
+ return false;
1751
+ }
1752
+
1753
+ // At this point, the outgoing message serialization version can't change.
1754
+ const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
1755
+
1756
+ if (strCommand == NetMsgType::VERACK)
1757
+ {
1758
+ pfrom->SetRecvVersion(std::min(pfrom->nVersion.load(), PROTOCOL_VERSION));
1759
+
1760
+ if (!pfrom->fInbound) {
1761
+ // Mark this node as currently connected, so we update its timestamp later.
1762
+ LOCK(cs_main);
1763
+ State(pfrom->GetId())->fCurrentlyConnected = true;
1764
+ }
1765
+
1766
+ if (pfrom->nVersion >= SENDHEADERS_VERSION) {
1767
+ // Tell our peer we prefer to receive headers rather than inv's
1768
+ // We send this to non-NODE NETWORK peers as well, because even
1769
+ // non-NODE NETWORK peers can announce blocks (such as pruning
1770
+ // nodes)
1771
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::SENDHEADERS));
1772
+ }
1773
+ if (pfrom->nVersion >= SHORT_IDS_BLOCKS_VERSION) {
1774
+ // Tell our peer we are willing to provide version 1 or 2 cmpctblocks
1775
+ // However, we do not request new block announcements using
1776
+ // cmpctblock messages.
1777
+ // We send this to non-NODE NETWORK peers as well, because
1778
+ // they may wish to request compact blocks from us
1779
+ bool fAnnounceUsingCMPCTBLOCK = false;
1780
+ uint64_t nCMPCTBLOCKVersion = 2;
1781
+ if (pfrom->GetLocalServices() & NODE_WITNESS)
1782
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
1783
+ nCMPCTBLOCKVersion = 1;
1784
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
1785
+ }
1786
+ pfrom->fSuccessfullyConnected = true;
1787
+ }
1788
+
1789
+ else if (!pfrom->fSuccessfullyConnected)
1790
+ {
1791
+ // Must have a verack message before anything else
1792
+ LOCK(cs_main);
1793
+ Misbehaving(pfrom->GetId(), 1);
1794
+ return false;
1795
+ }
1796
+
1797
+ else if (strCommand == NetMsgType::ADDR)
1798
+ {
1799
+ std::vector<CAddress> vAddr;
1800
+ vRecv >> vAddr;
1801
+
1802
+ // Don't want addr from older versions unless seeding
1803
+ if (pfrom->nVersion < CADDR_TIME_VERSION && connman->GetAddressCount() > 1000)
1804
+ return true;
1805
+ if (vAddr.size() > 1000)
1806
+ {
1807
+ LOCK(cs_main);
1808
+ Misbehaving(pfrom->GetId(), 20);
1809
+ return error("message addr size() = %u", vAddr.size());
1810
+ }
1811
+
1812
+ // Store the new addresses
1813
+ std::vector<CAddress> vAddrOk;
1814
+ int64_t nNow = GetAdjustedTime();
1815
+ int64_t nSince = nNow - 10 * 60;
1816
+ for (CAddress& addr : vAddr)
1817
+ {
1818
+ if (interruptMsgProc)
1819
+ return true;
1820
+
1821
+ // We only bother storing full nodes, though this may include
1822
+ // things which we would not make an outbound connection to, in
1823
+ // part because we may make feeler connections to them.
1824
+ if (!MayHaveUsefulAddressDB(addr.nServices))
1825
+ continue;
1826
+
1827
+ if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60)
1828
+ addr.nTime = nNow - 5 * 24 * 60 * 60;
1829
+ pfrom->AddAddressKnown(addr);
1830
+ bool fReachable = IsReachable(addr);
1831
+ if (addr.nTime > nSince && !pfrom->fGetAddr && vAddr.size() <= 10 && addr.IsRoutable())
1832
+ {
1833
+ // Relay to a limited number of other nodes
1834
+ RelayAddress(addr, fReachable, connman);
1835
+ }
1836
+ // Do not store addresses outside our network
1837
+ if (fReachable)
1838
+ vAddrOk.push_back(addr);
1839
+ }
1840
+ connman->AddNewAddresses(vAddrOk, pfrom->addr, 2 * 60 * 60);
1841
+ if (vAddr.size() < 1000)
1842
+ pfrom->fGetAddr = false;
1843
+ if (pfrom->fOneShot)
1844
+ pfrom->fDisconnect = true;
1845
+ }
1846
+
1847
+ else if (strCommand == NetMsgType::SENDHEADERS)
1848
+ {
1849
+ LOCK(cs_main);
1850
+ State(pfrom->GetId())->fPreferHeaders = true;
1851
+ }
1852
+
1853
+ else if (strCommand == NetMsgType::SENDCMPCT)
1854
+ {
1855
+ bool fAnnounceUsingCMPCTBLOCK = false;
1856
+ uint64_t nCMPCTBLOCKVersion = 0;
1857
+ vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion;
1858
+ if (nCMPCTBLOCKVersion == 1 || ((pfrom->GetLocalServices() & NODE_WITNESS) && nCMPCTBLOCKVersion == 2)) {
1859
+ LOCK(cs_main);
1860
+ // fProvidesHeaderAndIDs is used to "lock in" version of compact blocks we send (fWantsCmpctWitness)
1861
+ if (!State(pfrom->GetId())->fProvidesHeaderAndIDs) {
1862
+ State(pfrom->GetId())->fProvidesHeaderAndIDs = true;
1863
+ State(pfrom->GetId())->fWantsCmpctWitness = nCMPCTBLOCKVersion == 2;
1864
+ }
1865
+ if (State(pfrom->GetId())->fWantsCmpctWitness == (nCMPCTBLOCKVersion == 2)) // ignore later version announces
1866
+ State(pfrom->GetId())->fPreferHeaderAndIDs = fAnnounceUsingCMPCTBLOCK;
1867
+ if (!State(pfrom->GetId())->fSupportsDesiredCmpctVersion) {
1868
+ if (pfrom->GetLocalServices() & NODE_WITNESS)
1869
+ State(pfrom->GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2);
1870
+ else
1871
+ State(pfrom->GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 1);
1872
+ }
1873
+ }
1874
+ }
1875
+
1876
+
1877
+ else if (strCommand == NetMsgType::INV)
1878
+ {
1879
+ std::vector<CInv> vInv;
1880
+ vRecv >> vInv;
1881
+ if (vInv.size() > MAX_INV_SZ)
1882
+ {
1883
+ LOCK(cs_main);
1884
+ Misbehaving(pfrom->GetId(), 20);
1885
+ return error("message inv size() = %u", vInv.size());
1886
+ }
1887
+
1888
+ bool fBlocksOnly = !fRelayTxes;
1889
+
1890
+ // Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistrelay is true
1891
+ if (pfrom->fWhitelisted && gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY))
1892
+ fBlocksOnly = false;
1893
+
1894
+ LOCK(cs_main);
1895
+
1896
+ uint32_t nFetchFlags = GetFetchFlags(pfrom);
1897
+
1898
+ for (CInv &inv : vInv)
1899
+ {
1900
+ if (interruptMsgProc)
1901
+ return true;
1902
+
1903
+ bool fAlreadyHave = AlreadyHave(inv);
1904
+ LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->GetId());
1905
+
1906
+ if (inv.type == MSG_TX) {
1907
+ inv.type |= nFetchFlags;
1908
+ }
1909
+
1910
+ if (inv.type == MSG_BLOCK) {
1911
+ UpdateBlockAvailability(pfrom->GetId(), inv.hash);
1912
+ if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
1913
+ // We used to request the full block here, but since headers-announcements are now the
1914
+ // primary method of announcement on the network, and since, in the case that a node
1915
+ // fell back to inv we probably have a reorg which we should get the headers for first,
1916
+ // we now only provide a getheaders response here. When we receive the headers, we will
1917
+ // then ask for the blocks we need.
1918
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), inv.hash));
1919
+ LogPrint(BCLog::NET, "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->GetId());
1920
+ }
1921
+ }
1922
+ else
1923
+ {
1924
+ pfrom->AddInventoryKnown(inv);
1925
+ if (fBlocksOnly) {
1926
+ LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), pfrom->GetId());
1927
+ } else if (!fAlreadyHave && !fImporting && !fReindex && !IsInitialBlockDownload()) {
1928
+ pfrom->AskFor(inv);
1929
+ }
1930
+ }
1931
+ }
1932
+ }
1933
+
1934
+ else if (strCommand == NetMsgType::GETDATA)
1935
+ {
1936
+ std::vector<CInv> vInv;
1937
+ vRecv >> vInv;
1938
+ if (vInv.size() > MAX_INV_SZ)
1939
+ {
1940
+ LOCK(cs_main);
1941
+ Misbehaving(pfrom->GetId(), 20);
1942
+ return error("message getdata size() = %u", vInv.size());
1943
+ }
1944
+
1945
+ LogPrint(BCLog::NET, "received getdata (%u invsz) peer=%d\n", vInv.size(), pfrom->GetId());
1946
+
1947
+ if (vInv.size() > 0) {
1948
+ LogPrint(BCLog::NET, "received getdata for: %s peer=%d\n", vInv[0].ToString(), pfrom->GetId());
1949
+ }
1950
+
1951
+ pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end());
1952
+ ProcessGetData(pfrom, chainparams.GetConsensus(), connman, interruptMsgProc);
1953
+ }
1954
+
1955
+ else if (strCommand == NetMsgType::GETASSETDATA)
1956
+ {
1957
+ if (IsInitialBlockDownload()) {
1958
+ LogPrint(BCLog::NET, "Ignoring getassetdata from peer=%d because node is in initial block download\n", pfrom->GetId());
1959
+ return true;
1960
+ }
1961
+
1962
+ std::vector<CInvAsset> vInvAsset;
1963
+ vRecv >> vInvAsset;
1964
+
1965
+ if (vInvAsset.size() > MAX_ASSET_INV_SZ)
1966
+ {
1967
+ LOCK(cs_main);
1968
+ Misbehaving(pfrom->GetId(), 20);
1969
+ return error("message getassetdata size() = %u", vInvAsset.size());
1970
+ }
1971
+
1972
+ for (auto item : vInvAsset) {
1973
+ if (item.name.size() > MAX_ASSET_LENGTH) {
1974
+ LOCK(cs_main);
1975
+ Misbehaving(pfrom->GetId(), 100);
1976
+ return error("message getassetdata assetname size() = %u", item.name.size());
1977
+ }
1978
+ }
1979
+
1980
+ LogPrint(BCLog::NET, "received getassetdata (%u invassetsz) peer=%d\n", vInvAsset.size(), pfrom->GetId());
1981
+
1982
+ if (vInvAsset.size() > 0) {
1983
+ LogPrint(BCLog::NET, "received getassetdata for: %s peer=%d\n", vInvAsset[0].ToString(), pfrom->GetId());
1984
+ }
1985
+
1986
+ pfrom->vRecvAssetGetData.insert(pfrom->vRecvAssetGetData.end(), vInvAsset.begin(), vInvAsset.end());
1987
+ ProcessAssetGetData(pfrom, chainparams.GetConsensus(), connman, interruptMsgProc);
1988
+ }
1989
+
1990
+ else if (strCommand == NetMsgType::GETBLOCKS)
1991
+ {
1992
+ CBlockLocator locator;
1993
+ uint256 hashStop;
1994
+ vRecv >> locator >> hashStop;
1995
+
1996
+ if (locator.vHave.size() > MAX_LOCATOR_SZ) {
1997
+ LogPrint(BCLog::NET, "getblocks locator size %lld > %d, disconnect peer=%d\n", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom->GetId());
1998
+ pfrom->fDisconnect = true;
1999
+ return true;
2000
+ }
2001
+
2002
+ // We might have announced the currently-being-connected tip using a
2003
+ // compact block, which resulted in the peer sending a getblocks
2004
+ // request, which we would otherwise respond to without the new block.
2005
+ // To avoid this situation we simply verify that we are on our best
2006
+ // known chain now. This is super overkill, but we handle it better
2007
+ // for getheaders requests, and there are no known nodes which support
2008
+ // compact blocks but still use getblocks to request blocks.
2009
+ {
2010
+ std::shared_ptr<const CBlock> a_recent_block;
2011
+ {
2012
+ LOCK(cs_most_recent_block);
2013
+ a_recent_block = most_recent_block;
2014
+ }
2015
+ CValidationState dummy;
2016
+ ActivateBestChain(dummy, GetParams(), a_recent_block);
2017
+ }
2018
+
2019
+ LOCK(cs_main);
2020
+
2021
+ // Find the last block the caller has in the main chain
2022
+ const CBlockIndex* pindex = FindForkInGlobalIndex(chainActive, locator);
2023
+
2024
+ // Send the rest of the chain
2025
+ if (pindex)
2026
+ pindex = chainActive.Next(pindex);
2027
+ int nLimit = 500;
2028
+ LogPrint(BCLog::NET, "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), nLimit, pfrom->GetId());
2029
+ for (; pindex; pindex = chainActive.Next(pindex))
2030
+ {
2031
+ if (pindex->GetBlockHash() == hashStop)
2032
+ {
2033
+ LogPrint(BCLog::NET, " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
2034
+ break;
2035
+ }
2036
+ // If pruning, don't inv blocks unless we have on disk and are likely to still have
2037
+ // for some reasonable time window (1 hour) that block relay might require.
2038
+ const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / chainparams.GetConsensus().nPowTargetSpacing;
2039
+ if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= chainActive.Tip()->nHeight - nPrunedBlocksLikelyToHave))
2040
+ {
2041
+ LogPrint(BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
2042
+ break;
2043
+ }
2044
+ pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
2045
+ if (--nLimit <= 0)
2046
+ {
2047
+ // When this block is requested, we'll send an inv that'll
2048
+ // trigger the peer to getblocks the next batch of inventory.
2049
+ LogPrint(BCLog::NET, " getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
2050
+ pfrom->hashContinue = pindex->GetBlockHash();
2051
+ break;
2052
+ }
2053
+ }
2054
+ }
2055
+
2056
+
2057
+ else if (strCommand == NetMsgType::GETBLOCKTXN)
2058
+ {
2059
+ BlockTransactionsRequest req;
2060
+ vRecv >> req;
2061
+
2062
+ std::shared_ptr<const CBlock> recent_block;
2063
+ {
2064
+ LOCK(cs_most_recent_block);
2065
+ if (most_recent_block_hash == req.blockhash)
2066
+ recent_block = most_recent_block;
2067
+ // Unlock cs_most_recent_block to avoid cs_main lock inversion
2068
+ }
2069
+ if (recent_block) {
2070
+ SendBlockTransactions(*recent_block, req, pfrom, connman);
2071
+ return true;
2072
+ }
2073
+
2074
+ LOCK(cs_main);
2075
+
2076
+ BlockMap::iterator it = mapBlockIndex.find(req.blockhash);
2077
+ if (it == mapBlockIndex.end() || !(it->second->nStatus & BLOCK_HAVE_DATA)) {
2078
+ LogPrintf("Peer %d sent us a getblocktxn for a block we don't have", pfrom->GetId());
2079
+ return true;
2080
+ }
2081
+
2082
+ if (it->second->nHeight < chainActive.Height() - MAX_BLOCKTXN_DEPTH) {
2083
+ // If an older block is requested (should never happen in practice,
2084
+ // but can happen in tests) send a block response instead of a
2085
+ // blocktxn response. Sending a full block response instead of a
2086
+ // small blocktxn response is preferable in the case where a peer
2087
+ // might maliciously send lots of getblocktxn requests to trigger
2088
+ // expensive disk reads, because it will require the peer to
2089
+ // actually receive all the data read from disk over the network.
2090
+ LogPrint(BCLog::NET, "Peer %d sent us a getblocktxn for a block > %i deep", pfrom->GetId(), MAX_BLOCKTXN_DEPTH);
2091
+ CInv inv;
2092
+ inv.type = State(pfrom->GetId())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK;
2093
+ inv.hash = req.blockhash;
2094
+ pfrom->vRecvGetData.push_back(inv);
2095
+ ProcessGetData(pfrom, chainparams.GetConsensus(), connman, interruptMsgProc);
2096
+ return true;
2097
+ }
2098
+
2099
+ CBlock block;
2100
+ bool ret = ReadBlockFromDisk(block, it->second, chainparams.GetConsensus());
2101
+ assert(ret);
2102
+
2103
+ SendBlockTransactions(block, req, pfrom, connman);
2104
+ }
2105
+
2106
+
2107
+ else if (strCommand == NetMsgType::GETHEADERS)
2108
+ {
2109
+ CBlockLocator locator;
2110
+ uint256 hashStop;
2111
+ vRecv >> locator >> hashStop;
2112
+
2113
+ if (locator.vHave.size() > MAX_LOCATOR_SZ) {
2114
+ LogPrint(BCLog::NET, "getheaders locator size %lld > %d, disconnect peer=%d\n", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom->GetId());
2115
+ pfrom->fDisconnect = true;
2116
+ return true;
2117
+ }
2118
+
2119
+ LOCK(cs_main);
2120
+ if (IsInitialBlockDownload() && !pfrom->fWhitelisted) {
2121
+ LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d because node is in initial block download\n", pfrom->GetId());
2122
+ return true;
2123
+ }
2124
+
2125
+ CNodeState *nodestate = State(pfrom->GetId());
2126
+ const CBlockIndex* pindex = nullptr;
2127
+ if (locator.IsNull())
2128
+ {
2129
+ // If locator is null, return the hashStop block
2130
+ BlockMap::iterator mi = mapBlockIndex.find(hashStop);
2131
+ if (mi == mapBlockIndex.end())
2132
+ return true;
2133
+ pindex = (*mi).second;
2134
+
2135
+ if (!chainActive.Contains(pindex) &&
2136
+ !StaleBlockRequestAllowed(pindex, chainparams.GetConsensus())) {
2137
+ LogPrintf("%s: ignoring request from peer=%i for old block header that isn't in the main chain\n", __func__, pfrom->GetId());
2138
+ return true;
2139
+ }
2140
+ }
2141
+ else
2142
+ {
2143
+ // Find the last block the caller has in the main chain
2144
+ pindex = FindForkInGlobalIndex(chainActive, locator);
2145
+ if (pindex)
2146
+ pindex = chainActive.Next(pindex);
2147
+ }
2148
+
2149
+ // we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end
2150
+ std::vector<CBlock> vHeaders;
2151
+ int nLimit = MAX_HEADERS_RESULTS;
2152
+ LogPrint(BCLog::NET, "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), pfrom->GetId());
2153
+ for (; pindex; pindex = chainActive.Next(pindex))
2154
+ {
2155
+ vHeaders.push_back(pindex->GetBlockHeader());
2156
+ if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
2157
+ break;
2158
+ }
2159
+ // pindex can be nullptr either if we sent chainActive.Tip() OR
2160
+ // if our peer has chainActive.Tip() (and thus we are sending an empty
2161
+ // headers message). In both cases it's safe to update
2162
+ // pindexBestHeaderSent to be our tip.
2163
+ //
2164
+ // It is important that we simply reset the BestHeaderSent value here,
2165
+ // and not max(BestHeaderSent, newHeaderSent). We might have announced
2166
+ // the currently-being-connected tip using a compact block, which
2167
+ // resulted in the peer sending a headers request, which we respond to
2168
+ // without the new block. By resetting the BestHeaderSent, we ensure we
2169
+ // will re-announce the new block via headers (or compact blocks again)
2170
+ // in the SendMessages logic.
2171
+ nodestate->pindexBestHeaderSent = pindex ? pindex : chainActive.Tip();
2172
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::HEADERS, vHeaders));
2173
+ }
2174
+
2175
+
2176
+ else if (strCommand == NetMsgType::TX)
2177
+ {
2178
+ // Stop processing the transaction early if
2179
+ // We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off
2180
+ if (!fRelayTxes && (!pfrom->fWhitelisted || !gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)))
2181
+ {
2182
+ LogPrint(BCLog::NET, "transaction sent in violation of protocol peer=%d\n", pfrom->GetId());
2183
+ return true;
2184
+ }
2185
+
2186
+ std::deque<COutPoint> vWorkQueue;
2187
+ std::vector<uint256> vEraseQueue;
2188
+ CTransactionRef ptx;
2189
+ vRecv >> ptx;
2190
+ const CTransaction& tx = *ptx;
2191
+
2192
+ CInv inv(MSG_TX, tx.GetHash());
2193
+ pfrom->AddInventoryKnown(inv);
2194
+
2195
+ LOCK(cs_main);
2196
+
2197
+ bool fMissingInputs = false;
2198
+ CValidationState state;
2199
+
2200
+ pfrom->setAskFor.erase(inv.hash);
2201
+ mapAlreadyAskedFor.erase(inv.hash);
2202
+
2203
+ std::list<CTransactionRef> lRemovedTxn;
2204
+
2205
+ if (!AlreadyHave(inv) &&
2206
+ AcceptToMemoryPool(mempool, state, ptx, &fMissingInputs, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
2207
+ mempool.check(pcoinsTip);
2208
+ RelayTransaction(tx, connman);
2209
+ for (unsigned int i = 0; i < tx.vout.size(); i++) {
2210
+ vWorkQueue.emplace_back(inv.hash, i);
2211
+ }
2212
+
2213
+ pfrom->nLastTXTime = GetTime();
2214
+
2215
+ LogPrint(BCLog::MEMPOOL, "AcceptToMemoryPool: peer=%d: accepted %s (poolsz %u txn, %u kB)\n",
2216
+ pfrom->GetId(),
2217
+ tx.GetHash().ToString(),
2218
+ mempool.size(), mempool.DynamicMemoryUsage() / 1000);
2219
+
2220
+ // Recursively process any orphan transactions that depended on this one
2221
+ std::set<NodeId> setMisbehaving;
2222
+ while (!vWorkQueue.empty()) {
2223
+ auto itByPrev = mapOrphanTransactionsByPrev.find(vWorkQueue.front());
2224
+ vWorkQueue.pop_front();
2225
+ if (itByPrev == mapOrphanTransactionsByPrev.end())
2226
+ continue;
2227
+ for (auto mi = itByPrev->second.begin();
2228
+ mi != itByPrev->second.end();
2229
+ ++mi)
2230
+ {
2231
+ const CTransactionRef& porphanTx = (*mi)->second.tx;
2232
+ const CTransaction& orphanTx = *porphanTx;
2233
+ const uint256& orphanHash = orphanTx.GetHash();
2234
+ NodeId fromPeer = (*mi)->second.fromPeer;
2235
+ bool fMissingInputs2 = false;
2236
+ // Use a dummy CValidationState so someone can't setup nodes to counter-DoS based on orphan
2237
+ // resolution (that is, feeding people an invalid transaction based on LegitTxX in order to get
2238
+ // anyone relaying LegitTxX banned)
2239
+ CValidationState stateDummy;
2240
+
2241
+
2242
+ if (setMisbehaving.count(fromPeer))
2243
+ continue;
2244
+ if (AcceptToMemoryPool(mempool, stateDummy, porphanTx, &fMissingInputs2, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
2245
+ LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
2246
+ RelayTransaction(orphanTx, connman);
2247
+ for (unsigned int i = 0; i < orphanTx.vout.size(); i++) {
2248
+ vWorkQueue.emplace_back(orphanHash, i);
2249
+ }
2250
+ vEraseQueue.push_back(orphanHash);
2251
+ }
2252
+ else if (!fMissingInputs2)
2253
+ {
2254
+ int nDos = 0;
2255
+ if (stateDummy.IsInvalid(nDos) && nDos > 0)
2256
+ {
2257
+ // Punish peer that gave us an invalid orphan tx
2258
+ Misbehaving(fromPeer, nDos);
2259
+ setMisbehaving.insert(fromPeer);
2260
+ LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s\n", orphanHash.ToString());
2261
+ }
2262
+ // Has inputs but not accepted to mempool
2263
+ // Probably non-standard or insufficient fee
2264
+ LogPrint(BCLog::MEMPOOL, " removed orphan tx %s\n", orphanHash.ToString());
2265
+ vEraseQueue.push_back(orphanHash);
2266
+ if (!orphanTx.HasWitness() && !stateDummy.CorruptionPossible()) {
2267
+ // Do not use rejection cache for witness transactions or
2268
+ // witness-stripped transactions, as they can have been malleated.
2269
+ // See https://github.com/bitcoin/bitcoin/issues/8279 for details.
2270
+ assert(recentRejects);
2271
+ recentRejects->insert(orphanHash);
2272
+ }
2273
+ }
2274
+ mempool.check(pcoinsTip);
2275
+ }
2276
+ }
2277
+
2278
+ for (uint256 hash : vEraseQueue)
2279
+ EraseOrphanTx(hash);
2280
+ }
2281
+ else if (fMissingInputs)
2282
+ {
2283
+ bool fRejectedParents = false; // It may be the case that the orphans parents have all been rejected
2284
+ for (const CTxIn& txin : tx.vin) {
2285
+ if (recentRejects->contains(txin.prevout.hash)) {
2286
+ fRejectedParents = true;
2287
+ break;
2288
+ }
2289
+ }
2290
+ if (!fRejectedParents) {
2291
+ uint32_t nFetchFlags = GetFetchFlags(pfrom);
2292
+ for (const CTxIn& txin : tx.vin) {
2293
+ CInv _inv(MSG_TX | nFetchFlags, txin.prevout.hash);
2294
+ pfrom->AddInventoryKnown(_inv);
2295
+ if (!AlreadyHave(_inv)) pfrom->AskFor(_inv);
2296
+ }
2297
+ AddOrphanTx(ptx, pfrom->GetId());
2298
+
2299
+ // DoS prevention: do not allow mapOrphanTransactions to grow unbounded
2300
+ unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, gArgs.GetArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS));
2301
+ unsigned int nEvicted = LimitOrphanTxSize(nMaxOrphanTx);
2302
+ if (nEvicted > 0) {
2303
+ LogPrint(BCLog::MEMPOOL, "mapOrphan overflow, removed %u tx\n", nEvicted);
2304
+ }
2305
+ } else {
2306
+ LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString());
2307
+ // We will continue to reject this tx since it has rejected
2308
+ // parents so avoid re-requesting it from other peers.
2309
+ recentRejects->insert(tx.GetHash());
2310
+ }
2311
+ } else {
2312
+ if (!tx.HasWitness() && !state.CorruptionPossible()) {
2313
+ // Do not use rejection cache for witness transactions or
2314
+ // witness-stripped transactions, as they can have been malleated.
2315
+ // See https://github.com/bitcoin/bitcoin/issues/8279 for details.
2316
+ assert(recentRejects);
2317
+ recentRejects->insert(tx.GetHash());
2318
+ if (RecursiveDynamicUsage(*ptx) < 100000) {
2319
+ AddToCompactExtraTransactions(ptx);
2320
+ }
2321
+ } else if (tx.HasWitness() && RecursiveDynamicUsage(*ptx) < 100000) {
2322
+ AddToCompactExtraTransactions(ptx);
2323
+ }
2324
+
2325
+ if (pfrom->fWhitelisted && gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
2326
+ // Always relay transactions received from whitelisted peers, even
2327
+ // if they were already in the mempool or rejected from it due
2328
+ // to policy, allowing the node to function as a gateway for
2329
+ // nodes hidden behind it.
2330
+ //
2331
+ // Never relay transactions that we would assign a non-zero DoS
2332
+ // score for, as we expect peers to do the same with us in that
2333
+ // case.
2334
+ int nDoS = 0;
2335
+ if (!state.IsInvalid(nDoS) || nDoS == 0) {
2336
+ LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->GetId());
2337
+ RelayTransaction(tx, connman);
2338
+ } else {
2339
+ LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s)\n", tx.GetHash().ToString(), pfrom->GetId(), FormatStateMessage(state));
2340
+ }
2341
+ }
2342
+ }
2343
+
2344
+ for (const CTransactionRef& removedTx : lRemovedTxn)
2345
+ AddToCompactExtraTransactions(removedTx);
2346
+
2347
+ int nDoS = 0;
2348
+ if (state.IsInvalid(nDoS))
2349
+ {
2350
+ LogPrint(BCLog::MEMPOOLREJ, "%s from peer=%d was not accepted: %s\n", tx.GetHash().ToString(),
2351
+ pfrom->GetId(),
2352
+ FormatStateMessage(state));
2353
+ if (state.GetRejectCode() > 0 && state.GetRejectCode() < REJECT_INTERNAL) // Never send AcceptToMemoryPool's internal codes over P2P
2354
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::REJECT, strCommand, (unsigned char)state.GetRejectCode(),
2355
+ state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), inv.hash));
2356
+ if (nDoS > 0) {
2357
+ Misbehaving(pfrom->GetId(), nDoS);
2358
+ }
2359
+ }
2360
+ }
2361
+
2362
+
2363
+ else if (strCommand == NetMsgType::CMPCTBLOCK && !fImporting && !fReindex) // Ignore blocks received while importing
2364
+ {
2365
+ CBlockHeaderAndShortTxIDs cmpctblock;
2366
+ vRecv >> cmpctblock;
2367
+
2368
+ bool received_new_header = false;
2369
+
2370
+ {
2371
+ LOCK(cs_main);
2372
+
2373
+ if (mapBlockIndex.find(cmpctblock.header.hashPrevBlock) == mapBlockIndex.end()) {
2374
+ // Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
2375
+ if (!IsInitialBlockDownload())
2376
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), uint256()));
2377
+ return true;
2378
+ }
2379
+
2380
+ if (mapBlockIndex.find(cmpctblock.header.GetHash()) == mapBlockIndex.end()) {
2381
+ received_new_header = true;
2382
+ }
2383
+ }
2384
+
2385
+ const CBlockIndex *pindex = nullptr;
2386
+ CValidationState state;
2387
+ if (!ProcessNewBlockHeaders({cmpctblock.header}, state, chainparams, &pindex)) {
2388
+ int nDoS;
2389
+ if (state.IsInvalid(nDoS)) {
2390
+ if (nDoS > 0) {
2391
+ LOCK(cs_main);
2392
+ Misbehaving(pfrom->GetId(), nDoS);
2393
+ }
2394
+ LogPrintf("Peer %d sent us invalid header via cmpctblock\n", pfrom->GetId());
2395
+ return true;
2396
+ }
2397
+ }
2398
+
2399
+ // When we succeed in decoding a block's txids from a cmpctblock
2400
+ // message we typically jump to the BLOCKTXN handling code, with a
2401
+ // dummy (empty) BLOCKTXN message, to re-use the logic there in
2402
+ // completing processing of the putative block (without cs_main).
2403
+ bool fProcessBLOCKTXN = false;
2404
+ CDataStream blockTxnMsg(SER_NETWORK, PROTOCOL_VERSION);
2405
+
2406
+ // If we end up treating this as a plain headers message, call that as well
2407
+ // without cs_main.
2408
+ bool fRevertToHeaderProcessing = false;
2409
+
2410
+ // Keep a CBlock for "optimistic" compactblock reconstructions (see
2411
+ // below)
2412
+ std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
2413
+ bool fBlockReconstructed = false;
2414
+
2415
+ {
2416
+ LOCK(cs_main);
2417
+ // If AcceptBlockHeader returned true, it set pindex
2418
+ assert(pindex);
2419
+ UpdateBlockAvailability(pfrom->GetId(), pindex->GetBlockHash());
2420
+
2421
+ CNodeState *nodestate = State(pfrom->GetId());
2422
+
2423
+ // If this was a new header with more work than our tip, update the
2424
+ // peer's last block announcement time
2425
+ if (received_new_header && pindex->nChainWork > chainActive.Tip()->nChainWork) {
2426
+ nodestate->m_last_block_announcement = GetTime();
2427
+ }
2428
+
2429
+ std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator blockInFlightIt = mapBlocksInFlight.find(pindex->GetBlockHash());
2430
+ bool fAlreadyInFlight = blockInFlightIt != mapBlocksInFlight.end();
2431
+
2432
+ if (pindex->nStatus & BLOCK_HAVE_DATA) // Nothing to do here
2433
+ return true;
2434
+
2435
+ if (pindex->nChainWork <= chainActive.Tip()->nChainWork || // We know something better
2436
+ pindex->nTx != 0) { // We had this block at some point, but pruned it
2437
+ if (fAlreadyInFlight) {
2438
+ // We requested this block for some reason, but our mempool will probably be useless
2439
+ // so we just grab the block via normal getdata
2440
+ std::vector<CInv> vInv(1);
2441
+ vInv[0] = CInv(MSG_BLOCK | GetFetchFlags(pfrom), cmpctblock.header.GetHash());
2442
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETDATA, vInv));
2443
+ }
2444
+ return true;
2445
+ }
2446
+
2447
+ // If we're not close to tip yet, give up and let parallel block fetch work its magic
2448
+ if (!fAlreadyInFlight && !CanDirectFetch(chainparams.GetConsensus()))
2449
+ return true;
2450
+
2451
+ if (IsWitnessEnabled(pindex->pprev, chainparams.GetConsensus()) && !nodestate->fSupportsDesiredCmpctVersion) {
2452
+ // Don't bother trying to process compact blocks from v1 peers
2453
+ // after segwit activates.
2454
+ return true;
2455
+ }
2456
+
2457
+ // We want to be a bit conservative just to be extra careful about DoS
2458
+ // possibilities in compact block processing...
2459
+ if (pindex->nHeight <= chainActive.Height() + 2) {
2460
+ if ((!fAlreadyInFlight && nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
2461
+ (fAlreadyInFlight && blockInFlightIt->second.first == pfrom->GetId())) {
2462
+ std::list<QueuedBlock>::iterator* queuedBlockIt = nullptr;
2463
+ if (!MarkBlockAsInFlight(pfrom->GetId(), pindex->GetBlockHash(), pindex, &queuedBlockIt)) {
2464
+ if (!(*queuedBlockIt)->partialBlock)
2465
+ (*queuedBlockIt)->partialBlock.reset(new PartiallyDownloadedBlock(&mempool));
2466
+ else {
2467
+ // The block was already in flight using compact blocks from the same peer
2468
+ LogPrint(BCLog::NET, "Peer sent us compact block we were already syncing!\n");
2469
+ return true;
2470
+ }
2471
+ }
2472
+
2473
+ PartiallyDownloadedBlock& partialBlock = *(*queuedBlockIt)->partialBlock;
2474
+ ReadStatus status = partialBlock.InitData(cmpctblock, vExtraTxnForCompact);
2475
+ if (status == READ_STATUS_INVALID) {
2476
+ MarkBlockAsReceived(pindex->GetBlockHash()); // Reset in-flight state in case of whitelist
2477
+ Misbehaving(pfrom->GetId(), 100);
2478
+ LogPrintf("Peer %d sent us invalid compact block\n", pfrom->GetId());
2479
+ return true;
2480
+ } else if (status == READ_STATUS_FAILED) {
2481
+ // Duplicate txindexes, the block is now in-flight, so just request it
2482
+ std::vector<CInv> vInv(1);
2483
+ vInv[0] = CInv(MSG_BLOCK | GetFetchFlags(pfrom), cmpctblock.header.GetHash());
2484
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETDATA, vInv));
2485
+ return true;
2486
+ }
2487
+
2488
+ BlockTransactionsRequest req;
2489
+ for (size_t i = 0; i < cmpctblock.BlockTxCount(); i++) {
2490
+ if (!partialBlock.IsTxAvailable(i))
2491
+ req.indexes.push_back(i);
2492
+ }
2493
+ if (req.indexes.empty()) {
2494
+ // Dirty hack to jump to BLOCKTXN code (TODO: move message handling into their own functions)
2495
+ BlockTransactions txn;
2496
+ txn.blockhash = cmpctblock.header.GetHash();
2497
+ blockTxnMsg << txn;
2498
+ fProcessBLOCKTXN = true;
2499
+ } else {
2500
+ req.blockhash = pindex->GetBlockHash();
2501
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETBLOCKTXN, req));
2502
+ }
2503
+ } else {
2504
+ // This block is either already in flight from a different
2505
+ // peer, or this peer has too many blocks outstanding to
2506
+ // download from.
2507
+ // Optimistically try to reconstruct anyway since we might be
2508
+ // able to without any round trips.
2509
+ PartiallyDownloadedBlock tempBlock(&mempool);
2510
+ ReadStatus status = tempBlock.InitData(cmpctblock, vExtraTxnForCompact);
2511
+ if (status != READ_STATUS_OK) {
2512
+ // TODO: don't ignore failures
2513
+ return true;
2514
+ }
2515
+ std::vector<CTransactionRef> dummy;
2516
+ status = tempBlock.FillBlock(*pblock, dummy);
2517
+ if (status == READ_STATUS_OK) {
2518
+ fBlockReconstructed = true;
2519
+ }
2520
+ }
2521
+ } else {
2522
+ if (fAlreadyInFlight) {
2523
+ // We requested this block, but its far into the future, so our
2524
+ // mempool will probably be useless - request the block normally
2525
+ std::vector<CInv> vInv(1);
2526
+ vInv[0] = CInv(MSG_BLOCK | GetFetchFlags(pfrom), cmpctblock.header.GetHash());
2527
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETDATA, vInv));
2528
+ return true;
2529
+ } else {
2530
+ // If this was an announce-cmpctblock, we want the same treatment as a header message
2531
+ fRevertToHeaderProcessing = true;
2532
+ }
2533
+ }
2534
+ } // cs_main
2535
+
2536
+ if (fProcessBLOCKTXN)
2537
+ return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman, interruptMsgProc);
2538
+
2539
+ if (fRevertToHeaderProcessing) {
2540
+ // Headers received from HB compact block peers are permitted to be
2541
+ // relayed before full validation (see BIP 152), so we don't want to disconnect
2542
+ // the peer if the header turns out to be for an invalid block.
2543
+ // Note that if a peer tries to build on an invalid chain, that
2544
+ // will be detected and the peer will be banned.
2545
+ return ProcessHeadersMessage(pfrom, connman, {cmpctblock.header}, chainparams, /*punish_duplicate_invalid=*/false);
2546
+ }
2547
+
2548
+ if (fBlockReconstructed) {
2549
+ // If we got here, we were able to optimistically reconstruct a
2550
+ // block that is in flight from some other peer.
2551
+ {
2552
+ LOCK(cs_main);
2553
+ mapBlockSource.emplace(pblock->GetHash(), std::make_pair(pfrom->GetId(), false));
2554
+ }
2555
+ bool fNewBlock = false;
2556
+ // Setting fForceProcessing to true means that we bypass some of
2557
+ // our anti-DoS protections in AcceptBlock, which filters
2558
+ // unrequested blocks that might be trying to waste our resources
2559
+ // (eg disk space). Because we only try to reconstruct blocks when
2560
+ // we're close to caught up (via the CanDirectFetch() requirement
2561
+ // above, combined with the behavior of not requesting blocks until
2562
+ // we have a chain with at least nMinimumChainWork), and we ignore
2563
+ // compact blocks with less work than our tip, it is safe to treat
2564
+ // reconstructed compact blocks as having been requested.
2565
+ ProcessNewBlock(chainparams, pblock, /*fForceProcessing=*/true, &fNewBlock);
2566
+ if (fNewBlock) {
2567
+ pfrom->nLastBlockTime = GetTime();
2568
+ } else {
2569
+ LOCK(cs_main);
2570
+ mapBlockSource.erase(pblock->GetHash());
2571
+ }
2572
+ LOCK(cs_main); // hold cs_main for CBlockIndex::IsValid()
2573
+ if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS)) {
2574
+ // Clear download state for this block, which is in
2575
+ // process from some other peer. We do this after calling
2576
+ // ProcessNewBlock so that a malleated cmpctblock announcement
2577
+ // can't be used to interfere with block relay.
2578
+ if (pblock->fChecked) {
2579
+ MarkBlockAsReceived(pblock->GetHash());
2580
+ } else {
2581
+ uint256 mix_hash;
2582
+ MarkBlockAsReceived(pblock->GetHashFull(mix_hash));
2583
+ }
2584
+ }
2585
+ }
2586
+
2587
+ }
2588
+
2589
+ else if (strCommand == NetMsgType::BLOCKTXN && !fImporting && !fReindex) // Ignore blocks received while importing
2590
+ {
2591
+ BlockTransactions resp;
2592
+ vRecv >> resp;
2593
+
2594
+ std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
2595
+ bool fBlockRead = false;
2596
+ {
2597
+ LOCK(cs_main);
2598
+
2599
+ std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator it = mapBlocksInFlight.find(resp.blockhash);
2600
+ if (it == mapBlocksInFlight.end() || !it->second.second->partialBlock ||
2601
+ it->second.first != pfrom->GetId()) {
2602
+ LogPrint(BCLog::NET, "Peer %d sent us block transactions for block we weren't expecting\n", pfrom->GetId());
2603
+ return true;
2604
+ }
2605
+
2606
+ PartiallyDownloadedBlock& partialBlock = *it->second.second->partialBlock;
2607
+ ReadStatus status = partialBlock.FillBlock(*pblock, resp.txn);
2608
+ if (status == READ_STATUS_INVALID) {
2609
+ MarkBlockAsReceived(resp.blockhash); // Reset in-flight state in case of whitelist
2610
+ Misbehaving(pfrom->GetId(), 100);
2611
+ LogPrintf("Peer %d sent us invalid compact block/non-matching block transactions\n", pfrom->GetId());
2612
+ return true;
2613
+ } else if (status == READ_STATUS_FAILED) {
2614
+ // Might have collided, fall back to getdata now :(
2615
+ std::vector<CInv> invs;
2616
+ invs.push_back(CInv(MSG_BLOCK | GetFetchFlags(pfrom), resp.blockhash));
2617
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETDATA, invs));
2618
+ } else {
2619
+ // Block is either okay, or possibly we received
2620
+ // READ_STATUS_CHECKBLOCK_FAILED.
2621
+ // Note that CheckBlock can only fail for one of a few reasons:
2622
+ // 1. bad-proof-of-work (impossible here, because we've already
2623
+ // accepted the header)
2624
+ // 2. merkleroot doesn't match the transactions given (already
2625
+ // caught in FillBlock with READ_STATUS_FAILED, so
2626
+ // impossible here)
2627
+ // 3. the block is otherwise invalid (eg invalid coinbase,
2628
+ // block is too big, too many legacy sigops, etc).
2629
+ // So if CheckBlock failed, #3 is the only possibility.
2630
+ // Under BIP 152, we don't DoS-ban unless proof of work is
2631
+ // invalid (we don't require all the stateless checks to have
2632
+ // been run). This is handled below, so just treat this as
2633
+ // though the block was successfully read, and rely on the
2634
+ // handling in ProcessNewBlock to ensure the block index is
2635
+ // updated, reject messages go out, etc.
2636
+ MarkBlockAsReceived(resp.blockhash); // it is now an empty pointer
2637
+ fBlockRead = true;
2638
+ // mapBlockSource is only used for sending reject messages and DoS scores,
2639
+ // so the race between here and cs_main in ProcessNewBlock is fine.
2640
+ // BIP 152 permits peers to relay compact blocks after validating
2641
+ // the header only; we should not punish peers if the block turns
2642
+ // out to be invalid.
2643
+ mapBlockSource.emplace(resp.blockhash, std::make_pair(pfrom->GetId(), false));
2644
+ }
2645
+ } // Don't hold cs_main when we call into ProcessNewBlock
2646
+ if (fBlockRead) {
2647
+ bool fNewBlock = false;
2648
+ // Since we requested this block (it was in mapBlocksInFlight), force it to be processed,
2649
+ // even if it would not be a candidate for new tip (missing previous block, chain not long enough, etc)
2650
+ // This bypasses some anti-DoS logic in AcceptBlock (eg to prevent
2651
+ // disk-space attacks), but this should be safe due to the
2652
+ // protections in the compact block handler -- see related comment
2653
+ // in compact block optimistic reconstruction handling.
2654
+ ProcessNewBlock(chainparams, pblock, /*fForceProcessing=*/true, &fNewBlock);
2655
+ if (fNewBlock) {
2656
+ pfrom->nLastBlockTime = GetTime();
2657
+ } else {
2658
+ LOCK(cs_main);
2659
+ if (pblock->fChecked) {
2660
+ mapBlockSource.erase(pblock->GetHash());
2661
+ } else {
2662
+ uint256 mix_hash;
2663
+ mapBlockSource.erase(pblock->GetHashFull(mix_hash));
2664
+ }
2665
+ }
2666
+ }
2667
+ }
2668
+
2669
+
2670
+ else if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex) // Ignore headers received while importing
2671
+ {
2672
+ std::vector<CBlockHeader> headers;
2673
+
2674
+ // Bypass the normal CBlock deserialization, as we don't want to risk deserializing 2000 full blocks.
2675
+ unsigned int nCount = ReadCompactSize(vRecv);
2676
+ if (nCount > MAX_HEADERS_RESULTS) {
2677
+ LOCK(cs_main);
2678
+ Misbehaving(pfrom->GetId(), 20);
2679
+ return error("headers message size = %u", nCount);
2680
+ }
2681
+ headers.resize(nCount);
2682
+ for (unsigned int n = 0; n < nCount; n++) {
2683
+ vRecv >> headers[n];
2684
+ ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
2685
+ }
2686
+
2687
+ // Headers received via a HEADERS message should be valid, and reflect
2688
+ // the chain the peer is on. If we receive a known-invalid header,
2689
+ // disconnect the peer if it is using one of our outbound connection
2690
+ // slots.
2691
+ bool should_punish = !pfrom->fInbound && !pfrom->m_manual_connection;
2692
+ return ProcessHeadersMessage(pfrom, connman, headers, chainparams, should_punish);
2693
+ }
2694
+
2695
+ else if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex) // Ignore blocks received while importing
2696
+ {
2697
+ std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
2698
+ vRecv >> *pblock;
2699
+
2700
+ LogPrint(BCLog::NET, "received block %s peer=%d\n", pblock->GetHash().ToString(), pfrom->GetId());
2701
+
2702
+ bool forceProcessing = false;
2703
+ const uint256 hash(pblock->GetHash());
2704
+ {
2705
+ LOCK(cs_main);
2706
+ // Also always process if we requested the block explicitly, as we may
2707
+ // need it even though it is not a candidate for a new best tip.
2708
+ forceProcessing |= MarkBlockAsReceived(hash);
2709
+ // mapBlockSource is only used for sending reject messages and DoS scores,
2710
+ // so the race between here and cs_main in ProcessNewBlock is fine.
2711
+ mapBlockSource.emplace(hash, std::make_pair(pfrom->GetId(), true));
2712
+ }
2713
+ bool fNewBlock = false;
2714
+ ProcessNewBlock(chainparams, pblock, forceProcessing, &fNewBlock);
2715
+ if (fNewBlock) {
2716
+ pfrom->nLastBlockTime = GetTime();
2717
+ } else {
2718
+ LOCK(cs_main);
2719
+ mapBlockSource.erase(pblock->GetHash());
2720
+ }
2721
+ }
2722
+
2723
+
2724
+ else if (strCommand == NetMsgType::GETADDR)
2725
+ {
2726
+ // This asymmetric behavior for inbound and outbound connections was introduced
2727
+ // to prevent a fingerprinting attack: an attacker can send specific fake addresses
2728
+ // to users' AddrMan and later request them by sending getaddr messages.
2729
+ // Making nodes which are behind NAT and can only make outgoing connections ignore
2730
+ // the getaddr message mitigates the attack.
2731
+ if (!pfrom->fInbound) {
2732
+ LogPrint(BCLog::NET, "Ignoring \"getaddr\" from outbound connection. peer=%d\n", pfrom->GetId());
2733
+ return true;
2734
+ }
2735
+
2736
+ // Only send one GetAddr response per connection to reduce resource waste
2737
+ // and discourage addr stamping of INV announcements.
2738
+ if (pfrom->fSentAddr) {
2739
+ LogPrint(BCLog::NET, "Ignoring repeated \"getaddr\". peer=%d\n", pfrom->GetId());
2740
+ return true;
2741
+ }
2742
+ pfrom->fSentAddr = true;
2743
+
2744
+ pfrom->vAddrToSend.clear();
2745
+ std::vector<CAddress> vAddr = connman->GetAddresses();
2746
+ FastRandomContext insecure_rand;
2747
+ for (const CAddress &addr : vAddr)
2748
+ pfrom->PushAddress(addr, insecure_rand);
2749
+ }
2750
+
2751
+
2752
+ else if (strCommand == NetMsgType::MEMPOOL)
2753
+ {
2754
+ if (!(pfrom->GetLocalServices() & NODE_BLOOM) && !pfrom->fWhitelisted)
2755
+ {
2756
+ LogPrint(BCLog::NET, "mempool request with bloom filters disabled, disconnect peer=%d\n", pfrom->GetId());
2757
+ pfrom->fDisconnect = true;
2758
+ return true;
2759
+ }
2760
+
2761
+ if (connman->OutboundTargetReached(false) && !pfrom->fWhitelisted)
2762
+ {
2763
+ LogPrint(BCLog::NET, "mempool request with bandwidth limit reached, disconnect peer=%d\n", pfrom->GetId());
2764
+ pfrom->fDisconnect = true;
2765
+ return true;
2766
+ }
2767
+
2768
+ LOCK(pfrom->cs_inventory);
2769
+ pfrom->fSendMempool = true;
2770
+ }
2771
+
2772
+
2773
+ else if (strCommand == NetMsgType::PING)
2774
+ {
2775
+ if (pfrom->nVersion > BIP0031_VERSION)
2776
+ {
2777
+ uint64_t nonce = 0;
2778
+ vRecv >> nonce;
2779
+ // Echo the message back with the nonce. This allows for two useful features:
2780
+ //
2781
+ // 1) A remote node can quickly check if the connection is operational
2782
+ // 2) Remote nodes can measure the latency of the network thread. If this node
2783
+ // is overloaded it won't respond to pings quickly and the remote node can
2784
+ // avoid sending us more work, like chain download requests.
2785
+ //
2786
+ // The nonce stops the remote getting confused between different pings: without
2787
+ // it, if the remote node sends a ping once per second and this node takes 5
2788
+ // seconds to respond to each, the 5th ping the remote sends would appear to
2789
+ // return very quickly.
2790
+ connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::PONG, nonce));
2791
+ }
2792
+ }
2793
+
2794
+
2795
+ else if (strCommand == NetMsgType::PONG)
2796
+ {
2797
+ int64_t pingUsecEnd = nTimeReceived;
2798
+ uint64_t nonce = 0;
2799
+ size_t nAvail = vRecv.in_avail();
2800
+ bool bPingFinished = false;
2801
+ std::string sProblem;
2802
+
2803
+ if (nAvail >= sizeof(nonce)) {
2804
+ vRecv >> nonce;
2805
+
2806
+ // Only process pong message if there is an outstanding ping (old ping without nonce should never pong)
2807
+ if (pfrom->nPingNonceSent != 0) {
2808
+ if (nonce == pfrom->nPingNonceSent) {
2809
+ // Matching pong received, this ping is no longer outstanding
2810
+ bPingFinished = true;
2811
+ int64_t pingUsecTime = pingUsecEnd - pfrom->nPingUsecStart;
2812
+ if (pingUsecTime > 0) {
2813
+ // Successful ping time measurement, replace previous
2814
+ pfrom->nPingUsecTime = pingUsecTime;
2815
+ pfrom->nMinPingUsecTime = std::min(pfrom->nMinPingUsecTime.load(), pingUsecTime);
2816
+ } else {
2817
+ // This should never happen
2818
+ sProblem = "Timing mishap";
2819
+ }
2820
+ } else {
2821
+ // Nonce mismatches are normal when pings are overlapping
2822
+ sProblem = "Nonce mismatch";
2823
+ if (nonce == 0) {
2824
+ // This is most likely a bug in another implementation somewhere; cancel this ping
2825
+ bPingFinished = true;
2826
+ sProblem = "Nonce zero";
2827
+ }
2828
+ }
2829
+ } else {
2830
+ sProblem = "Unsolicited pong without ping";
2831
+ }
2832
+ } else {
2833
+ // This is most likely a bug in another implementation somewhere; cancel this ping
2834
+ bPingFinished = true;
2835
+ sProblem = "Short payload";
2836
+ }
2837
+
2838
+ if (!(sProblem.empty())) {
2839
+ LogPrint(BCLog::NET, "pong peer=%d: %s, %x expected, %x received, %u bytes\n",
2840
+ pfrom->GetId(),
2841
+ sProblem,
2842
+ pfrom->nPingNonceSent,
2843
+ nonce,
2844
+ nAvail);
2845
+ }
2846
+ if (bPingFinished) {
2847
+ pfrom->nPingNonceSent = 0;
2848
+ }
2849
+ }
2850
+
2851
+
2852
+ else if (strCommand == NetMsgType::FILTERLOAD)
2853
+ {
2854
+ CBloomFilter filter;
2855
+ vRecv >> filter;
2856
+
2857
+ if (!filter.IsWithinSizeConstraints())
2858
+ {
2859
+ // There is no excuse for sending a too-large filter
2860
+ LOCK(cs_main);
2861
+ Misbehaving(pfrom->GetId(), 100);
2862
+ }
2863
+ else
2864
+ {
2865
+ LOCK(pfrom->cs_filter);
2866
+ delete pfrom->pfilter;
2867
+ pfrom->pfilter = new CBloomFilter(filter);
2868
+ pfrom->pfilter->UpdateEmptyFull();
2869
+ pfrom->fRelayTxes = true;
2870
+ }
2871
+ }
2872
+
2873
+
2874
+ else if (strCommand == NetMsgType::FILTERADD)
2875
+ {
2876
+ std::vector<unsigned char> vData;
2877
+ vRecv >> vData;
2878
+
2879
+ // Nodes must NEVER send a data item > 520 bytes (the max size for a script data object,
2880
+ // and thus, the maximum size any matched object can have) in a filteradd message
2881
+ bool bad = false;
2882
+ if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE) {
2883
+ bad = true;
2884
+ } else {
2885
+ LOCK(pfrom->cs_filter);
2886
+ if (pfrom->pfilter) {
2887
+ pfrom->pfilter->insert(vData);
2888
+ } else {
2889
+ bad = true;
2890
+ }
2891
+ }
2892
+ if (bad) {
2893
+ LOCK(cs_main);
2894
+ Misbehaving(pfrom->GetId(), 100);
2895
+ }
2896
+ }
2897
+
2898
+
2899
+ else if (strCommand == NetMsgType::FILTERCLEAR)
2900
+ {
2901
+ LOCK(pfrom->cs_filter);
2902
+ if (pfrom->GetLocalServices() & NODE_BLOOM) {
2903
+ delete pfrom->pfilter;
2904
+ pfrom->pfilter = new CBloomFilter();
2905
+ }
2906
+ pfrom->fRelayTxes = true;
2907
+ }
2908
+
2909
+ else if (strCommand == NetMsgType::FEEFILTER) {
2910
+ CAmount newFeeFilter = 0;
2911
+ vRecv >> newFeeFilter;
2912
+ if (MoneyRange(newFeeFilter)) {
2913
+ {
2914
+ LOCK(pfrom->cs_feeFilter);
2915
+ pfrom->minFeeFilter = newFeeFilter;
2916
+ }
2917
+ LogPrint(BCLog::NET, "received: feefilter of %s from peer=%d\n", CFeeRate(newFeeFilter).ToString(), pfrom->GetId());
2918
+ }
2919
+ }
2920
+
2921
+ else if (strCommand == NetMsgType::NOTFOUND) {
2922
+ // We do not care about the NOTFOUND message, but logging an Unknown Command
2923
+ // message would be undesirable as we transmit it ourselves.
2924
+ }
2925
+
2926
+ else if (strCommand == NetMsgType::ASSETNOTFOUND) {
2927
+ // We do not care about the ASSETNOTFOUND message, but logging an Unknown Command
2928
+ // message would be undesirable as we transmit it ourselves.
2929
+ }
2930
+
2931
+ else {
2932
+ // Ignore unknown commands for extensibility
2933
+ LogPrint(BCLog::NET, "Unknown command \"%s\" from peer=%d\n", SanitizeString(strCommand), pfrom->GetId());
2934
+ }
2935
+
2936
+
2937
+
2938
+ return true;
2939
+ }
2940
+
2941
+ static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman* connman)
2942
+ {
2943
+ AssertLockHeld(cs_main);
2944
+ CNodeState &state = *State(pnode->GetId());
2945
+
2946
+ for (const CBlockReject& reject : state.rejects) {
2947
+ connman->PushMessage(pnode, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, (std::string)NetMsgType::BLOCK, reject.chRejectCode, reject.strRejectReason, reject.hashBlock));
2948
+ }
2949
+ state.rejects.clear();
2950
+
2951
+ if (state.fShouldBan) {
2952
+ state.fShouldBan = false;
2953
+ if (pnode->fWhitelisted)
2954
+ LogPrintf("Warning: not punishing whitelisted peer %s!\n", pnode->addr.ToString());
2955
+ else if (pnode->m_manual_connection)
2956
+ LogPrintf("Warning: not punishing manually-connected peer %s!\n", pnode->addr.ToString());
2957
+ else {
2958
+ pnode->fDisconnect = true;
2959
+ if (pnode->addr.IsLocal())
2960
+ LogPrintf("Warning: not banning local peer %s!\n", pnode->addr.ToString());
2961
+ else
2962
+ {
2963
+ connman->Ban(pnode->addr, BanReasonNodeMisbehaving);
2964
+ }
2965
+ }
2966
+ return true;
2967
+ }
2968
+ return false;
2969
+ }
2970
+
2971
+ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& interruptMsgProc)
2972
+ {
2973
+ const CChainParams& chainparams = GetParams();
2974
+ //
2975
+ // Message format
2976
+ // (4) message start
2977
+ // (12) command
2978
+ // (4) size
2979
+ // (4) checksum
2980
+ // (x) data
2981
+ //
2982
+ bool fMoreWork = false;
2983
+
2984
+ if (!pfrom->vRecvGetData.empty())
2985
+ ProcessGetData(pfrom, chainparams.GetConsensus(), connman, interruptMsgProc);
2986
+
2987
+ if (pfrom->fDisconnect)
2988
+ return false;
2989
+
2990
+ // this maintains the order of responses
2991
+ if (!pfrom->vRecvGetData.empty()) return true;
2992
+
2993
+ // Don't bother if send buffer is too full to respond anyway
2994
+ if (pfrom->fPauseSend)
2995
+ return false;
2996
+
2997
+ std::list<CNetMessage> msgs;
2998
+ {
2999
+ LOCK(pfrom->cs_vProcessMsg);
3000
+ if (pfrom->vProcessMsg.empty())
3001
+ return false;
3002
+ // Just take one message
3003
+ msgs.splice(msgs.begin(), pfrom->vProcessMsg, pfrom->vProcessMsg.begin());
3004
+ pfrom->nProcessQueueSize -= msgs.front().vRecv.size() + CMessageHeader::HEADER_SIZE;
3005
+ pfrom->fPauseRecv = pfrom->nProcessQueueSize > connman->GetReceiveFloodSize();
3006
+ fMoreWork = !pfrom->vProcessMsg.empty();
3007
+ }
3008
+ CNetMessage& msg(msgs.front());
3009
+
3010
+ msg.SetVersion(pfrom->GetRecvVersion());
3011
+ // Scan for message start
3012
+ if (memcmp(msg.hdr.pchMessageStart, chainparams.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) {
3013
+ LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->GetId());
3014
+ pfrom->fDisconnect = true;
3015
+ return false;
3016
+ }
3017
+
3018
+ // Read header
3019
+ CMessageHeader& hdr = msg.hdr;
3020
+ if (!hdr.IsValid(chainparams.MessageStart()))
3021
+ {
3022
+ LogPrintf("PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n", SanitizeString(hdr.GetCommand()), pfrom->GetId());
3023
+ return fMoreWork;
3024
+ }
3025
+ std::string strCommand = hdr.GetCommand();
3026
+
3027
+ // Message size
3028
+ unsigned int nMessageSize = hdr.nMessageSize;
3029
+
3030
+ // Checksum
3031
+ CDataStream& vRecv = msg.vRecv;
3032
+ const uint256& hash = msg.GetMessageHash();
3033
+ if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0)
3034
+ {
3035
+ LogPrintf("%s(%s, %u bytes): CHECKSUM ERROR expected %s was %s\n", __func__,
3036
+ SanitizeString(strCommand), nMessageSize,
3037
+ HexStr(hash.begin(), hash.begin()+CMessageHeader::CHECKSUM_SIZE),
3038
+ HexStr(hdr.pchChecksum, hdr.pchChecksum+CMessageHeader::CHECKSUM_SIZE));
3039
+ return fMoreWork;
3040
+ }
3041
+
3042
+ // Process message
3043
+ bool fRet = false;
3044
+ try
3045
+ {
3046
+ fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime, chainparams, connman, interruptMsgProc);
3047
+ if (interruptMsgProc)
3048
+ return false;
3049
+ if (!pfrom->vRecvGetData.empty())
3050
+ fMoreWork = true;
3051
+ }
3052
+ catch (const std::ios_base::failure& e)
3053
+ {
3054
+ connman->PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_MALFORMED, std::string("error parsing message")));
3055
+ if (strstr(e.what(), "end of data"))
3056
+ {
3057
+ // Allow exceptions from under-length message on vRecv
3058
+ LogPrintf("%s(%s, %u bytes): Exception '%s' caught, normally caused by a message being shorter than its stated length\n", __func__, SanitizeString(strCommand), nMessageSize, e.what());
3059
+ }
3060
+ else if (strstr(e.what(), "size too large"))
3061
+ {
3062
+ // Allow exceptions from over-long size
3063
+ LogPrintf("%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what());
3064
+ }
3065
+ else if (strstr(e.what(), "non-canonical ReadCompactSize()"))
3066
+ {
3067
+ // Allow exceptions from non-canonical encoding
3068
+ LogPrintf("%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what());
3069
+ }
3070
+ else
3071
+ {
3072
+ PrintExceptionContinue(&e, "ProcessMessages()");
3073
+ }
3074
+ }
3075
+ catch (const std::exception& e) {
3076
+ PrintExceptionContinue(&e, "ProcessMessages()");
3077
+ } catch (...) {
3078
+ PrintExceptionContinue(nullptr, "ProcessMessages()");
3079
+ }
3080
+
3081
+ if (!fRet) {
3082
+ LogPrintf("%s(%s, %u bytes) FAILED peer=%d\n", __func__, SanitizeString(strCommand), nMessageSize, pfrom->GetId());
3083
+ }
3084
+
3085
+ LOCK(cs_main);
3086
+ SendRejectsAndCheckIfBanned(pfrom, connman);
3087
+
3088
+ return fMoreWork;
3089
+ }
3090
+
3091
+ void PeerLogicValidation::ConsiderEviction(CNode *pto, int64_t time_in_seconds)
3092
+ {
3093
+ AssertLockHeld(cs_main);
3094
+
3095
+ CNodeState &state = *State(pto->GetId());
3096
+ const CNetMsgMaker msgMaker(pto->GetSendVersion());
3097
+
3098
+ if (!state.m_chain_sync.m_protect && IsOutboundDisconnectionCandidate(pto) && state.fSyncStarted) {
3099
+ // This is an outbound peer subject to disconnection if they don't
3100
+ // announce a block with as much work as the current tip within
3101
+ // CHAIN_SYNC_TIMEOUT + HEADERS_RESPONSE_TIME seconds (note: if
3102
+ // their chain has more work than ours, we should sync to it,
3103
+ // unless it's invalid, in which case we should find that out and
3104
+ // disconnect from them elsewhere).
3105
+ if (state.pindexBestKnownBlock != nullptr && state.pindexBestKnownBlock->nChainWork >= chainActive.Tip()->nChainWork) {
3106
+ if (state.m_chain_sync.m_timeout != 0) {
3107
+ state.m_chain_sync.m_timeout = 0;
3108
+ state.m_chain_sync.m_work_header = nullptr;
3109
+ state.m_chain_sync.m_sent_getheaders = false;
3110
+ }
3111
+ } else if (state.m_chain_sync.m_timeout == 0 || (state.m_chain_sync.m_work_header != nullptr && state.pindexBestKnownBlock != nullptr && state.pindexBestKnownBlock->nChainWork >= state.m_chain_sync.m_work_header->nChainWork)) {
3112
+ // Our best block known by this peer is behind our tip, and we're either noticing
3113
+ // that for the first time, OR this peer was able to catch up to some earlier point
3114
+ // where we checked against our tip.
3115
+ // Either way, set a new timeout based on current tip.
3116
+ state.m_chain_sync.m_timeout = time_in_seconds + CHAIN_SYNC_TIMEOUT;
3117
+ state.m_chain_sync.m_work_header = chainActive.Tip();
3118
+ state.m_chain_sync.m_sent_getheaders = false;
3119
+ } else if (state.m_chain_sync.m_timeout > 0 && time_in_seconds > state.m_chain_sync.m_timeout) {
3120
+ // No evidence yet that our peer has synced to a chain with work equal to that
3121
+ // of our tip, when we first detected it was behind. Send a single getheaders
3122
+ // message to give the peer a chance to update us.
3123
+ if (state.m_chain_sync.m_sent_getheaders) {
3124
+ // They've run out of time to catch up!
3125
+ LogPrintf("Disconnecting outbound peer %d for old chain, best known block = %s\n", pto->GetId(), state.pindexBestKnownBlock != nullptr ? state.pindexBestKnownBlock->GetBlockHash().ToString() : "<none>");
3126
+ pto->fDisconnect = true;
3127
+ } else {
3128
+ LogPrint(BCLog::NET, "sending getheaders to outbound peer=%d to verify chain work (current best known block:%s, benchmark blockhash: %s)\n", pto->GetId(), state.pindexBestKnownBlock != nullptr ? state.pindexBestKnownBlock->GetBlockHash().ToString() : "<none>", state.m_chain_sync.m_work_header->GetBlockHash().ToString());
3129
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(state.m_chain_sync.m_work_header->pprev), uint256()));
3130
+ state.m_chain_sync.m_sent_getheaders = true;
3131
+ constexpr int64_t HEADERS_RESPONSE_TIME = 120; // 2 minutes
3132
+ // Bump the timeout to allow a response, which could clear the timeout
3133
+ // (if the response shows the peer has synced), reset the timeout (if
3134
+ // the peer syncs to the required work but not to our tip), or result
3135
+ // in disconnect (if we advance to the timeout and pindexBestKnownBlock
3136
+ // has not sufficiently progressed)
3137
+ state.m_chain_sync.m_timeout = time_in_seconds + HEADERS_RESPONSE_TIME;
3138
+ }
3139
+ }
3140
+ }
3141
+ }
3142
+
3143
+ void PeerLogicValidation::EvictExtraOutboundPeers(int64_t time_in_seconds)
3144
+ {
3145
+ // Check whether we have too many outbound peers
3146
+ int extra_peers = connman->GetExtraOutboundCount();
3147
+ if (extra_peers > 0) {
3148
+ // If we have more outbound peers than we target, disconnect one.
3149
+ // Pick the outbound peer that least recently announced
3150
+ // us a new block, with ties broken by choosing the more recent
3151
+ // connection (higher node id)
3152
+ NodeId worst_peer = -1;
3153
+ int64_t oldest_block_announcement = std::numeric_limits<int64_t>::max();
3154
+
3155
+ LOCK(cs_main);
3156
+
3157
+ connman->ForEachNode([&](CNode* pnode) {
3158
+ // Ignore non-outbound peers, or nodes marked for disconnect already
3159
+ if (!IsOutboundDisconnectionCandidate(pnode) || pnode->fDisconnect) return;
3160
+ CNodeState *state = State(pnode->GetId());
3161
+ if (state == nullptr) return; // shouldn't be possible, but just in case
3162
+ // Don't evict our protected peers
3163
+ if (state->m_chain_sync.m_protect) return;
3164
+ if (state->m_last_block_announcement < oldest_block_announcement || (state->m_last_block_announcement == oldest_block_announcement && pnode->GetId() > worst_peer)) {
3165
+ worst_peer = pnode->GetId();
3166
+ oldest_block_announcement = state->m_last_block_announcement;
3167
+ }
3168
+ });
3169
+ if (worst_peer != -1) {
3170
+ bool disconnected = connman->ForNode(worst_peer, [&](CNode *pnode) {
3171
+ // Only disconnect a peer that has been connected to us for
3172
+ // some reasonable fraction of our check-frequency, to give
3173
+ // it time for new information to have arrived.
3174
+ // Also don't disconnect any peer we're trying to download a
3175
+ // block from.
3176
+ CNodeState &state = *State(pnode->GetId());
3177
+ if (time_in_seconds - pnode->nTimeConnected > MINIMUM_CONNECT_TIME && state.nBlocksInFlight == 0) {
3178
+ LogPrint(BCLog::NET, "disconnecting extra outbound peer=%d (last block announcement received at time %d)\n", pnode->GetId(), oldest_block_announcement);
3179
+ pnode->fDisconnect = true;
3180
+ return true;
3181
+ } else {
3182
+ LogPrint(BCLog::NET, "keeping outbound peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n", pnode->GetId(), pnode->nTimeConnected, state.nBlocksInFlight);
3183
+ return false;
3184
+ }
3185
+ });
3186
+ if (disconnected) {
3187
+ // If we disconnected an extra peer, that means we successfully
3188
+ // connected to at least one peer after the last time we
3189
+ // detected a stale tip. Don't try any more extra peers until
3190
+ // we next detect a stale tip, to limit the load we put on the
3191
+ // network from these extra connections.
3192
+ connman->SetTryNewOutboundPeer(false);
3193
+ }
3194
+ }
3195
+ }
3196
+ }
3197
+
3198
+ void PeerLogicValidation::CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams)
3199
+ {
3200
+ if (connman == nullptr) return;
3201
+
3202
+ int64_t time_in_seconds = GetTime();
3203
+
3204
+ EvictExtraOutboundPeers(time_in_seconds);
3205
+
3206
+ if (time_in_seconds > m_stale_tip_check_time) {
3207
+ LOCK(cs_main);
3208
+ // Check whether our tip is stale, and if so, allow using an extra
3209
+ // outbound peer
3210
+ if (TipMayBeStale(consensusParams)) {
3211
+ LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n", time_in_seconds - g_last_tip_update);
3212
+ connman->SetTryNewOutboundPeer(true);
3213
+ } else if (connman->GetTryNewOutboundPeer()) {
3214
+ connman->SetTryNewOutboundPeer(false);
3215
+ }
3216
+ m_stale_tip_check_time = time_in_seconds + STALE_CHECK_INTERVAL;
3217
+ }
3218
+ }
3219
+
3220
+ class CompareInvMempoolOrder
3221
+ {
3222
+ CTxMemPool *mp;
3223
+ public:
3224
+ explicit CompareInvMempoolOrder(CTxMemPool *_mempool)
3225
+ {
3226
+ mp = _mempool;
3227
+ }
3228
+
3229
+ bool operator()(std::set<uint256>::iterator a, std::set<uint256>::iterator b)
3230
+ {
3231
+ /* As std::make_heap produces a max-heap, we want the entries with the
3232
+ * fewest ancestors/highest fee to sort later. */
3233
+ return mp->CompareDepthAndScore(*b, *a);
3234
+ }
3235
+ };
3236
+
3237
+ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptMsgProc)
3238
+ {
3239
+ const Consensus::Params& consensusParams = GetParams().GetConsensus();
3240
+ {
3241
+ // Don't send anything until the version handshake is complete
3242
+ if (!pto->fSuccessfullyConnected || pto->fDisconnect)
3243
+ return true;
3244
+
3245
+ // If we get here, the outgoing message serialization version is set and can't change.
3246
+ const CNetMsgMaker msgMaker(pto->GetSendVersion());
3247
+
3248
+ //
3249
+ // Message: ping
3250
+ //
3251
+ bool pingSend = false;
3252
+ if (pto->fPingQueued) {
3253
+ // RPC ping request by user
3254
+ pingSend = true;
3255
+ }
3256
+ if (pto->nPingNonceSent == 0 && pto->nPingUsecStart + PING_INTERVAL * 1000000 < GetTimeMicros()) {
3257
+ // Ping automatically sent as a latency probe & keepalive.
3258
+ pingSend = true;
3259
+ }
3260
+ if (pingSend) {
3261
+ uint64_t nonce = 0;
3262
+ while (nonce == 0) {
3263
+ GetRandBytes((unsigned char*)&nonce, sizeof(nonce));
3264
+ }
3265
+ pto->fPingQueued = false;
3266
+ pto->nPingUsecStart = GetTimeMicros();
3267
+ if (pto->nVersion > BIP0031_VERSION) {
3268
+ pto->nPingNonceSent = nonce;
3269
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::PING, nonce));
3270
+ } else {
3271
+ // Peer is too old to support ping command with nonce, pong will never arrive.
3272
+ pto->nPingNonceSent = 0;
3273
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::PING));
3274
+ }
3275
+ }
3276
+
3277
+ TRY_LOCK(cs_main, lockMain); // Acquire cs_main for IsInitialBlockDownload() and CNodeState()
3278
+ if (!lockMain)
3279
+ return true;
3280
+
3281
+ if (SendRejectsAndCheckIfBanned(pto, connman))
3282
+ return true;
3283
+ CNodeState &state = *State(pto->GetId());
3284
+
3285
+ // Address refresh broadcast
3286
+ int64_t nNow = GetTimeMicros();
3287
+ if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
3288
+ AdvertiseLocal(pto);
3289
+ pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
3290
+ }
3291
+
3292
+ //
3293
+ // Message: addr
3294
+ //
3295
+ if (pto->nNextAddrSend < nNow) {
3296
+ pto->nNextAddrSend = PoissonNextSend(nNow, AVG_ADDRESS_BROADCAST_INTERVAL);
3297
+ std::vector<CAddress> vAddr;
3298
+ vAddr.reserve(pto->vAddrToSend.size());
3299
+ for (const CAddress& addr : pto->vAddrToSend)
3300
+ {
3301
+ if (!pto->addrKnown.contains(addr.GetKey()))
3302
+ {
3303
+ pto->addrKnown.insert(addr.GetKey());
3304
+ vAddr.push_back(addr);
3305
+ // receiver rejects addr messages larger than 1000
3306
+ if (vAddr.size() >= 1000)
3307
+ {
3308
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::ADDR, vAddr));
3309
+ vAddr.clear();
3310
+ }
3311
+ }
3312
+ }
3313
+ pto->vAddrToSend.clear();
3314
+ if (!vAddr.empty())
3315
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::ADDR, vAddr));
3316
+ // we only send the big addr message once
3317
+ if (pto->vAddrToSend.capacity() > 40)
3318
+ pto->vAddrToSend.shrink_to_fit();
3319
+ }
3320
+
3321
+ //
3322
+ // Message: getassetdata
3323
+ //
3324
+ if (pto->nVersion >= ASSETDATA_VERSION && pto->fGetAssetData) {
3325
+ LOCK(pto->cs_inventory);
3326
+
3327
+ pto->fGetAssetData = false;
3328
+
3329
+ // Produce a vector with all candidates for sending
3330
+ std::vector<CInvAsset> vInvAssets;
3331
+ vInvAssets.reserve(std::max<size_t>(pto->setInventoryAssetsSend.size(), INVENTORY_BROADCAST_MAX));
3332
+
3333
+ // Add asset inv
3334
+ for (auto& it : pto->setInventoryAssetsSend) {
3335
+ vInvAssets.push_back(CInvAsset(it));
3336
+ if (vInvAssets.size() == MAX_ASSET_INV_SZ) {
3337
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETASSETDATA, vInvAssets));
3338
+ vInvAssets.clear();
3339
+ }
3340
+ }
3341
+ pto->setInventoryAssetsSend.clear();
3342
+
3343
+ if (!vInvAssets.empty())
3344
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETASSETDATA, vInvAssets));
3345
+ }
3346
+
3347
+ // Start block sync
3348
+ if (pindexBestHeader == nullptr)
3349
+ pindexBestHeader = chainActive.Tip();
3350
+ bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do.
3351
+ if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) {
3352
+ // Only actively request headers from a single peer, unless we're close to today.
3353
+ if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) {
3354
+ state.fSyncStarted = true;
3355
+ state.nHeadersSyncTimeout = GetTimeMicros() + HEADERS_DOWNLOAD_TIMEOUT_BASE + HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER * (GetAdjustedTime() - pindexBestHeader->GetBlockTime())/(consensusParams.nPowTargetSpacing);
3356
+ nSyncStarted++;
3357
+ const CBlockIndex *pindexStart = pindexBestHeader;
3358
+ /* If possible, start at the block preceding the currently
3359
+ best known header. This ensures that we always get a
3360
+ non-empty list of headers back as long as the peer
3361
+ is up-to-date. With a non-empty response, we can initialise
3362
+ the peer's known best block. This wouldn't be possible
3363
+ if we requested starting at pindexBestHeader and
3364
+ got back an empty response. */
3365
+ if (pindexStart->pprev)
3366
+ pindexStart = pindexStart->pprev;
3367
+ LogPrint(BCLog::NET, "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->GetId(), pto->nStartingHeight);
3368
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexStart), uint256()));
3369
+ }
3370
+ }
3371
+
3372
+ // Resend wallet transactions that haven't gotten in a block yet
3373
+ // Except during reindex, importing and IBD, when old wallet
3374
+ // transactions become unconfirmed and spams other nodes.
3375
+ if (!fReindex && !fImporting && !IsInitialBlockDownload())
3376
+ {
3377
+ GetMainSignals().Broadcast(nTimeBestReceived, connman);
3378
+ }
3379
+
3380
+ //
3381
+ // Try sending block announcements via headers
3382
+ //
3383
+ {
3384
+ // If we have less than MAX_BLOCKS_TO_ANNOUNCE in our
3385
+ // list of block hashes we're relaying, and our peer wants
3386
+ // headers announcements, then find the first header
3387
+ // not yet known to our peer but would connect, and send.
3388
+ // If no header would connect, or if we have too many
3389
+ // blocks, or if the peer doesn't want headers, just
3390
+ // add all to the inv queue.
3391
+ LOCK(pto->cs_inventory);
3392
+ std::vector<CBlock> vHeaders;
3393
+ bool fRevertToInv = ((!state.fPreferHeaders &&
3394
+ (!state.fPreferHeaderAndIDs || pto->vBlockHashesToAnnounce.size() > 1)) ||
3395
+ pto->vBlockHashesToAnnounce.size() > MAX_BLOCKS_TO_ANNOUNCE);
3396
+ const CBlockIndex *pBestIndex = nullptr; // last header queued for delivery
3397
+ ProcessBlockAvailability(pto->GetId()); // ensure pindexBestKnownBlock is up-to-date
3398
+
3399
+ if (!fRevertToInv) {
3400
+ bool fFoundStartingHeader = false;
3401
+ // Try to find first header that our peer doesn't have, and
3402
+ // then send all headers past that one. If we come across any
3403
+ // headers that aren't on chainActive, give up.
3404
+ for (const uint256 &hash : pto->vBlockHashesToAnnounce) {
3405
+ BlockMap::iterator mi = mapBlockIndex.find(hash);
3406
+ assert(mi != mapBlockIndex.end());
3407
+ const CBlockIndex *pindex = mi->second;
3408
+ if (chainActive[pindex->nHeight] != pindex) {
3409
+ // Bail out if we reorged away from this block
3410
+ fRevertToInv = true;
3411
+ break;
3412
+ }
3413
+ if (pBestIndex != nullptr && pindex->pprev != pBestIndex) {
3414
+ // This means that the list of blocks to announce don't
3415
+ // connect to each other.
3416
+ // This shouldn't really be possible to hit during
3417
+ // regular operation (because reorgs should take us to
3418
+ // a chain that has some block not on the prior chain,
3419
+ // which should be caught by the prior check), but one
3420
+ // way this could happen is by using invalidateblock /
3421
+ // reconsiderblock repeatedly on the tip, causing it to
3422
+ // be added multiple times to vBlockHashesToAnnounce.
3423
+ // Robustly deal with this rare situation by reverting
3424
+ // to an inv.
3425
+ fRevertToInv = true;
3426
+ break;
3427
+ }
3428
+ pBestIndex = pindex;
3429
+ if (fFoundStartingHeader) {
3430
+ // add this to the headers message
3431
+ vHeaders.push_back(pindex->GetBlockHeader());
3432
+ } else if (PeerHasHeader(&state, pindex)) {
3433
+ continue; // keep looking for the first new block
3434
+ } else if (pindex->pprev == nullptr || PeerHasHeader(&state, pindex->pprev)) {
3435
+ // Peer doesn't have this header but they do have the prior one.
3436
+ // Start sending headers.
3437
+ fFoundStartingHeader = true;
3438
+ vHeaders.push_back(pindex->GetBlockHeader());
3439
+ } else {
3440
+ // Peer doesn't have this header or the prior one -- nothing will
3441
+ // connect, so bail out.
3442
+ fRevertToInv = true;
3443
+ break;
3444
+ }
3445
+ }
3446
+ }
3447
+ if (!fRevertToInv && !vHeaders.empty()) {
3448
+ if (vHeaders.size() == 1 && state.fPreferHeaderAndIDs) {
3449
+ // We only send up to 1 block as header-and-ids, as otherwise
3450
+ // probably means we're doing an initial-ish-sync or they're slow
3451
+ LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", __func__,
3452
+ vHeaders.front().GetHash().ToString(), pto->GetId());
3453
+
3454
+ int nSendFlags = state.fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
3455
+
3456
+ bool fGotBlockFromCache = false;
3457
+ {
3458
+ LOCK(cs_most_recent_block);
3459
+ if (most_recent_block_hash == pBestIndex->GetBlockHash()) {
3460
+ if (state.fWantsCmpctWitness || !fWitnessesPresentInMostRecentCompactBlock)
3461
+ connman->PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *most_recent_compact_block));
3462
+ else {
3463
+ CBlockHeaderAndShortTxIDs cmpctblock(*most_recent_block, state.fWantsCmpctWitness);
3464
+ connman->PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
3465
+ }
3466
+ fGotBlockFromCache = true;
3467
+ }
3468
+ }
3469
+ if (!fGotBlockFromCache) {
3470
+ CBlock block;
3471
+ bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
3472
+ assert(ret);
3473
+ CBlockHeaderAndShortTxIDs cmpctblock(block, state.fWantsCmpctWitness);
3474
+ connman->PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
3475
+ }
3476
+ state.pindexBestHeaderSent = pBestIndex;
3477
+ } else if (state.fPreferHeaders) {
3478
+ if (vHeaders.size() > 1) {
3479
+ LogPrint(BCLog::NET, "%s: %u headers, range (%s, %s), to peer=%d\n", __func__,
3480
+ vHeaders.size(),
3481
+ vHeaders.front().GetHash().ToString(),
3482
+ vHeaders.back().GetHash().ToString(), pto->GetId());
3483
+ } else {
3484
+ LogPrint(BCLog::NET, "%s: sending header %s to peer=%d\n", __func__,
3485
+ vHeaders.front().GetHash().ToString(), pto->GetId());
3486
+ }
3487
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::HEADERS, vHeaders));
3488
+ state.pindexBestHeaderSent = pBestIndex;
3489
+ } else
3490
+ fRevertToInv = true;
3491
+ }
3492
+ if (fRevertToInv) {
3493
+ // If falling back to using an inv, just try to inv the tip.
3494
+ // The last entry in vBlockHashesToAnnounce was our tip at some point
3495
+ // in the past.
3496
+ if (!pto->vBlockHashesToAnnounce.empty()) {
3497
+ const uint256 &hashToAnnounce = pto->vBlockHashesToAnnounce.back();
3498
+ BlockMap::iterator mi = mapBlockIndex.find(hashToAnnounce);
3499
+ assert(mi != mapBlockIndex.end());
3500
+ const CBlockIndex *pindex = mi->second;
3501
+
3502
+ // Warn if we're announcing a block that is not on the main chain.
3503
+ // This should be very rare and could be optimized out.
3504
+ // Just log for now.
3505
+ if (chainActive[pindex->nHeight] != pindex) {
3506
+ LogPrint(BCLog::NET, "Announcing block %s not on main chain (tip=%s)\n",
3507
+ hashToAnnounce.ToString(), chainActive.Tip()->GetBlockHash().ToString());
3508
+ }
3509
+
3510
+ // If the peer's chain has this block, don't inv it back.
3511
+ if (!PeerHasHeader(&state, pindex)) {
3512
+ pto->PushInventory(CInv(MSG_BLOCK, hashToAnnounce));
3513
+ LogPrint(BCLog::NET, "%s: sending inv peer=%d hash=%s\n", __func__,
3514
+ pto->GetId(), hashToAnnounce.ToString());
3515
+ }
3516
+ }
3517
+ }
3518
+ pto->vBlockHashesToAnnounce.clear();
3519
+ }
3520
+
3521
+ //
3522
+ // Message: inventory
3523
+ //
3524
+ std::vector<CInv> vInv;
3525
+ {
3526
+ LOCK(pto->cs_inventory);
3527
+ vInv.reserve(std::max<size_t>(pto->vInventoryBlockToSend.size(), INVENTORY_BROADCAST_MAX));
3528
+
3529
+ // Add blocks
3530
+ for (const uint256& hash : pto->vInventoryBlockToSend) {
3531
+ vInv.push_back(CInv(MSG_BLOCK, hash));
3532
+ if (vInv.size() == MAX_INV_SZ) {
3533
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
3534
+ vInv.clear();
3535
+ }
3536
+ }
3537
+ pto->vInventoryBlockToSend.clear();
3538
+
3539
+ // Check whether periodic sends should happen
3540
+ bool fSendTrickle = pto->fWhitelisted;
3541
+ if (pto->nNextInvSend < nNow) {
3542
+ fSendTrickle = true;
3543
+ // Use half the delay for outbound peers, as there is less privacy concern for them.
3544
+ pto->nNextInvSend = PoissonNextSend(nNow, INVENTORY_BROADCAST_INTERVAL >> !pto->fInbound);
3545
+ }
3546
+
3547
+ // Time to send but the peer has requested we not relay transactions.
3548
+ if (fSendTrickle) {
3549
+ LOCK(pto->cs_filter);
3550
+ if (!pto->fRelayTxes) pto->setInventoryTxToSend.clear();
3551
+ }
3552
+
3553
+ // Respond to BIP35 mempool requests
3554
+ if (fSendTrickle && pto->fSendMempool) {
3555
+ auto vtxinfo = mempool.infoAll();
3556
+ pto->fSendMempool = false;
3557
+ CAmount filterrate = 0;
3558
+ {
3559
+ LOCK(pto->cs_feeFilter);
3560
+ filterrate = pto->minFeeFilter;
3561
+ }
3562
+
3563
+ LOCK(pto->cs_filter);
3564
+
3565
+ for (const auto& txinfo : vtxinfo) {
3566
+ const uint256& hash = txinfo.tx->GetHash();
3567
+ CInv inv(MSG_TX, hash);
3568
+ pto->setInventoryTxToSend.erase(hash);
3569
+ if (filterrate) {
3570
+ if (txinfo.feeRate.GetFeePerK() < filterrate)
3571
+ continue;
3572
+ }
3573
+ if (pto->pfilter) {
3574
+ if (!pto->pfilter->IsRelevantAndUpdate(*txinfo.tx)) continue;
3575
+ }
3576
+ pto->filterInventoryKnown.insert(hash);
3577
+ vInv.push_back(inv);
3578
+ if (vInv.size() == MAX_INV_SZ) {
3579
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
3580
+ vInv.clear();
3581
+ }
3582
+ }
3583
+ pto->timeLastMempoolReq = GetTime();
3584
+ }
3585
+
3586
+ // Determine transactions to relay
3587
+ if (fSendTrickle) {
3588
+ // Produce a vector with all candidates for sending
3589
+ std::vector<std::set<uint256>::iterator> vInvTx;
3590
+ vInvTx.reserve(pto->setInventoryTxToSend.size());
3591
+ for (std::set<uint256>::iterator it = pto->setInventoryTxToSend.begin(); it != pto->setInventoryTxToSend.end(); it++) {
3592
+ vInvTx.push_back(it);
3593
+ }
3594
+ CAmount filterrate = 0;
3595
+ {
3596
+ LOCK(pto->cs_feeFilter);
3597
+ filterrate = pto->minFeeFilter;
3598
+ }
3599
+ // Topologically and fee-rate sort the inventory we send for privacy and priority reasons.
3600
+ // A heap is used so that not all items need sorting if only a few are being sent.
3601
+ CompareInvMempoolOrder compareInvMempoolOrder(&mempool);
3602
+ std::make_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder);
3603
+ // No reason to drain out at many times the network's capacity,
3604
+ // especially since we have many peers and some will draw much shorter delays.
3605
+ unsigned int nRelayedTransactions = 0;
3606
+ LOCK(pto->cs_filter);
3607
+ while (!vInvTx.empty() && nRelayedTransactions < INVENTORY_BROADCAST_MAX) {
3608
+ // Fetch the top element from the heap
3609
+ std::pop_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder);
3610
+ std::set<uint256>::iterator it = vInvTx.back();
3611
+ vInvTx.pop_back();
3612
+ uint256 hash = *it;
3613
+ // Remove it from the to-be-sent set
3614
+ pto->setInventoryTxToSend.erase(it);
3615
+ // Check if not in the filter already
3616
+ if (pto->filterInventoryKnown.contains(hash)) {
3617
+ continue;
3618
+ }
3619
+ // Not in the mempool anymore? don't bother sending it.
3620
+ auto txinfo = mempool.info(hash);
3621
+ if (!txinfo.tx) {
3622
+ continue;
3623
+ }
3624
+ if (filterrate && txinfo.feeRate.GetFeePerK() < filterrate) {
3625
+ continue;
3626
+ }
3627
+ if (pto->pfilter && !pto->pfilter->IsRelevantAndUpdate(*txinfo.tx)) continue;
3628
+ // Send
3629
+ vInv.push_back(CInv(MSG_TX, hash));
3630
+ nRelayedTransactions++;
3631
+ {
3632
+ // Expire old relay messages
3633
+ while (!vRelayExpiration.empty() && vRelayExpiration.front().first < nNow)
3634
+ {
3635
+ mapRelay.erase(vRelayExpiration.front().second);
3636
+ vRelayExpiration.pop_front();
3637
+ }
3638
+
3639
+ auto ret = mapRelay.insert(std::make_pair(hash, std::move(txinfo.tx)));
3640
+ if (ret.second) {
3641
+ vRelayExpiration.push_back(std::make_pair(nNow + 15 * 60 * 1000000, ret.first));
3642
+ }
3643
+ }
3644
+ if (vInv.size() == MAX_INV_SZ) {
3645
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
3646
+ vInv.clear();
3647
+ }
3648
+ pto->filterInventoryKnown.insert(hash);
3649
+ }
3650
+ }
3651
+ }
3652
+ if (!vInv.empty())
3653
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
3654
+
3655
+ // Detect whether we're stalling
3656
+ nNow = GetTimeMicros();
3657
+ if (state.nStallingSince && state.nStallingSince < nNow - 1000000 * BLOCK_STALLING_TIMEOUT) {
3658
+ // Stalling only triggers when the block download window cannot move. During normal steady state,
3659
+ // the download window should be much larger than the to-be-downloaded set of blocks, so disconnection
3660
+ // should only happen during initial block download.
3661
+ LogPrintf("Peer=%d is stalling block download, disconnecting\n", pto->GetId());
3662
+ pto->fDisconnect = true;
3663
+ return true;
3664
+ }
3665
+ // In case there is a block that has been in flight from this peer for 2 + 0.5 * N times the block interval
3666
+ // (with N the number of peers from which we're downloading validated blocks), disconnect due to timeout.
3667
+ // We compensate for other peers to prevent killing off peers due to our own downstream link
3668
+ // being saturated. We only count validated in-flight blocks so peers can't advertise non-existing block hashes
3669
+ // to unreasonably increase our timeout.
3670
+ if (state.vBlocksInFlight.size() > 0) {
3671
+ QueuedBlock &queuedBlock = state.vBlocksInFlight.front();
3672
+ int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - (state.nBlocksInFlightValidHeaders > 0);
3673
+ if (nNow > state.nDownloadingSince + consensusParams.nPowTargetSpacing * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
3674
+ LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", queuedBlock.hash.ToString(), pto->GetId());
3675
+ pto->fDisconnect = true;
3676
+ return true;
3677
+ }
3678
+ }
3679
+ // Check for headers sync timeouts
3680
+ if (state.fSyncStarted && state.nHeadersSyncTimeout < std::numeric_limits<int64_t>::max()) {
3681
+ // Detect whether this is a stalling initial-headers-sync peer
3682
+ if (pindexBestHeader->GetBlockTime() <= GetAdjustedTime() - 24*60*60) {
3683
+ if (nNow > state.nHeadersSyncTimeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1)) {
3684
+ // Disconnect a (non-whitelisted) peer if it is our only sync peer,
3685
+ // and we have others we could be using instead.
3686
+ // Note: If all our peers are inbound, then we won't
3687
+ // disconnect our sync peer for stalling; we have bigger
3688
+ // problems if we can't get any outbound peers.
3689
+ if (!pto->fWhitelisted) {
3690
+ LogPrintf("Timeout downloading headers from peer=%d, disconnecting\n", pto->GetId());
3691
+ pto->fDisconnect = true;
3692
+ return true;
3693
+ } else {
3694
+ LogPrintf("Timeout downloading headers from whitelisted peer=%d, not disconnecting\n", pto->GetId());
3695
+ // Reset the headers sync state so that we have a
3696
+ // chance to try downloading from a different peer.
3697
+ // Note: this will also result in at least one more
3698
+ // getheaders message to be sent to
3699
+ // this peer (eventually).
3700
+ state.fSyncStarted = false;
3701
+ nSyncStarted--;
3702
+ state.nHeadersSyncTimeout = 0;
3703
+ }
3704
+ }
3705
+ } else {
3706
+ // After we've caught up once, reset the timeout so we can't trigger
3707
+ // disconnect later.
3708
+ state.nHeadersSyncTimeout = std::numeric_limits<int64_t>::max();
3709
+ }
3710
+ }
3711
+
3712
+ // Check that outbound peers have reasonable chains
3713
+ // GetTime() is used by this anti-DoS logic so we can test this using mocktime
3714
+ ConsiderEviction(pto, GetTime());
3715
+
3716
+ //
3717
+ // Message: getdata (blocks)
3718
+ //
3719
+ std::vector<CInv> vGetData;
3720
+ if (!pto->fClient && (fFetch || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
3721
+ std::vector<const CBlockIndex*> vToDownload;
3722
+ NodeId staller = -1;
3723
+ FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller, consensusParams);
3724
+ for (const CBlockIndex *pindex : vToDownload) {
3725
+ uint32_t nFetchFlags = GetFetchFlags(pto);
3726
+ vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
3727
+ MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), pindex);
3728
+ LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
3729
+ pindex->nHeight, pto->GetId());
3730
+ }
3731
+ if (state.nBlocksInFlight == 0 && staller != -1) {
3732
+ if (State(staller)->nStallingSince == 0) {
3733
+ State(staller)->nStallingSince = nNow;
3734
+ LogPrint(BCLog::NET, "Stall started peer=%d\n", staller);
3735
+ }
3736
+ }
3737
+ }
3738
+
3739
+ //
3740
+ // Message: getdata (non-blocks)
3741
+ //
3742
+ while (!pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow)
3743
+ {
3744
+ const CInv& inv = (*pto->mapAskFor.begin()).second;
3745
+ if (!AlreadyHave(inv))
3746
+ {
3747
+ LogPrint(BCLog::NET, "Requesting %s peer=%d\n", inv.ToString(), pto->GetId());
3748
+ vGetData.push_back(inv);
3749
+ if (vGetData.size() >= 1000)
3750
+ {
3751
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETDATA, vGetData));
3752
+ vGetData.clear();
3753
+ }
3754
+ } else {
3755
+ //If we're not going to ask, don't expect a response.
3756
+ pto->setAskFor.erase(inv.hash);
3757
+ }
3758
+ pto->mapAskFor.erase(pto->mapAskFor.begin());
3759
+ }
3760
+ if (!vGetData.empty())
3761
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETDATA, vGetData));
3762
+
3763
+ //
3764
+ // Message: feefilter
3765
+ //
3766
+ // We don't want white listed peers to filter txs to us if we have -whitelistforcerelay
3767
+ if (pto->nVersion >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) &&
3768
+ !(pto->fWhitelisted && gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY))) {
3769
+ CAmount currentFilter = mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
3770
+ int64_t timeNow = GetTimeMicros();
3771
+ if (timeNow > pto->nextSendTimeFeeFilter) {
3772
+ static CFeeRate default_feerate(DEFAULT_MIN_RELAY_TX_FEE);
3773
+ static FeeFilterRounder filterRounder(default_feerate);
3774
+ CAmount filterToSend = filterRounder.round(currentFilter);
3775
+ // We always have a fee filter of at least minRelayTxFee
3776
+ filterToSend = std::max(filterToSend, ::minRelayTxFee.GetFeePerK());
3777
+ if (filterToSend != pto->lastSentFeeFilter) {
3778
+ connman->PushMessage(pto, msgMaker.Make(NetMsgType::FEEFILTER, filterToSend));
3779
+ pto->lastSentFeeFilter = filterToSend;
3780
+ }
3781
+ pto->nextSendTimeFeeFilter = PoissonNextSend(timeNow, AVG_FEEFILTER_BROADCAST_INTERVAL);
3782
+ }
3783
+ // If the fee filter has changed substantially and it's still more than MAX_FEEFILTER_CHANGE_DELAY
3784
+ // until scheduled broadcast, then move the broadcast to within MAX_FEEFILTER_CHANGE_DELAY.
3785
+ else if (timeNow + MAX_FEEFILTER_CHANGE_DELAY * 1000000 < pto->nextSendTimeFeeFilter &&
3786
+ (currentFilter < 3 * pto->lastSentFeeFilter / 4 || currentFilter > 4 * pto->lastSentFeeFilter / 3)) {
3787
+ pto->nextSendTimeFeeFilter = timeNow + GetRandInt(MAX_FEEFILTER_CHANGE_DELAY) * 1000000;
3788
+ }
3789
+ }
3790
+ }
3791
+ return true;
3792
+ }
3793
+
3794
+ class CNetProcessingCleanup
3795
+ {
3796
+ public:
3797
+ CNetProcessingCleanup() {}
3798
+ ~CNetProcessingCleanup() {
3799
+ // orphan transactions
3800
+ mapOrphanTransactions.clear();
3801
+ mapOrphanTransactionsByPrev.clear();
3802
+ }
3803
+ } instance_of_cnetprocessingcleanup;