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

Cache peers in database #1608

merged 8 commits into from Jan 29, 2019


4 participants
Copy link

commented Jan 19, 2019

This solves #1374

There are ~500 peers (full nodes) on the live nano network at the time of writing, it takes time to find them all when starting the node. This PR periodically (hardcoded to every 5 minutes) saves the peers (ip & port) to the main database store. When the node is next run it reads from the database and sends out handshake requests to all of the stored peers. It now handshakes with 95% of the peers within a second compared with 5% before this change.

No "value" is needed in the key/value pair so only endpoints are stored as a key. There was a no_value enum in the mdb_store class, however as we do everything through the block_store interface, this has been moved to a more common location so the it can be used with peers_begin/end to iterate through all the peers.

The mdb store file has no dependency on boost::asio, so I didn't want to add one. Instead everything is done through a new class endpoint_key, which is ultimately (de)serialized to the database.

A new CLI command is added "--debug_peers" which reads from the store, this is only refreshed every 5 minutes. To see real-time peers, use the JSON-RPC command { "action" : "peers" }.

Someone handily added an empty add_initial_peers (); function so I've just hijacked this to put the code for reading from the database when starting the node.

Some constructor member initializers were converted to in-class member initializers to reduce duplication in constructors.

@wezrule wezrule self-assigned this Jan 19, 2019

@wezrule wezrule added the enhancement label Jan 20, 2019

Show resolved Hide resolved nano/secure/common.cpp Outdated
Copy link

left a comment

LGTM pending comments.

@wezrule wezrule force-pushed the wezrule:cache_peers branch from f5f9792 to 44e5fc0 Jan 21, 2019

@zhyatt zhyatt added this to the V18.0 milestone Jan 22, 2019

@zhyatt zhyatt added this to CP 3 (2018-01-23) in V18 Jan 25, 2019

@zhyatt zhyatt requested a review from cryptocode Jan 28, 2019

@wezrule wezrule force-pushed the wezrule:cache_peers branch from 76b0335 to 2dd5896 Jan 28, 2019

wezrule added some commits Jan 28, 2019

Copy link

left a comment

LGTM. Getting to the peer count I reliably have now is reduced from 90 to 60 secs, and getting to 50% peers is much faster than before.

@wezrule wezrule merged commit ea192aa into nanocurrency:master Jan 29, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed

@wezrule wezrule referenced this pull request Jan 30, 2019


Cache peers #1374

@wezrule wezrule deleted the wezrule:cache_peers branch Mar 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.