message: Add env var to enable detailed consensus metric logging
diff: use std::{
  collections::{BTreeMap, HashSet},
  + env,
  fmt::{self, Debug, Display, Formatter},
  };
  use datasize::DataSize;
  use itertools::Itertools;
  +use once_cell::sync::Lazy;
  use schemars::JsonSchema;
  use serde::{Deserialize, Serialize};
  use tracing::{debug, warn};
  @@ -23,6 +25,11 @@ use crate::{
  types::{ProtoBlock, Timestamp},
  };
  +const CASPER_ENABLE_DETAILED_CONSENSUS_METRICS_ENV_VAR: &str =
  + "CASPER_ENABLE_DETAILED_CONSENSUS_METRICS";
  +static CASPER_ENABLE_DETAILED_CONSENSUS_METRICS: Lazy<bool> =
  + Lazy::new(|| env::var(CASPER_ENABLE_DETAILED_CONSENSUS_METRICS_ENV_VAR).is_ok());
  +
  #[derive(
  DataSize,
  Debug,
  @@ -249,7 +256,6 @@ impl<I> Era<I> {
  pub(crate) fn set_paused(&mut self, paused: bool) {
  self.consensus.set_paused(paused);
  }
  -
  /// Removes and returns all candidate blocks with no missing dependencies.
  fn remove_complete_candidates(&mut self) -> Vec<CandidateBlock> {
  let (complete, candidates): (Vec<_>, Vec<_>) = self
  @@ -290,15 +296,16 @@ where
  let any_ref = consensus.as_any();
  if let Some(highway) = any_ref.downcast_ref::<HighwayProtocol<I, ClContext>>() {
  - // TODO: Allow switching between `detailed`, `flat` and `off` via envvar or config.
  + if *CASPER_ENABLE_DETAILED_CONSENSUS_METRICS {
  let detailed = (*highway).estimate_detailed_heap_size();
  -
  match serde_json::to_string(&detailed) {
  Ok(encoded) => debug!(%encoded, "consensus memory metrics"),
  Err(err) => warn!(%err, "error encoding consensus memory metrics"),
  }
  -
  detailed.total()
  + } else {
  + (*highway).estimate_heap_size()
  + }
  } else {
  warn!(
  "could not downcast consensus protocol to \
  