Files
lighthouse/validator_client/slashing_protection/src/signed_block.rs
Daniel Knopik 3d92e3663b Modularize validator store (#6705)
- Create trait `ValidatorStore` with all functions used by the `validator_services`
- Make `validator_services` generic on `S: ValidatorStore`
- Introduce `LighthouseValidatorStore`, which has identical functionality to the old `ValidatorStore`
- Remove dependencies (especially `environment`) from `validator_services` and `beacon_node_fallback` in order to be able to cleanly use them in Anchor
2025-05-07 03:43:33 +00:00

37 lines
1.1 KiB
Rust

use crate::{signing_root_from_row, SigningRoot};
use types::{BeaconBlockHeader, Hash256, SignedRoot, Slot};
/// A block that has previously been signed.
#[derive(Clone, Debug, PartialEq)]
pub struct SignedBlock {
pub slot: Slot,
pub signing_root: SigningRoot,
}
/// Reasons why a block may be slashable.
#[derive(PartialEq, Debug, Clone)]
pub enum InvalidBlock {
DoubleBlockProposal(SignedBlock),
SlotViolatesLowerBound { block_slot: Slot, bound_slot: Slot },
}
impl SignedBlock {
pub fn new(slot: Slot, signing_root: SigningRoot) -> Self {
Self { slot, signing_root }
}
pub fn from_header(header: &BeaconBlockHeader, domain: Hash256) -> Self {
Self {
slot: header.slot,
signing_root: header.signing_root(domain).into(),
}
}
/// Parse an SQLite row of `(slot, signing_root)`.
pub fn from_row(row: &rusqlite::Row) -> rusqlite::Result<Self> {
let slot = row.get(0)?;
let signing_root = signing_root_from_row(1, row)?;
Ok(SignedBlock { slot, signing_root })
}
}