Skip to content

Commit cf70016

Browse files
authored
[sui-genesis-builder] Start genesis with correct framework for protocol version (#13885)
Previously we would always start genesis with the current set of framework modules. This causes issues in the compatibility tests if the current version of the framework is not backwards compatible with the old version (e.g., by adding a new type in the new version of the framework). This updates the genesis creation to now use the correct framework snapshot for all protocol versions, defaulting to the current framework if a snapshot for the given protocol version is not found. This also updates framework snapshots to be ordered based on the order in which they need to be published. ## Test Plan Added a type to the framework locally, and made sure the `test_upgrade_compatibility` test passes with these changes.
1 parent 19d72b0 commit cf70016

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

crates/sui-genesis-builder/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ shared-crypto.workspace = true
2525
sui-config.workspace = true
2626
sui-execution.workspace = true
2727
sui-framework.workspace = true
28+
sui-framework-snapshot.workspace = true
2829
sui-protocol-config.workspace = true
2930
sui-types.workspace = true
3031
workspace-hack = { version = "0.1", path = "../workspace-hack" }

crates/sui-genesis-builder/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use sui_config::genesis::{
1717
UnsignedGenesis,
1818
};
1919
use sui_execution::{self, Executor};
20-
use sui_framework::BuiltInFramework;
20+
use sui_framework::{BuiltInFramework, SystemPackage};
2121
use sui_protocol_config::{Chain, ProtocolConfig, ProtocolVersion};
2222
use sui_types::base_types::{
2323
ExecutionDigests, ObjectID, SequenceNumber, SuiAddress, TransactionDigest, TxContext,
@@ -664,13 +664,14 @@ fn create_genesis_context(
664664
genesis_chain_parameters: &GenesisChainParameters,
665665
genesis_validators: &[GenesisValidatorMetadata],
666666
token_distribution_schedule: &TokenDistributionSchedule,
667+
system_packages: &[SystemPackage],
667668
) -> TxContext {
668669
let mut hasher = DefaultHash::default();
669670
hasher.update(b"sui-genesis");
670671
hasher.update(&bcs::to_bytes(genesis_chain_parameters).unwrap());
671672
hasher.update(&bcs::to_bytes(genesis_validators).unwrap());
672673
hasher.update(&bcs::to_bytes(token_distribution_schedule).unwrap());
673-
for system_package in BuiltInFramework::iter_system_packages() {
674+
for system_package in system_packages {
674675
hasher.update(&bcs::to_bytes(system_package.bytes()).unwrap());
675676
}
676677

@@ -717,11 +718,19 @@ fn build_unsigned_genesis_data(
717718

718719
let epoch_data = EpochData::new_genesis(genesis_chain_parameters.chain_start_timestamp_ms);
719720

721+
// Get the correct system packages for our protocol version. If we cannot find the snapshot
722+
// that means that we must be at the latest version and we should use the latest version of the
723+
// framework.
724+
let system_packages =
725+
sui_framework_snapshot::load_bytecode_snapshot(parameters.protocol_version.as_u64())
726+
.unwrap_or_else(|_| BuiltInFramework::iter_system_packages().cloned().collect());
727+
720728
let mut genesis_ctx = create_genesis_context(
721729
&epoch_data,
722730
&genesis_chain_parameters,
723731
&genesis_validators,
724732
token_distribution_schedule,
733+
&system_packages,
725734
);
726735

727736
// Use a throwaway metrics registry for genesis transaction execution.
@@ -734,6 +743,7 @@ fn build_unsigned_genesis_data(
734743
&genesis_validators,
735744
&genesis_chain_parameters,
736745
token_distribution_schedule,
746+
system_packages,
737747
metrics.clone(),
738748
);
739749

@@ -867,6 +877,7 @@ fn create_genesis_objects(
867877
validators: &[GenesisValidatorMetadata],
868878
parameters: &GenesisChainParameters,
869879
token_distribution_schedule: &TokenDistributionSchedule,
880+
system_packages: Vec<SystemPackage>,
870881
metrics: Arc<LimitsMetrics>,
871882
) -> Vec<Object> {
872883
let mut store = InMemoryStorage::new(Vec::new());
@@ -884,7 +895,7 @@ fn create_genesis_objects(
884895
let executor = sui_execution::executor(&protocol_config, paranoid_checks, silent)
885896
.expect("Creating an executor should not fail here");
886897

887-
for system_package in BuiltInFramework::iter_system_packages() {
898+
for system_package in system_packages.into_iter() {
888899
process_package(
889900
&mut store,
890901
executor.as_ref(),

0 commit comments

Comments
 (0)