Peer-to-peer networking
The peer-to-peer networking system connects NEAR nodes into a resilient network. It discovers usable peers, checks that they belong to the same chain, keeps a view of network paths, and carries chain data and node coordination traffic to the right recipients.
Network role
The networking system sits between the node's chain services and remote nodes. Local services submit requests such as blocks, transactions, state parts, and validator messages. The network selects a direct peer or a routed path, then delivers the message over a connection that matches its purpose. The reverse path accepts remote messages and passes them to the client or another node service. State-sync callers also receive an explicit update when a request was not sent, so they can retry without waiting for a remote response. Outgoing queue space and incoming message memory are part of this delivery contract, so a caller can reserve response capacity before expensive work starts. The main public boundary is chain/…/lib.rs• L1-41, with request and response types in chain/…/types.rs• L170-327 and client adapters in chain/…/client.rs• L195-211.
Connection tiers
The network separates traffic into three logical tiers so that high-value coordination traffic does not compete with gossip or large state transfers. TIER2 builds the peer graph and carries most node traffic. TIER1 provides direct or proxy-assisted paths for validator and other time-sensitive coordination traffic. TIER3 provides a short-lived direct path for large state-sync responses. The wire schema uses separate handshake variants for each tier so both ends agree on the connection purpose. chain/…/network.proto• L456-466 and chain/…/tcp_transport.rs• L34-38 define this model.
| Tier | Network purpose | Typical traffic |
|---|---|---|
| TIER1 | Direct coordination between current consensus participants and their trusted proxies | Approvals, partial chunks, state witnesses, endorsements, contract data, and SPICE coordination |
| TIER2 | General peer discovery, gossip, routing, and chain data exchange | Blocks, optimistic blocks, headers, transactions, transaction status, chunk requests, state requests, routing data, and node coordination |
| TIER3 | Direct transfer of large data after a TIER2 request | State headers and state parts |
The tiers work together rather than forming separate systems. TIER2 discovery carries the information needed to form TIER1 links, while snapshot-host discovery can lead to a direct TIER3 request or to a TIER2 request followed by a TIER3 response. chain/…/mod.rs• L600-638, chain/…/mod.rs• L185-192, and chain/…/peer_manager_actor.rs• L791-932 describe these relationships.
References: chain/…/network.proto• L456-466 chain/…/mod.rs• L600-638 chain/…/tcp_transport.rs• L34-38 chain/…/mod.rs• L185-192 chain/…/peer_manager_actor.rs• L791-932
Network actors and state
The network has a connection manager, one session handler per peer connection, shared network state, and a routing graph. The peer manager supervises admission, reconnection, broadcasts, and the boundary to the rest of the node. A session handler performs the handshake and moves messages between the wire and shared network state. Shared state joins connected-peer metadata, known peers, account routes, snapshot hosts, forwarded-transaction limits, and chain-facing adapters. It also keeps a small durable history of stable outbound TIER2 connections so useful peer relationships can survive a restart. chain/…/peer_manager_actor.rs• L334-403, chain/…/mod.rs• L123-214, and chain/…/mod.rs• L16-25 define these roles.
The NetworkTransport interface is the narrow boundary between network decisions and message delivery. Production TCP owns one connection pool for each tier, while test transport can follow the same network flow without using sockets. Transport facts such as pending dials and bandwidth stay separate from business metadata such as chain progress, tracked shards, and validator ownership. The connection boundary also maps each tier to the message classes it may carry. TIER1 remains reserved for consensus traffic, TIER2 carries discovery and general chain traffic, and TIER3 carries state-sync traffic. chain/…/network_transport.rs• L14-105, chain/…/tcp_transport.rs• L27-105, and chain/…/mod.rs• L26-75 define this boundary.
Connection registration is staged. The network validates the peer and its tier, inserts the session into the transport pool, and then updates connected-peer state and peer discovery. When a session closes, the pool is cleaned first and shared state is updated after it. For an outbound TIER2 session, the close decision also removes peers that must not be retried or queues stable stored peers for reconnection. This order prevents routing from treating a connection as ready before delivery can use it. Registration actions wait until this decision completes, so messages cannot observe a half-registered connection. chain/…/mod.rs• L432-549, chain/…/mod.rs• L590-611, chain/…/mod.rs• L91-114, and chain/…/peer_actor.rs• L805-969 describe the admission and removal flow.
References: chain/…/peer_manager_actor.rs• L334-403 chain/…/mod.rs• L123-214 chain/…/mod.rs• L16-25 chain/…/network_transport.rs• L14-105 chain/…/tcp_transport.rs• L27-105 chain/…/mod.rs• L26-75 chain/…/mod.rs• L167-355 chain/…/mod.rs• L432-549 chain/…/peer_actor.rs• L805-969 chain/…/peer_actor.rs• L1600-1661
Peer discovery and admission
Peer discovery grows from a small trusted starting set into a working set of known nodes. The node learns peer addresses from boot nodes, direct sessions, and peer lists received from other nodes. It then chooses candidates while respecting bans, blacklists, address trust, connection limits, and the desired number of outbound links. These policies are supplied through chain/…/config_json.rs• L85-232 and assembled into the validated network configuration in chain/…/config.rs• L241-340.
Peer lifecycle
Each known peer moves through a small lifecycle: unknown, known but disconnected, connected, or temporarily banned. The in-memory peer store records how the node learned an address and gives signed knowledge more weight than indirect information. It expires peers that remain unseen and lifts bans after the ban window. The store starts from boot nodes after a restart, while the separate connection store adds up to 40 outbound TIER2 peers that stayed connected for at least ten minutes. This durable history gives reconnection a preference for peers that have already proved stable. chain/…/types.rs• L95-120, chain/…/mod.rs• L1-9, and chain/…/mod.rs• L16-19 describe the lifecycle and storage boundary.
The following flow shows how a node turns a candidate peer into an admitted session.
flowchart TD
A[Boot node or learned peer] --> B[Candidate selection]
B --> C[TCP connection attempt]
C --> D[Handshake]
D --> E{Identity, chain, version, tier, and capacity checks}
E -- Reject --> F[Close, retry, or ban]
E -- Accept --> G[Register connected peer]
G --> H[Exchange routing and service information]
H --> I[Use peer for discovery and message delivery]
I --> J{Connection closes}
J --> K[Update store and schedule reconnection]
K --> B
The handshake binds a peer identity to a connection and checks the target identity, protocol compatibility, chain genesis, signed connection proof, and the requested tier. It also bounds information received before authentication, such as the peer's tracked-shard list. A validator can include a signed account-key ownership proof, which lets the network confirm that the claimed validator identity belongs to the connecting peer. The proof must use an encoding accepted by the current transition policy and must name the same peer as the handshake. TIER3 admission additionally distinguishes expected state-sync hosts from inbound requesters, so a large-data session is accepted only within its request and capacity rules. A successful session is registered only after the network accepts its tier, capacity, address, and account-identity rules. chain/…/handshake.rs• L82-152, chain/…/tests.rs• L251-279, chain/…/peer_actor.rs• L582-749, chain/…/mod.rs• L432-492, and chain/…/connection_pool.rs• L24-173 cover the admission boundary.
References: chain/…/types.rs• L95-120 chain/…/mod.rs• L32-76 chain/…/handshake.rs• L82-152 chain/…/tests.rs• L251-279 chain/…/peer_actor.rs• L582-749 chain/…/mod.rs• L432-492 chain/…/connection_pool.rs• L24-173 chain/…/connection_pool.rs• L662-720
Peer exchange
Connected TIER2 peers exchange healthy peer information so that discovery can continue after the initial boot set. A node treats received peers as indirect knowledge until a later connection or signed message gives it stronger proof. Peer lists also provide reports of the address at which other peers see this node. chain/…/peer_actor.rs• L1122-1182 describes this exchange.
The peer store is a bounded cache. It keeps address-to-identity relationships consistent, evicts old entries when full, expires peers that remain unseen, and unbans peers after the ban window. These limits make discovery useful without allowing unbounded remote input to become durable network state. chain/…/mod.rs• L78-89 and chain/…/config_json.rs• L154-163 provide the governing policy.
References: chain/…/peer_actor.rs• L1122-1182 chain/…/mod.rs• L78-89 chain/…/config_json.rs• L154-163
Public address discovery
Public address discovery determines the IP that a node advertises for direct TIER3 state-sync connections when no address is configured. Each connected TIER2 peer reports the IP it observes. The network groups reports by peer network, ignores addresses that the listener cannot accept or that are not public, and chooses the IP reported by the most groups. chain/…/mod.rs• L13-95 and chain/…/mod.rs• L1639-1680 define this rule.
A configured TIER3 address always wins. Otherwise, the voted IP uses the node's configured listening port. The private-address exception exists for local test networks only. A node needs a usable public address before it advertises its own snapshot or uses the legacy path to a host without an advertised address. It can instead open TIER3 directly to a host that signs and advertises its address. chain/…/config.rs• L241-254, chain/…/mod.rs• L1646-1680, and chain/…/config_json.rs• L165-211 cover these outcomes.
References: chain/…/mod.rs• L13-95 chain/…/mod.rs• L1639-1680 chain/…/config.rs• L241-254 chain/…/config_json.rs• L165-211
Network graph and routing
The network represents validated peer relationships as an undirected graph. A signed edge proves that two peer identities formed a connection. The graph turns that view into next-hop choices so a message can travel across TIER2 peers without every node maintaining a direct connection to every destination. chain/…/routing.rs• L33-85 and the routing graph described in the prior network model define this role.
Edge propagation
Peers share new or changed edges through routing-table updates. The receiving node removes duplicates and stale information, checks signatures, rejects invalid or unsafe graph input, and broadcasts accepted changes. It also applies message, source, peer-count, and total-graph bounds. This lets a local connection improve reachability for other nodes while keeping the graph bounded. chain/…/routing.rs• L17-31, chain/…/routing.rs• L77-121, and chain/…/peer_actor.rs• L1442-1469 describe the update path.
An edge also has a version-like nonce and can represent removal. The graph prunes old or unreachable relationships, so routing follows a current view instead of preserving every connection that ever existed. The peer manager periodically repairs differences between local connections and local graph edges. chain/…/mod.rs• L1527-1620 and chain/…/config.rs• L323-339 show these rules.
References: chain/…/routing.rs• L17-31 chain/…/routing.rs• L77-121 chain/…/peer_actor.rs• L1442-1469 chain/…/mod.rs• L1527-1620 chain/…/config.rs• L323-339
Routed message delivery
A routed message names a peer or a route-back token. It carries its author, a signature, and a hop limit. Requests that expect a reply record enough route-back state to send the response toward the request's source. Recent-message caches suppress duplicates, while timestamps and hop counts help the network measure delivery delay and path length. chain/…/mod.rs• L1312-1380 and chain/…/mod.rs• L1126-1187 define the message shape and outcomes.
Responses with an unknown route-back token, the wrong kind, or the wrong author are dropped. The route-back cache expires old entries and bounds its use, so fabricated requests cannot easily displace useful reply paths. The routing choice can also use chain context, such as a peer's chain height or tracked shards, to select a useful next hop. chain/…/mod.rs• L657-685 and chain/…/peer_manager_actor.rs• L464-489 define these checks.
For message-level behavior and compatibility rules, see the related page Peer network protocol. Routing behavior is exercised across paths, hop limits, duplicate messages, and reply validation in chain/…/mod.rs• L1126-1187.
References: chain/…/mod.rs• L1312-1380 chain/…/mod.rs• L657-685 chain/…/mod.rs• L1126-1187 chain/…/peer_manager_actor.rs• L464-489
Chain data and coordination traffic
The networking system carries both chain data and the control data needed to coordinate nodes. Chain services use the network boundary for blocks, block headers, transactions, approvals, chunks, state-sync data, epoch-sync proofs, and validation-related messages. The same boundary also carries peer lists, routing edges, validator proxy data, and snapshot-host data. chain/…/types.rs• L226-326 and chain/…/client.rs• L195-211 show the chain-facing request and delivery categories.
Chain data transport
TIER2 distributes normal chain data and routes requests to suitable peers. Block and header requests support catch-up and fork checks. Transaction and approval messages support consensus progress and transaction spread. Chunk, witness, contract-data, optimistic-block, and SPICE messages support sharded execution and validation through the tier that matches their delivery needs. Versioned witness messages retain older wire forms while newer nodes add the versioned forms to the same TIER1 or routed delivery model. The message families are defined in chain/…/message_kind.rs• L17-44, chain/…/mod.rs• L600-638, chain/…/tests.rs• L500-633, and chain/…/types.rs• L271-326.
Forwarded transactions are accepted through the routed T2 path and then passed to chain services as forwarded work. The network shares a counter across peers and starts a new count when a block arrives. It limits both the total forwarded transaction load and the smaller share reserved for forwarded execution-call transactions, so transaction forwarding cannot take too much attention from consensus traffic. chain/…/forwarded_txs.rs• L5-45 and chain/…/peer_actor.rs• L1107-1122 define this admission rule.
Large state responses use a different path from ordinary gossip. When a snapshot host advertises a signed address, the requester opens TIER3 directly and receives the acknowledgement and response there. Older hosts use a compatibility path: the request travels over routed TIER2 with the requester's public address, then the host opens TIER3 back to the requester. Direct requests to the same host can share one connection, while a failed connection reports NotSent to the chain service so it can choose another host. This keeps large reads from delaying normal peer traffic and lets the requester match each response to the state-sync request. chain/…/peer_manager_actor.rs• L791-935 and chain/…/client.rs• L87-135 describe this relationship.
References: chain/…/types.rs• L226-326 chain/…/client.rs• L195-211 chain/…/message_kind.rs• L17-44 chain/…/mod.rs• L600-638 chain/…/tests.rs• L500-633 chain/…/forwarded_txs.rs• L5-45 chain/…/peer_manager_actor.rs• L791-935 chain/…/client.rs• L87-135
Validator and snapshot coordination
Validator-related coordination starts on TIER2 and can establish direct TIER1 paths. Signed account data maps validator accounts to node identities and trusted proxies. The cache keeps only the newest signed record for each important account. It verifies new records before insertion and broadcasts valid progress even if a later record in the same update is invalid. This prevents one bad record from forcing repeated verification of data that the network already accepted. TIER1 nodes use these mappings to connect to a validator or one of its proxies, then send time-sensitive validator and execution traffic over that path. chain/…/mod.rs• L45-85, chain/…/mod.rs• L235-319, and chain/…/tier1.rs• L201-380 describe this bootstrap and delivery model.
TIER1 connection management keeps a direct validator link when possible and otherwise uses a trusted proxy. A validator advertises only proxies that it can reach, including an address learned from STUN when it acts as its own proxy. Nodes remove TIER1 links that no longer serve a current validator or proxy relationship, while the TIER2 link can remain for normal peer traffic. chain/…/tier1.rs• L34-197, chain/…/tier1.rs• L238-417, and chain/…/tier1.rs• L410-471 cover this separation.
The account-data cache also protects local validator data. When a node restarts and sees an older record for its own account key, it can issue a newer signed record from its local data instead of accepting the old value. Signed data is accepted only when its encoding is allowed by the active network transition policy. chain/…/mod.rs• L117-195 and chain/…/config.rs• L142-231 define this rule.
Nodes also advertise state snapshots that other nodes can use for sync. A snapshot host record identifies the state root, epoch, shards, and public serving address. The host signs the record, including the address, so a relay cannot redirect a requester to another endpoint. The record keeps a legacy signature as well, which allows older nodes to verify the snapshot data while newer nodes verify the full record. chain/…/state_sync.rs• L15-37, chain/…/state_sync.rs• L74-133, and chain/…/peer_message.rs• L229-245 define this contract.
The snapshot-host cache keeps the freshest record for each peer, rejects duplicate or invalid records, and removes records outside the current epoch window. Valid records can still update the cache when another record in the same batch fails verification. The local node and validator nodes use reserved slots. Other hosts use a bounded cache. When a node starts a state sync, it indexes hosts for the active sync hash and requested shard. Header requests choose an available host. Part requests spread retries across hosts and reset that choice when a part arrives. chain/…/mod.rs• L170-193, chain/…/mod.rs• L227-337, chain/…/mod.rs• L340-393, and chain/…/tests.rs• L45-184 define this selection model.
For message-level behavior and compatibility rules, see the related page Peer network protocol.
References: chain/…/mod.rs• L45-85 chain/…/mod.rs• L117-195 chain/…/mod.rs• L235-319 chain/…/tier1.rs• L34-197 chain/…/tier1.rs• L238-417 chain/…/tier1.rs• L117-232 chain/…/tier1.rs• L342-471 chain/…/config.rs• L142-231 chain/…/state_sync.rs• L15-37 chain/…/state_sync.rs• L74-133 chain/…/peer_message.rs• L229-245 chain/…/tests.rs• L636-756 chain/…/mod.rs• L170-193 chain/…/mod.rs• L227-337 chain/…/mod.rs• L340-393 chain/…/tests.rs• L205-277 chain/…/tests.rs• L280-429 chain/…/tests.rs• L546-614
Wire transport and resource safety
The production network uses framed TCP sessions. Each frame carries a length followed by a binary peer message. The session reads and writes asynchronously, tracks traffic, and reports a connection error when a peer stalls or a buffer exceeds its limit. A transport interface separates these delivery operations from network decisions, so production TCP and test transports follow the same network flow. chain/…/network_transport.rs• L14-83 and chain/…/tcp_transport.rs• L180-205 describe this boundary.
Message boundaries
The wire protocol wraps all peer messages in a length-prefixed envelope. Protobuf uses one frame per message. Borsh uses a small header frame followed by a body frame; the header names the message kind and can carry distributed trace context. The receiver can therefore select the kind-specific size limit and connect the remote operation to local tracing before it reads or dispatches the body. chain/…/mod.rs• L99-156 and chain/…/mod.rs• L656-705 define this boundary.
The receiver chooses the connection encoding from the first accepted handshake. A node that supports both formats sends the initial handshake in each accepted format, then ignores the extra copy and uses the format selected by the peer. For Borsh messages, the receiver checks the header, reads the bounded body, and confirms that the header kind matches the body kind before delivery. Protocol-specific limits protect the cost of parsing individual message kinds. Conversion also rejects oversized transaction and routed bodies before their nested data is materialized. chain/…/peer_actor.rs• L507-555, chain/…/peer_message.rs• L509-537, and chain/…/config.rs• L142-231 provide the framing and compatibility policy.
The protocol conversion layer maps wire envelopes to the internal message model. It accepts older routed forms and upgrades them to the current tier-aware form, while preserving the message identity used for signatures and replies. It accepts legacy and address-signed snapshot records only when their fields form a valid version. Account-key payloads use the same signed-payload rule: verification checks both the signature and the serialized account data it covers. The network configuration controls the staged move from protobuf to Borsh for connection messages and signed structures, so peers can be upgraded without breaking the protocol boundary. During this transition, signed account records must remain tied to the encoding that produced their signature. chain/…/account_key.rs• L75-110, chain/…/account_key.rs• L180-197, chain/…/peer_message.rs• L250-567, chain/…/tests.rs• L87-249, chain/…/tests.rs• L636-756, and chain/…/config.rs• L168-231 define this boundary.
The raw connection API provides a smaller client for direct TIER2 use. It performs the handshake, exposes direct block and header messages, and exposes a limited set of routed messages. It keeps route references for replies and ignores protocol messages that are outside this small API. This interface is useful for callers that need peer I/O without the full peer-manager lifecycle. chain/…/connection.rs• L26-49, chain/…/connection.rs• L204-365, and chain/…/connection.rs• L367-485 describe this boundary.
References: chain/…/network_transport.rs• L14-83 chain/…/tcp_transport.rs• L180-205 chain/…/mod.rs• L99-156 chain/…/mod.rs• L656-705 chain/…/peer_actor.rs• L507-555 chain/…/peer_message.rs• L509-567 chain/…/account_key.rs• L75-110 chain/…/account_key.rs• L180-197 chain/…/tests.rs• L87-249 chain/…/tests.rs• L403-420 chain/…/tests.rs• L636-756 chain/…/connection.rs• L204-365 chain/…/connection.rs• L367-485 chain/…/config.rs• L168-231
Message rate limits
Each connection can apply token-bucket limits by message kind. The limits cover discovery, chain data, routed requests, validation traffic, and sync responses. A message consumes a token only when its kind has a configured bucket, so operators can tune protection without changing the message contract. Legacy and versioned forms of the same validation traffic share a bucket during rolling upgrades. The peer session applies the limit after decoding and before dispatching the message to network state. chain/…/messages_limits.rs• L10-57, chain/…/messages_limits.rs• L104-195, and chain/…/peer_actor.rs• L1629-1667 define this policy.
References: chain/…/messages_limits.rs• L10-57 chain/…/messages_limits.rs• L104-195 chain/…/peer_actor.rs• L1629-1667
Capacity and abuse controls
Admission and delivery controls limit the impact of bad peers or overloaded links. They include connection caps, peer bans, per-message receive limits, per-message rate limits, handshake limits on tracked shards, graph size limits, duplicate suppression, time-to-live checks, bounded incoming memory, bounded outgoing memory, bounded route-back state, and per-block limits on forwarded transactions. These controls protect both the network graph and the node services that consume messages. chain/…/config.rs• L241-340, chain/…/mod.rs• L194-202, chain/…/tcp_transport.rs• L53-54, and chain/…/forwarded_txs.rs• L5-45 define the main policy inputs.
The controls affect reliability as well as security. A full write buffer or a stalled socket closes a session. An invalid handshake, signed edge, or snapshot record blocks admission or propagation. A message that has exceeded its lifetime, exceeded its rate budget, or cannot find a route is dropped instead of looping through the graph. Forwarded transaction limits reject excess work until the next block arrives. Large state and epoch-sync responses reserve outgoing capacity before they are produced, so overload returns a busy result instead of creating unbounded work. Drop reasons, route delay, route hop counts, message encoding, and message kind are exposed as network metrics to help operators distinguish overload from reachability or peer faults. chain/…/client.rs• L168-186, chain/…/peer_manager_actor.rs• L865-932, chain/…/mod.rs• L1126-1187, and chain/…/mod.rs• L194-202 describe these outcomes.
References: chain/…/config.rs• L241-340 chain/…/mod.rs• L194-202 chain/…/tcp_transport.rs• L53-54 chain/…/forwarded_txs.rs• L5-45 chain/…/client.rs• L168-186 chain/…/peer_manager_actor.rs• L865-932 chain/…/mod.rs• L1126-1187
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to
PeerMessagefields, tier mappings, message-kind discriminants, or message limits must preserve wire compatibility and keep generated protocol code aligned with chain/…/network.proto. Changes to routed-message versions must preserve conversion for peers on older protocol versions. - Changes to connection encoding, Borsh headers, trace context, or signed account payloads must keep first-message negotiation, header/body kind matching, signature coverage, and cross-node tracing compatible during the transition from protobuf.
- Changes to tier admission or message routing must keep TIER1 validator traffic separate from TIER2 routed traffic and TIER3 bulk transfer. Keep the allow-list in connection/mod.rs aligned with the tier handshake and all send paths.
- Changes to
NetworkTransport, connection registration, or connection removal must preserve the pool/state ordering and keep the production TCP and test transport contracts aligned. - Changes to account data or proxy data must preserve the mapping from validator account keys to reachable peer identities.
- Changes to account-data verification or cache updates must preserve partial progress for valid entries while rejecting the bad peer, and must keep local validator data authoritative after restart.
- Changes to edge validation, nonce handling, reachability timestamps, or pruning must keep graph state and local connection state consistent.
- Changes to route-back keys, expected response kind or responder, duplicate detection, or routed-message TTL must preserve reply delivery without allowing loops or unsolicited replies.
- Changes to route-back cache capacity or eviction policy must protect both legitimate reply paths and fair space use across peers.
- Changes to frame sizes, decode-time body caps, rate-limit buckets, or queue limits must account for both incoming memory permits and outgoing queue permits.
- Changes to forwarded transaction admission must keep the shared counter, block-triggered reset, total transaction cap, and execution-call cap aligned with the drop metrics.
- Changes to tracked-shard or snapshot-host limits must account for both handshake admission and the signed records accepted by remote nodes.
- Changes to public-address voting or TIER3 address configuration must preserve listener-family checks, network-group voting, the configured-address override, and the port used for state-sync connections.
- Changes to snapshot-host signature fields must preserve the address covered by the current signature and the legacy signature needed during the compatibility window.
- Changes to snapshot selection or state-sync requests must preserve the active sync-hash index, public-address field, direct-address path, and pending-TIER3 request contract. Failed connection attempts must still produce a
NotSentupdate. - Changes to client-facing network messages must preserve the delivery contract for responses, receive permits, and reserved outgoing capacity.
- Changes to persisted recent outbound connections must preserve their stored key and value formats. They must also keep the stable-connection threshold, bounded cache order, duplicate replacement, and close-reason rules aligned so restart bootstrap does not prefer stale or unsuitable peers.
- Changes to routed-message timestamps, hop counts, drop reasons, metric labels, or encoding labels must preserve the meaning and bounded cardinality of operational metrics.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Peer reports a different genesis or has no compatible protocol version | Handshake fails and the session does not join the network | Handshake checks chain identity and version ranges before registration |
| Peer sends too many tracked shards or an invalid owned-account proof | The handshake is rejected before the session is registered | Decode bounds and signed account-key checks run before admission |
| Peer sends an owned-account proof in an encoding that the node does not accept | The session closes without a ban so a peer on another release can retry after upgrade | The transition policy checks signed-struct encoding separately from signature validity |
| Peer sends an invalid edge, an unsafe nonce, or a signed identity proof that does not verify | Connection or routing update is rejected and the peer can be banned | Signature, nonce, target, time, and tier checks run during admission and edge updates |
| Peer sends an address-signed snapshot record with a changed address or invalid legacy signature | The record is not accepted or relayed | The host signs the current address and the cache verifies every required signature |
| Peer sends duplicate, empty, stale, or over-capacity snapshot records | No usable snapshot source is added | Duplicate checks, epoch windows, signed freshness, and reserved cache slots limit accepted records |
| Peer sends too many peers or invalid account or snapshot data | Discovery or sync data is not accepted and the session can be stopped | Count, signature, version, epoch, and cache-bound checks limit remote state |
| Peer sends multiple account-data records for one account in one update | The update is treated as abusive and the peer can be stopped | The account-data cache rejects duplicate account keys before signature work |
| Peer sends valid account data followed by an invalid signature | The valid prefix remains available, but the peer is rejected | Verification inserts all successful records even when a later record fails |
| Peer reports only private, unusable, or conflicting listener-family addresses | The node has no usable TIER3 address and cannot use the legacy state-sync path | Public-address voting filters reports by reachability and listener family, then uses network-group counts |
| Peer store, snapshot cache, or routing graph reaches its configured bound | New discovery, snapshot sources, or routes may be unavailable | Bounded caches, graph caps, expiry, and connection monitoring limit growth |
| An outbound TIER2 connection closes before it is stable enough to store | A restart cannot use that peer as a preferred reconnect target | The connection store records only outbound sessions that meet its minimum lifetime |
| A second TIER1 peer proves the same validator account key | The new connection is rejected because the validator identity is ambiguous | Connection pools and the TIER1 account index allow only one active peer per account key |
| A routed response has no matching request, the wrong response kind, or the wrong author | The response is dropped instead of reaching node services | Route-back entries record the expected responder and response kind |
| Routed message has no path, an expired route-back entry, zero TTL, or an exhausted message budget | Message or response is dropped | Next-hop lookup, bounded route-back caches, hop limits, and token buckets define explicit drop outcomes |
| Forwarded transactions exceed the total or execution-call limit before the next block | Further forwarded transactions are dropped while ordinary chain coordination continues | Shared counters cap forwarded work and reset when a block message arrives |
| State-sync requester has no known public address or no matching snapshot host | State header or part request cannot start | Public-address discovery and signed snapshot-host selection gate the legacy request path |
| A directly advertised snapshot-host address is unreachable or rejects the requester's identity | The state request is reported as NotSent, and the chain service can retry another host | Pending TIER3 connection tracking and explicit client updates close the failed request path |
| State response generation cannot reserve outgoing queue capacity | The requester receives a busy acknowledgement and no TIER3 payload | Response bytes are reserved before the chain service produces the response |
| Peer stalls or fills a write buffer | The session closes and queued traffic is not delivered | Read/write timeouts and per-connection plus global queue limits detect overload |
| Remote peer opens an unmatched TIER3 response session or exceeds the requester limit | The connection is rejected | Pending request records, inbound requester caps, and tier-specific admission checks control TIER3 sessions |
| Peer sends an oversized frame, body, or message kind | The stream stops before the body reaches network state | Frame, kind-specific body, and header/body matching checks run during receive |
| A peer repeats a handshake on an established TIER3 session | The short-lived state transfer session closes before idle cleanup | Established sessions accept only messages allowed for their tier |
Key files
| File | Why to read it |
|---|---|
| chain/…/lib.rs | Entry point and public boundary of the networking subsystem |
| chain/…/types.rs | Chain-facing network requests, responses, peer state, and tier metadata |
| chain/…/client.rs | Messages that connect the network to chain services, including explicit state-request failure updates and response resource ownership |
| chain/…/config.rs | Validated peer, tier, graph, queue, encoding, and rate-limit policy |
| chain/…/config_json.rs | Operator-facing network, public-address, and TIER1 configuration |
| chain/…/mod.rs | Peer message families, tier assignments, routed message shape, response matching, signed account data, framing, and trace propagation |
| chain/…/handshake.rs | Handshake conversion and bounded chain and identity data at the wire boundary |
| chain/…/account_key.rs | Conversion and verification boundary for signed validator account data and ownership proofs |
| chain/…/peer_message.rs | Conversion between wire messages and node messages, including decode-time size gates and legacy routed-message conversion |
| chain/…/peer_manager_actor.rs | Connection supervision, reconnection, request routing, direct and legacy state-sync coordination, and node-facing delivery |
| chain/…/network_transport.rs | Transport contract used by network decisions and test transports |
| chain/…/tcp_transport.rs | TCP listener, dialing, tier pools, and production transport operations |
| chain/…/mod.rs | Tier message allow-lists and the ready-connection pool |
| chain/…/mod.rs | Bounded known-peer state, address trust, discovery, expiry, and bans |
| chain/…/mod.rs | Shared state that joins peers, graph data, caches, admission, routing, reconnection, and chain service adapters |
| chain/…/tier1.rs | Validator account-key routing, proxy discovery, and TIER1 connection selection |
| chain/…/forwarded_txs.rs | Shared admission limits for forwarded transactions between blocks |
| chain/…/routing.rs | Edge exchange, route selection, and route-back behavior |
| chain/…/peer_actor.rs | Handshake, per-peer message flow, admission checks, and connection cleanup |
| chain/…/state_sync.rs | State-sync requests and signed snapshot-host records |
| chain/…/mod.rs | Snapshot-host validation, retention, reserved slots, and state-part source selection |
| chain/…/messages_limits.rs | Per-message rate-limit policy and upgrade-safe bucket mapping |
| chain/…/connection.rs | Small direct connection API for handshakes, direct chain messages, and selected routed messages |
| chain/…/mod.rs | Durable recent-outbound history and the rules that decide when a TIER2 peer is retried |