sui_core/epoch/
reconfiguration.rs1use crate::authority::authority_per_epoch_store::AuthorityPerEpochStore;
5use serde::{Deserialize, Serialize};
6use std::sync::Arc;
7use tracing::info;
8
9#[derive(Clone, Debug, Serialize, Deserialize)]
11pub enum ReconfigCertStatus {
12 AcceptAllCerts,
13
14 RejectUserCerts,
18
19 RejectAllCerts,
23
24 RejectAllTx,
26}
27
28#[derive(Clone, Debug, Serialize, Deserialize)]
29pub struct ReconfigState {
30 status: ReconfigCertStatus,
31}
32
33impl Default for ReconfigState {
34 fn default() -> Self {
35 Self {
36 status: ReconfigCertStatus::AcceptAllCerts,
37 }
38 }
39}
40
41impl ReconfigState {
42 pub fn close_user_certs(&mut self) {
43 if matches!(self.status, ReconfigCertStatus::AcceptAllCerts) {
44 self.status = ReconfigCertStatus::RejectUserCerts;
45 }
46 }
47
48 pub fn is_reject_user_certs(&self) -> bool {
49 matches!(self.status, ReconfigCertStatus::RejectUserCerts)
50 }
51
52 pub fn close_all_certs(&mut self) {
53 if !matches!(self.status, ReconfigCertStatus::RejectAllTx) {
54 info!("closing all certs");
55 self.status = ReconfigCertStatus::RejectAllCerts;
56 }
57 }
58
59 pub fn should_accept_user_certs(&self) -> bool {
60 matches!(self.status, ReconfigCertStatus::AcceptAllCerts)
61 }
62
63 pub fn should_accept_consensus_certs(&self) -> bool {
64 matches!(
65 self.status,
66 ReconfigCertStatus::AcceptAllCerts | ReconfigCertStatus::RejectUserCerts
67 )
68 }
69
70 pub fn is_reject_all_certs(&self) -> bool {
71 matches!(self.status, ReconfigCertStatus::RejectAllCerts)
72 }
73
74 pub fn close_all_tx(&mut self) {
75 self.status = ReconfigCertStatus::RejectAllTx;
76 }
77
78 pub fn should_accept_tx(&self) -> bool {
79 !matches!(self.status, ReconfigCertStatus::RejectAllTx)
80 }
81
82 pub fn is_reject_all_tx(&self) -> bool {
83 matches!(self.status, ReconfigCertStatus::RejectAllTx)
84 }
85}
86
87pub trait ReconfigurationInitiator {
88 fn close_epoch(&self, epoch_store: &Arc<AuthorityPerEpochStore>);
89}