1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::Error;
use consensus_types::common::{Author, Round};
use diem_logger::Schema;
use diem_types::waypoint::Waypoint;
use serde::Serialize;

#[derive(Schema)]
pub struct SafetyLogSchema<'a> {
    name: LogEntry,
    event: LogEvent,
    round: Option<Round>,
    preferred_round: Option<u64>,
    last_voted_round: Option<u64>,
    epoch: Option<u64>,
    #[schema(display)]
    error: Option<&'a Error>,
    waypoint: Option<Waypoint>,
    author: Option<Author>,
}

impl<'a> SafetyLogSchema<'a> {
    pub fn new(name: LogEntry, event: LogEvent) -> Self {
        Self {
            name,
            event,
            round: None,
            preferred_round: None,
            last_voted_round: None,
            epoch: None,
            error: None,
            waypoint: None,
            author: None,
        }
    }
}

#[derive(Clone, Copy, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum LogEntry {
    ConsensusState,
    ConstructAndSignVote,
    ConstructAndSignVoteTwoChain,
    Epoch,
    Initialize,
    KeyReconciliation,
    LastVotedRound,
    OneChainRound,
    PreferredRound,
    SignProposal,
    SignTimeout,
    SignTimeoutWithQC,
    State,
    Waypoint,
    SignCommitVote,
}

impl LogEntry {
    pub fn as_str(&self) -> &'static str {
        match self {
            LogEntry::ConsensusState => "consensus_state",
            LogEntry::ConstructAndSignVote => "construct_and_sign_vote",
            LogEntry::ConstructAndSignVoteTwoChain => "construct_and_sign_vote_2chain",
            LogEntry::Epoch => "epoch",
            LogEntry::Initialize => "initialize",
            LogEntry::LastVotedRound => "last_voted_round",
            LogEntry::KeyReconciliation => "key_reconciliation",
            LogEntry::OneChainRound => "one_chain_round",
            LogEntry::PreferredRound => "preferred_round",
            LogEntry::SignProposal => "sign_proposal",
            LogEntry::SignTimeout => "sign_timeout",
            LogEntry::SignTimeoutWithQC => "sign_timeout_with_qc",
            LogEntry::State => "state",
            LogEntry::Waypoint => "waypoint",
            LogEntry::SignCommitVote => "sign_commit_vote",
        }
    }
}

#[derive(Clone, Copy, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum LogEvent {
    Error,
    Request,
    Success,
    Update,
}