Skip to content

Commit ef9e0a9

Browse files
committed
crc: use ‘define_named_enum’ macro to avoid display trait for enum, #5918
1 parent a31b2ab commit ef9e0a9

File tree

1 file changed

+10
-22
lines changed
  • stacks-signer/src/monitoring

1 file changed

+10
-22
lines changed

stacks-signer/src/monitoring/mod.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,26 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use stacks_common::define_named_enum;
18+
1719
#[cfg(feature = "monitoring_prom")]
1820
mod prometheus;
1921

2022
#[cfg(feature = "monitoring_prom")]
2123
mod server;
2224

25+
define_named_enum!(
2326
/// Represent different state change reason on signer agreement protocol
24-
pub enum SignerAgreementStateChangeReason {
27+
SignerAgreementStateChangeReason {
2528
/// A new burn block has arrived
26-
BurnBlockArrival,
29+
BurnBlockArrival("burn_block_arrival"),
2730
/// A new stacks block has arrived
28-
StacksBlockArrival,
31+
StacksBlockArrival("stacks_block_arrival"),
2932
/// A miner is inactive when it should be starting its tenure
30-
InactiveMiner,
33+
InactiveMiner("inactive_miner"),
3134
/// Signer agreement protocol version has been upgraded
32-
ProtocalUpgrade,
33-
}
34-
35-
impl std::fmt::Display for SignerAgreementStateChangeReason {
36-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37-
write!(
38-
f,
39-
"{}",
40-
match self {
41-
SignerAgreementStateChangeReason::BurnBlockArrival => "burn_block_arrival",
42-
SignerAgreementStateChangeReason::StacksBlockArrival => "stacks_block_arrival",
43-
SignerAgreementStateChangeReason::InactiveMiner => "inactive_miner",
44-
SignerAgreementStateChangeReason::ProtocalUpgrade => "protocol_upgrade",
45-
}
46-
)
47-
}
48-
}
35+
ProtocalUpgrade("protocol_upgrade"),
36+
});
4937

5038
/// Actions for updating metrics
5139
#[cfg(feature = "monitoring_prom")]
@@ -140,7 +128,7 @@ pub mod actions {
140128
pub fn increment_signer_agreement_state_change_reason(
141129
reason: SignerAgreementStateChangeReason,
142130
) {
143-
let label_value = reason.to_string();
131+
let label_value = reason.get_name();
144132
SIGNER_AGREEMENT_STATE_CHANGE_REASONS
145133
.with_label_values(&[&label_value])
146134
.inc();

0 commit comments

Comments
 (0)