Skip to main content

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