Skip to content

Network

prasad-kumkar edited this page May 5, 2025 · 1 revision

Network

The jam.network module implements the networking layer for Tessera, handling peer discovery, message propagation, and data synchronization between nodes.

Protocol Components

The networking layer consists of several key components:

QUIC Protocol

Tessera uses the QUIC protocol for network communication, which provides:

  • Multiplexed connections over UDP
  • Built-in encryption and security
  • Low-latency connection establishment
  • Stream and datagram-based messaging

Protocol Messages

The JAM network protocol defines several message types:

  • UP0: Block announcement messages
  • CE128/CE129: State synchronization messages
  • CE131/CE132: Ticket extrinsic messages
  • CE133: Work proof sharing
  • CE135: Work report messages
  • CE141: Assurance messages
  • CE142: Preimage messages
  • CE145: Judgement messages

Peer Discovery

The peer discovery system allows nodes to find and connect to other nodes in the network:

  • Bootstrap Nodes: Well-known nodes for initial discovery
  • Peer Exchange: Sharing of known peers
  • DHT: Distributed Hash Table for peer discovery
  • mDNS: Local network discovery

Synchronization

Tessera supports multiple synchronization methods:

  • Full Sync: Download and validate all blocks from genesis
  • Fast Sync: Download recent state and blocks
  • Light Sync: Minimal state verification for light clients

Configuration

Network parameters can be configured in the node configuration:

network_config = {
    "listening_address": "0.0.0.0",
    "listening_port": 30333,
    "max_peers": 50,
    "bootstrap_nodes": [
        "/ip4/1.2.3.4/tcp/30333/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N",
        "/ip4/5.6.7.8/tcp/30333/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N"
    ],
    "reserved_nodes": [
        "/ip4/9.10.11.12/tcp/30333/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N"
    ],
    "sync_mode": "full"
}

Usage

from jam.network import NetworkService
from jam.config import NodeConfig

# Initialize network service
config = NodeConfig.from_file("config.json")
network = NetworkService(config.network)

# Start network service
network.start()

# Get connected peers
peers = network.get_peers()
print(f"Connected to {len(peers)} peers")

# Broadcast a block
network.broadcast_block(block)

# Send a message to a specific peer
network.send_message(peer_id, message)

Stream Handling

Tessera manages different stream types for various protocol operations:

# Handle incoming messages based on prefix
def handle_message(stream):
    prefix = stream.read_prefix()
    
    if prefix == PrefixType.UP0:
        handle_block_announcement(stream)
    elif prefix == PrefixType.CE133:
        handle_work_proof(stream)
    else:
        # Unknown prefix
        pass

For more detailed information on the networking system design, see ADR-0005: Networking System.

Clone this wiki locally