Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(network): permanent peer store #1354

Merged
merged 4 commits into from
Jun 22, 2024
Merged

Conversation

kehiy
Copy link
Contributor

@kehiy kehiy commented Jun 19, 2024

Description

This PR adds a permanent json-based peer store. It keeps a backup of all connected peers at runtime when we turn the node off and restore/use it when we try to start our node again.

This change will enhance the syncing process. here is a part of peers.json after my test for a few second:

[
    "/ip4/5.161.222.154/tcp/21888/p2p/12D3KooWQN2VN1RWQ5eWq8rVexpBnwVSy7k34Rpep4R6V57XWYau",
    "/ip4/135.181.97.206/tcp/21888/p2p/12D3KooWBC5YQJdRAvupSXUPNYHiSctzZeTPNzen1JsRwj9aEyYZ",
    "/ip4/65.21.69.53/tcp/21888/p2p/12D3KooWQ1izUE5jcmMyjmxRdb2CmASe8Nfn81UL2G5rYjptC2RV",
    "/ip4/45.134.226.48/tcp/21888/p2p/12D3KooWBSP8AdiHkkvPunpbhfZE96YTY6om4hw35Xpe3bJFBUjh",
    "/ip4/104.234.1.82/tcp/21888/p2p/12D3KooWK1z7QAskVrQd98r98UMSPwTLr4out8B9NkQTrCdZPCZx",
    "/dns/pactus-bootnode.stake.works/tcp/21888/p2p/12D3KooWJPuhW7Ejmb8KprpVNRzn1eUQXDHU3n5eTo2vodgvVxoJ",
    "/ip4/37.27.26.40/tcp/21888/p2p/12D3KooWPehhWgfdZG6x9zE7QdQxuAcfbQPAyBPjcXLfVYfU9FAd",
    "/ip4/185.216.75.142/tcp/21888/p2p/12D3KooWNjYFZpq5YwdUC6JgHfkZhUY7SyxTAQCHrdNwf2t1FXSn",
    "/ip4/84.247.172.23/tcp/21888/p2p/12D3KooWFJYk55mUD6FR9Gx2YGQ34PYziwTQhY1kZ3TMS6fGUz6g",
    "/ip4/84.247.165.249/tcp/21888/p2p/12D3KooWQmv2FcNQfh1EhA98twt8ePdkQaxEPeYfinEYyVS16juY",
    "/dns/pactus-bootstrap.thd.io.vn/tcp/21888/p2p/12D3KooWDgsSSGJzihBJxqNJFqbGwbTEDXRoUBph1BCfwm11R6KY",
    "/ip4/159.148.146.149/tcp/21888/p2p/12D3KooWKCokWtpdudxgsLRoFcnrW35vhn6w632iGWCga7E5e68Q",
    "/ip4/84.247.184.95/tcp/21888/p2p/12D3KooWSjp5GFmCCsYkKcqicrghyHqfjdDCfLfgfqWmG5JTQSDu",
    "/ip4/161.97.145.100/tcp/21888/p2p/12D3KooWCjZ35Hu8Mt5GjZ6fJzJBZuUSsAppAzXcbMcXkswR4HrU",
    "/dns/pactus-bootstrap.teoviteovi.com/tcp/21888/p2p/12D3KooWMP5qWNHF1RfzhpAkBmQZzBfbaSJZCo3QF1fxs5CFXkv8",
    "/ip4/195.201.112.164/tcp/21888/p2p/12D3KooWKiYGT4mCapgcqLPSwbkJY1KgZMW5hdC8XJMQSU23tiSL",
    "/ip4/37.60.245.47/tcp/21888/p2p/12D3KooWBH27VEPdGBYzq1vYciRgnDn3ozStRaUYd2vJWGgaKEUZ",
    "/ip4/128.140.103.90/tcp/21888/p2p/12D3KooWN4eypkp61j12SMSkmrEfQv4RjnggmRfcEfom4mcKUpsR",
    "/dns/pactus-bootstrap.sensifai.com/tcp/21888/p2p/12D3KooWLpgBQt7A1W8FhTLVYwQMEnTBEX7uudLvd1YMZsDHqqWh",
    "/ip4/75.119.159.113/tcp/21888/p2p/12D3KooWL7nUsmd7JNrhrfbBjg6JxPFiZA5LXbdCDPnw5Xpdp4a9",
    "/ip4/173.212.254.120/tcp/21888/p2p/12D3KooWJR19vjuBzuJTceCoy3LG8jggkHCBGb9j5SzdKtoPL7Yb",
    "/ip4/194.163.164.10/tcp/21888/p2p/12D3KooWDRFCW5ksbnn6Uq7kx3HZt3EnrKjujqqs8QBQmA7TK5o6",
    "/ip4/62.171.134.3/tcp/21888/p2p/12D3KooWSv5jsXMg1b4PBd2SCcPLj3Mc5KzzBYnpPkiS7JjuqhHF",
    "/ip4/94.72.120.50/tcp/21888/p2p/12D3KooWCJX9aLnzmEFtEasvbbaFqHLTboFVFptZxeFnbnSxpb2m",
    "/ip4/65.21.180.80/tcp/21888/p2p/12D3KooWANqay6T1xCrK3imfAEr3GpiGzxT6SWCEsRapo8tJWAZN",
    "/ip4/42.117.247.180/tcp/21888/p2p/12D3KooWLVZSkgkFgrRNMfkCtULqtErYcNgjqgueeH944vDpDCPv",
    "/ip4/158.220.91.129/tcp/21888/p2p/12D3KooWGfehwyZJBu6WUMLyzJ8sDJachvhxhqw5Wh4uU3H99GLq",
    "/ip4/65.21.155.128/tcp/21888/p2p/12D3KooWPykSnzWpEasRijCgQ99vxAxWKL32zY24MmvtaXsHapSf",
    "/ip4/20.174.33.162/tcp/21888/p2p/12D3KooWKg6aLa77yAaqMCb45aH5iQuTr5GzRUWUCJ1sZYB5vnoL",
    "/ip4/43.135.166.197/tcp/21888/p2p/12D3KooWEqyjMNzFe92HFZMZQd3YZ6zvztuPaC3a4wAUvPf4moyP",
    "/ip4/109.123.253.88/tcp/21888/p2p/12D3KooWFUJhDjYcAXgEnW1pTLRDWnH9CLgBPcezgU7pCpxMngt8",
    "/dns/bootstrap1.pactus.org/tcp/21888/p2p/12D3KooWMnDsu8TDTk2VV8uD8zsNSB6eUkqtQs6ttg4bHq9zNaBe",
    "/ip4/37.60.241.89/tcp/21888/p2p/12D3KooWMZtkk5HS69ukYYdfxD3CgBgTtKZg7kv43mCz1HMrDnQw",
    "/ip4/37.60.233.235/tcp/21888/p2p/12D3KooWNzbuBESYzbKGm7UyLkD22cHSgjRMUx4rjEKLBfVSZuY1",
    "/dns/bootstrap2.pactus.org/tcp/21888/p2p/12D3KooWM39ag7ghta49qybf7McADgT8FLakTYkCsiBvwdnjuG5q",
    "/ip4/157.90.22.45/tcp/21888/p2p/12D3KooWLUYJ55DyJjSZvwPJDQNVYSBYqiMxJ9bFzRcVBgvSkN9L",
    "/dns/bootstrap3.pactus.org/tcp/21888/p2p/12D3KooWBCPSZWheet6tMoHbVBCDfBwQm4yzCwcQ8hJ6NMCN97sj",
    "/ip4/167.86.121.11/tcp/21888/p2p/12D3KooWMpVXMQkr26ff3y8gC5z1h9RZNxTvW4WzZBML8GHHUoL5",
    "/dns/pactus-bootstrap.stakers.world/tcp/21888/p2p/12D3KooWK1DAcxf8RJA2PVkwr9ehk1zgXcnjLyPCsYCpvw1NSfhc",
    "/ip4/154.38.187.40/tcp/21888/p2p/12D3KooWQyt7JCyhhnZ8jyT1vso4GGYVbpJhoXJy5KRpnqa8DmPg",
    "/dns/pactus-bootstrap.codeblocklabs.com/tcp/21888/p2p/12D3KooWSdmPLqWbmv5x5pBiL5nHwKN5S2jhP96oXCKmoEmAhV4Z",
    "/ip4/46.250.233.5/tcp/21888/p2p/12D3KooWH1kam9g1QFWmtWMLzP2MDY4ptpLTMPU8wSq3Q4k3rvnn",
    "/ip4/49.13.27.37/tcp/21888/p2p/12D3KooWPSh9KMa6tRfSewK3sUC4BDSPnXseVDGJxWqNZxKcXnGM",
    "/ip4/65.108.68.214/tcp/21888/p2p/12D3KooWD7X8BDqV9r6zGmoo2dpMYo4Z6YoyDQp6j4UnB2Bj3Fq2",
    "/ip4/62.171.130.196/tcp/21888/p2p/12D3KooWSkwB8AiWz3VGyG5cgC3ry5dmCw3TthQNc1jvRNe9EEKH",
    "/dns/pactus-bootstrap.ionode.online/tcp/21888/p2p/12D3KooWG5tvvfS8PRd2Bgyxxqrok7QfohkHSprFPxmT3HTh8dVD",
    "/ip4/85.190.246.251/tcp/21888/p2p/12D3KooWMTPKpr6EHMmZ2NSXkup4NaqwKnYmScHEsN3HpcqYgBZL",
    "/ip4/116.203.238.65/tcp/21888/p2p/12D3KooWKf32k9dLE4fA5tkh4KvvEAQDmHxHLWiahjpt2Hfx3d88",
    "/ip4/135.181.42.222/tcp/21888/p2p/12D3KooWN46UYQNoZvzd9GiJPQC7LByj6RAg8rRxdUTiQ24vHsN1",
    "/ip4/65.109.143.78/tcp/21888/p2p/12D3KooWPnWgEFV32cvpfuv98oioZQJJKvRM46BEsFaoXYijvgvc",
    "/ip4/95.111.242.225/tcp/21888/p2p/12D3KooWRNTZpo1XNWKQx2Z5HEu5RnqKeNDV5y4qMKX5f4aLtbv9",
    "/dns/pactus-bootstrap.mflow.tech/tcp/21888/p2p/12D3KooWJD2PBAur6kXjX31dyrPzjSV947ppZ885QDKCXEvLm9Vb",
    "/ip4/95.216.222.135/tcp/21888/p2p/12D3KooWHicbZ3dBnR7JaVKr4U7WNUWyhDnUn2TwMVmPqW8Ftqop",
    "/ip4/46.196.214.35/tcp/21888/p2p/12D3KooWJ3H7YAyemqxtToG6yRRzTfLdZD3eJk2xsQRaKxfdNhKf",
    "/ip4/109.123.240.5/tcp/21888/p2p/12D3KooWCT92yaS4JgrHHzeRPsJxaLzRdSEknGEN4HxQFfscoY8k",
    "/ip4/167.86.116.61/tcp/21888/p2p/12D3KooWAmc69XaFh6T76BQQaFmSakYFgDyvzDLfVBgTzqmNtyXM",
    "/ip4/65.108.211.187/tcp/21888/p2p/12D3KooWGLrSiE5KWoc9GpXfryvKqheHj6j78ryMDDC17SY4YoCi",
    "/ip4/167.86.80.169/tcp/21888/p2p/12D3KooWDqAPjeRR41GYoQw9RQaSZdFx59k3SpkR29yAycpJUhfF",
    "/ip4/38.242.225.172/tcp/21888/p2p/12D3KooWDTP7CKGvbcg5WiuKB2Bt4acf2LWMdbUjMqU63dKKCVMB",
    "/ip4/37.27.25.245/tcp/21888/p2p/12D3KooWAmhn86b5igYjzFbaJddE57xT9UpZePFiEoc3jcuYHDvn",
    "/ip4/194.163.189.255/tcp/21888/p2p/12D3KooWExbN79BrgDWjdLUd8TZaP2LvCDN8zJkMuPhRHkjKDcJS",
    "/ip4/65.21.152.153/tcp/21888/p2p/12D3KooWCirKBMmhmL6a4Ng5TVHQ4Leb6Wfj4M8s9raUzdFQn5aP"
]

