
Study & contribute to Bitcoin and lightning open source

Hands on, guided learning to make you confident in bitcoin development.

List of good first issues from curated bitcoin FOSS projects

Interactive AI chat to learn about Bitcoin technology and its history

Technical Bitcoin search engine

Daily summary of key Bitcoin tech development discussions and updates

Engaging Bitcoin dev intro for coders using technical texts and code challenges

Review technical Bitcoin transcripts and earn sats
Date
23 October, 2025
Speakers
Not Available
Transcript by
Not Available
Net Processing Refactor Discussion (transcript #1)
This discussion covers two refactoring proposals for Bitcoin Core's peer-to-peer networking layer:
CConnman contains mixed responsibilities:
Problem: Socket management and network logic are tightly coupled, making the code difficult to test, reason about, and reuse.
Goal: Isolate socket management into a separate, modular component
Benefits:
CConnman structure (created 8 years ago):
Example of tight coupling—disconnection logic:
Disconnect initiated
→ boolean flag set in CNode
→ CConnman detects flag
→ CConnman notifies PeerMan
→ multi-step teardown dance
Core idea:
Scope: Massive refactor (~200 commits)
Natural evolution of the separation:
Significance: The fact that this is possible proves the architecture is correct.
Clarify PR status:
Form working group:
CNode-to-Peer refactor:
Net Processing Refactor Discussion (transcript #2)
GOAL: turn CNode into a shared_ptr inside of CConnman, because it
clarifies lifetimes. Move all the state that PeerManager needs to node into
Peer, and make CNode an implementation detail of CConnman.
p2p and sockman stuff are mixed together, as demonstrated in [[Low level sockets
abstraction]]. The overlap of PeerManager and CConman is CNode. There is a
bit of an interface around CNode, but we violate it all of the time, e.g. for
disconnecting. When either side wants to disconnect, it updates a bool inside
CNode, CConnman picks it up and notifies PeerManager, starting a teardown
dance.
CNode was intended to go away. CConnman became a kitchen sink, which was
then intended to be broken up (but that hasn't happened yet). The
net/net_processing split work is orthogonal to [[Low level sockets abstraction]]
work.
CConnman and PeerManager are separated, but they depend on the state of each
other. CConnman tells PeerManager how to run.
CNode is a giant class that represents the entire state of a connection on the
p2p network, but it also has higher-level state. E.g. CConnman needs to know
if its connected, how much bytes sent, ... but it shouldn't need to know e.g.
"Am I finished with IBD?"?
Peer was created to store higher-level state for PeerManager, e.g.
synchronization status, and it takes cs_main. There was an earlier big effort to
add multiple locks to reduce cs_main usage. Last ping-time probably should be a
net thing, but is currently a messaging layer thing.
Another effort was to take things out of CNodeState into Peer (using the
individual locks).
Right now, we have CNode and pointers to it here and there, and manually count
references to CNode. When refs drop to zero, we delete it. This manual
approach could be replaced with a shared_ptr, however we have a need for
specific teardown sequence - i.e. we need certain code to be executed upon
deletion.
PeerManager takes a copy of all of CConnman's CNode's, ups the refcount
for all of them, runs through the even loop, and then drop the refs. Ideally,
CNode should not be leaked out of CConnman.
This work is pretty hard because code is very entangled.
One example of difficulty: both PeerManager and CConnman need to know about
eviction. E.g. CConnman says "something needs to be evicted", and then
PeerManager decides what gets evicted. Further complicated by whitelists. If
PeerManager and CConnman were running in totally separate processes, which
should be in charge of that eviction logic?
When PR? The code change is huge: 200 commits, mostly moving stuff from CNode
to Peer. The logic is very chunkable, luckily. Some things are easily moved,
but others are complicated.
PeerManager can run its own event loop once all the CNode logic it needs is
moved into Peers. Changes like that are tougher to review conceptually, but it
allows more things to run async, and you can reason about state much better.
It's possible that you're trying to send messages to a peer that's already
disconnected, but that's no issue except for wasting a bit of time. Makes
testing and fuzzing a ton easier. Because net/net_processing distinction is now
so much clearer, you can now e.g. have 2 CConnman instances (e.g. tor and
ipv4, even thought that's probably not a great idea) for just 1 PeerManager.
Going further, net (CConnman) can run in a separate process with IPC. Once the
separation is done (~175 commits), adding multiprocess is trivial (~2 commits).
net/CConnman can also be turned into a library. That in combination with
kernel, means you can write a node does that ibd with just a few hundred lines
of glue code. Separating it out as a library may not be a goal, but is a good
indicator that it's a healthy approach.
One idea suggested is to have a PeerManager per-network.
The new approach e.g. copies fDisconnect so that PeerManager and CConnman
have their own view. This makes sense conceptually, e.g. if you send a tx and
then disconnect, then CConnman should treat that as disconnected, but
PeerManager shouldn't yet, because there is still work to do. The definition
of "disconnected" is different for both sides.
We've gone through these splitting exercises in the past a couple of times, and there was support each time. If this is going to be pushed forward.
One concern raised: some of the prefill logic depends on factors like size of the TCP window. That can be abstracted, however.
Instead of separating PeerManager and CConnman, another approach would be to
merge them together more. This could be beneficial for performance by e.g.
avoiding NodeId lookups using shared memory.
The plan is to form a working group to get reviewers and move things forward. It's a large project, but attendants suggested this can still progress quickly if there is good enthusiasm, let's not already assume that it's going to take 2 years.
CNode while we work on this separationCommunity-maintained archive to unlocking knowledge from technical Bitcoin transcripts




