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

Handle missing slasher backend in tests #4305

Closed
wants to merge 3 commits into from
Closed
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
18 changes: 15 additions & 3 deletions beacon_node/beacon_chain/tests/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,21 @@ async fn block_gossip_verification() {
#[tokio::test]
async fn verify_block_for_gossip_slashing_detection() {
let slasher_dir = tempdir().unwrap();
let slasher = Arc::new(
Slasher::open(SlasherConfig::new(slasher_dir.path().into()), test_logger()).unwrap(),
);

let slasher_result =
Slasher::open(SlasherConfig::new(slasher_dir.path().into()), test_logger());

// The slasher should only instantiate if a backend feature-flag has been
// provided.
let slasher = if Slasher::<E>::any_backend_feature_flag_is_present() {
Arc::new(slasher_result.unwrap())
} else {
assert!(matches!(
slasher_result,
Err(slasher::Error::SlasherDatabaseBackendDisabled)
));
return;
};

let inner_slasher = slasher.clone();
let harness = BeaconChainHarness::builder(MainnetEthSpec)
Expand Down
8 changes: 8 additions & 0 deletions slasher/src/slasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ impl<E: EthSpec> Slasher<E> {
})
}

// Returns `true` if any of the backend feature flags have been enabled.
//
// For example, returns `true` Lighthouse has been compiled with `--features
// slasher/lmdb` or `--features slasher/mdbx`.
pub const fn any_backend_feature_flag_is_present() -> bool {
cfg!(any(feature = "mdbx", feature = "lmdb"))
}

/// Harvest all attester slashings found, removing them from the slasher.
pub fn get_attester_slashings(&self) -> HashSet<AttesterSlashing<E>> {
std::mem::take(&mut self.attester_slashings.lock())
Expand Down