I suggest you guys test it on your side with your environment to ensure it works properly.

Related issue

@kehiy kehiy added enhancement New feature or request network labels Jun 19, 2024
@kehiy
Copy link
Contributor Author

kehiy commented Jun 19, 2024

Three additional notes:

  1. The peers.json can be shared offline same as offline chain data download for better syncing. (for example, I'm running a new node so I can use the previous node peer store to have more seed nodes to connect to.)

  2. We can add a disable option for this peer store in the config but I thought it was unnecessary.

  3. offline nodes, private IPs, etc will be ignored, and checking them or removing them from the peer manager and saving the store then is not very efficient or helpful. (simply won't make anything worse or better that affects the health status of the node, if you think it does, please add details.)

network/peermgr.go Outdated Show resolved Hide resolved
@kehiy kehiy requested a review from Ja7ad June 19, 2024 16:17
network/peermgr.go Outdated Show resolved Hide resolved
network/peermgr.go Outdated Show resolved Hide resolved
@kehiy kehiy force-pushed the feature/peer-store branch from bb4a686 to 0046d26 Compare June 22, 2024 11:19
@kehiy kehiy requested a review from b00f June 22, 2024 11:22
config/config.go Outdated Show resolved Hide resolved
network/errors.go Outdated Show resolved Hide resolved
network/peermgr.go Outdated Show resolved Hide resolved
network/config.go Show resolved Hide resolved
@kehiy kehiy force-pushed the feature/peer-store branch from bf05f22 to 4c5e820 Compare June 22, 2024 12:14
@kehiy kehiy requested a review from b00f June 22, 2024 12:16
@b00f b00f merged commit 472c347 into pactus-project:main Jun 22, 2024
10 checks passed
@kehiy kehiy deleted the feature/peer-store branch June 23, 2024 09:50
themantre pushed a commit that referenced this pull request Jun 25, 2024
themantre pushed a commit that referenced this pull request Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request network
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keeping peer list when node goes off
3 participants