[go: up one dir, main page]

Fix in the p2p maintenance triggers

Context

The maintenance of the lib_p2p maintains the number of active connections between a minimal and a maximal number of connections. When a new connection is established, the maintenance is triggered, if there are too many connections. When a connection is closed, the maintenance is triggered, if there are too few connections.

To maintain the number of active connections, multiple values are used:

  • There are 3 concerned fields in the type P2p_maintenance.config:
    • min_connections: the strict minimum number of connections, this value is used to trigger an urgency maintenance,
    • max_connections: the maximum number of connections, this value is used to trigger an urgency maintenance,
    • expected_connections: the targeted number of connections to reach.
  • There is the record P2p_maintenance.bounds, used in the maintenance:
    • min_target: the minimal number of connections to establish when there are too few of them,
    • max_target: the maximal number of connections to establish when there are too few of them,
    • min_threshold: the minimum number of connections that trigger a maintenance,
    • max_threshold: the maximum number of connections that trigger a maintenance.

The record P2p_maintenance.bounds values are computed from the P2p_maintenance.config values with those formulas:

  • step_min = (expected_connections - min_connections) / 3
  • step_max = (max_connections - expected_connections) / 3
  • min_target = min_connections + 2*step_min
  • max_target = max_connections - 2*step_max

          Min                             Max
       Threshold                       Threshold
           |                               |
           |      Min             Max      |
           |     Target          Target    |
           |       |               |       |
   |<-1/3--|--1/3--|--1/3->|<-1/3--|--1/3--|--1/3->|
   |       |       |       |       |       |       |
  Min------|-------|----Expected---|-------|------Max

Bug

In P2p_connect_handler.create_connection the two conditions that trigger a maintenance were swapped. When a new connection is established, the maintenance is triggered if there are too few connections and when a connection is closed, the maintenance is triggered if there are too many connections.

Fixes

Swap the two conditions to trigger a maintenance if there are too many connections, when a new connection is established and to trigger a maintenance if there are too few connections, when a connection is closed.

Complications

When the triggers are reestablished, the maintenance seems to have a wrong behavior:

  • the wave of connections are not synchronized (same for disconnections),
  • the average time a connection is alive decrease (~20min for default settings on mainnet).

https://gitlab.com/nomadic-labs/tezos/-/tree/p2p_master-next

Edited by Vivien Pelletier