Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metrics): pass the epoch manager to spawn_trie_metrics_loop #12811

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions nearcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,19 @@ pub fn start_with_config_and_synchronization(
None
};

let epoch_manager = EpochManager::new_arc_handle(
storage.get_hot_store(),
&config.genesis.config,
Some(home_dir),
);

let trie_metrics_arbiter = spawn_trie_metrics_loop(
config.clone(),
storage.get_hot_store(),
config.client_config.log_summary_period,
epoch_manager.clone(),
)?;

let epoch_manager = EpochManager::new_arc_handle(
storage.get_hot_store(),
&config.genesis.config,
Some(home_dir),
);
let genesis_epoch_config = epoch_manager.get_epoch_config(&EpochId::default())?;
// Initialize genesis_state in store either from genesis config or dump before other components.
// We only initialize if the genesis state is not already initialized in store.
Expand Down
13 changes: 8 additions & 5 deletions nearcore/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::NearConfig;
use actix_rt::ArbiterHandle;
use near_async::time::Duration;
use near_chain::{Block, ChainStore, ChainStoreAccess};
use near_epoch_manager::EpochManager;
use near_epoch_manager::EpochManagerAdapter;
use near_o11y::metrics::{
exponential_buckets, try_create_histogram_vec, try_create_int_counter_vec,
try_create_int_gauge, try_create_int_gauge_vec, HistogramVec, IntCounterVec, IntGauge,
Expand Down Expand Up @@ -107,15 +107,17 @@ fn log_trie_item(key: Vec<u8>, value: Vec<u8>) {
}
}

fn export_postponed_receipt_count(near_config: &NearConfig, store: &Store) -> anyhow::Result<()> {
fn export_postponed_receipt_count(
near_config: &NearConfig,
store: &Store,
epoch_manager: &dyn EpochManagerAdapter,
) -> anyhow::Result<()> {
let chain_store = ChainStore::new(
store.clone(),
near_config.genesis.config.genesis_height,
near_config.client_config.save_trie_changes,
near_config.genesis.config.transaction_validity_period,
);
let epoch_manager =
EpochManager::new_from_genesis_config(store.clone(), &near_config.genesis.config)?;

let head = chain_store.final_head()?;
let block = chain_store.get_block(&head.last_block_hash)?;
Expand Down Expand Up @@ -194,6 +196,7 @@ pub fn spawn_trie_metrics_loop(
near_config: NearConfig,
store: Store,
period: Duration,
epoch_manager: Arc<dyn EpochManagerAdapter>,
) -> anyhow::Result<ArbiterHandle> {
tracing::debug!(target:"metrics", "Spawning the trie metrics loop.");
let arbiter = actix_rt::Arbiter::new();
Expand All @@ -208,7 +211,7 @@ pub fn spawn_trie_metrics_loop(
interval.tick().await;

let start_time = std::time::Instant::now();
let result = export_postponed_receipt_count(&near_config, &store);
let result = export_postponed_receipt_count(&near_config, &store, epoch_manager.as_ref());
if let Err(err) = result {
tracing::error!(target: "metrics", "Error when exporting postponed receipts count {err}.");
};
Expand Down
Loading