iota_core/epoch/
reconfiguration.rs

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