-
Notifications
You must be signed in to change notification settings - Fork 87
sync_peer option to specify preferred nodes #1319
base: master
Are you sure you want to change the base?
Conversation
cbad321
to
08574df
Compare
src/blockchain_worker.erl
Outdated
State#state{sync_pid = Pid, sync_ref = Ref} | ||
end. | ||
|
||
get_configured_or_random_peer(SwarmTID) -> | ||
case get_configured_sync_peer(SwarmTID) of | ||
undefined-> get_random_peer(SwarmTID); |
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.
undefined-> get_random_peer(SwarmTID); | |
undefined -> get_random_peer(SwarmTID); |
Co-authored-by: Jeff Grunewald <jeff@grunewalddesign.com>
src/blockchain_worker.erl
Outdated
[] -> | ||
lager:debug("No sync_peers configured"), | ||
undefined; | ||
ConfiguredPeers -> |
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.
ConfiguredPeers -> | |
ConfiguredPeers when is_list(ConfiguredPeers) -> |
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.
As long as we're validating, we should check [P | _] when is_list(P)
to make sure it is a list of strings, also should gracefully fail back to random so the node will still try to sync if the config is pooched.
src/blockchain_worker.erl
Outdated
{Left, Right} = lists:split(rand:uniform(length(ConfiguredPeers)), ConfiguredPeers), | ||
get_configured_sync_peer(SwarmTID, Peerbook, Right ++ Left) |
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.
is this "cutting the deck" of configured peers so to speak? just a cheaper version of shuffling the list?
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.
Yes, exactly. We only need one peer, the rest of the list is only used if the chosen one fails to connect.
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.
slick solution 👍
adds blockchain sync_peers configuration option, accepts a list of string multi-addresses