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
merged 8 commits into from
Jan 29, 2019
Merged

Cache peers in database #1608

merged 8 commits into from
Jan 29, 2019

Conversation

wezrule
Copy link
Contributor

@wezrule wezrule 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
Copy link
Contributor

@clemahieu clemahieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending comments.

@zhyatt zhyatt added this to the V18.0 milestone Jan 22, 2019
@zhyatt zhyatt requested a review from cryptocode January 28, 2019 15:01
Copy link
Contributor

@cryptocode cryptocode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@wezrule wezrule mentioned this pull request Jan 30, 2019
@wezrule wezrule deleted the cache_peers branch March 18, 2019 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants