diff --git a/chain/chain/src/test_utils.rs b/chain/chain/src/test_utils.rs index fe928555867..2eef3c96f17 100644 --- a/chain/chain/src/test_utils.rs +++ b/chain/chain/src/test_utils.rs @@ -407,7 +407,11 @@ impl KeyValueRuntime { } } -impl EpochManagerAdapter for KeyValueRuntime {} +impl EpochManagerAdapter for KeyValueRuntime { + fn epoch_exists(&self, epoch_id: &EpochId) -> bool { + self.hash_to_valset.write().unwrap().contains_key(epoch_id) + } +} impl RuntimeAdapter for KeyValueRuntime { fn genesis_state(&self) -> (Store, Vec) { @@ -1159,10 +1163,6 @@ impl RuntimeAdapter for KeyValueRuntime { } } - fn epoch_exists(&self, epoch_id: &EpochId) -> bool { - self.hash_to_valset.write().unwrap().contains_key(epoch_id) - } - fn get_epoch_minted_amount(&self, _epoch_id: &EpochId) -> Result { Ok(0) } diff --git a/chain/chain/src/types.rs b/chain/chain/src/types.rs index 9b31e06ff3c..c89d90544d5 100644 --- a/chain/chain/src/types.rs +++ b/chain/chain/src/types.rs @@ -550,9 +550,6 @@ pub trait RuntimeAdapter: EpochManagerAdapter + Send + Sync { /// Get the block height for which garbage collection should not go over fn get_gc_stop_height(&self, block_hash: &CryptoHash) -> BlockHeight; - /// Check if epoch exists. - fn epoch_exists(&self, epoch_id: &EpochId) -> bool; - /// Amount of tokens minted in given epoch. fn get_epoch_minted_amount(&self, epoch_id: &EpochId) -> Result; diff --git a/chain/epoch-manager/src/adapter.rs b/chain/epoch-manager/src/adapter.rs index 62aceaf026d..65bb5038b14 100644 --- a/chain/epoch-manager/src/adapter.rs +++ b/chain/epoch-manager/src/adapter.rs @@ -1,3 +1,5 @@ +use near_primitives::types::EpochId; + use crate::{EpochManager, EpochManagerHandle}; use std::sync::{RwLockReadGuard, RwLockWriteGuard}; @@ -8,7 +10,10 @@ use std::sync::{RwLockReadGuard, RwLockWriteGuard}; /// we move it to a new trait. The end goal is for the code to use the concrete /// epoch manager type directly. Though, we might want to still keep this trait /// in, to allow for easy overriding of epoch manager in tests. -pub trait EpochManagerAdapter: Send + Sync {} +pub trait EpochManagerAdapter: Send + Sync { + /// Check if epoch exists. + fn epoch_exists(&self, epoch_id: &EpochId) -> bool; +} /// A technical plumbing trait to conveniently implement [`EpochManagerAdapter`] /// for `NightshadeRuntime` without too much copy-paste. @@ -30,4 +35,9 @@ impl HasEpochMangerHandle for EpochManagerHandle { } } -impl EpochManagerAdapter for T {} +impl EpochManagerAdapter for T { + fn epoch_exists(&self, epoch_id: &EpochId) -> bool { + let epoch_manager = self.read(); + epoch_manager.get_epoch_info(epoch_id).is_ok() + } +} diff --git a/nearcore/src/runtime/mod.rs b/nearcore/src/runtime/mod.rs index ba54bf763d6..4efdd887375 100644 --- a/nearcore/src/runtime/mod.rs +++ b/nearcore/src/runtime/mod.rs @@ -1231,11 +1231,6 @@ impl RuntimeAdapter for NightshadeRuntime { .unwrap_or(self.genesis_config.genesis_height) } - fn epoch_exists(&self, epoch_id: &EpochId) -> bool { - let epoch_manager = self.epoch_manager.read(); - epoch_manager.get_epoch_info(epoch_id).is_ok() - } - fn get_epoch_minted_amount(&self, epoch_id: &EpochId) -> Result { let epoch_manager = self.epoch_manager.read(); Ok(epoch_manager.get_epoch_info(epoch_id)?.minted_amount())