-
Notifications
You must be signed in to change notification settings - Fork 795
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
Cache peers in database #1608
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending comments.
…lar to boost's endpoint for nano::endpoint_key
There was a problem hiding this 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.
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 themdb_store
class, however as we do everything through theblock_store
interface, this has been moved to a more common location so the it can be used withpeers_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.