sui_core/authority/
epoch_start_configuration.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use enum_dispatch::enum_dispatch;
5use serde::{Deserialize, Serialize};
6use std::collections::BTreeMap;
7use sui_config::NodeConfig;
8
9use std::fmt;
10use sui_types::base_types::{ObjectID, SequenceNumber};
11use sui_types::bridge::is_bridge_committee_initiated;
12use sui_types::epoch_data::EpochData;
13use sui_types::error::SuiResult;
14use sui_types::messages_checkpoint::{CheckpointDigest, CheckpointTimestamp};
15use sui_types::object::Owner;
16use sui_types::storage::ObjectStore;
17use sui_types::sui_system_state::epoch_start_sui_system_state::{
18    EpochStartSystemState, EpochStartSystemStateTrait,
19};
20use sui_types::{
21    SUI_ACCUMULATOR_ROOT_OBJECT_ID, SUI_ADDRESS_ALIAS_STATE_OBJECT_ID,
22    SUI_AUTHENTICATOR_STATE_OBJECT_ID, SUI_BRIDGE_OBJECT_ID, SUI_COIN_REGISTRY_OBJECT_ID,
23    SUI_DENY_LIST_OBJECT_ID, SUI_DISPLAY_REGISTRY_OBJECT_ID, SUI_RANDOMNESS_STATE_OBJECT_ID,
24};
25
26/// Well-known shared system objects whose initial shared version is recorded in
27/// the epoch start configuration. To make a new system object's initial shared
28/// version available at epoch start, add its object id here -- no new
29/// `EpochStartConfiguration` version is required.
30const SYSTEM_SHARED_OBJECT_IDS: &[ObjectID] = &[
31    SUI_AUTHENTICATOR_STATE_OBJECT_ID,
32    SUI_RANDOMNESS_STATE_OBJECT_ID,
33    SUI_DENY_LIST_OBJECT_ID,
34    SUI_BRIDGE_OBJECT_ID,
35    SUI_ACCUMULATOR_ROOT_OBJECT_ID,
36    SUI_COIN_REGISTRY_OBJECT_ID,
37    SUI_DISPLAY_REGISTRY_OBJECT_ID,
38    SUI_ADDRESS_ALIAS_STATE_OBJECT_ID,
39];
40
41/// Reads the initial shared version of a system shared object from the store.
42/// Returns `None` if the object does not yet exist at the start of the epoch.
43fn get_system_object_initial_shared_version(
44    object_store: &dyn ObjectStore,
45    object_id: ObjectID,
46) -> Option<SequenceNumber> {
47    object_store
48        .get_object(&object_id)
49        .map(|obj| match obj.owner {
50            Owner::Shared {
51                initial_shared_version,
52            } => initial_shared_version,
53            _ => unreachable!("System object {object_id} must be shared"),
54        })
55}
56
57/// Helper for the frozen legacy configurations (V1..V10), whose individual
58/// `Option<SequenceNumber>` fields predate the generic version map. Looks up
59/// `object_id` against the (id, version) pairs the configuration stored.
60fn legacy_lookup(
61    object_id: ObjectID,
62    pairs: &[(ObjectID, Option<SequenceNumber>)],
63) -> Option<SequenceNumber> {
64    pairs
65        .iter()
66        .find(|(id, _)| *id == object_id)
67        .and_then(|(_, version)| *version)
68}
69
70#[enum_dispatch]
71pub trait EpochStartConfigTrait {
72    fn epoch_digest(&self) -> CheckpointDigest;
73    fn epoch_start_state(&self) -> &EpochStartSystemState;
74    fn flags(&self) -> &[EpochFlag];
75    fn bridge_committee_initiated(&self) -> bool;
76    /// Returns the initial shared version of the given system object as of the
77    /// start of the epoch, or `None` if the object did not exist yet.
78    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber>;
79}
80
81// IMPORTANT: Assign explicit values to each variant to ensure that the values are stable.
82// When cherry-picking changes from one branch to another, the value of variants must never
83// change.
84//
85// Unlikely: If you cherry pick a change from one branch to another, and there is a collision
86// in the value of some variant, the branch which has been released should take precedence.
87// In this case, the picked-from branch is inconsistent with the released branch, and must
88// be fixed.
89#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
90pub enum EpochFlag {
91    // The deprecated flags have all been in production for long enough that
92    // we have deleted the old code paths they were guarding.
93    // We retain them here in order not to break deserialization.
94    _InMemoryCheckpointRootsDeprecated = 0,
95    _PerEpochFinalizedTransactionsDeprecated = 1,
96    _ObjectLockSplitTablesDeprecated = 2,
97    _WritebackCacheEnabledDeprecated = 3,
98    _GlobalStateHashV2EnabledDeprecated = 4,
99    _GlobalStateHashV2EnabledTestnetDeprecated = 5,
100    _GlobalStateHashV2EnabledMainnetDeprecated = 6,
101    _ExecutedInEpochTableDeprecated = 7,
102    _UseVersionAssignmentTablesV3 = 8,
103    _DataQuarantineFromBeginningOfEpochDeprecated = 9,
104    _UseCommitHandlerV2Deprecated = 10,
105
106    // Used for `test_epoch_flag_upgrade`.
107    #[cfg(msim)]
108    DummyFlag = 11,
109}
110
111impl EpochFlag {
112    pub fn default_flags_for_new_epoch(_config: &NodeConfig) -> Vec<Self> {
113        // NodeConfig arg is not currently used, but we keep it here for future
114        // flags that might depend on the config.
115        Self::default_flags_impl()
116    }
117
118    // Return flags that are mandatory for the current version of the code. This is used
119    // so that `test_epoch_flag_upgrade` can still work correctly even when there are no
120    // optional flags.
121    pub fn mandatory_flags() -> Vec<Self> {
122        vec![]
123    }
124
125    /// For situations in which there is no config available (e.g. setting up a downloaded snapshot).
126    pub fn default_for_no_config() -> Vec<Self> {
127        Self::default_flags_impl()
128    }
129
130    fn default_flags_impl() -> Vec<Self> {
131        #[cfg(msim)]
132        {
133            vec![EpochFlag::DummyFlag]
134        }
135        #[cfg(not(msim))]
136        {
137            vec![]
138        }
139    }
140}
141
142impl fmt::Display for EpochFlag {
143    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
144        // Important - implementation should return low cardinality values because this is used as metric key
145        match self {
146            EpochFlag::_InMemoryCheckpointRootsDeprecated => {
147                write!(f, "InMemoryCheckpointRoots (DEPRECATED)")
148            }
149            EpochFlag::_PerEpochFinalizedTransactionsDeprecated => {
150                write!(f, "PerEpochFinalizedTransactions (DEPRECATED)")
151            }
152            EpochFlag::_ObjectLockSplitTablesDeprecated => {
153                write!(f, "ObjectLockSplitTables (DEPRECATED)")
154            }
155            EpochFlag::_WritebackCacheEnabledDeprecated => {
156                write!(f, "WritebackCacheEnabled (DEPRECATED)")
157            }
158            EpochFlag::_GlobalStateHashV2EnabledDeprecated => {
159                write!(f, "GlobalStateHashV2EnabledDeprecated (DEPRECATED)")
160            }
161            EpochFlag::_ExecutedInEpochTableDeprecated => {
162                write!(f, "ExecutedInEpochTable (DEPRECATED)")
163            }
164            EpochFlag::_GlobalStateHashV2EnabledTestnetDeprecated => {
165                write!(f, "GlobalStateHashV2EnabledTestnet (DEPRECATED)")
166            }
167            EpochFlag::_GlobalStateHashV2EnabledMainnetDeprecated => {
168                write!(f, "GlobalStateHashV2EnabledMainnet (DEPRECATED)")
169            }
170            EpochFlag::_UseVersionAssignmentTablesV3 => {
171                write!(f, "UseVersionAssignmentTablesV3 (DEPRECATED)")
172            }
173            EpochFlag::_DataQuarantineFromBeginningOfEpochDeprecated => {
174                write!(f, "DataQuarantineFromBeginningOfEpoch (DEPRECATED)")
175            }
176            EpochFlag::_UseCommitHandlerV2Deprecated => {
177                write!(f, "UseCommitHandlerV2 (DEPRECATED)")
178            }
179            #[cfg(msim)]
180            EpochFlag::DummyFlag => {
181                write!(f, "DummyFlag")
182            }
183        }
184    }
185}
186
187/// Parameters of the epoch fixed at epoch start.
188#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
189#[enum_dispatch(EpochStartConfigTrait)]
190pub enum EpochStartConfiguration {
191    V1(EpochStartConfigurationV1),
192    V2(EpochStartConfigurationV2),
193    V3(EpochStartConfigurationV3),
194    V4(EpochStartConfigurationV4),
195    V5(EpochStartConfigurationV5),
196    V6(EpochStartConfigurationV6),
197    V7(EpochStartConfigurationV7),
198    V8(EpochStartConfigurationV8),
199    V9(EpochStartConfigurationV9),
200    V10(EpochStartConfigurationV10),
201    V11(EpochStartConfigurationV11),
202}
203
204impl EpochStartConfiguration {
205    pub fn new(
206        system_state: EpochStartSystemState,
207        epoch_digest: CheckpointDigest,
208        object_store: &dyn ObjectStore,
209        initial_epoch_flags: Vec<EpochFlag>,
210    ) -> SuiResult<Self> {
211        let mut system_object_versions = BTreeMap::new();
212        for &object_id in SYSTEM_SHARED_OBJECT_IDS {
213            if let Some(version) = get_system_object_initial_shared_version(object_store, object_id)
214            {
215                system_object_versions.insert(object_id, version);
216            }
217        }
218        let bridge_committee_initiated = is_bridge_committee_initiated(object_store)?;
219        Ok(Self::V11(EpochStartConfigurationV11 {
220            system_state,
221            epoch_digest,
222            flags: initial_epoch_flags,
223            system_object_versions,
224            bridge_committee_initiated,
225        }))
226    }
227
228    pub fn new_at_next_epoch_for_testing(&self) -> Self {
229        // We only need to implement this function for the latest version.
230        // When a new version is introduced, this function should be updated.
231        match self {
232            Self::V11(config) => Self::V11(EpochStartConfigurationV11 {
233                system_state: config.system_state.new_at_next_epoch_for_testing(),
234                epoch_digest: config.epoch_digest,
235                flags: config.flags.clone(),
236                system_object_versions: config.system_object_versions.clone(),
237                bridge_committee_initiated: config.bridge_committee_initiated,
238            }),
239            _ => panic!(
240                "This function is only implemented for the latest version of EpochStartConfiguration"
241            ),
242        }
243    }
244
245    pub fn epoch_data(&self) -> EpochData {
246        EpochData::new(
247            self.epoch_start_state().epoch(),
248            self.epoch_start_state().epoch_start_timestamp_ms(),
249            self.epoch_digest(),
250        )
251    }
252
253    pub fn epoch_start_timestamp_ms(&self) -> CheckpointTimestamp {
254        self.epoch_start_state().epoch_start_timestamp_ms()
255    }
256
257    // Convenience accessors for the well-known system objects. These delegate to
258    // the generic `system_object_initial_shared_version` lookup, so a new system
259    // object does not strictly require its own accessor.
260    pub fn authenticator_obj_initial_shared_version(&self) -> Option<SequenceNumber> {
261        self.system_object_initial_shared_version(SUI_AUTHENTICATOR_STATE_OBJECT_ID)
262    }
263
264    pub fn randomness_obj_initial_shared_version(&self) -> Option<SequenceNumber> {
265        self.system_object_initial_shared_version(SUI_RANDOMNESS_STATE_OBJECT_ID)
266    }
267
268    pub fn coin_deny_list_obj_initial_shared_version(&self) -> Option<SequenceNumber> {
269        self.system_object_initial_shared_version(SUI_DENY_LIST_OBJECT_ID)
270    }
271
272    pub fn bridge_obj_initial_shared_version(&self) -> Option<SequenceNumber> {
273        self.system_object_initial_shared_version(SUI_BRIDGE_OBJECT_ID)
274    }
275
276    pub fn accumulator_root_obj_initial_shared_version(&self) -> Option<SequenceNumber> {
277        self.system_object_initial_shared_version(SUI_ACCUMULATOR_ROOT_OBJECT_ID)
278    }
279
280    pub fn coin_registry_obj_initial_shared_version(&self) -> Option<SequenceNumber> {
281        self.system_object_initial_shared_version(SUI_COIN_REGISTRY_OBJECT_ID)
282    }
283
284    pub fn display_registry_obj_initial_shared_version(&self) -> Option<SequenceNumber> {
285        self.system_object_initial_shared_version(SUI_DISPLAY_REGISTRY_OBJECT_ID)
286    }
287
288    pub fn address_alias_state_obj_initial_shared_version(&self) -> Option<SequenceNumber> {
289        self.system_object_initial_shared_version(SUI_ADDRESS_ALIAS_STATE_OBJECT_ID)
290    }
291}
292
293#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
294pub struct EpochStartConfigurationV1 {
295    system_state: EpochStartSystemState,
296    /// epoch_digest is defined as following
297    /// (1) For the genesis epoch it is set to 0
298    /// (2) For all other epochs it is a digest of the last checkpoint of a previous epoch
299    /// Note that this is in line with how epoch start timestamp is defined
300    epoch_digest: CheckpointDigest,
301}
302
303#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
304pub struct EpochStartConfigurationV2 {
305    system_state: EpochStartSystemState,
306    epoch_digest: CheckpointDigest,
307    flags: Vec<EpochFlag>,
308}
309
310#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
311pub struct EpochStartConfigurationV3 {
312    system_state: EpochStartSystemState,
313    epoch_digest: CheckpointDigest,
314    flags: Vec<EpochFlag>,
315    /// Does the authenticator state object exist at the beginning of the epoch?
316    authenticator_obj_initial_shared_version: Option<SequenceNumber>,
317}
318
319#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
320pub struct EpochStartConfigurationV4 {
321    system_state: EpochStartSystemState,
322    epoch_digest: CheckpointDigest,
323    flags: Vec<EpochFlag>,
324    /// Do the state objects exist at the beginning of the epoch?
325    authenticator_obj_initial_shared_version: Option<SequenceNumber>,
326    randomness_obj_initial_shared_version: Option<SequenceNumber>,
327}
328
329#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
330pub struct EpochStartConfigurationV5 {
331    system_state: EpochStartSystemState,
332    epoch_digest: CheckpointDigest,
333    flags: Vec<EpochFlag>,
334    /// Do the state objects exist at the beginning of the epoch?
335    authenticator_obj_initial_shared_version: Option<SequenceNumber>,
336    randomness_obj_initial_shared_version: Option<SequenceNumber>,
337    coin_deny_list_obj_initial_shared_version: Option<SequenceNumber>,
338}
339
340#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
341pub struct EpochStartConfigurationV6 {
342    system_state: EpochStartSystemState,
343    epoch_digest: CheckpointDigest,
344    flags: Vec<EpochFlag>,
345    /// Do the state objects exist at the beginning of the epoch?
346    authenticator_obj_initial_shared_version: Option<SequenceNumber>,
347    randomness_obj_initial_shared_version: Option<SequenceNumber>,
348    coin_deny_list_obj_initial_shared_version: Option<SequenceNumber>,
349    bridge_obj_initial_shared_version: Option<SequenceNumber>,
350    bridge_committee_initiated: bool,
351}
352
353#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
354pub struct EpochStartConfigurationV7 {
355    system_state: EpochStartSystemState,
356    epoch_digest: CheckpointDigest,
357    flags: Vec<EpochFlag>,
358    /// Do the state objects exist at the beginning of the epoch?
359    authenticator_obj_initial_shared_version: Option<SequenceNumber>,
360    randomness_obj_initial_shared_version: Option<SequenceNumber>,
361    coin_deny_list_obj_initial_shared_version: Option<SequenceNumber>,
362    bridge_obj_initial_shared_version: Option<SequenceNumber>,
363    bridge_committee_initiated: bool,
364    accumulator_root_obj_initial_shared_version: Option<SequenceNumber>,
365}
366
367#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
368pub struct EpochStartConfigurationV8 {
369    system_state: EpochStartSystemState,
370    epoch_digest: CheckpointDigest,
371    flags: Vec<EpochFlag>,
372    /// Do the state objects exist at the beginning of the epoch?
373    authenticator_obj_initial_shared_version: Option<SequenceNumber>,
374    randomness_obj_initial_shared_version: Option<SequenceNumber>,
375    coin_deny_list_obj_initial_shared_version: Option<SequenceNumber>,
376    bridge_obj_initial_shared_version: Option<SequenceNumber>,
377    bridge_committee_initiated: bool,
378    accumulator_root_obj_initial_shared_version: Option<SequenceNumber>,
379    coin_registry_obj_initial_shared_version: Option<SequenceNumber>,
380}
381
382#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
383pub struct EpochStartConfigurationV9 {
384    system_state: EpochStartSystemState,
385    epoch_digest: CheckpointDigest,
386    flags: Vec<EpochFlag>,
387    /// Do the state objects exist at the beginning of the epoch?
388    authenticator_obj_initial_shared_version: Option<SequenceNumber>,
389    randomness_obj_initial_shared_version: Option<SequenceNumber>,
390    coin_deny_list_obj_initial_shared_version: Option<SequenceNumber>,
391    bridge_obj_initial_shared_version: Option<SequenceNumber>,
392    bridge_committee_initiated: bool,
393    accumulator_root_obj_initial_shared_version: Option<SequenceNumber>,
394    coin_registry_obj_initial_shared_version: Option<SequenceNumber>,
395    display_registry_obj_initial_shared_version: Option<SequenceNumber>,
396}
397
398#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
399pub struct EpochStartConfigurationV10 {
400    system_state: EpochStartSystemState,
401    epoch_digest: CheckpointDigest,
402    flags: Vec<EpochFlag>,
403    /// Do the state objects exist at the beginning of the epoch?
404    authenticator_obj_initial_shared_version: Option<SequenceNumber>,
405    randomness_obj_initial_shared_version: Option<SequenceNumber>,
406    coin_deny_list_obj_initial_shared_version: Option<SequenceNumber>,
407    bridge_obj_initial_shared_version: Option<SequenceNumber>,
408    bridge_committee_initiated: bool,
409    accumulator_root_obj_initial_shared_version: Option<SequenceNumber>,
410    coin_registry_obj_initial_shared_version: Option<SequenceNumber>,
411    display_registry_obj_initial_shared_version: Option<SequenceNumber>,
412    address_alias_state_obj_initial_shared_version: Option<SequenceNumber>,
413}
414
415/// Current configuration shape. The per-object initial shared versions are kept
416/// in a map keyed by object id, so introducing a new system shared object only
417/// requires extending `SYSTEM_SHARED_OBJECT_IDS` -- no new configuration version.
418#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
419pub struct EpochStartConfigurationV11 {
420    system_state: EpochStartSystemState,
421    epoch_digest: CheckpointDigest,
422    flags: Vec<EpochFlag>,
423    /// Initial shared versions of the system shared objects that existed at the
424    /// start of the epoch, keyed by object id. Objects absent from the map did
425    /// not exist yet.
426    system_object_versions: BTreeMap<ObjectID, SequenceNumber>,
427    bridge_committee_initiated: bool,
428}
429
430impl EpochStartConfigurationV1 {
431    pub fn new(system_state: EpochStartSystemState, epoch_digest: CheckpointDigest) -> Self {
432        Self {
433            system_state,
434            epoch_digest,
435        }
436    }
437}
438
439impl EpochStartConfigTrait for EpochStartConfigurationV1 {
440    fn epoch_digest(&self) -> CheckpointDigest {
441        self.epoch_digest
442    }
443
444    fn epoch_start_state(&self) -> &EpochStartSystemState {
445        &self.system_state
446    }
447
448    fn flags(&self) -> &[EpochFlag] {
449        &[]
450    }
451
452    fn bridge_committee_initiated(&self) -> bool {
453        false
454    }
455
456    fn system_object_initial_shared_version(&self, _object_id: ObjectID) -> Option<SequenceNumber> {
457        None
458    }
459}
460
461impl EpochStartConfigTrait for EpochStartConfigurationV2 {
462    fn epoch_digest(&self) -> CheckpointDigest {
463        self.epoch_digest
464    }
465
466    fn epoch_start_state(&self) -> &EpochStartSystemState {
467        &self.system_state
468    }
469
470    fn flags(&self) -> &[EpochFlag] {
471        &self.flags
472    }
473
474    fn bridge_committee_initiated(&self) -> bool {
475        false
476    }
477
478    fn system_object_initial_shared_version(&self, _object_id: ObjectID) -> Option<SequenceNumber> {
479        None
480    }
481}
482
483impl EpochStartConfigTrait for EpochStartConfigurationV3 {
484    fn epoch_digest(&self) -> CheckpointDigest {
485        self.epoch_digest
486    }
487
488    fn epoch_start_state(&self) -> &EpochStartSystemState {
489        &self.system_state
490    }
491
492    fn flags(&self) -> &[EpochFlag] {
493        &self.flags
494    }
495
496    fn bridge_committee_initiated(&self) -> bool {
497        false
498    }
499
500    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber> {
501        legacy_lookup(
502            object_id,
503            &[(
504                SUI_AUTHENTICATOR_STATE_OBJECT_ID,
505                self.authenticator_obj_initial_shared_version,
506            )],
507        )
508    }
509}
510
511impl EpochStartConfigTrait for EpochStartConfigurationV4 {
512    fn epoch_digest(&self) -> CheckpointDigest {
513        self.epoch_digest
514    }
515
516    fn epoch_start_state(&self) -> &EpochStartSystemState {
517        &self.system_state
518    }
519
520    fn flags(&self) -> &[EpochFlag] {
521        &self.flags
522    }
523
524    fn bridge_committee_initiated(&self) -> bool {
525        false
526    }
527
528    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber> {
529        legacy_lookup(
530            object_id,
531            &[
532                (
533                    SUI_AUTHENTICATOR_STATE_OBJECT_ID,
534                    self.authenticator_obj_initial_shared_version,
535                ),
536                (
537                    SUI_RANDOMNESS_STATE_OBJECT_ID,
538                    self.randomness_obj_initial_shared_version,
539                ),
540            ],
541        )
542    }
543}
544
545impl EpochStartConfigTrait for EpochStartConfigurationV5 {
546    fn epoch_digest(&self) -> CheckpointDigest {
547        self.epoch_digest
548    }
549
550    fn epoch_start_state(&self) -> &EpochStartSystemState {
551        &self.system_state
552    }
553
554    fn flags(&self) -> &[EpochFlag] {
555        &self.flags
556    }
557
558    fn bridge_committee_initiated(&self) -> bool {
559        false
560    }
561
562    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber> {
563        legacy_lookup(
564            object_id,
565            &[
566                (
567                    SUI_AUTHENTICATOR_STATE_OBJECT_ID,
568                    self.authenticator_obj_initial_shared_version,
569                ),
570                (
571                    SUI_RANDOMNESS_STATE_OBJECT_ID,
572                    self.randomness_obj_initial_shared_version,
573                ),
574                (
575                    SUI_DENY_LIST_OBJECT_ID,
576                    self.coin_deny_list_obj_initial_shared_version,
577                ),
578            ],
579        )
580    }
581}
582
583impl EpochStartConfigTrait for EpochStartConfigurationV6 {
584    fn epoch_digest(&self) -> CheckpointDigest {
585        self.epoch_digest
586    }
587
588    fn epoch_start_state(&self) -> &EpochStartSystemState {
589        &self.system_state
590    }
591
592    fn flags(&self) -> &[EpochFlag] {
593        &self.flags
594    }
595
596    fn bridge_committee_initiated(&self) -> bool {
597        self.bridge_committee_initiated
598    }
599
600    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber> {
601        legacy_lookup(
602            object_id,
603            &[
604                (
605                    SUI_AUTHENTICATOR_STATE_OBJECT_ID,
606                    self.authenticator_obj_initial_shared_version,
607                ),
608                (
609                    SUI_RANDOMNESS_STATE_OBJECT_ID,
610                    self.randomness_obj_initial_shared_version,
611                ),
612                (
613                    SUI_DENY_LIST_OBJECT_ID,
614                    self.coin_deny_list_obj_initial_shared_version,
615                ),
616                (SUI_BRIDGE_OBJECT_ID, self.bridge_obj_initial_shared_version),
617            ],
618        )
619    }
620}
621
622impl EpochStartConfigTrait for EpochStartConfigurationV7 {
623    fn epoch_digest(&self) -> CheckpointDigest {
624        self.epoch_digest
625    }
626
627    fn epoch_start_state(&self) -> &EpochStartSystemState {
628        &self.system_state
629    }
630
631    fn flags(&self) -> &[EpochFlag] {
632        &self.flags
633    }
634
635    fn bridge_committee_initiated(&self) -> bool {
636        self.bridge_committee_initiated
637    }
638
639    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber> {
640        legacy_lookup(
641            object_id,
642            &[
643                (
644                    SUI_AUTHENTICATOR_STATE_OBJECT_ID,
645                    self.authenticator_obj_initial_shared_version,
646                ),
647                (
648                    SUI_RANDOMNESS_STATE_OBJECT_ID,
649                    self.randomness_obj_initial_shared_version,
650                ),
651                (
652                    SUI_DENY_LIST_OBJECT_ID,
653                    self.coin_deny_list_obj_initial_shared_version,
654                ),
655                (SUI_BRIDGE_OBJECT_ID, self.bridge_obj_initial_shared_version),
656                (
657                    SUI_ACCUMULATOR_ROOT_OBJECT_ID,
658                    self.accumulator_root_obj_initial_shared_version,
659                ),
660            ],
661        )
662    }
663}
664
665impl EpochStartConfigTrait for EpochStartConfigurationV8 {
666    fn epoch_digest(&self) -> CheckpointDigest {
667        self.epoch_digest
668    }
669
670    fn epoch_start_state(&self) -> &EpochStartSystemState {
671        &self.system_state
672    }
673
674    fn flags(&self) -> &[EpochFlag] {
675        &self.flags
676    }
677
678    fn bridge_committee_initiated(&self) -> bool {
679        self.bridge_committee_initiated
680    }
681
682    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber> {
683        legacy_lookup(
684            object_id,
685            &[
686                (
687                    SUI_AUTHENTICATOR_STATE_OBJECT_ID,
688                    self.authenticator_obj_initial_shared_version,
689                ),
690                (
691                    SUI_RANDOMNESS_STATE_OBJECT_ID,
692                    self.randomness_obj_initial_shared_version,
693                ),
694                (
695                    SUI_DENY_LIST_OBJECT_ID,
696                    self.coin_deny_list_obj_initial_shared_version,
697                ),
698                (SUI_BRIDGE_OBJECT_ID, self.bridge_obj_initial_shared_version),
699                (
700                    SUI_ACCUMULATOR_ROOT_OBJECT_ID,
701                    self.accumulator_root_obj_initial_shared_version,
702                ),
703                (
704                    SUI_COIN_REGISTRY_OBJECT_ID,
705                    self.coin_registry_obj_initial_shared_version,
706                ),
707            ],
708        )
709    }
710}
711
712impl EpochStartConfigTrait for EpochStartConfigurationV9 {
713    fn epoch_digest(&self) -> CheckpointDigest {
714        self.epoch_digest
715    }
716
717    fn epoch_start_state(&self) -> &EpochStartSystemState {
718        &self.system_state
719    }
720
721    fn flags(&self) -> &[EpochFlag] {
722        &self.flags
723    }
724
725    fn bridge_committee_initiated(&self) -> bool {
726        self.bridge_committee_initiated
727    }
728
729    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber> {
730        legacy_lookup(
731            object_id,
732            &[
733                (
734                    SUI_AUTHENTICATOR_STATE_OBJECT_ID,
735                    self.authenticator_obj_initial_shared_version,
736                ),
737                (
738                    SUI_RANDOMNESS_STATE_OBJECT_ID,
739                    self.randomness_obj_initial_shared_version,
740                ),
741                (
742                    SUI_DENY_LIST_OBJECT_ID,
743                    self.coin_deny_list_obj_initial_shared_version,
744                ),
745                (SUI_BRIDGE_OBJECT_ID, self.bridge_obj_initial_shared_version),
746                (
747                    SUI_ACCUMULATOR_ROOT_OBJECT_ID,
748                    self.accumulator_root_obj_initial_shared_version,
749                ),
750                (
751                    SUI_COIN_REGISTRY_OBJECT_ID,
752                    self.coin_registry_obj_initial_shared_version,
753                ),
754                (
755                    SUI_DISPLAY_REGISTRY_OBJECT_ID,
756                    self.display_registry_obj_initial_shared_version,
757                ),
758            ],
759        )
760    }
761}
762
763impl EpochStartConfigTrait for EpochStartConfigurationV10 {
764    fn epoch_digest(&self) -> CheckpointDigest {
765        self.epoch_digest
766    }
767
768    fn epoch_start_state(&self) -> &EpochStartSystemState {
769        &self.system_state
770    }
771
772    fn flags(&self) -> &[EpochFlag] {
773        &self.flags
774    }
775
776    fn bridge_committee_initiated(&self) -> bool {
777        self.bridge_committee_initiated
778    }
779
780    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber> {
781        legacy_lookup(
782            object_id,
783            &[
784                (
785                    SUI_AUTHENTICATOR_STATE_OBJECT_ID,
786                    self.authenticator_obj_initial_shared_version,
787                ),
788                (
789                    SUI_RANDOMNESS_STATE_OBJECT_ID,
790                    self.randomness_obj_initial_shared_version,
791                ),
792                (
793                    SUI_DENY_LIST_OBJECT_ID,
794                    self.coin_deny_list_obj_initial_shared_version,
795                ),
796                (SUI_BRIDGE_OBJECT_ID, self.bridge_obj_initial_shared_version),
797                (
798                    SUI_ACCUMULATOR_ROOT_OBJECT_ID,
799                    self.accumulator_root_obj_initial_shared_version,
800                ),
801                (
802                    SUI_COIN_REGISTRY_OBJECT_ID,
803                    self.coin_registry_obj_initial_shared_version,
804                ),
805                (
806                    SUI_DISPLAY_REGISTRY_OBJECT_ID,
807                    self.display_registry_obj_initial_shared_version,
808                ),
809                (
810                    SUI_ADDRESS_ALIAS_STATE_OBJECT_ID,
811                    self.address_alias_state_obj_initial_shared_version,
812                ),
813            ],
814        )
815    }
816}
817
818impl EpochStartConfigTrait for EpochStartConfigurationV11 {
819    fn epoch_digest(&self) -> CheckpointDigest {
820        self.epoch_digest
821    }
822
823    fn epoch_start_state(&self) -> &EpochStartSystemState {
824        &self.system_state
825    }
826
827    fn flags(&self) -> &[EpochFlag] {
828        &self.flags
829    }
830
831    fn bridge_committee_initiated(&self) -> bool {
832        self.bridge_committee_initiated
833    }
834
835    fn system_object_initial_shared_version(&self, object_id: ObjectID) -> Option<SequenceNumber> {
836        self.system_object_versions.get(&object_id).copied()
837    }
838}