Skip to main content

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// Certs are legacy names for transactions before fastpath was removed.
10#[derive(Clone, Debug, Serialize, Deserialize)]
11pub enum ReconfigCertStatus {
12    AcceptAllCerts,
13
14    // This state is only used during manual epoch close, to close user transaction submission
15    // and persist the manually closed epoch state.
16    // Transactions received through consensus are still accepted.
17    RejectUserCerts,
18
19    // All certs rejected, including ones received through consensus.
20    // But we still accept other transactions from consensus (e.g. randomness DKG)
21    // and process previously-deferred transactions.
22    RejectAllCerts,
23
24    // All tx rejected, including system tx.
25    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}