New stats for elections (#2731)

* New stats for elections

election_non_priority, election_priority, election_block_conflict, election_difficulty_update,
election_drop, election_restart

* Unecessary explicit ctor delete (Wes comment)
This commit is contained in:
Guilherme Lawless 2020-04-24 15:20:20 +01:00 committed by GitHub
commit 9fb7908a01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 2 deletions

View file

@ -236,6 +236,7 @@ TEST (active_transactions, keep_local)
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (1, node.active.recently_dropped.size ());
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_drop));
}
TEST (active_transactions, prioritize_chains)
@ -794,6 +795,9 @@ TEST (active_transactions, insertion_prioritization)
ASSERT_FALSE (node.active.insert (blocks[5]).election->prioritized ());
update_active_multiplier ();
ASSERT_FALSE (node.active.insert (blocks[6]).election->prioritized ());
ASSERT_EQ (4, node.stats.count (nano::stat::type::election, nano::stat::detail::election_non_priority));
ASSERT_EQ (3, node.stats.count (nano::stat::type::election, nano::stat::detail::election_priority));
}
TEST (active_multiplier, less_than_one)
@ -944,6 +948,8 @@ TEST (active_transactions, election_difficulty_update_old)
node.block_processor.flush ();
ASSERT_EQ (1, node.active.size ());
ASSERT_GT (node.active.roots.begin ()->multiplier, multiplier);
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_difficulty_update));
}
TEST (active_transactions, election_difficulty_update_fork)
@ -979,10 +985,14 @@ TEST (active_transactions, election_difficulty_update_fork)
node.process_active (fork_send);
node.block_processor.flush ();
ASSERT_EQ (1, node.active.size ());
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_block_conflict));
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_difficulty_update));
auto multiplier_send = node.active.roots.begin ()->multiplier;
node.process_active (fork_receive);
node.block_processor.flush ();
ASSERT_EQ (1, node.active.size ());
ASSERT_EQ (2, node.stats.count (nano::stat::type::election, nano::stat::detail::election_block_conflict));
ASSERT_EQ (2, node.stats.count (nano::stat::type::election, nano::stat::detail::election_difficulty_update));
auto multiplier_receive = node.active.roots.begin ()->multiplier;
ASSERT_GT (multiplier_send, multiplier_change);
@ -998,6 +1008,8 @@ TEST (active_transactions, election_difficulty_update_fork)
node.process_active (fork_receive);
node.block_processor.flush ();
ASSERT_EQ (1, node.active.size ());
ASSERT_EQ (2, node.stats.count (nano::stat::type::election, nano::stat::detail::election_block_conflict));
ASSERT_EQ (3, node.stats.count (nano::stat::type::election, nano::stat::detail::election_difficulty_update));
auto multiplier_receive_updated = node.active.roots.begin ()->multiplier;
ASSERT_GT (multiplier_receive_updated, multiplier_receive);
}
@ -1046,6 +1058,7 @@ TEST (active_transactions, restart_dropped)
node.process_active (send);
node.block_processor.flush ();
ASSERT_EQ (1, node.active.size ());
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_restart));
auto ledger_block (node.store.block_get (node.store.tx_begin_read (), send->hash ()));
ASSERT_NE (nullptr, ledger_block);
// Exact same block, including work value must have been re-written
@ -1059,6 +1072,7 @@ TEST (active_transactions, restart_dropped)
node.process_active (send);
node.block_processor.flush ();
ASSERT_EQ (0, node.active.size ());
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::election_restart));
// Verify the block was not updated in the ledger
ASSERT_EQ (*node.store.block_get (node.store.tx_begin_read (), send->hash ()), *send);
// Generate even higher difficulty work
@ -1071,6 +1085,7 @@ TEST (active_transactions, restart_dropped)
node.block_processor.flush ();
ASSERT_EQ (1, node.active.size ());
ASSERT_EQ (1, node.ledger.cache.cemented_count);
ASSERT_EQ (2, node.stats.count (nano::stat::type::election, nano::stat::detail::election_restart));
// Wait for the election to complete
ASSERT_TIMELY (5s, node.ledger.cache.cemented_count == 2);
}

View file

