cardano course
  • Welcome!
  • Video lessons
  • Handbook
    • Module 1. Building and running the node
      • Building the node
      • Running the node and connecting to a network
    • Module 2. Basic operations
      • Creating keys and addresses
      • Creating a simple transaction
      • Registering the stake address and delegating
    • Module 3. Protocol parameters and configuration files
      • Protocol parameters
      • Byron genesis file
      • Shelley genesis file
      • Alonzo genesis file
      • Conway genesis file
      • Node configuration file
      • Topology file
    • Module 4. Peer-to-peer (P2P) networking
    • Module 5. Creating a stake pool
      • The setup
      • Generating keys
      • Registering a stake pool
      • Runtime system options
      • Running the nodes
      • Stake snapshots
      • Upgrading cardano-node and cardano-cli
      • Pool operations and maintenance
      • Retiring a stake pool
    • Module 6. Monitoring the nodes
    • Module 7. Cardano governance
      • Update proposals
      • Polls
    • Module 8. Setting up a local cluster
      • Creating a local cluster
      • Spending the genesis UTXO
      • From Byron to Shelley
      • Moving funds to a Shelley address
      • Creating a first stake pool
      • Bringing decentralization parameter down to .80
      • From Shelley to Alonzo
      • Creating a second stake pool before moving to the Babbage era
      • Redelegating genesis keys
      • Vasil hard fork
      • Creating a local cluster with the mkfiles script
    • Module 9. Simple scripts and Plutus scripts
    • Module 10. New tracing system
    • Module 11. Running the SMASH server
    • Module 12. Running the token metadata server
  • Curated playlist
Powered by GitBook
On this page
  • What is next?
  • The P2P topology file
  • Configuring the node to use P2P

Was this helpful?

Edit on GitHub
  1. Handbook

Module 4. Peer-to-peer (P2P) networking

PreviousTopology fileNextModule 5. Creating a stake pool

Last updated 1 year ago

Was this helpful?

  • Through automatic P2P, registered nodes can discover and establish connections with each other

  • Nodes can establish full-duplex connections, operating simultaneously as servers and clients for the mini-protocols

  • Nodes can maintain certain static topologies, including their own relays and block producers, as well as trusted peers with which continuous connections are desired

  • Root peers can be reloaded using the SIGHUP signal, eliminating the need for a restart

  • The node can dynamically manage the connections, each node maintains a set of peers mapped into three categories:

    • cold peers ‒ existing (known) peers without an established network connection

    • warm peers ‒ peers with an established bearer connection, which is only used for network measurements without implementing any of the node-to-node mini-protocols (not active)

    • hot peers ‒ peers that have a connection, which is being used by all three node-to-node mini-protocols (active peers)

    Newly discovered peers are initially added to the cold peer set. The P2P governor is then responsible for peer connection management.

  • Maintaining diversity in hop distances contributes to better block distribution times across the globally distributed network

  • In the case of adversarial behavior, the peer can be immediately demoted from the hot, warm, or cold sets

Upstream peers are classified into three categories: known, established, and active.

What is next?

  • Peer sharing

  • Ouroboros Genesis release

The P2P topology file

The new P2P topology file format (please use it with node v.1.35.6 and later):

Example of a topology file for a node not involved in block production or block propagation:

{
   "localRoots":[
      {
         "accessPoints":[
            
         ],
         "advertise":false,
         "valency":1
      }
   ],
   "publicRoots":[
      {
         "accessPoints":[
            {
               "address":"relays-new.cardano-mainnet.iohk.io",
               "port":3001
            }
         ],
         "advertise":false
      }
   ],
   "useLedgerAfterSlot":322000
}

Example of topology files for a stake pool

The block-producing node includes its own relays (x.x.x.x and y.y.y.y) under local roots. Note that the example uses "useLedgerAfterSlot": -1 to indicate that it should never use LedgerPeers.

{
   "localRoots":[
      {
         "accessPoints":[
            {
               "address":"x.x.x.x",
               "port":3000
            },
            {
               "address":"y.y.y.y",
               "port":3000
            }
         ],
         "advertise":false,
         "valency":1
      }
   ],
   "publicRoots":[
      {
         "accessPoints":[
            
         ],
         "advertise":false
      }
   ],
   "useLedgerAfterSlot":-1
}

The relay x.x.x.x includes its own block-producing node (z.z.z.z), the other relay (y.y.y.y) under local roots, and a few other root peers under public roots. Note that this time, the example does use LedgerPeers - "useLedgerAfterSlot": 10000000.

{
   "localRoots":[
      {
         "accessPoints":[
            {
               "address":"z.z.z.z",
               "port":3000
            },
            {
               "address":"y.y.y.y",
               "port":3000
            }
         ],
         "advertise":false,
         "valency":1
      }
   ],
   "publicRoots":[
      {
         "accessPoints":[
            {
               "address":"relays-new.cardano-mainnet.iohk.io",
               "port":3001
            }
         ],
         "advertise":false
      }
   ],
   "useLedgerAfterSlot":322000
}

Configuring the node to use P2P

On the preview testnet, the default is true since this network is already running with P2P. You will also need to configure the target number of active, established and known peers, together with the target number of root peers:

{
...
  "EnableP2P": true,
...
  "TargetNumberOfActivePeers": 20,
  "TargetNumberOfEstablishedPeers": 40,
  "TargetNumberOfKnownPeers": 100,
  "TargetNumberOfRootPeers": 100,
}

{% embed url="" %}

You can enable P2P from the configuration file. For example, in the preview testnet , you will find the field EnableP2P, which can be set to either false or true.

Peer-to-peer (P2P) networking
Interview with the networking team lead
input-output-hk/cardano-node#4559
configuration file
Page cover image