diff --git a/crates/sui-genesis-builder/src/lib.rs b/crates/sui-genesis-builder/src/lib.rs index 7d440f701f309..269c044e3f913 100644 --- a/crates/sui-genesis-builder/src/lib.rs +++ b/crates/sui-genesis-builder/src/lib.rs @@ -19,9 +19,7 @@ use sui_config::genesis::{ use sui_execution::{self, Executor}; use sui_framework::{BuiltInFramework, SystemPackage}; use sui_protocol_config::{Chain, ProtocolConfig, ProtocolVersion}; -use sui_types::base_types::{ - ExecutionDigests, ObjectID, SequenceNumber, SuiAddress, TransactionDigest, TxContext, -}; +use sui_types::base_types::{ExecutionDigests, ObjectID, SequenceNumber, TransactionDigest}; use sui_types::bridge::{BridgeChainId, BRIDGE_CREATE_FUNCTION_NAME, BRIDGE_MODULE_NAME}; use sui_types::committee::Committee; use sui_types::crypto::{ @@ -681,16 +679,15 @@ impl Builder { } } -// Create a Genesis Txn Context to be used when generating genesis objects by hashing all of the +// Create a Genesis Txn Digest to be used when generating genesis objects by hashing all of the // inputs into genesis ans using that as our "Txn Digest". This is done to ensure that coin objects // created between chains are unique -fn create_genesis_context( - epoch_data: &EpochData, +fn create_genesis_digest( genesis_chain_parameters: &GenesisChainParameters, genesis_validators: &[GenesisValidatorMetadata], token_distribution_schedule: &TokenDistributionSchedule, system_packages: &[SystemPackage], -) -> TxContext { +) -> TransactionDigest { let mut hasher = DefaultHash::default(); hasher.update(b"sui-genesis"); hasher.update(bcs::to_bytes(genesis_chain_parameters).unwrap()); @@ -701,13 +698,7 @@ fn create_genesis_context( } let hash = hasher.finalize(); - let genesis_transaction_digest = TransactionDigest::new(hash.into()); - - TxContext::new( - &SuiAddress::default(), - &genesis_transaction_digest, - epoch_data, - ) + TransactionDigest::new(hash.into()) } fn get_genesis_protocol_config(version: ProtocolVersion) -> ProtocolConfig { @@ -755,8 +746,7 @@ fn build_unsigned_genesis_data( // This is a no-op under normal conditions and only an issue with certain tests. update_system_packages_from_objects(&mut system_packages, objects); - let mut genesis_ctx = create_genesis_context( - &epoch_data, + let genesis_digest = create_genesis_digest( &genesis_chain_parameters, &genesis_validators, token_distribution_schedule, @@ -768,7 +758,8 @@ fn build_unsigned_genesis_data( let metrics = Arc::new(LimitsMetrics::new(®istry)); let objects = create_genesis_objects( - &mut genesis_ctx, + &epoch_data, + &genesis_digest, objects, &genesis_validators, &genesis_chain_parameters, @@ -957,7 +948,8 @@ fn create_genesis_transaction( } fn create_genesis_objects( - genesis_ctx: &mut TxContext, + epoch_data: &EpochData, + genesis_digest: &TransactionDigest, input_objects: &[Object], validators: &[GenesisValidatorMetadata], parameters: &GenesisChainParameters, @@ -982,7 +974,8 @@ fn create_genesis_objects( process_package( &mut store, executor.as_ref(), - genesis_ctx, + epoch_data, + genesis_digest, &system_package.modules(), system_package.dependencies().to_vec(), &protocol_config, @@ -1001,7 +994,8 @@ fn create_genesis_objects( &mut store, executor.as_ref(), validators, - genesis_ctx, + epoch_data, + genesis_digest, parameters, token_distribution_schedule, metrics, @@ -1014,7 +1008,8 @@ fn create_genesis_objects( fn process_package( store: &mut InMemoryStorage, executor: &dyn Executor, - ctx: &mut TxContext, + epoch_data: &EpochData, + genesis_digest: &TransactionDigest, modules: &[CompiledModule], dependencies: Vec, protocol_config: &ProtocolConfig, @@ -1070,7 +1065,9 @@ fn process_package( &*store, protocol_config, metrics, - ctx, + epoch_data.epoch_id(), + epoch_data.epoch_start_timestamp(), + genesis_digest, CheckedInputObjects::new_for_genesis(loaded_dependencies), pt, )?; @@ -1084,7 +1081,8 @@ pub fn generate_genesis_system_object( store: &mut InMemoryStorage, executor: &dyn Executor, genesis_validators: &[GenesisValidatorMetadata], - genesis_ctx: &mut TxContext, + epoch_data: &EpochData, + genesis_digest: &TransactionDigest, genesis_chain_parameters: &GenesisChainParameters, token_distribution_schedule: &TokenDistributionSchedule, metrics: Arc, @@ -1196,7 +1194,9 @@ pub fn generate_genesis_system_object( &*store, &protocol_config, metrics, - genesis_ctx, + epoch_data.epoch_id(), + epoch_data.epoch_start_timestamp(), + genesis_digest, CheckedInputObjects::new_for_genesis(vec![]), pt, )?; diff --git a/sui-execution/latest/sui-adapter/src/execution_engine.rs b/sui-execution/latest/sui-adapter/src/execution_engine.rs index 306e2a9d25126..d06e5d2789841 100644 --- a/sui-execution/latest/sui-adapter/src/execution_engine.rs +++ b/sui-execution/latest/sui-adapter/src/execution_engine.rs @@ -292,6 +292,7 @@ mod checked { let is_genesis_tx = matches!(transaction_kind, TransactionKind::Genesis(_)); let advance_epoch_gas_summary = transaction_kind.get_advance_epoch_tx_gas_summary(); + let digest = tx_ctx.digest(); // We must charge object read here during transaction execution, because if this fails // we must still ensure an effect is committed and all objects versions incremented @@ -371,7 +372,7 @@ mod checked { if let Err(e) = run_conservation_checks::( temporary_store, gas_charger, - tx_ctx, + digest, move_vm, protocol_config.simple_conservation_checks(), enable_expensive_checks, @@ -390,7 +391,7 @@ mod checked { fn run_conservation_checks( temporary_store: &mut TemporaryStore<'_>, gas_charger: &mut GasCharger, - tx_ctx: &mut TxContext, + tx_digest: TransactionDigest, move_vm: &Arc, simple_conservation_checks: bool, enable_expensive_checks: bool, @@ -449,7 +450,7 @@ mod checked { // we will create or destroy SUI otherwise panic!( "SUI conservation fail in tx block {}: {}\nGas status is {}\nTx was ", - tx_ctx.digest(), + tx_digest, recovery_err, gas_charger.summary() ) @@ -888,11 +889,11 @@ mod checked { if result.is_err() { tracing::error!( - "Failed to execute advance epoch transaction. Switching to safe mode. Error: {:?}. Input objects: {:?}. Tx data: {:?}", - result.as_ref().err(), - temporary_store.objects(), - change_epoch, - ); + "Failed to execute advance epoch transaction. Switching to safe mode. Error: {:?}. Input objects: {:?}. Tx data: {:?}", + result.as_ref().err(), + temporary_store.objects(), + change_epoch, + ); temporary_store.drop_writes(); // Must reset the storage rebate since we are re-executing. gas_charger.reset_storage_cost_and_rebate(); @@ -954,6 +955,7 @@ mod checked { protocol_config: &ProtocolConfig, metrics: Arc, ) { + let digest = tx_ctx.digest(); let binary_config = to_binary_config(protocol_config); for (version, modules, dependencies) in change_epoch.system_packages.into_iter() { let deserialized_modules: Vec<_> = modules @@ -986,7 +988,7 @@ mod checked { &deserialized_modules, version, dependencies, - tx_ctx.digest(), + digest, ); info!( diff --git a/sui-execution/latest/sui-adapter/src/temporary_store.rs b/sui-execution/latest/sui-adapter/src/temporary_store.rs index 8e4223f2485ed..b172ed3e79180 100644 --- a/sui-execution/latest/sui-adapter/src/temporary_store.rs +++ b/sui-execution/latest/sui-adapter/src/temporary_store.rs @@ -123,6 +123,10 @@ impl<'backing> TemporaryStore<'backing> { &self.input_objects } + pub fn objects_created_count(&self) -> usize { + self.execution_results.created_object_ids.len() + } + pub fn update_object_version_and_prev_tx(&mut self) { self.execution_results.update_version_and_previous_tx( self.lamport_timestamp, diff --git a/sui-execution/src/executor.rs b/sui-execution/src/executor.rs index 62b0628012c07..765627bc18439 100644 --- a/sui-execution/src/executor.rs +++ b/sui-execution/src/executor.rs @@ -5,7 +5,7 @@ use std::{collections::HashSet, sync::Arc}; use sui_protocol_config::ProtocolConfig; use sui_types::storage::BackingStore; use sui_types::{ - base_types::{ObjectRef, SuiAddress, TxContext}, + base_types::{ObjectRef, SuiAddress}, committee::EpochId, digests::TransactionDigest, effects::TransactionEffects, @@ -81,8 +81,11 @@ pub trait Executor { // Configuration protocol_config: &ProtocolConfig, metrics: Arc, - // Genesis State - tx_context: &mut TxContext, + // Epoch + epoch_id: EpochId, + epoch_timestamp_ms: u64, + // Genesis Digest + transaction_digest: &TransactionDigest, // Transaction input_objects: CheckedInputObjects, pt: ProgrammableTransaction, diff --git a/sui-execution/src/latest.rs b/sui-execution/src/latest.rs index 4fb142dda49b9..a4d8a4c09c4c8 100644 --- a/sui-execution/src/latest.rs +++ b/sui-execution/src/latest.rs @@ -167,16 +167,24 @@ impl executor::Executor for Executor { store: &dyn BackingStore, protocol_config: &ProtocolConfig, metrics: Arc, - tx_context: &mut TxContext, + epoch_id: EpochId, + epoch_timestamp_ms: u64, + transaction_digest: &TransactionDigest, input_objects: CheckedInputObjects, pt: ProgrammableTransaction, ) -> Result { + let mut tx_context = TxContext::new_from_components( + &SuiAddress::default(), + transaction_digest, + &epoch_id, + epoch_timestamp_ms, + ); execute_genesis_state_update( store, protocol_config, metrics, &self.0, - tx_context, + &mut tx_context, input_objects, pt, ) diff --git a/sui-execution/src/v0.rs b/sui-execution/src/v0.rs index dd01e5f0dce65..12646da866cf9 100644 --- a/sui-execution/src/v0.rs +++ b/sui-execution/src/v0.rs @@ -167,10 +167,18 @@ impl executor::Executor for Executor { store: &dyn BackingStore, protocol_config: &ProtocolConfig, metrics: Arc, - tx_context: &mut TxContext, + epoch_id: EpochId, + epoch_timestamp_ms: u64, + transaction_digest: &TransactionDigest, input_objects: CheckedInputObjects, pt: ProgrammableTransaction, ) -> Result { + let tx_context = &mut TxContext::new_from_components( + &SuiAddress::default(), + transaction_digest, + &epoch_id, + epoch_timestamp_ms, + ); execute_genesis_state_update( store, protocol_config, diff --git a/sui-execution/src/v1.rs b/sui-execution/src/v1.rs index 4f6c15f0c7e6b..bf1c1d81394b1 100644 --- a/sui-execution/src/v1.rs +++ b/sui-execution/src/v1.rs @@ -167,10 +167,18 @@ impl executor::Executor for Executor { store: &dyn BackingStore, protocol_config: &ProtocolConfig, metrics: Arc, - tx_context: &mut TxContext, + epoch_id: EpochId, + epoch_timestamp_ms: u64, + transaction_digest: &TransactionDigest, input_objects: CheckedInputObjects, pt: ProgrammableTransaction, ) -> Result { + let tx_context = &mut TxContext::new_from_components( + &SuiAddress::default(), + transaction_digest, + &epoch_id, + epoch_timestamp_ms, + ); execute_genesis_state_update( store, protocol_config, diff --git a/sui-execution/src/v2.rs b/sui-execution/src/v2.rs index 98c978bfe038d..2b08600c7c078 100644 --- a/sui-execution/src/v2.rs +++ b/sui-execution/src/v2.rs @@ -167,10 +167,18 @@ impl executor::Executor for Executor { store: &dyn BackingStore, protocol_config: &ProtocolConfig, metrics: Arc, - tx_context: &mut TxContext, + epoch_id: EpochId, + epoch_timestamp_ms: u64, + transaction_digest: &TransactionDigest, input_objects: CheckedInputObjects, pt: ProgrammableTransaction, ) -> Result { + let tx_context = &mut TxContext::new_from_components( + &SuiAddress::default(), + transaction_digest, + &epoch_id, + epoch_timestamp_ms, + ); execute_genesis_state_update( store, protocol_config,