P2P Connections
- Outbound Peer
- Attempts to maintain maximum # of outbound connections.
- Local acquires remote addresses through gossiping
- Inbound Peer
- Node accepts up to maximum set # inbound connections.
- Inbound peers obtains local address through gossiping.
- Manual Peer
- Node can set permanent peers in settings.
- Will always attempt to maintain connection to these.
- All peer connection types follow the same Bitcoin messaging protocol once established.
Ping Protocol
- Ping protocol determines whether underlying TCP connection still active.
- Received/Sent: PING
- Peer attempts ping transmission.
- Successful socket transmission indicates live connection.
- Otherwise node will close peer connection.
- Heartbeat intervals are in node settings.
- Received: PONG
- Version 60001 and above.
- Peer responds to PING with PONG.
- Includes same nonce as in PING.
- Indicates responsive service/Roundtrip latency.
- Received: PONG
- Resubscriptions to messages are renewed after each received message.
Address Protocol
- Peer discovery through address protocol.
- Received: GETADDR
- Requests known addresses from peer.
- One response to GETADDR only allowed per connection.
- Received: ADDR
- Can be sent proactively.
- Seeding Peer: Sends own address.
- Response to GETADDR: Up to 1000 addresses.
- Sent: GETADDR
- Requests host address from peer.
Channel Lifetime
- Handshake Protocol.
- Negotiate channel version.
- Subsequently: Ping/Pong/Address
- Channel heartbeat.
- Exchange of known peers.
- Maintain channel is closed.
- Other messaging protocols provide:
- (Initial) blockchain sync.
- Propagation of mempool transactions.
- Exchange of chain-extending blocks.
- Other protocol types for different sessions.
Peer Lifetime
- Seed Sessions.
- Contact seed peers to seed peer addresses.
- Node Settings:
- Seeding peer addresses.
- Min # addresses to be acquired.
- All seed channels disconnect after seeding.
- Manual/Outbound/Inbound Session
- Contact seed peers to seed peer addresses.
- Node Settings:
- Max In/Outbound channels.
- Manual channel peers.
- Same protocols attached to each channel.
- Channel Protocols.
- Seed/Address: Exchange known peer addresses.
- Transaction in/out:
- Propagate new mempool TX’s
- Block in/out:
- Propagate new blocks
- Exchange of chain-extending blocks.
Transaction-In Protocol
- Received: TRANSACTION(TX)
- Can be received anytime.
- OOrganised into mempool.
- Received: INV(TX)
- Inventory message includes up to 50’000 TXIDs.
- GETDATA(INV) to request transaction data.
- Sent: FEEFILTER
- minimum feerate sat/kb for tx relay
- Sent: MEMPOOL
- Request mempool, peer responds with single/multiple INVs.
Transaction-Out Protocol
- Received: FEEFILTER
- Received: MEMPOOL
- Inventory message includes up to 50’000 TXIDs.
- Received: GETDATA
- Payload identical to INV message
- Respond with serialised transaction
- Node mempool event:
- For new transaction organised into mempool, announce to peer.
Block-Out Protocol
- Received: GET_HEADERS
- Lookup included header hashes.
- Send beginning with highest common strong chain hash.
- Received: GET_BLOCKS
- Lookup included header hashes.
- Send INV beginning with highest common strong chain hash.
- Received: GET_DATA
- Send type of block requested:
- witness_block/block
- compact_block
- filtered_block
- Sent: SEND_COMPACT
- Send compact blocks (BIP152)
- Compact block: Header+Short IDs.
- Only unknown TXs data is requested.
- Broadcast of new blocks
- INV/Header/Compactblocks depending on peer.