Bitcoin P2P Handshake Explained: version, verack, and Service Bits
When Bitcoin peers connect, they must establish which protocol features they can use before exchanging ordinary application data. The classic handshake begins with version messages and acknowledgement via verack. It negotiates communication behavior; it does not make either peer a trusted authority.
The version message
A version message conveys protocol-related information such as a protocol version, advertised service flags, time, and other connection metadata. Some fields have changed or become less important across releases. Software must follow the actual protocol version and feature rules rather than assume every historic field remains meaningful.
The verack message
A verack acknowledges the peer's version message. After the handshake completes, peers can exchange messages permitted by their negotiated capabilities. A handshake failure, incompatible protocol, or malformed message may cause a disconnect.
Service bits are claims of capability
A peer may advertise service flags indicating that it can provide particular kinds of data. Examples include NODE_NETWORK, NODE_WITNESS, and NODE_COMPACT_FILTERS. These bits guide requests and peer selection; they are not cryptographic proof that a remote node will behave correctly or serve valid information.
Feature negotiation is layered
Some capabilities use separate messages or rules. For example, compact block relay uses sendcmpct, while BIP339 specifies wtxidrelay negotiation. BIP324's encrypted v2 transport is a transport-layer mechanism and should not be confused with the traditional application handshake itself.
Security and debugging
A peer completing version/verack can still send malformed, inconsistent, or misleading data. Applications should impose message limits, track negotiated features, and validate received blocks and transactions independently. When troubleshooting, distinguish transport establishment, handshake completion, header synchronization, and block validation: each is a separate milestone.
Primary references
Bitcoin Developer Reference — P2P Network: https://developer.bitcoin.org/reference/p2p_networking.html
BIP339 — WTXID-based Transaction Relay: https://github.com/bitcoin/bips/blob/master/bip-0339.mediawiki
BIP324 — Version 2 P2P Encrypted Transport Protocol: https://github.com/bitcoin/bips/blob/master/bip-0324.mediawiki
