Simplify enum -> str with strum (#2164)

## Issue Addressed

NA

## Proposed Changes

As per #2100, uses derives from the sturm library to implement AsRef<str> and AsStaticRef to easily get str values from enums without creating new Strings. Furthermore unifies all attestation error counter into one IntCounterVec vector.

These works are originally by @blacktemplar, I've just created this PR so I can resolve some merge conflicts.

## Additional Info

NA


Co-authored-by: blacktemplar <blacktemplar@a1.net>
This commit is contained in:
Paul Hauner
2021-01-19 06:33:58 +00:00
parent 8892114f52
commit 805e152f66
14 changed files with 82 additions and 255 deletions

View File

@@ -158,8 +158,8 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
metrics::inc_counter_vec(
&metrics::PEER_ACTION_EVENTS_PER_CLIENT,
&[
info.client.kind.as_static_ref(),
PeerAction::Fatal.as_static_str(),
info.client.kind.as_ref(),
PeerAction::Fatal.as_ref(),
source.into(),
],
);
@@ -193,11 +193,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
info.apply_peer_action_to_score(action);
metrics::inc_counter_vec(
&metrics::PEER_ACTION_EVENTS_PER_CLIENT,
&[
info.client.kind.as_static_ref(),
action.as_static_str(),
source.into(),
],
&[info.client.kind.as_ref(), action.as_ref(), source.into()],
);
Self::handle_score_transitions(
@@ -407,9 +403,9 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
metrics::inc_counter_vec(
&metrics::TOTAL_RPC_ERRORS_PER_CLIENT,
&[
client.kind.as_static_ref(),
client.kind.as_ref(),
err.as_static_str(),
direction.as_static_str(),
direction.as_ref(),
],
);