use alloc::vec::Vec;
use crate::proposal::Proposal;
use crate::recorder::Register;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ProposalView {
pub priority: u64,
pub origin: u32,
pub incarnation: u64,
pub seq: u64,
pub digest: u64,
}
impl ProposalView {
pub fn value(&self) -> (u32, u64, u64, u64) {
(self.origin, self.incarnation, self.seq, self.digest)
}
}
impl From<&Proposal> for ProposalView {
fn from(p: &Proposal) -> Self {
let digest = p
.value
.iter()
.fold(0xcbf2_9ce4_8422_2325u64, |h, &b| (h ^ u64::from(b)).wrapping_mul(0x0100_0000_01b3));
Self {
priority: p.priority,
origin: p.key.origin.0,
incarnation: p.key.incarnation,
seq: p.key.seq,
digest,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct RegisterView {
pub step: u32,
pub first: Option<ProposalView>,
pub agg: Option<ProposalView>,
pub prev_agg: Option<ProposalView>,
}
impl From<&Register> for RegisterView {
fn from(r: &Register) -> Self {
Self {
step: r.step,
first: r.first.as_ref().map(Into::into),
agg: r.agg.as_ref().map(Into::into),
prev_agg: r.prev_agg.as_ref().map(Into::into),
}
}
}
#[derive(Clone, Debug, Default)]
pub struct Inspection {
pub registers: Vec<(u64, RegisterView)>,
pub decided_here: Vec<(u64, ProposalView, u32)>,
pub decided: Vec<(u64, ProposalView)>,
pub local_batches: usize,
}