@ -613,6 +613,24 @@ std::string nano::stat::detail_to_string (uint32_t key)
case nano::stat::detail::late_block_seconds:
res = "late_block_seconds";
break;
case nano::stat::detail::election_non_priority:
res = "election_non_priority";
break;
case nano::stat::detail::election_priority:
res = "election_priority";
break;
case nano::stat::detail::election_block_conflict:
res = "election_block_conflict";
break;
case nano::stat::detail::election_difficulty_update:
res = "election_difficulty_update";
break;
case nano::stat::detail::election_drop:
res = "election_drop";
break;
case nano::stat::detail::election_restart:
res = "election_restart";
break;
case nano::stat::detail::blocking:
res = "blocking";
break;

View file

@ -201,7 +201,7 @@ public:
aggregator,
requests,
filter,
telemetry
telemetry,
};
/** Optional detail type */
@ -273,6 +273,12 @@ public:
vote_cached,
late_block,
late_block_seconds,
election_non_priority,
election_priority,
election_block_conflict,
election_difficulty_update,
election_drop,
election_restart,
// udp
blocking,

View file

@ -15,11 +15,12 @@
using namespace std::chrono;
nano::active_transactions::active_transactions (nano::node & node_a, nano::confirmation_height_processor & confirmation_height_processor_a) :
recently_dropped (node_a.stats),
confirmation_height_processor (confirmation_height_processor_a),
generator (node_a.config, node_a.store, node_a.wallets, node_a.vote_processor, node_a.votes_cache, node_a.network),
node (node_a),
multipliers_cb (20, 1.),
trended_active_multiplier (1.0),
generator (node_a.config, node_a.store, node_a.wallets, node_a.vote_processor, node_a.votes_cache, node_a.network),
check_all_elections_period (node_a.network_params.network.is_test_network () ? 10ms : 5s),
election_time_to_live (node_a.network_params.network.is_test_network () ? 0s : 2s),
prioritized_cutoff (std::max<size_t> (1, node_a.config.active_elections_size / 10)),
@ -521,6 +522,7 @@ nano::election_insertion_result nano::active_transactions::insert_impl (std::sha
blocks.emplace (hash, result.election);
add_adjust_difficulty (hash);
result.election->insert_inactive_votes_cache (hash);
node.stats.inc (nano::stat::type::election, prioritized ? nano::stat::detail::election_priority : nano::stat::detail::election_non_priority);
}
}
else
@ -661,6 +663,7 @@ void nano::active_transactions::update_difficulty_impl (nano::active_transaction
info_a.multiplier = multiplier;
});
add_adjust_difficulty (block_a.hash ());
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_difficulty_update);
}
}
@ -691,6 +694,7 @@ void nano::active_transactions::restart (std::shared_ptr<nano::block> const & bl
{
insert_result.election->transition_active ();
recently_dropped.erase (ledger_block->qualified_root ());
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_restart);
}
}
}
@ -976,6 +980,7 @@ bool nano::active_transactions::publish (std::shared_ptr<nano::block> block_a)
if (!result)
{
blocks.emplace (block_a->hash (), election);
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_block_conflict);
}
}
return result;
@ -1198,8 +1203,14 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (ac
return composite;
}
nano::dropped_elections::dropped_elections (nano::stat & stats_a) :
stats (stats_a)
{
}
void nano::dropped_elections::add (nano::qualified_root const & root_a)
{
stats.inc (nano::stat::type::election, nano::stat::detail::election_drop);
nano::lock_guard<std::mutex> guard (mutex);
auto & items_by_sequence = items.get<tag_sequence> ();
items_by_sequence.emplace_back (nano::election_timepoint{ std::chrono::steady_clock::now (), root_a });

View file

@ -31,6 +31,7 @@ class election;
class vote;
class transaction;
class confirmation_height_processor;
class stat;
class cementable_account final
{
@ -60,6 +61,7 @@ public:
class dropped_elections final
{
public:
dropped_elections (nano::stat &);
void add (nano::qualified_root const &);
void erase (nano::qualified_root const &);
std::chrono::steady_clock::time_point find (nano::qualified_root const &) const;
@ -80,6 +82,7 @@ public:
private:
ordered_dropped items;
mutable std::mutex mutex;
nano::stat & stats;
};
class election_insertion_result final