# P2P Topology File Explained

As we move to full P2P we try to explain how and why your P2P files should be configured below.

{% embed url="<https://www.essentialcardano.io/article/approaching-full-p2p-node-operations>" %}
Approaching full P2P node operations via [www.essentialcardano.io](http://www.essentialcardano.io)
{% endembed %}

{% hint style="info" %}
Credits to  <img src="https://2549074837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8PjW7zFPfe4PgCsPtkZx%2Fuploads%2FdeDDjDpMxICIBY02VHeW%2Fpanl-logo.png?alt=media&#x26;token=7b850645-14e7-4dd8-90eb-ef6c3d41d1db" alt="" data-size="line"> [<mark style="color:blue;">PANL Pool</mark>](https://www.panl.org/) and <img src="https://earncoinpool.com/images/coin_v3.png" alt="" data-size="line"> [Earn Coin Pool](https://earncoinpool.com/) for this guide.
{% endhint %}

## What we are looking to explain:

❓What is the real difference from Public and Local peers and when and where should you use each?

❓Why use bootstrapping peers? What does it do and why is it need or not needed?

❓When to use advertise flag and why?

❓Can you have multiple Access Points and why?

❓When to use trustable flag and why?

* [Local vs Public Peers](#local-vs-public-peers)
* [Bootstrapping Peers](#bootstrapping-peers)
* [Advertise Flag](#a-dvertise-flag)
* [Access Points](#access-points)
* [Trustable Flag](#trustable-flag)

***

### Sample scenarios and example topology files:

* [x] [BP P2P Topology with two relays](#p2p-topology-for-bp-with-2-relays-sample)
* [x] [Relay P2P Topology with two relays and one BP](#p2p-topology-for-relay-using-2-access-points-one-for-relays-and-one-for-bp)
* [x] [Relay P2P Topology with two relays, BP and SPO friend relays](#p2p-topology-for-relay-using-3-access-points-one-for-relays-one-for-bp-and-one-for-spo-friends)

***

### If this is the first time you are Enabling P2P on your node, reminder of steps you need to take:

* [x] [Steps to enabling P2P on your node for the first time](#reminder)

***

### Local vs Public Peers

> **What are local vs public peers and when should you use each?**
>
> As stated at link below:
>
> *<mark style="color:red;">**local roots:**</mark>* should comprise local relays or a local block-producing node, and any other peers that the node needs to maintain a connection with. These connections are typically kept private.\
> \
> \&#xNAN;*<mark style="color:red;">**public roots**</mark>*<mark style="color:red;">**:**</mark> publicly known nodes (e.g. IOG relays, or ledger nodes). They are either read from the configuration file directly or from the chain. The configured ones will be used to pass a recent snapshot of peers needed before the node caches up with the recent enough chain to construct root peers by itself.\
> \
> ⚠️The node does not guarantee a connection with every public root, unlike local ones. However, by being present in the set, it gets an opportunity to establish an outbound connection with that peer.
>
> &#x20;
>
> **Local Roots** is designed for peers that the node should always keep as hot or warm, such as its own block producer. On the other hand, **Public Roots** serves as a source of fallback peers.\
> &#x20;
>
> Source:
>
> <https://github.com/input-output-hk/cardano-node-wiki/blob/main/docs/getting-started/understanding-config-files.md#the-p2p-topologyjson-file>

### Bootstrapping Peers

> Bootstrapping peers are good for when your node has had an extended outage, you'll sync from those and trusted peers and then ledger once on tip.

### Advertise Flag

> Advertise will tell your peers <mark style="color:blue;">"hey I have this really good peer, you should try to connect to them"</mark> which can give that relay more inbound connections. \
> \
> Could be used for situations like unregistered relays.

{% hint style="warning" %}
If you set advertise to true in topology file you must also add the following to your mainnet-config.json file:<br>

```
"PeerSharing": true

```

Node Versions BEFORE 8.9.1 also require:

`"ExperimentalProtocolsEnabled": true,`
{% endhint %}

### Access Points

> You can have multiple access points within Local Roots. Why would you want to use this? This way you can keep advertise as false for your BP while True for your relay. \
> \
> For example, [below is a sample topology file](#p2p-topology-for-relay-using-2-access-points-one-for-relays-and-one-for-bp) for P2P where we have two access points

### Trustable Flag

> Trustable peers are composed by the bootstrap peers and the trustable local root peers. By default local root peers are not trustable.<br>
>
> <mark style="color:red;">Your own Relays and BP should be set to "trustable": true</mark>
>
> \
> Source:\
> <https://github.com/input-output-hk/cardano-node-wiki/blob/main/docs/getting-started/understanding-config-files.md#the-p2p-topologyjson-file>

***

## P2P Topology for BP with 2 Relays Sample

✅Here we set <mark style="color:red;">`"useLedgerAfterSlot": -1`</mark> so the BP doesn't try to connect to other nodes using ledger peer data.

✅We set `"advertise": false`, since these are local root on BP and we want to keep private.

✅Since we have 2 Relays we set `"valency": 2`, if we had 3 Relays it would be set to 3.

✅We need to set `"bootstrapPeers": null` on BP and set our Relays to `"trustable": true,`&#x20;

✅Last of all we leave Public Roots blank by using `"publicRoots": []`&#x20;

{% hint style="warning" %}
In the sample below you need to change "relay1.Address"  and "relay2.Address" to your relay address and change "port": 3001 to the port you use.
{% endhint %}

```
{
  "bootstrapPeers": null,
  "localRoots": [
    {
      "accessPoints": [
        {
          "address": "relay1.Address",
          "port": 3001
        },
        {
          "address": "relay2.Address",
          "port": 3001
        }
      ],
      "advertise": false,
      "trustable": true,
      "valency": 2
    }
  ],
  "publicRoots": [],
  "useLedgerAfterSlot": -1
}
```

***

## P2P Topology for Relay using 2 Access Points, one for relays and one for BP

✅Here we use 2 Access Points under local roots so we can advertise our relays while hiding our BP

✅We set `"advertise": false`, on BP Access Point since we want to keep private.

✅Since we have 1 additional Relays, (2 relays in total) we set `"valency": 1`, if we had 2 additional Relays (3 relays in total), we would set `"valency": 2`, and so on.

✅We need to set `"bootstrapPeers"` to the address below and set our Relays to `"trustable": true,` so we can sync if we get too far off the tip.

✅Last of all we leave Public Roots blank by using `"publicRoots": []`&#x20;

{% hint style="warning" %}
In the sample below you need to change "relay2.Address" and "blockProducerAddress" to your relay and BP address and change "port": 3001 to the port you use.&#x20;

Leave "bootstrapPeers" addresses and ports as is
{% endhint %}

```
{
  "localRoots": [
    {
      "accessPoints": [
        {
          "address": "relay2.Address",
          "port": 3001
        }
      ],
      "advertise": true,
      "valency": 1,
      "trustable": true
    },
    {
      "accessPoints": [
        {
          "address": "blockProducerAddress",
          "port": 3001
        }
      ],
      "advertise": false,
      "valency": 1,
      "trustable": true
    }
  ],
  "bootstrapPeers": [
    {
      "address": "backbone.cardano.iog.io",
      "port": 3001
    },
    {
      "address": "backbone.mainnet.emurgornd.com",
      "port": 3001
    },
    {
      "address": "backbone.mainnet.cardanofoundation.org",
      "port": 3001
    }
  ],
  "publicRoots": [
    {
      "accessPoints": [],
      "advertise": false
    }
  ],
  "useLedgerAfterSlot": 116812831
}
```

## P2P Topology for Relay using 3 Access Points, one for relays, one for BP, and one for SPO friends

✅See notes from example [above](#p2p-topology-for-relay-using-2-access-points-one-for-relays-and-one-for-bp) and don't forget to change SPO.relay.Addresses and port below to match your SPO friends address and ports

```
{
  "localRoots": [
    {
      "accessPoints": [
        {
          "address": "relay2.Address",
          "port": 3001
        }
      ],
      "advertise": true,
      "valency": 1,
      "trustable": true
    },
    {
      "accessPoints": [
        {
          "address": "blockProducerAddress",
          "port": 3001
        }
      ],
      "advertise": false,
      "valency": 1,
      "trustable": true
    },
    {
      "accessPoints": [
        {
          "address": "SPO.relay2.Address",
          "port": 3001
        },
        {
          "address": "SPO.relay2.Address",
          "port": 3001
        }
      ],
      "advertise": false,
      "valency": 2,
      "trustable": false
    }
  ],
  "bootstrapPeers": [
    {
      "address": "backbone.cardano.iog.io",
      "port": 3001
    },
    {
      "address": "backbone.mainnet.emurgornd.com",
      "port": 3001
    },
    {
      "address": "backbone.mainnet.cardanofoundation.org",
      "port": 3001
    }
  ],
  "publicRoots": [
    {
      "accessPoints": [],
      "advertise": false
    }
  ],
  "useLedgerAfterSlot": 128908821
}
```

***

{% hint style="success" %}
Using these 3 samples you can modify to fit your situation.&#x20;

You can add access points, turnoff or on advertise flag and trustable flag where necessary.
{% endhint %}

### ⚠️REMINDER:

If this is the first time you are Enabling P2P on your node you need to make sure you took these 2 steps:

#### 1) Update mainnet-conf json

```
cd $NODE_HOME
sudo nano mainnet-config.json
```

add:&#x20;

```
"EnableP2P": true,
"PeerSharing": true,
"TargetNumberOfRootPeers": 100,
"TargetNumberOfKnownPeers": 100,
"TargetNumberOfEstablishedPeers": 50,
"TargetNumberOfActivePeers": 20,
"TargetNumberOfKnownBigLedgerPeers": 15,
"TargetNumberOfEstablishedBigLedgerPeers": 10,
"TargetNumberOfActiveBigLedgerPeers": 5,
```

{% hint style="info" %}
On BP just add <mark style="color:red;">`"EnableP2P": true,`</mark> line

and <mark style="color:red;">`"PeerSharing": false,`</mark> line.
{% endhint %}

{% hint style="warning" %}
If you set advertise to true in topology file you must also add the following to your mainnet-config.json file:<br>

```
"PeerSharing": true

```

Node Versions BEFORE 8.9.1 also require:

`"ExperimentalProtocolsEnabled": true,`
{% endhint %}

#### 2) Remove relay-topology\_pull.sh or remove cronjob for it

List crontabs by running:

```
crontab -l
```

Edit Crontab and remove relay-topology\_pull.sh if you have one by running:

```
crontab -e
```

Take opportunity to update server and reboot

```
sudo systemctl stop cardano-node
sudo apt-get update && sudo apt-get upgrade -y && sudo reboot
```

## Congratulations you did it!

***

## Additional Resources:

{% embed url="<https://github.com/input-output-hk/cardano-node-wiki/blob/main/docs/getting-started/understanding-config-files.md#the-p2p-topologyjson-file>" %}

{% embed url="<https://book.play.dev.cardano.org/env-mainnet.html>" %}

{% embed url="<https://updates.cardano.intersectmbo.org/2024-04-15-network/>" %}

{% hint style="info" %}
Additional Resources:<br>

<https://github.com/input-output-hk/cardano-node-wiki/blob/main/docs/getting-started/understanding-config-files.md#the-p2p-topologyjson-file>

<https://book.play.dev.cardano.org/env-mainnet.html><br>

<https://updates.cardano.intersectmbo.org/2024-04-15-network/>
{% endhint %}

## Contributors&#x20;

Thanks to the following pools for helping to put together these guides. Please consider delegating to their pools to support them.  Are you a pool? Consider buying them a coffee

![](https://img.cexplorer.io/a/5/7/2/1/pool12wpfng6cu7dz38yduaul3ngfm44xhv5xmech68m5fwe4wu77udd.png) [Apex Cardano Pool - Ticker: APEX](https://cexplorer.io/pool/pool12wpfng6cu7dz38yduaul3ngfm44xhv5xmech68m5fwe4wu77udd)

![](https://img.cexplorer.io/7/e/1/9/f/pool16cdtqyk0fvxzfkhjg3esjcuty4tnlpds5lj0lkmqmwdjyzaj7p8.png)  [Earn Coin Pool - Ticker: ECP](https://cexplorer.io/pool/pool16cdtqyk0fvxzfkhjg3esjcuty4tnlpds5lj0lkmqmwdjyzaj7p8)

![](https://img.cexplorer.io/f/4/3/4/6/pool1qhs3cf9ymc2nvmrd2j8cs36cj9jdqgnqk6s9ngyvy2lz5s8rak8.png) [PANL Stake Pool - Ticker PANL](https://cexplorer.io/pool/pool1qhs3cf9ymc2nvmrd2j8cs36cj9jdqgnqk6s9ngyvy2lz5s8rak8)&#x20;

![xSPO Alliance Logo](https://2549074837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8PjW7zFPfe4PgCsPtkZx%2Fuploads%2F0sqzqoHnqVXizi2RHABd%2FxSPO_NFT_64x64.png?alt=media\&token=1c1b130e-26df-4b1e-8e0e-e85fae1ee73e) [xSPO Alliance](http://xspo-alliance.org/discord)
