Commit Graph
261 Commits
Author SHA1 Message Date
DanSandClaude Opus 5.5 93f8b3768b rpc: read the peer list under cs_vNodes in getinfo/getnetworkinfo; z_getoperationstatus without cs_main
From origin/perf/wallet-scan-rpc-costs, both still on dev:

- getinfo and getnetworkinfo read vNodes.size() and iterated vNodes without cs_vNodes, racing the
  network threads that add and remove peers (a reallocation mid-iteration is undefined behaviour).
  Both now count through one helper that takes the lock.
- z_getoperationstatus and z_listoperationids took cs_main and cs_wallet, though they only read the
  async queue (which has its own mutex) and each operation's status. GUIs poll them, so every poll
  contended with block validation. Regtest: z_getoperationstatus reports a running sweep normally.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-20 20:10:01 -06:00
DanSandClaude Opus 5.5 dbe154c2dc net: stop sending every ADDR message once per address, and filter PushAddress on the right address
Two bugs from the general audit (origin/audit-fixes-20260901), both still on dev:

- SendMessages pushed the whole of vAddrToSend once for every address the peer did not know yet, so
  one getaddr reply of N addresses went out as N messages of N addresses each, all serialized and
  checksummed while cs_main is held. The locally built vAddr was never sent. Restore the upstream
  idiom: collect the unknown addresses, send them in MAX_ADDR_TO_SEND batches, then the rest once.
  The ADDR/ADDRV2 choice and the wire format are unchanged.
- CNode::PushAddress tested IsAddressKnown(addr) -- the CNode member holding this peer's own address
  -- instead of _addr, the address being queued. Once the peer's own address was in its addrKnown
  (routine: it advertises itself, or it comes back in a getaddr reply), every address queued for that
  peer was dropped until the daily addrKnown.reset(). Fixed together with the first bug, since it
  re-enables relay paths that would otherwise be amplified.

Regtest, two nodes over TLS, node A holding ~1000 addresses and B connecting and sending getaddr:
the old binary answered with 18 identical 235-byte addrv2 messages (5017 bytes to the peer); this
sends the same 235-byte message once (614 bytes). On mainnet a reply carries far more addresses,
and the waste grows with the square of that count. New gtest NetAddrRelay.PushAddressFiltersOnQueuedAddress
fails with the old filter.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-20 19:51:15 -06:00
DanSandClaude Opus 5.5 d91e069da3 net: stop wolfSSL's CloseSocket macro from turning P2P closes into double closes
wolfssl/wolfio.h (included by <wolfssl/ssl.h> in net.h) does
`#ifndef CloseSocket / #define CloseSocket(s) close(s)`. Every TU that
includes net.h after that point compiles CloseSocket(x) to a bare
close(x). That includes all 15 calls in net.cpp, among them the ones
in CloseSocketDisconnect and ~CNode. util/sock.cpp's
CloseSocket(SOCKET&), the only thing that sets the handle to
INVALID_SOCKET, was never called from net.cpp. This has been the case
since OpenSSL was replaced by wolfSSL (Hush 9ff756590, 2020), so every
DragonX release is affected.

So CNode::hSocket kept its number after the socket was closed. Every
P2P disconnect closed that same number again, 2 to 4 times:
- CloseSocketDisconnect (net.cpp:572) runs once per disconnect trigger
  (ThreadSocketHandler, SocketSendData, the TLS socket handler,
  ThreadMessageHandler), and each run still saw a valid-looking hSocket;
- ~CNode (net.cpp:2819) then closed it once more.
Meanwhile the socket handler kept FD_SETting, send()ing and recv()ing on
the stale number. In between, other threads get that number from the
kernel's lowest-free-fd rule:
- BDB reopening wallet.dat or database/log.* (ThreadFlushWalletDB, ~11/s);
- fopen("rb+") of a block file for getdata/getblock;
- an HTTP RPC accept.
The stray close then closes it. BDB keeps doing I/O on the dead number:
'wallet.dat: write failed for page N' / 'Illegal seek' / 'BDB0060
PANIC', or silent wallet-page writes into a blocks/blk*.dat that got
the number next. Its failing reads later threw out of ThreadNotifyWallets
(std::terminate). A closed HTTP connection fd makes libevent re-arm
and later close whatever owns that number next ('Epoll ADD ... failed').

Reproduced on isolated regtest with an LD_PRELOAD close() guard:
- one disconnectnode gives exactly one EBADF double close (49
  disconnects, 50 EBADF; with strace and no shim, 29 disconnects gave
  30 'close(N) = -1 EBADF');
