Skip to content

Instantly share code, notes, and snippets.

@segun
Created December 16, 2022 09:24
Show Gist options
  • Save segun/e1421a820870cc74a6cc40679f3a2279 to your computer and use it in GitHub Desktop.
Save segun/e1421a820870cc74a6cc40679f3a2279 to your computer and use it in GitHub Desktop.

Synopsis

On the d14n server, we have several services that is tied together. One of that is a gbc-crawler that crawls the Gnosis network for nodes and stores information like geo location, client name, client version etc.

Issue

The crawler finds about 1500 nodes (called discovered peers) but is only able to connect to 35. We need to find the reason why so many nodes (also called peers) are showing as offline.

TODO

Exercise 1: Use another lib asides the one used by gbc-crawler to get a list of connected node

We need to connect to the mongo-db instance and run a script on each peer to try and connect to it. Ideally all nodes should have a UDP port open and we should be able to just ping it. There's an example https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/devp2p/examples/simple.ts (in javascript) that tries to ping it's bootnodes. We can adapt this, for instance here's an adaption of that code, using Gnosis Chain boot nodes.

import chalk from "chalk";

import { DPT } from "@ethereumjs/devp2p";
import { Chain, Common } from "@ethereumjs/common";

const PRIVATE_KEY = "d772e3d6a001a38064dd23964dd2836239fa0e6cec8b28972a87460a17210fe9";

const GCBootstrapNodes = [
    {
        ip: "165.232.138.187",
        port: 9000,
        id: "a2f8e56f6b1d1b0b9df8089d5eaa9c68db1ed1056036abccb8036df899dfc607",
        location: "",
        comment: "",
    },
    {
        ip: "143.198.156.24",
        port: 9000,
        id: "d7124b4d1062429f8df8b508ae6d5a7e0eb131f14d9ec66a5fdfdfe0f9faddd6",
        location: "",
        comment: "",
    },
    {
        ip: "159.223.213.61",
        port: 9000,
        id: "e93e8844ef2255c684f13526ea9c71457150365131a344b0a2de8d41edf1f8a1",
        location: "",
        comment: "",
    },
    {
        ip: "178.62.194.136",
        port: 9000,
        id: "7c0ec817dc0bec84da95cd7418cb6b7427058b378528f988808b7d6320187620",
        location: "",
        comment: "",
    },
];

const config = new Common({ chain: Chain.Mainnet });
// const bootstrapNodes = config.bootstrapNodes();
const bootstrapNodes = GCBootstrapNodes;

const BOOTNODES = bootstrapNodes.map((node) => {
    return {
        id: node.id,
        address: node.ip,
        udpPort: node.port,
        tcpPort: node.port,
    };
});

const dpt = new DPT(Buffer.from(PRIVATE_KEY, "hex"), {
    endpoint: {
        address: "0.0.0.0",
        udpPort: 13000,
        tcpPort: 9000,
    },
});

/* eslint-disable no-console */
dpt.on("error", (err) => console.error(chalk.red(err.stack ?? err)));

dpt.on("peer:added", (peer) => {
    const info = `(${peer.id.toString("hex")},${peer.address},${peer.udpPort},${peer.tcpPort})`;
    console.log(chalk.green(`New peer: ${info} (total: ${dpt.getPeers().length})`));
});

dpt.on("peer:removed", (peer) => {
    console.log(
        chalk.yellow(`Remove peer: ${peer.id.toString("hex")} (total: ${dpt.getPeers().length})`),
    );
});

// for accept incoming connections uncomment next line
dpt.bind(30303, '0.0.0.0')

for (const bootnode of BOOTNODES) {
    dpt.bootstrap(bootnode).catch((err) => console.error(chalk.bold.red(err.stack ?? err)));
}

The aim of this exercise is to determine if we can connect to more bootnodes using for instance @ethereumjs/devp2p. There are other libs in other languages. You can find a list of supported languages on this page https://github.com/ethereum/devp2p

Excercise 2: Make sure our node is up-to-date (lower priority)

1. We need to do a checkpoint sync using this node ` --checkpoint-sync-url http://68.183.230.177:5052`. We need to restart the lighthouse client with this argument. 
2. Also the lighthouse client doesn't seem to be connecting to the Nethermind client (you can see some errors in the logs). We need o fix this too.
3. We need to open port 9000 on our node instance.

Information

Repository: https://github.com/Gnosis-Builders/d14n-server/
    This repo contains a deployer folder with a Makefile. This should tell you how we currently deploy the backend. 
Server: 157.230.30.73
    Connection is via ssh keys only, so provide your public key so I can add it to the server
    MongoDB is running on port 27017 (You can see this from the repo above too)
    Lighthouse is using lighthouse-launch and we running from this folder: /home/gnosis/src/lighthouse-launch
    Nethermind is run from this folder: /home/gnosis/src/nethermind        
@nks89
Copy link

nks89 commented Dec 22, 2022

Connection Failure Rates Comparison between GBC and ETH Crawlers
(Log collected over period of 18 hours. The number of tries is fairly representative of the number of peers in DB).

GBC:
Total connection tries: 1542
Success Rate: 2%
I/O Timeout: 73%
Conn Refused: 12%
Protocol Negotiation Failed-Conn Reset: 0%
Protocol Negotiation Failed-Peer ID Mismatch: 3%
Dial Backoff: 3%
No route to host: 6%
Other errors: 1%

ETH:
Total connection tries: 113347
Success Rate: 6%
I/O Timeout: 57%
Conn Refused: 17%
Protocol Negotiation Failed-Conn Reset: 9%
Protocol Negotiation Failed-Peer ID Mismatch: 5%
Dial Backoff: 3%
No route to host: 1%
Other errors: 2%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment