Increase rep_crawl count if observed peers weight < online_weight_minimum (#1001)
* Increase rep_crawl speed if observed peers weight < online_weight_minimum * Use uint16_t * peers.online_weight_minimum * Improve network::broadcast_confirm_req * Calculate if representative isn't recorded for several IP addresses
This commit is contained in:
parent
c7605b1470
commit
9d693857bf
2 changed files with 26 additions and 4 deletions
|
@ -264,7 +264,7 @@ void rai::network::republish_vote (std::shared_ptr<rai::vote> vote_a)
|
|||
void rai::network::broadcast_confirm_req (std::shared_ptr<rai::block> block_a)
|
||||
{
|
||||
auto list (std::make_shared<std::vector<rai::peer_information>> (node.peers.representatives (std::numeric_limits<size_t>::max ())));
|
||||
if (list->empty () || node.online_reps.online_stake () == node.config.online_weight_minimum.number ())
|
||||
if (list->empty () || node.peers.total_weight () < node.config.online_weight_minimum.number ())
|
||||
{
|
||||
// broadcast request to all peers
|
||||
list = std::make_shared<std::vector<rai::peer_information>> (node.peers.list_vector ());
|
||||
|
@ -1830,6 +1830,7 @@ stats (config.stat_config)
|
|||
node_id = rai::keypair (store.get_node_id (transaction));
|
||||
BOOST_LOG (log) << "Node ID: " << node_id.pub.to_account ();
|
||||
}
|
||||
peers.online_weight_minimum = config.online_weight_minimum.number ();
|
||||
if (rai::rai_network == rai::rai_networks::rai_live_network)
|
||||
{
|
||||
extern const char rai_bootstrap_weights[];
|
||||
|
@ -3093,10 +3094,12 @@ std::vector<rai::peer_information> rai::peer_container::purge_list (std::chrono:
|
|||
std::vector<rai::endpoint> rai::peer_container::rep_crawl ()
|
||||
{
|
||||
std::vector<rai::endpoint> result;
|
||||
result.reserve (10);
|
||||
// If there is enough observed peers weight, crawl 10 peers. Otherwise - 40
|
||||
uint16_t max_count = (total_weight () > online_weight_minimum) ? 10 : 40;
|
||||
result.reserve (max_count);
|
||||
std::lock_guard<std::mutex> lock (mutex);
|
||||
auto count (0);
|
||||
for (auto i (peers.get<5> ().begin ()), n (peers.get<5> ().end ()); i != n && count < 10; ++i, ++count)
|
||||
uint16_t count (0);
|
||||
for (auto i (peers.get<5> ().begin ()), n (peers.get<5> ().end ()); i != n && count < max_count; ++i, ++count)
|
||||
{
|
||||
result.push_back (i->endpoint);
|
||||
};
|
||||
|
@ -3115,6 +3118,23 @@ size_t rai::peer_container::size_sqrt ()
|
|||
return result;
|
||||
}
|
||||
|
||||
rai::uint128_t rai::peer_container::total_weight ()
|
||||
{
|
||||
rai::uint128_t result (0);
|
||||
std::unordered_set<rai::account> probable_reps;
|
||||
std::lock_guard<std::mutex> lock (mutex);
|
||||
for (auto i (peers.get<6> ().begin ()), n (peers.get<6> ().end ()); i != n; ++i)
|
||||
{
|
||||
// Calculate if representative isn't recorded for several IP addresses
|
||||
if (probable_reps.find (i->probable_rep_account) == probable_reps.end ())
|
||||
{
|
||||
result = result + i->rep_weight.number ();
|
||||
probable_reps.insert (i->probable_rep_account);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool rai::peer_container::empty ()
|
||||
{
|
||||
return size () == 0;
|
||||
|
|
|
@ -249,6 +249,8 @@ public:
|
|||
bool validate_syn_cookie (rai::endpoint const &, rai::account, rai::signature);
|
||||
size_t size ();
|
||||
size_t size_sqrt ();
|
||||
rai::uint128_t total_weight ();
|
||||
rai::uint128_t online_weight_minimum;
|
||||
bool empty ();
|
||||
std::mutex mutex;
|
||||
rai::endpoint self;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue