Refine and test slashing protection semantics (#1885)

## Issue Addressed

Closes #1873

## Proposed Changes

Fixes the bug in slashing protection import (#1873) by pruning the database upon import.

Also expands the test generator to cover this case and a few others which are under discussion here:

https://ethereum-magicians.org/t/eip-3076-validator-client-interchange-format-slashing-protection/4883

## Additional Info

Depending on the outcome of the discussion on Eth Magicians, we can either wait for consensus before merging, or merge our preferred solution and patch things later.
This commit is contained in:
Michael Sproul
2020-11-24 07:21:14 +00:00
parent 84b3387d09
commit 20339ade01
11 changed files with 763 additions and 236 deletions

View File

@@ -1,11 +1,11 @@
use crate::hash256_from_row;
use crate::{hash256_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: Hash256,
pub signing_root: SigningRoot,
}
/// Reasons why a block may be slashable.
@@ -16,21 +16,21 @@ pub enum InvalidBlock {
}
impl SignedBlock {
pub fn new(slot: Slot, signing_root: Hash256) -> Self {
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),
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 = hash256_from_row(1, row)?;
let signing_root = hash256_from_row(1, row)?.into();
Ok(SignedBlock { slot, signing_root })
}
}