- P2P churn alone gives non-owner closes of block files and wallet.dat;
- RPC-only and Tor-only loads give none.
Disassembly of CloseSocketDisconnect and ~CNode shows 'call close@plt'
before this change and 'call CloseSocket(unsigned int&)' after.

Undefine the macro right after the wolfSSL include in net.h; wolfio.h
is include-guarded, so it can't come back. net.cpp gets an #error
tripwire in case it ever does. NetCloseSocket.ClosedNodeNeverClosesAReusedFdNumber
fails on the old code (a closed CNode closes the fd number's new owner)
and passes now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 21:23:00 -05:00
DanSandClaude Opus 4.8 817c6b2d0e hygiene: Phase 5 — correct stale comments + name safe magic numbers
Fifth phase of the code-hygiene remediation, done per-file (18 files) via an
18-agent Workflow with strict guardrails. No consensus or security VALUES
changed (verified: pow/hush_utils/hush_bitcoind/net.h/crypter/stratum have
zero non-comment numeric changes); built clean, self-mined, verifychain=true.

Totals: 57 stale comments corrected, 46 user-facing branding fixes, 6
behavior-preserving named constants, 4 stratum warnings, 77 items deliberately
left (consensus/security values, copyright headers).

- Stale comments -> DragonX: corrected HUSH3/HUSH/Komodo/Equihash/Arrakis
  leftovers that misdescribed the active chain (pow AWT/lwma notes, txdb
  "Equihash solution" -> RandomX, wallet CLTV/overwinter/Sapling@1 notes,
  util datadir provenance, crypter's stale mapSproutSpendingKeys invariant).
  Replaced unprofessional/editorializing comments (profane TODOs, "developers
  are elite") with neutral technical notes, preserving the real design info.
- User-facing branding: dumpwallet header "created by Hush" -> "DragonX";
  RPC help text hushd/hush-cli/hushprivkey/hushaddress/Agama -> dragonx*;
  rebranded provably-dead "HUSH3" symbol-fallback literals to DRAGONX.
- Named constants (same values, non-consensus/non-security): addrman
  peer-selection factors (kChanceFactorGrowth/kChanceScale/deprioritize),
  sietch MIN_ZOUTS, an init notarization-DB cache size.
- Left the security macros (ECC/TFM_TIMING_RESISTANT=420, comment-clarified
  only), the consensus subsidy/commission literals + 128/129 TRANSITION
  (comment only), and copyright headers untouched.
- Added a prominent WARNING that the stratum server is Equihash-era and NOT
  updated for DragonX's RandomX PoW (flagged, not rewritten).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-27 15:19:22 -05:00
Duke efbaff9d89 Wolfssl uses a typedef called 'byte' which is no longer allowed in gcc15 2025-12-30 02:37:40 -05:00
Duke cbc8995b36 -clearnet=0 2025-02-28 12:58:01 -05:00
Duke 53cf574c03 Use constants for the defaults of disableipv4/disableipv6 so the code and docs cannot be out of sync 2025-02-12 17:23:48 -05:00
onryo 58b65f9670 Update copyrights 2024-02-27 23:59:59 +01:00
Duke 63ad87f69b Ensure CNode::addrKnown immediately takes little memory when we disconnect the node 2023-03-17 00:21:00 -04:00
Duke c1baab7b8a Rate limit incoming addr p2p messages 2023-03-16 22:33:25 -04:00
Duke e033a2e6eb Update copyrights to 2023 2023-02-09 18:06:03 -05:00
zanzibar 512da314a5 BIP155 (addrv2)
Tor v3 + i2p
2023-01-06 15:23:22 +00:00
Jonathan "Duke" Leto 5d2307a709 Update copyrights to 2022 2022-09-19 15:45:30 -07:00
Duke Leto 860541d2e4 Show relay status in getpeerinfo 2021-05-04 12:25:12 -04:00
Duke Leto 4a536d62dc Update copyrights 2021-04-17 13:03:22 -04:00
Duke Leto 161750c807 Merge branch 'danger' into duke
Conflicts:
	src/net.h
2021-04-09 23:51:19 -04:00
Duke Leto 4d252334bf . 2021-04-09 14:53:26 -04:00
Duke Leto ea2b68c1d3 Feeler connections ported from BTC core, eclipse attack mitigation 2021-02-28 23:28:49 -05:00
Duke Leto cf57365698 Deletions and cleanups 2021-01-26 08:56:08 -05:00
Duke Leto 1488a03f1c Improved TLS error handling and teach getpeerinfo about cipher of each connection 2021-01-24 15:06:34 -05:00
Duke Leto c9b4dfa9c7 Force WolfSSL side-channel resistance
There seems to be some build-bug in WolfSSL, such that even though
--enable-harden (HARDEN) is default, it's not set correctly in options.h .

So we define it correctly just after parsing all other config options
BUT BEFORE we load the rest of WolfSSL headers.

These will be defined no matter what options are given to wolfssl ./configure:

ECC_TIMING_RESISTANT
TFM_TIMING_RESISTANT
2021-01-24 13:09:25 -05:00
Duke Leto 1f4c4f27e6 Refactoring 2021-01-24 08:51:17 -05:00
Duke Leto cde6d33ad1 The term 'whitelist' is racist and so we choose to call this feature 'allowlist' 2021-01-10 10:46:22 -05:00
Duke Leto 8fe3e238f0 Exclusively TLS connections at p2p layer; dump peers more often 2021-01-10 09:54:42 -05:00
Duke Leto b58c15b9fb update copyrights 2020-12-10 07:45:36 -05:00
Duke Leto abc0b55d05 Hush Hush Hush 2020-12-04 09:42:59 -05:00
miodragpop 3ae6205a9b tls shape-up 2020-11-03 16:09:20 +01:00
miodragpop 9ff7565901 OpenSSL replaced by WolfSSL 2020-10-28 22:13:52 +01:00
miodragpop eaed7355c6 tls rework 2020-10-23 21:17:20 +02:00
Duke Leto be16f80abc Hush Full Node is now GPLv3
Any projects which want to use Hush code from now on will need to be licensed as
GPLv3 or we will send the lawyers: https://www.softwarefreedom.org/

Notably, Komodo (KMD) is licensed as GPLv2 and is no longer compatible to receive
code changes, without causing legal issues. MIT projects, such as Zcash, also cannot pull
in changes from the Hush Full Node without permission from The Hush Developers,
which may in some circumstances grant an MIT license on a case-by-case basis.
2020-10-21 07:28:10 -04:00
miodragpop 56d9c00749 asmap bucketing ported from Komodo 2020-10-02 11:10:26 +02:00
miodragpop 62f67821ec tls implemented 2020-09-29 13:08:45 +02:00
Duke Leto a7f88a87aa Update copyright URL to be https 2020-09-20 13:17:38 -04:00
jl777 6cb639c2b7 nspv_listtransactions initial 2019-07-13 01:49:05 -11:00
jl777 c3343e237e Getinfo, login, listunspent, spentinfo rpc calls 2019-07-03 20:36:31 -11:00
jl777 bc89c1de30 -prints 2019-07-03 07:03:28 -11:00
jl777 0dc11fbb02 Spent info rpc helper 2019-07-02 09:16:11 -11:00
jl777 e28d1005be Rest of nSPV function stubs 2019-07-02 06:43:05 -11:00
jl777 e9a2714441 uint32_t lastutxos,lastinfo; 2019-07-02 05:49:14 -11:00
jl777 4b876b6118 Throttle rate of nSPV requests 2019-07-02 05:30:56 -11:00
jl777 cb3756eb07 Print 2019-07-02 02:46:30 -11:00
blackjok3r 8d7234bf22 Test fix to stop nodes forceing an attacking chain onto others. 2019-02-11 01:10:27 +08:00
jl777 932b358243 +comments how to update to 8MB blocks 2019-01-25 17:15:56 -11:00
jl777 352c93f2c4 -<<<<< HEAD 2019-01-25 16:59:55 -11:00
jl777 1231c3240d Merge remote-tracking branch 'origin/FSM' into FSM
# Conflicts:
#	src/cc/CCtx.cpp
2019-01-25 16:45:19 -11:00
jl777 524342f7ba Single #define _MAX_BLOCK_SIZE to set max block size 2019-01-25 16:43:57 -11:00
jl777 e4791f54e6 Merge branch 'FSM' into patch-gcc-8 2019-01-25 16:33:13 -11:00
jl777 10b90968af +comments 2019-01-09 01:28:17 -11:00
jl777 7d56db54d1 Messages 2019-01-07 07:33:23 -11:00
jl777 348a23d6c4 tests 2019-01-07 07:29:36 -11:00