sui_core/epoch/
reconfiguration.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use 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)]
10pub enum ReconfigCertStatus {
11    AcceptAllCerts,
12
13    // User certs rejected, but we still accept certs received through consensus.
14    RejectUserCerts,
15
16    // All certs rejected, including ones received through consensus.
17    // But we still accept other transactions from consensus (e.g. randomness DKG)
18    // and process previously-deferred transactions.
19    RejectAllCerts,
20
21    // All tx rejected, including system tx.
22    RejectAllTx,
23}
24
25#[derive(Clone, Debug, Serialize, Deserialize)]
26pub struct ReconfigState {
27    status: ReconfigCertStatus,
28}
29
30impl Default for ReconfigState {
31    fn default() -> Self {
32        Self {
33            status: ReconfigCertStatus::AcceptAllCerts,
34        }
35    }
36}
37
38impl ReconfigState {
39    pub fn close_user_certs(&mut self) {
40        if matches!(self.status, ReconfigCertStatus::AcceptAllCerts) {
41            self.status = ReconfigCertStatus::RejectUserCerts;
42        }
43    }
44
45    pub fn is_reject_user_certs(&self) -> bool {
46        matches!(self.status, ReconfigCertStatus::RejectUserCerts)
47    }
48
49    pub fn close_all_certs(&mut self) {
50        if !matches!(self.status, ReconfigCertStatus::RejectAllTx) {
51            info!("closing all certs");
52            self.status = ReconfigCertStatus::RejectAllCerts;
53        }
54    }
55
56    pub fn should_accept_user_certs(&self) -> bool {
57        matches!(self.status, ReconfigCertStatus::AcceptAllCerts)
58    }
59
60    pub fn should_accept_consensus_certs(&self) -> bool {
61        matches!(
62            self.status,
63            ReconfigCertStatus::AcceptAllCerts | ReconfigCertStatus::RejectUserCerts
64        )
65    }
66
67    pub fn is_reject_all_certs(&self) -> bool {
68        matches!(self.status, ReconfigCertStatus::RejectAllCerts)
69    }
70
71    pub fn close_all_tx(&mut self) {
72        self.status = ReconfigCertStatus::RejectAllTx;
73    }
74
75    pub fn should_accept_tx(&self) -> bool {
76        !matches!(self.status, ReconfigCertStatus::RejectAllTx)
77    }
78
79    pub fn is_reject_all_tx(&self) -> bool {
80        matches!(self.status, ReconfigCertStatus::RejectAllTx)
81    }
82}
83
84pub trait ReconfigurationInitiator {
85    fn close_epoch(&self, epoch_store: &Arc<AuthorityPerEpochStore>);
86}