use {
crate::{duplicate_block_proof::DuplicateBlockProofData, error::SlashingError},
solana_program::{clock::Slot, pubkey::Pubkey},
};
const PACKET_DATA_SIZE: usize = 1232;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ProofType {
InvalidType,
DuplicateBlockProof,
}
impl ProofType {
pub const fn proof_account_length(&self) -> usize {
match self {
Self::InvalidType => panic!("Cannot determine size of invalid proof type"),
Self::DuplicateBlockProof => {
DuplicateBlockProofData::size_of(PACKET_DATA_SIZE)
}
}
}
pub fn violation_str(&self) -> &str {
match self {
Self::InvalidType => "invalid",
Self::DuplicateBlockProof => "duplicate block",
}
}
}
impl From<ProofType> for u8 {
fn from(value: ProofType) -> Self {
match value {
ProofType::InvalidType => 0,
ProofType::DuplicateBlockProof => 1,
}
}
}
impl From<u8> for ProofType {
fn from(value: u8) -> Self {
match value {
1 => Self::DuplicateBlockProof,
_ => Self::InvalidType,
}
}
}
pub trait SlashingProofData<'a> {
const PROOF_TYPE: ProofType;
fn unpack(data: &'a [u8]) -> Result<Self, SlashingError>
where
Self: Sized;
fn verify_proof(self, slot: Slot, pubkey: &Pubkey) -> Result<(), SlashingError>;
}
#[cfg(test)]
mod tests {
use crate::state::PACKET_DATA_SIZE;
#[test]
fn test_packet_size_parity() {
assert_eq!(PACKET_DATA_SIZE, solana_sdk::packet::PACKET_DATA_SIZE);
}
}