mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
* Implement slashing protection Roll-up of #588 with some conflicts resolved * WIP improvements * Require slot uniqueness for blocks (rather than epochs) * Native DB support for Slot and Epoch * Simplify surrounding/surrounded-by queries * Implement unified slashing protection database A single SQL database saves on open file descriptors. * Make slashing protection concurrency safe. Revive tests, add parallel tests. * Some simplifications * Auto-registration, test clean-ups * More tests, clean-ups, hardening * Fix comments in BLS * Optimise bulk validator registration * Delete outdated tests * Use bundled SQLite in slashing protection * Auto-register validators in simulation * Use real signing_root in slashing protection * Update book for --auto-register * Refine log messages and help flags * Correct typo in Cargo.toml authors * Fix merge conflicts * Safer error handling in sqlite slot/epoch * Address review comments * Add attestation test mutating block root Co-authored-by: pscott <scottpiriou@gmail.com>
36 lines
966 B
Rust
36 lines
966 B
Rust
use crate::hash256_from_row;
|
|
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: Hash256,
|
|
}
|
|
|
|
/// Reasons why a block may be slashable.
|
|
#[derive(PartialEq, Debug)]
|
|
pub enum InvalidBlock {
|
|
DoubleBlockProposal(SignedBlock),
|
|
}
|
|
|
|
impl SignedBlock {
|
|
pub fn new(slot: Slot, signing_root: Hash256) -> Self {
|
|
Self { slot, signing_root }
|
|
}
|
|
|
|
pub fn from_header(header: &BeaconBlockHeader, domain: Hash256) -> Self {
|
|
Self {
|
|
slot: header.slot,
|
|
signing_root: header.signing_root(domain),
|
|
}
|
|
}
|
|
|
|
/// 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 = hash256_from_row(1, row)?;
|
|
Ok(SignedBlock { slot, signing_root })
|
|
}
|
|
}
|