Commit graph

5 commits

Author SHA1 Message Date
Olaoluwa Osuntokun
58ee9ef65a server+connmgr: make outbound startup deterministic
In this commit, we define TargetOutbound as the number of automatic
connections and treat explicit Connect requests as additional peers.

Permanent requests could previously consume connection IDs before Start
sampled the shared counter. The resulting automatic count depended on
goroutine scheduling, while the listener reserved the worst-case total.
We now start the configured automatic count directly and cap it by the
peer budget left after permanent peers.

The composition test covers permanent requests on both sides of Start and
pins the same automatic+permanent total for either ordering.
2026-07-21 16:45:44 -07:00
Olaoluwa Osuntokun
95c11c560a server+inbound: correct inbound admission accounting
In this commit, we keep loopback and whitelisted peers inside the ordinary
pending-handshake and V2 source budgets, while preserving their existing
no-ban behavior.

We also derive the listener reservation from the configured peer mode.
Connect-only and simnet nodes now reserve just their permanent peers, while
automatic mode accounts for both its target and addpeers without exceeding
MaxPeers.

Finally, a bound V2 handshake consumes its rate budgets once, but reacquires
the concurrency slot for each CPU-bound responder phase. This keeps rate
limiting scoped to the handshake while bounding both expensive phases.
2026-07-21 16:44:43 -07:00
Boris Nagaev
6c056ec471
server: centralize inbound handshake admission
In this commit, we introduce a server-wide admission policy for
incomplete inbound handshakes and the CPU-bound portion of v2 responder
setup. Source accounting uses normalized IPv4 and IPv6 prefixes, while
global, per-source, and concurrent v2 budgets remain independent and
bounded.

Peer construction passes the policy through a small interface only for
inbound v2 responders. Handshake slots release on verack or disconnect,
and the connection manager reserves MaxPeers capacity for automatic
outbound peers.
2026-07-18 00:17:55 -05:00
Oliver Gugger
dccea8feba multi: use new v2 modules everywhere 2026-05-14 18:05:33 -07:00
Or Aharonee
08be37f3b6
server, integration: add unit regression tests for peer lifecycle fix
Address review feedback on the peer add/done race fix:

Add three direct unit tests in server_test.go that exercise the fix
without the full server or rpctest harness:

- TestOnVerAckDoubleCall: call OnVerAck twice on the same serverPeer,
  assert no panic and verAckCh remains closed.
- TestPeerLifecycleOrdering: verack before disconnect emits peerAdd
  then peerDone in order.
- TestPeerLifecycleSimultaneousReady: both verAckCh and Peer.Done()
  ready before the handler runs; assert peerDone always arrives and
  peerAdd, if emitted, precedes it (100 iterations).

Harden integration tests in sync_race_test.go:

- Check fakePeerConn errors via require.NoError instead of discarding.
- Extract dialAndSendVersion helper for TestPreVerackDisconnect;
  check all errors instead of silently continuing.
- Fix comment wording ("produces" -> "is expected to produce").
2026-04-09 18:19:15 +03:00