This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / knot2 / crates / knot-sim / src / trace.rs
2.2 kB 92 lines
1use knot_runtime::UnixMicros; 2use knot_types::{AccountDid, HttpStatus, RepoDid}; 3use serde::Serialize; 4 5const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325; 6const FNV_PRIME: u64 = 0x0000_0100_0000_01b3; 7 8pub(crate) fn fnv1a(bytes: &[u8]) -> u64 { 9 bytes.iter().fold(FNV_OFFSET, |hash, byte| { 10 (hash ^ u64::from(*byte)).wrapping_mul(FNV_PRIME) 11 }) 12} 13 14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize)] 15#[serde(transparent)] 16pub struct RoundNumber(u32); 17 18impl RoundNumber { 19 pub const fn new(value: u32) -> Self { 20 Self(value) 21 } 22 23 pub const fn get(self) -> u32 { 24 self.0 25 } 26} 27 28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize)] 29#[serde(transparent)] 30pub struct OperationIndex(u32); 31 32impl OperationIndex { 33 pub const fn new(value: u32) -> Self { 34 Self(value) 35 } 36 37 pub const fn get(self) -> u32 { 38 self.0 39 } 40} 41 42#[derive(Debug, Clone, PartialEq, Eq, Serialize)] 43#[serde(tag = "kind", rename_all = "snake_case")] 44pub enum Outcome { 45 Answered { status: HttpStatus, body: u64 }, 46 Killed, 47} 48 49#[derive(Debug, Clone, PartialEq, Eq, Serialize)] 50pub struct Step { 51 pub round: RoundNumber, 52 pub index: OperationIndex, 53 pub op: &'static str, 54 pub actor: String, 55 pub fault: &'static str, 56 pub outcome: Outcome, 57} 58 59#[derive(Debug, Clone, PartialEq, Eq, Serialize)] 60pub struct RepoCollaborators { 61 pub repo: RepoDid, 62 pub subjects: Vec<AccountDid>, 63} 64 65#[derive(Debug, Clone, PartialEq, Eq, Serialize)] 66pub struct Projection { 67 pub members: Vec<AccountDid>, 68 pub blocked: Vec<AccountDid>, 69} 70 71#[derive(Debug, Clone, PartialEq, Eq, Serialize)] 72pub struct Snapshot { 73 pub round: RoundNumber, 74 pub clock_micros: UnixMicros, 75 pub members: Vec<AccountDid>, 76 pub blocked: Vec<AccountDid>, 77 pub repos: Vec<RepoDid>, 78 pub collaborators: Vec<RepoCollaborators>, 79} 80 81#[derive(Debug, Clone, PartialEq, Eq, Serialize)] 82pub struct Trace { 83 pub seed: u64, 84 pub steps: Vec<Step>, 85 pub snapshots: Vec<Snapshot>, 86} 87 88impl Trace { 89 pub fn digest(&self) -> u64 { 90 fnv1a(&serde_json::to_vec(self).expect("trace is always serializable")) 91 } 92}