From d91f3d77ebe79be420d85bffd806c6cff4a779cc Mon Sep 17 00:00:00 2001 From: Valerii Reutov Date: Wed, 30 Oct 2024 01:36:56 -0700 Subject: [PATCH] fix(iota-e2e-tests): fixed framework update tests (#3736) * fix(iota-e2e-tests): fixed framework update tests data * fix(iota-core): assert in case if an advance epoch transaction was executed in the safe mode * fix(iota-core): code cleanup --- crates/iota-core/src/authority.rs | 18 ++- crates/iota-core/src/checkpoints/mod.rs | 11 +- .../base/sources/genesis.move | 24 ++-- .../base/sources/iota_system.move | 44 ++++--- .../base/sources/iota_system_state_inner.move | 92 ++++++++++---- .../base/sources/validator.move | 19 ++- .../base/sources/validator_wrapper.move | 26 ++-- .../deep_upgrade/sources/genesis.move | 26 ++-- .../deep_upgrade/sources/iota_system.move | 45 ++++--- .../sources/iota_system_state_inner.move | 115 ++++++++++++------ .../deep_upgrade/sources/validator.move | 19 ++- .../sources/validator_wrapper.move | 25 ++-- .../safe_mode/sources/genesis.move | 24 ++-- .../safe_mode/sources/iota_system.move | 42 ++++--- .../sources/iota_system_state_inner.move | 83 +++++++++---- .../safe_mode/sources/validator.move | 13 +- .../safe_mode/sources/validator_wrapper.move | 2 +- .../shallow_upgrade/sources/genesis.move | 24 ++-- .../shallow_upgrade/sources/iota_system.move | 45 ++++--- .../sources/iota_system_state_inner.move | 104 +++++++++++----- .../shallow_upgrade/sources/validator.move | 13 +- .../sources/validator_wrapper.move | 26 ++-- .../simtest_iota_system_state_inner.rs | 4 + 23 files changed, 533 insertions(+), 311 deletions(-) diff --git a/crates/iota-core/src/authority.rs b/crates/iota-core/src/authority.rs index b783c447b90..2148444201e 100644 --- a/crates/iota-core/src/authority.rs +++ b/crates/iota-core/src/authority.rs @@ -4514,7 +4514,11 @@ impl AuthorityState { gas_cost_summary: &GasCostSummary, checkpoint: CheckpointSequenceNumber, epoch_start_timestamp_ms: CheckpointTimestamp, - ) -> anyhow::Result<(IotaSystemState, SystemEpochInfoEventV1, TransactionEffects)> { + ) -> anyhow::Result<( + IotaSystemState, + Option, + TransactionEffects, + )> { let mut txns = Vec::new(); if let Some(tx) = self.create_authenticator_state_tx(epoch_store) { @@ -4644,11 +4648,13 @@ impl AuthorityState { .data .iter() .find(|event| event.is_system_epoch_info_event()) - .expect("end of epoch tx must emit system epoch info event"); - let system_epoch_info_event = bcs::from_bytes::( - &system_epoch_info_event.contents, - ) - .expect("deserialization should succeed since we asserted that the event is of this type"); + .map(|event| { + bcs::from_bytes::(&event.contents) + .expect("event deserialization should succeed as type was pre-validated") + }); + // The system epoch info event can be `None` in case if the `advance_epoch` + // Move function call failed and was executed in the safe mode. + assert!(system_epoch_info_event.is_some() || system_obj.safe_mode()); // We must write tx and effects to the state sync tables so that state sync is // able to deliver to the transaction to CheckpointExecutor after it is diff --git a/crates/iota-core/src/checkpoints/mod.rs b/crates/iota-core/src/checkpoints/mod.rs index f23767c8f84..5fcec61ad33 100644 --- a/crates/iota-core/src/checkpoints/mod.rs +++ b/crates/iota-core/src/checkpoints/mod.rs @@ -1445,11 +1445,16 @@ impl CheckpointBuilder { ) .await?; + // The system epoch info event can be `None` in case if the `advance_epoch` + // Move function call failed and was executed in the safe mode. + // In this case, the tokens supply should be unchanged. + // // SAFETY: The number of minted and burnt tokens easily fit into an i64 and due // to those small numbers, no overflows will occur during conversion or // subtraction. - let epoch_supply_change = system_epoch_info_event.minted_tokens_amount as i64 - - system_epoch_info_event.burnt_tokens_amount as i64; + let epoch_supply_change = system_epoch_info_event.map_or(0, |event| { + event.minted_tokens_amount as i64 - event.burnt_tokens_amount as i64 + }); let committee = system_state_obj .get_current_epoch_committee() @@ -1574,7 +1579,7 @@ impl CheckpointBuilder { checkpoint_effects: &mut Vec, signatures: &mut Vec>, checkpoint: CheckpointSequenceNumber, - ) -> anyhow::Result<(IotaSystemState, SystemEpochInfoEventV1)> { + ) -> anyhow::Result<(IotaSystemState, Option)> { let (system_state, system_epoch_info_event, effects) = self .state .create_and_execute_advance_epoch_tx( diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/genesis.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/genesis.move index e6bff0442aa..f4d69976b8b 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/genesis.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/genesis.move @@ -3,12 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::genesis { - use std::vector; - use iota::balance::{Self, Balance}; - use iota::object::UID; - use iota::iota::IOTA; - use iota::tx_context::{Self, TxContext}; - use std::option::Option; + use std::string::String; + + use iota::balance; + use iota::iota::IotaTreasuryCap; + use iota::timelock::SystemTimelockCap; use iota_system::iota_system; use iota_system::validator; @@ -55,15 +54,20 @@ module iota_system::genesis { public struct TokenAllocation has drop { recipient_address: address, amount_nanos: u64, + staked_with_validator: Option
, + staked_with_timelock_expiration: Option, } + #[allow(unused_function)] fun create( iota_system_state_id: UID, - mut iota_supply: Balance, + mut iota_treasury_cap: IotaTreasuryCap, genesis_chain_parameters: GenesisChainParameters, genesis_validators: vector, _token_distribution_schedule: TokenDistributionSchedule, + _timelock_genesis_label: Option, + system_timelock_cap: SystemTimelockCap, ctx: &mut TxContext, ) { assert!(tx_context::epoch(ctx) == 0, 0); @@ -97,7 +101,7 @@ module iota_system::genesis { network_address, p2p_address, primary_address, - balance::split(&mut iota_supply, 2500), + iota_treasury_cap.mint_balance(2500, ctx), ctx ); @@ -108,11 +112,13 @@ module iota_system::genesis { iota_system::create( iota_system_state_id, + iota_treasury_cap, validators, - iota_supply, // storage_fund + balance::zero(), genesis_chain_parameters.protocol_version, genesis_chain_parameters.chain_start_timestamp_ms, genesis_chain_parameters.epoch_duration_ms, + system_timelock_cap, ctx, ); } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/iota_system.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/iota_system.move index 858f6d4d29d..9054f11b4a6 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/iota_system.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/iota_system.move @@ -3,18 +3,16 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::iota_system { - use std::vector; - use iota::balance::Balance; - use iota::object::UID; - use iota::iota::IOTA; - use iota::transfer; - use iota::tx_context::{Self, TxContext}; use iota::dynamic_field; + use iota::iota::IOTA; + use iota::iota::IotaTreasuryCap; + use iota::timelock::SystemTimelockCap; - use iota_system::validator::Validator; - use iota_system::iota_system_state_inner::IotaSystemStateInner; - use iota_system::iota_system_state_inner; + use iota_system::validator::ValidatorV1; + use iota_system::iota_system_state_inner::{Self, IotaSystemStateV1}; + + const SYSTEM_TIMELOCK_CAP_DF_KEY: vector = b"sys_timelock_cap"; public struct IotaSystemState has key { id: UID, @@ -23,14 +21,17 @@ module iota_system::iota_system { public(package) fun create( id: UID, - validators: vector, + iota_treasury_cap: IotaTreasuryCap, + validators: vector, storage_fund: Balance, protocol_version: u64, epoch_start_timestamp_ms: u64, epoch_duration_ms: u64, + system_timelock_cap: SystemTimelockCap, ctx: &mut TxContext, ) { let system_state = iota_system_state_inner::create( + iota_treasury_cap, validators, storage_fund, protocol_version, @@ -44,21 +45,22 @@ module iota_system::iota_system { version, }; dynamic_field::add(&mut self.id, version, system_state); + dynamic_field::add(&mut self.id, SYSTEM_TIMELOCK_CAP_DF_KEY, system_timelock_cap); transfer::share_object(self); } + #[allow(unused_function)] fun advance_epoch( + validator_target_reward: u64, storage_charge: Balance, computation_reward: Balance, wrapper: &mut IotaSystemState, new_epoch: u64, next_protocol_version: u64, storage_rebate: u64, - _non_refundable_storage_fee: u64, - _storage_fund_reinvest_rate: u64, // share of storage fund's rewards that's reinvested - // into storage fund, in basis point. - _reward_slashing_rate: u64, // how much rewards are slashed to punish a validator, in bps. - epoch_start_timestamp_ms: u64, // Timestamp of the epoch start + non_refundable_storage_fee: u64, + reward_slashing_rate: u64, + epoch_start_timestamp_ms: u64, ctx: &mut TxContext, ) : Balance { let self = load_system_state_mut(wrapper); @@ -67,28 +69,32 @@ module iota_system::iota_system { self, new_epoch, next_protocol_version, + validator_target_reward, storage_charge, computation_reward, storage_rebate, + non_refundable_storage_fee, + reward_slashing_rate, epoch_start_timestamp_ms, + ctx ); storage_rebate } - public fun active_validator_addresses(wrapper: &mut IotaSystemState): vector
{ + public fun active_validator_addresses(_wrapper: &mut IotaSystemState): vector
{ vector::empty() } - fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateInner { + fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateV1 { load_inner_maybe_upgrade(self) } - fun load_inner_maybe_upgrade(self: &mut IotaSystemState): &mut IotaSystemStateInner { + fun load_inner_maybe_upgrade(self: &mut IotaSystemState): &mut IotaSystemStateV1 { let version = self.version; // TODO: This is where we check the version and perform upgrade if necessary. - let inner: &mut IotaSystemStateInner = dynamic_field::borrow_mut(&mut self.id, version); + let inner: &mut IotaSystemStateV1 = dynamic_field::borrow_mut(&mut self.id, version); assert!(iota_system_state_inner::system_state_version(inner) == version, 0); inner } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/iota_system_state_inner.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/iota_system_state_inner.move index b5ecd4e6e21..e3abf0b3c56 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/iota_system_state_inner.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/iota_system_state_inner.move @@ -3,39 +3,53 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::iota_system_state_inner { + use iota::bag::{Self, Bag}; use iota::balance::{Self, Balance}; + use iota::event; use iota::iota::IOTA; - use iota::tx_context::TxContext; - use iota::bag::{Self, Bag}; + use iota::iota::IotaTreasuryCap; use iota::table::{Self, Table}; - use iota::object::ID; - use iota_system::validator::Validator; - use iota_system::validator_wrapper::ValidatorWrapper; + use iota_system::validator::ValidatorV1; + use iota_system::validator_wrapper::Validator; use iota_system::validator_wrapper; use iota_system::validator; - use iota::object; const SYSTEM_STATE_VERSION_V1: u64 = 18446744073709551605; // u64::MAX - 10 - public struct SystemParameters has store { + public struct SystemEpochInfoEventV1 has copy, drop { + epoch: u64, + protocol_version: u64, + reference_gas_price: u64, + total_stake: u64, + storage_charge: u64, + storage_rebate: u64, + storage_fund_balance: u64, + total_gas_fees: u64, + total_stake_rewards_distributed: u64, + burnt_tokens_amount: u64, + minted_tokens_amount: u64, + } + + public struct SystemParametersV1 has store { epoch_duration_ms: u64, extra_fields: Bag, } - public struct ValidatorSet has store { - active_validators: vector, - inactive_validators: Table, + public struct ValidatorSetV1 has store { + active_validators: vector, + inactive_validators: Table, extra_fields: Bag, } - public struct IotaSystemStateInner has store { + public struct IotaSystemStateV1 has store { epoch: u64, protocol_version: u64, system_state_version: u64, - validators: ValidatorSet, + iota_treasury_cap: IotaTreasuryCap, + validators: ValidatorSetV1, storage_fund: Balance, - parameters: SystemParameters, + parameters: SystemParametersV1, reference_gas_price: u64, safe_mode: bool, epoch_start_timestamp_ms: u64, @@ -43,21 +57,23 @@ module iota_system::iota_system_state_inner { } public(package) fun create( - validators: vector, + iota_treasury_cap: IotaTreasuryCap, + validators: vector, storage_fund: Balance, protocol_version: u64, epoch_start_timestamp_ms: u64, epoch_duration_ms: u64, ctx: &mut TxContext, - ): IotaSystemStateInner { + ): IotaSystemStateV1 { let validators = new_validator_set(validators, ctx); - let mut system_state = IotaSystemStateInner { + let mut system_state = IotaSystemStateV1 { epoch: 0, protocol_version, system_state_version: genesis_system_state_version(), + iota_treasury_cap, validators, storage_fund, - parameters: SystemParameters { + parameters: SystemParametersV1 { epoch_duration_ms, extra_fields: bag::new(ctx), }, @@ -72,13 +88,17 @@ module iota_system::iota_system_state_inner { } public(package) fun advance_epoch( - self: &mut IotaSystemStateInner, + self: &mut IotaSystemStateV1, new_epoch: u64, next_protocol_version: u64, - storage_charge: Balance, - computation_reward: Balance, - storage_rebate_amount: u64, + _validator_target_reward: u64, + mut storage_charge: Balance, + mut computation_reward: Balance, + mut storage_rebate_amount: u64, + mut _non_refundable_storage_fee_amount: u64, + _reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, + _ctx: &mut TxContext, ) : Balance { self.epoch_start_timestamp_ms = epoch_start_timestamp_ms; self.epoch = self.epoch + 1; @@ -86,19 +106,39 @@ module iota_system::iota_system_state_inner { self.safe_mode = false; self.protocol_version = next_protocol_version; + let storage_charge_value = storage_charge.value(); + let total_gas_fees = computation_reward.value(); + balance::join(&mut self.storage_fund, computation_reward); balance::join(&mut self.storage_fund, storage_charge); let storage_rebate = balance::split(&mut self.storage_fund, storage_rebate_amount); + + event::emit( + SystemEpochInfoEventV1 { + epoch: self.epoch, + protocol_version: self.protocol_version, + reference_gas_price: self.reference_gas_price, + total_stake: 0, + storage_charge: storage_charge_value, + storage_rebate: storage_rebate_amount, + storage_fund_balance: self.storage_fund.value(), + total_gas_fees, + total_stake_rewards_distributed: 0, + burnt_tokens_amount: 0, + minted_tokens_amount: 0, + } + ); + storage_rebate } - public(package) fun protocol_version(self: &IotaSystemStateInner): u64 { self.protocol_version } - public(package) fun system_state_version(self: &IotaSystemStateInner): u64 { self.system_state_version } + public(package) fun protocol_version(self: &IotaSystemStateV1): u64 { self.protocol_version } + public(package) fun system_state_version(self: &IotaSystemStateV1): u64 { self.system_state_version } public(package) fun genesis_system_state_version(): u64 { SYSTEM_STATE_VERSION_V1 } - public(package) fun add_dummy_inactive_validator_for_testing(self: &mut IotaSystemStateInner, ctx: &mut TxContext) { + public(package) fun add_dummy_inactive_validator_for_testing(self: &mut IotaSystemStateV1, ctx: &mut TxContext) { // Add a new entry to the inactive validator table for upgrade testing. let dummy_inactive_validator = validator_wrapper::create_v1( validator::new_dummy_inactive_validator(ctx), @@ -107,8 +147,8 @@ module iota_system::iota_system_state_inner { table::add(&mut self.validators.inactive_validators, object::id_from_address(@0x0), dummy_inactive_validator); } - fun new_validator_set(init_active_validators: vector, ctx: &mut TxContext): ValidatorSet { - ValidatorSet { + fun new_validator_set(init_active_validators: vector, ctx: &mut TxContext): ValidatorSetV1 { + ValidatorSetV1 { active_validators: init_active_validators, inactive_validators: table::new(ctx), extra_fields: bag::new(ctx), diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/validator.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/validator.move index c3aa4b4a4b3..8b3f056e0d2 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/validator.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/validator.move @@ -5,13 +5,12 @@ module iota_system::validator { use std::ascii; - use iota::tx_context::TxContext; use std::string::{Self, String}; use iota::bag::{Self, Bag}; use iota::balance::{Self, Balance}; use iota::iota::IOTA; - public struct ValidatorMetadata has store { + public struct ValidatorMetadataV1 has store { iota_address: address, authority_pubkey_bytes: vector, network_pubkey_bytes: vector, @@ -22,8 +21,8 @@ module iota_system::validator { extra_fields: Bag, } - public struct Validator has store { - metadata: ValidatorMetadata, + public struct ValidatorV1 has store { + metadata: ValidatorMetadataV1, voting_power: u64, stake: Balance, extra_fields: Bag, @@ -39,8 +38,8 @@ module iota_system::validator { primary_address: vector, init_stake: Balance, ctx: &mut TxContext - ): Validator { - let metadata = ValidatorMetadata { + ): ValidatorV1 { + let metadata = ValidatorMetadataV1 { iota_address, authority_pubkey_bytes, network_pubkey_bytes, @@ -51,7 +50,7 @@ module iota_system::validator { extra_fields: bag::new(ctx), }; - Validator { + ValidatorV1 { metadata, voting_power: balance::value(&init_stake), stake: init_stake, @@ -61,8 +60,8 @@ module iota_system::validator { public(package) fun new_dummy_inactive_validator( ctx: &mut TxContext - ): Validator { - let metadata = ValidatorMetadata { + ): ValidatorV1 { + let metadata = ValidatorMetadataV1 { iota_address: @0x0, authority_pubkey_bytes: vector[], network_pubkey_bytes: vector[], @@ -73,7 +72,7 @@ module iota_system::validator { extra_fields: bag::new(ctx), }; - Validator { + ValidatorV1 { metadata, voting_power: 0, stake: balance::zero(), diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/validator_wrapper.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/validator_wrapper.move index ed74b47dd7b..d83238f0b9d 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/validator_wrapper.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/base/sources/validator_wrapper.move @@ -3,47 +3,45 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::validator_wrapper { - use iota::versioned::Versioned; - use iota::versioned; - use iota::tx_context::TxContext; - use iota_system::validator::Validator; + use iota::versioned::{Self, Versioned}; + use iota_system::validator::ValidatorV1; const VALIDATOR_VERSION_V1: u64 = 18446744073709551605; // u64::MAX - 10 const EInvalidVersion: u64 = 0; - public struct ValidatorWrapper has store { + public struct Validator has store { inner: Versioned } // Validator corresponds to version 1. - public(package) fun create_v1(validator: Validator, ctx: &mut TxContext): ValidatorWrapper { - ValidatorWrapper { + public(package) fun create_v1(validator: ValidatorV1, ctx: &mut TxContext): Validator { + Validator { inner: versioned::create(VALIDATOR_VERSION_V1, validator, ctx) } } /// This function should always return the latest supported version. /// If the inner version is old, we upgrade it lazily in-place. - public(package) fun load_validator_maybe_upgrade(self: &mut ValidatorWrapper): &mut Validator { + public(package) fun load_validator_maybe_upgrade(self: &mut Validator): &mut ValidatorV1 { upgrade_to_latest(self); - versioned::load_value_mut(&mut self.inner) + versioned::load_value_mut(&mut self.inner) } /// Destroy the wrapper and retrieve the inner validator object. - public(package) fun destroy(mut self: ValidatorWrapper): Validator { - upgrade_to_latest(&mut self); - let ValidatorWrapper { inner } = self; + public(package) fun destroy(self: Validator): ValidatorV1 { + upgrade_to_latest(&self); + let Validator { inner } = self; versioned::destroy(inner) } - fun upgrade_to_latest(self: &mut ValidatorWrapper) { + fun upgrade_to_latest(self: &Validator) { let version = version(self); // TODO: When new versions are added, we need to explicitly upgrade here. assert!(version == VALIDATOR_VERSION_V1, EInvalidVersion); } - fun version(self: &ValidatorWrapper): u64 { + fun version(self: &Validator): u64 { versioned::version(&self.inner) } } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/genesis.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/genesis.move index 85852671040..f4d69976b8b 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/genesis.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/genesis.move @@ -3,12 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::genesis { - use std::vector; - use iota::balance::{Self, Balance}; - use iota::object::UID; - use iota::iota::IOTA; - use iota::tx_context::{Self, TxContext}; - use std::option::Option; + use std::string::String; + + use iota::balance; + use iota::iota::IotaTreasuryCap; + use iota::timelock::SystemTimelockCap; use iota_system::iota_system; use iota_system::validator; @@ -46,7 +45,7 @@ module iota_system::genesis { validator_very_low_stake_threshold: u64, validator_low_stake_grace_period: u64, } - + public struct TokenDistributionSchedule has drop { pre_minted_supply: u64, allocations: vector, @@ -55,15 +54,20 @@ module iota_system::genesis { public struct TokenAllocation has drop { recipient_address: address, amount_nanos: u64, + staked_with_validator: Option
, + staked_with_timelock_expiration: Option, } + #[allow(unused_function)] fun create( iota_system_state_id: UID, - mut iota_supply: Balance, + mut iota_treasury_cap: IotaTreasuryCap, genesis_chain_parameters: GenesisChainParameters, genesis_validators: vector, _token_distribution_schedule: TokenDistributionSchedule, + _timelock_genesis_label: Option, + system_timelock_cap: SystemTimelockCap, ctx: &mut TxContext, ) { assert!(tx_context::epoch(ctx) == 0, 0); @@ -97,7 +101,7 @@ module iota_system::genesis { network_address, p2p_address, primary_address, - balance::split(&mut iota_supply, 2500), + iota_treasury_cap.mint_balance(2500, ctx), ctx ); @@ -108,11 +112,13 @@ module iota_system::genesis { iota_system::create( iota_system_state_id, + iota_treasury_cap, validators, - iota_supply, // storage_fund + balance::zero(), genesis_chain_parameters.protocol_version, genesis_chain_parameters.chain_start_timestamp_ms, genesis_chain_parameters.epoch_duration_ms, + system_timelock_cap, ctx, ); } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/iota_system.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/iota_system.move index 2232766f243..549ba9c21a3 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/iota_system.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/iota_system.move @@ -3,17 +3,16 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::iota_system { - use std::vector; - use iota::balance::Balance; - use iota::object::UID; - use iota::iota::IOTA; - use iota::transfer; - use iota::tx_context::{Self, TxContext}; use iota::dynamic_field; + use iota::iota::IOTA; + use iota::iota::IotaTreasuryCap; + use iota::timelock::SystemTimelockCap; - use iota_system::validator::Validator; - use iota_system::iota_system_state_inner::{Self, IotaSystemStateInnerV2, IotaSystemStateInner}; + use iota_system::validator::ValidatorV1; + use iota_system::iota_system_state_inner::{Self, IotaSystemStateV1, IotaSystemStateV2}; + + const SYSTEM_TIMELOCK_CAP_DF_KEY: vector = b"sys_timelock_cap"; public struct IotaSystemState has key { id: UID, @@ -22,14 +21,17 @@ module iota_system::iota_system { public(package) fun create( id: UID, - validators: vector, + iota_treasury_cap: IotaTreasuryCap, + validators: vector, storage_fund: Balance, protocol_version: u64, epoch_start_timestamp_ms: u64, epoch_duration_ms: u64, + system_timelock_cap: SystemTimelockCap, ctx: &mut TxContext, ) { let system_state = iota_system_state_inner::create( + iota_treasury_cap, validators, storage_fund, protocol_version, @@ -43,21 +45,22 @@ module iota_system::iota_system { version, }; dynamic_field::add(&mut self.id, version, system_state); + dynamic_field::add(&mut self.id, SYSTEM_TIMELOCK_CAP_DF_KEY, system_timelock_cap); transfer::share_object(self); } + #[allow(unused_function)] fun advance_epoch( + validator_target_reward: u64, storage_charge: Balance, computation_reward: Balance, wrapper: &mut IotaSystemState, new_epoch: u64, next_protocol_version: u64, storage_rebate: u64, - _non_refundable_storage_fee: u64, - _storage_fund_reinvest_rate: u64, // share of storage fund's rewards that's reinvested - // into storage fund, in basis point. - _reward_slashing_rate: u64, // how much rewards are slashed to punish a validator, in bps. - epoch_start_timestamp_ms: u64, // Timestamp of the epoch start + non_refundable_storage_fee: u64, + reward_slashing_rate: u64, + epoch_start_timestamp_ms: u64, ctx: &mut TxContext, ) : Balance { let self = load_system_state_mut(wrapper); @@ -66,34 +69,38 @@ module iota_system::iota_system { self, new_epoch, next_protocol_version, + validator_target_reward, storage_charge, computation_reward, storage_rebate, + non_refundable_storage_fee, + reward_slashing_rate, epoch_start_timestamp_ms, + ctx ); storage_rebate } - public fun active_validator_addresses(wrapper: &mut IotaSystemState): vector
{ + public fun active_validator_addresses(_wrapper: &mut IotaSystemState): vector
{ vector::empty() } - fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateInnerV2 { + fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateV2 { load_inner_maybe_upgrade(self) } - fun load_inner_maybe_upgrade(self: &mut IotaSystemState): &mut IotaSystemStateInnerV2 { + fun load_inner_maybe_upgrade(self: &mut IotaSystemState): &mut IotaSystemStateV2 { let mut version = self.version; if (version == iota_system_state_inner::genesis_system_state_version()) { - let inner: IotaSystemStateInner = dynamic_field::remove(&mut self.id, version); + let inner: IotaSystemStateV1 = dynamic_field::remove(&mut self.id, version); let new_inner = iota_system_state_inner::v1_to_v2(inner); version = iota_system_state_inner::system_state_version(&new_inner); dynamic_field::add(&mut self.id, version, new_inner); self.version = version; }; - let inner: &mut IotaSystemStateInnerV2 = dynamic_field::borrow_mut(&mut self.id, version); + let inner: &mut IotaSystemStateV2 = dynamic_field::borrow_mut(&mut self.id, version); assert!(iota_system_state_inner::system_state_version(inner) == version, 0); inner } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/iota_system_state_inner.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/iota_system_state_inner.move index c37f2b07fdc..a1f64c1602d 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/iota_system_state_inner.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/iota_system_state_inner.move @@ -3,63 +3,76 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::iota_system_state_inner { - use std::vector; - + use iota::bag::{Self, Bag}; use iota::balance::{Self, Balance}; + use iota::event; use iota::iota::IOTA; - use iota::tx_context::TxContext; - use iota::bag::{Self, Bag}; + use iota::iota::IotaTreasuryCap; use iota::table::{Self, Table}; - use iota::object::ID; - use iota_system::validator::{Validator, ValidatorV2}; - use iota_system::validator_wrapper::ValidatorWrapper; + use iota_system::validator::{ValidatorV1, ValidatorV2}; + use iota_system::validator_wrapper::Validator; use iota_system::validator_wrapper; - use iota::object; use iota_system::validator; const SYSTEM_STATE_VERSION_V1: u64 = 18446744073709551605; // u64::MAX - 10 - // Not using MAX - 9 since it's already used in the shallow upgrade test. + // Not using MAX - 9 since it's already used in the shallow upgrade test. const SYSTEM_STATE_VERSION_V2: u64 = 18446744073709551607; // u64::MAX - 8 - public struct SystemParameters has store { + public struct SystemEpochInfoEventV1 has copy, drop { + epoch: u64, + protocol_version: u64, + reference_gas_price: u64, + total_stake: u64, + storage_charge: u64, + storage_rebate: u64, + storage_fund_balance: u64, + total_gas_fees: u64, + total_stake_rewards_distributed: u64, + burnt_tokens_amount: u64, + minted_tokens_amount: u64, + } + + public struct SystemParametersV1 has store { epoch_duration_ms: u64, extra_fields: Bag, } - public struct ValidatorSet has store { - active_validators: vector, - inactive_validators: Table, + public struct ValidatorSetV1 has store { + active_validators: vector, + inactive_validators: Table, extra_fields: Bag, } public struct ValidatorSetV2 has store { active_validators: vector, - inactive_validators: Table, + inactive_validators: Table, extra_fields: Bag, } - public struct IotaSystemStateInner has store { + public struct IotaSystemStateV1 has store { epoch: u64, protocol_version: u64, system_state_version: u64, - validators: ValidatorSet, + iota_treasury_cap: IotaTreasuryCap, + validators: ValidatorSetV1, storage_fund: Balance, - parameters: SystemParameters, + parameters: SystemParametersV1, reference_gas_price: u64, safe_mode: bool, epoch_start_timestamp_ms: u64, extra_fields: Bag, } - public struct IotaSystemStateInnerV2 has store { + public struct IotaSystemStateV2 has store { new_dummy_field: u64, epoch: u64, protocol_version: u64, system_state_version: u64, + iota_treasury_cap: IotaTreasuryCap, validators: ValidatorSetV2, storage_fund: Balance, - parameters: SystemParameters, + parameters: SystemParametersV1, reference_gas_price: u64, safe_mode: bool, epoch_start_timestamp_ms: u64, @@ -67,21 +80,23 @@ module iota_system::iota_system_state_inner { } public(package) fun create( - validators: vector, + iota_treasury_cap: IotaTreasuryCap, + validators: vector, storage_fund: Balance, protocol_version: u64, epoch_start_timestamp_ms: u64, epoch_duration_ms: u64, ctx: &mut TxContext, - ): IotaSystemStateInner { + ): IotaSystemStateV1 { let validators = new_validator_set(validators, ctx); - let system_state = IotaSystemStateInner { + let system_state = IotaSystemStateV1 { epoch: 0, protocol_version, system_state_version: genesis_system_state_version(), + iota_treasury_cap, validators, storage_fund, - parameters: SystemParameters { + parameters: SystemParametersV1 { epoch_duration_ms, extra_fields: bag::new(ctx), }, @@ -94,13 +109,17 @@ module iota_system::iota_system_state_inner { } public(package) fun advance_epoch( - self: &mut IotaSystemStateInnerV2, + self: &mut IotaSystemStateV2, new_epoch: u64, next_protocol_version: u64, - storage_charge: Balance, - computation_reward: Balance, - storage_rebate_amount: u64, + _validator_target_reward: u64, + mut storage_charge: Balance, + mut computation_reward: Balance, + mut storage_rebate_amount: u64, + mut _non_refundable_storage_fee_amount: u64, + _reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, + _ctx: &mut TxContext, ) : Balance { touch_dummy_inactive_validator(self); @@ -110,31 +129,52 @@ module iota_system::iota_system_state_inner { self.safe_mode = false; self.protocol_version = next_protocol_version; + let storage_charge_value = storage_charge.value(); + let total_gas_fees = computation_reward.value(); + balance::join(&mut self.storage_fund, computation_reward); balance::join(&mut self.storage_fund, storage_charge); let storage_rebate = balance::split(&mut self.storage_fund, storage_rebate_amount); + + event::emit( + SystemEpochInfoEventV1 { + epoch: self.epoch, + protocol_version: self.protocol_version, + reference_gas_price: self.reference_gas_price, + total_stake: 0, + storage_charge: storage_charge_value, + storage_rebate: storage_rebate_amount, + storage_fund_balance: self.storage_fund.value(), + total_gas_fees, + total_stake_rewards_distributed: 0, + burnt_tokens_amount: 0, + minted_tokens_amount: 0, + } + ); + storage_rebate } - public(package) fun protocol_version(self: &IotaSystemStateInnerV2): u64 { self.protocol_version } - public(package) fun system_state_version(self: &IotaSystemStateInnerV2): u64 { self.system_state_version } + public(package) fun protocol_version(self: &IotaSystemStateV2): u64 { self.protocol_version } + public(package) fun system_state_version(self: &IotaSystemStateV2): u64 { self.system_state_version } public(package) fun genesis_system_state_version(): u64 { SYSTEM_STATE_VERSION_V1 } - fun new_validator_set(init_active_validators: vector, ctx: &mut TxContext): ValidatorSet { - ValidatorSet { + fun new_validator_set(init_active_validators: vector, ctx: &mut TxContext): ValidatorSetV1 { + ValidatorSetV1 { active_validators: init_active_validators, inactive_validators: table::new(ctx), extra_fields: bag::new(ctx), } } - public(package) fun v1_to_v2(v1: IotaSystemStateInner): IotaSystemStateInnerV2 { - let IotaSystemStateInner { + public(package) fun v1_to_v2(v1: IotaSystemStateV1): IotaSystemStateV2 { + let IotaSystemStateV1 { epoch, protocol_version, system_state_version: old_system_state_version, + iota_treasury_cap, validators, storage_fund, parameters, @@ -145,11 +185,12 @@ module iota_system::iota_system_state_inner { } = v1; let new_validator_set = validator_set_v1_to_v2(validators); assert!(old_system_state_version == SYSTEM_STATE_VERSION_V1, 0); - IotaSystemStateInnerV2 { + IotaSystemStateV2 { new_dummy_field: 100, epoch, protocol_version, system_state_version: SYSTEM_STATE_VERSION_V2, + iota_treasury_cap, validators: new_validator_set, storage_fund, parameters, @@ -161,13 +202,13 @@ module iota_system::iota_system_state_inner { } /// Load the dummy inactive validator added in the base version, trigger it to be upgraded. - fun touch_dummy_inactive_validator(self: &mut IotaSystemStateInnerV2) { + fun touch_dummy_inactive_validator(self: &mut IotaSystemStateV2) { let validator_wrapper = table::borrow_mut(&mut self.validators.inactive_validators, object::id_from_address(@0x0)); let _ = validator_wrapper::load_validator_maybe_upgrade(validator_wrapper); } - fun validator_set_v1_to_v2(v1: ValidatorSet): ValidatorSetV2 { - let ValidatorSet { + fun validator_set_v1_to_v2(v1: ValidatorSetV1): ValidatorSetV2 { + let ValidatorSetV1 { mut active_validators, inactive_validators, extra_fields, diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/validator.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/validator.move index ea965ad4d15..a8e7744af84 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/validator.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/validator.move @@ -5,13 +5,12 @@ module iota_system::validator { use std::ascii; - use iota::tx_context::TxContext; use std::string::{Self, String}; use iota::bag::{Self, Bag}; use iota::balance::{Self, Balance}; use iota::iota::IOTA; - public struct ValidatorMetadata has store { + public struct ValidatorMetadataV1 has store { iota_address: address, authority_pubkey_bytes: vector, network_pubkey_bytes: vector, @@ -22,8 +21,8 @@ module iota_system::validator { extra_fields: Bag, } - public struct Validator has store { - metadata: ValidatorMetadata, + public struct ValidatorV1 has store { + metadata: ValidatorMetadataV1, voting_power: u64, stake: Balance, extra_fields: Bag, @@ -31,7 +30,7 @@ module iota_system::validator { public struct ValidatorV2 has store { new_dummy_field: u64, - metadata: ValidatorMetadata, + metadata: ValidatorMetadataV1, voting_power: u64, stake: Balance, extra_fields: Bag, @@ -47,8 +46,8 @@ module iota_system::validator { primary_address: vector, init_stake: Balance, ctx: &mut TxContext - ): Validator { - let metadata = ValidatorMetadata { + ): ValidatorV1 { + let metadata = ValidatorMetadataV1 { iota_address, authority_pubkey_bytes, network_pubkey_bytes, @@ -59,7 +58,7 @@ module iota_system::validator { extra_fields: bag::new(ctx), }; - Validator { + ValidatorV1 { metadata, voting_power: balance::value(&init_stake), stake: init_stake, @@ -67,8 +66,8 @@ module iota_system::validator { } } - public(package) fun v1_to_v2(v1: Validator): ValidatorV2 { - let Validator { + public(package) fun v1_to_v2(v1: ValidatorV1): ValidatorV2 { + let ValidatorV1 { metadata, voting_power, stake, diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/validator_wrapper.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/validator_wrapper.move index b6e389ee21a..3fc3b4a050f 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/validator_wrapper.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/deep_upgrade/sources/validator_wrapper.move @@ -3,43 +3,40 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::validator_wrapper { - use iota::versioned::Versioned; - use iota::versioned; - use iota::tx_context::TxContext; - use iota_system::validator::{Validator, ValidatorV2}; - use iota_system::validator; + use iota::versioned::{Self, Versioned}; + use iota_system::validator::{Self, ValidatorV1, ValidatorV2}; const VALIDATOR_VERSION_V1: u64 = 18446744073709551605; // u64::MAX - 10 const VALIDATOR_VERSION_V3: u64 = 18446744073709551607; // u64::MAX - 8 const EInvalidVersion: u64 = 0; - public struct ValidatorWrapper has store { + public struct Validator has store { inner: Versioned } // Validator corresponds to version 1. - public(package) fun create_v1(validator: Validator, ctx: &mut TxContext): ValidatorWrapper { - ValidatorWrapper { + public(package) fun create_v1(validator: ValidatorV1, ctx: &mut TxContext): Validator { + Validator { inner: versioned::create(VALIDATOR_VERSION_V1, validator, ctx) } } /// This function should always return the latest supported version. /// If the inner version is old, we upgrade it lazily in-place. - public(package) fun load_validator_maybe_upgrade(self: &mut ValidatorWrapper): &mut ValidatorV2 { + public(package) fun load_validator_maybe_upgrade(self: &mut Validator): &mut ValidatorV2 { upgrade_to_latest(self); - versioned::load_value_mut(&mut self.inner) + versioned::load_value_mut(&mut self.inner) } /// Destroy the wrapper and retrieve the inner validator object. - public(package) fun destroy(mut self: ValidatorWrapper): ValidatorV2 { + public(package) fun destroy(mut self: Validator): ValidatorV2 { upgrade_to_latest(&mut self); - let ValidatorWrapper { inner } = self; + let Validator { inner } = self; versioned::destroy(inner) } - fun upgrade_to_latest(self: &mut ValidatorWrapper) { + fun upgrade_to_latest(self: &mut Validator) { let version = version(self); if (version == VALIDATOR_VERSION_V1) { let (v1, cap) = versioned::remove_value_for_upgrade(&mut self.inner); @@ -49,7 +46,7 @@ module iota_system::validator_wrapper { assert!(version(self) == VALIDATOR_VERSION_V3, EInvalidVersion); } - fun version(self: &ValidatorWrapper): u64 { + fun version(self: &Validator): u64 { versioned::version(&self.inner) } } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/genesis.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/genesis.move index e6bff0442aa..f4d69976b8b 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/genesis.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/genesis.move @@ -3,12 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::genesis { - use std::vector; - use iota::balance::{Self, Balance}; - use iota::object::UID; - use iota::iota::IOTA; - use iota::tx_context::{Self, TxContext}; - use std::option::Option; + use std::string::String; + + use iota::balance; + use iota::iota::IotaTreasuryCap; + use iota::timelock::SystemTimelockCap; use iota_system::iota_system; use iota_system::validator; @@ -55,15 +54,20 @@ module iota_system::genesis { public struct TokenAllocation has drop { recipient_address: address, amount_nanos: u64, + staked_with_validator: Option
, + staked_with_timelock_expiration: Option, } + #[allow(unused_function)] fun create( iota_system_state_id: UID, - mut iota_supply: Balance, + mut iota_treasury_cap: IotaTreasuryCap, genesis_chain_parameters: GenesisChainParameters, genesis_validators: vector, _token_distribution_schedule: TokenDistributionSchedule, + _timelock_genesis_label: Option, + system_timelock_cap: SystemTimelockCap, ctx: &mut TxContext, ) { assert!(tx_context::epoch(ctx) == 0, 0); @@ -97,7 +101,7 @@ module iota_system::genesis { network_address, p2p_address, primary_address, - balance::split(&mut iota_supply, 2500), + iota_treasury_cap.mint_balance(2500, ctx), ctx ); @@ -108,11 +112,13 @@ module iota_system::genesis { iota_system::create( iota_system_state_id, + iota_treasury_cap, validators, - iota_supply, // storage_fund + balance::zero(), genesis_chain_parameters.protocol_version, genesis_chain_parameters.chain_start_timestamp_ms, genesis_chain_parameters.epoch_duration_ms, + system_timelock_cap, ctx, ); } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/iota_system.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/iota_system.move index c633757870f..113afd557ce 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/iota_system.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/iota_system.move @@ -3,18 +3,16 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::iota_system { - use std::vector; - use iota::balance::Balance; - use iota::object::UID; - use iota::iota::IOTA; - use iota::transfer; - use iota::tx_context::{Self, TxContext}; use iota::dynamic_field; + use iota::iota::IOTA; + use iota::iota::IotaTreasuryCap; + use iota::timelock::SystemTimelockCap; - use iota_system::validator::Validator; - use iota_system::iota_system_state_inner::IotaSystemStateInner; - use iota_system::iota_system_state_inner; + use iota_system::validator::ValidatorV1; + use iota_system::iota_system_state_inner::{Self, IotaSystemStateV1}; + + const SYSTEM_TIMELOCK_CAP_DF_KEY: vector = b"sys_timelock_cap"; public struct IotaSystemState has key { id: UID, @@ -23,14 +21,17 @@ module iota_system::iota_system { public(package) fun create( id: UID, - validators: vector, + iota_treasury_cap: IotaTreasuryCap, + validators: vector, storage_fund: Balance, protocol_version: u64, epoch_start_timestamp_ms: u64, epoch_duration_ms: u64, + system_timelock_cap: SystemTimelockCap, ctx: &mut TxContext, ) { let system_state = iota_system_state_inner::create( + iota_treasury_cap, validators, storage_fund, protocol_version, @@ -44,37 +45,44 @@ module iota_system::iota_system { version, }; dynamic_field::add(&mut self.id, version, system_state); + dynamic_field::add(&mut self.id, SYSTEM_TIMELOCK_CAP_DF_KEY, system_timelock_cap); transfer::share_object(self); } + #[allow(unused_function)] fun advance_epoch( + validator_target_reward: u64, storage_charge: Balance, computation_reward: Balance, wrapper: &mut IotaSystemState, _new_epoch: u64, _next_protocol_version: u64, storage_rebate: u64, - _non_refundable_storage_fee: u64, - _storage_fund_reinvest_rate: u64, - _reward_slashing_rate: u64, + non_refundable_storage_fee: u64, + reward_slashing_rate: u64, _epoch_start_timestamp_ms: u64, ctx: &mut TxContext, ) : Balance { let self = load_system_state_mut(wrapper); assert!(tx_context::sender(ctx) == @0x1, 0); // aborts here - iota_system_state_inner::advance_epoch( + let storage_rebate = iota_system_state_inner::advance_epoch( self, + validator_target_reward, storage_charge, computation_reward, storage_rebate, - ) + non_refundable_storage_fee, + reward_slashing_rate, + ctx + ); + storage_rebate } - public fun active_validator_addresses(wrapper: &mut IotaSystemState): vector
{ + public fun active_validator_addresses(_wrapper: &mut IotaSystemState): vector
{ vector::empty() } - fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateInner { + fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateV1 { let version = self.version; dynamic_field::borrow_mut(&mut self.id, version) } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/iota_system_state_inner.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/iota_system_state_inner.move index 6a7d2d9f11b..a2ea7aa1f8d 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/iota_system_state_inner.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/iota_system_state_inner.move @@ -3,36 +3,51 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::iota_system_state_inner { + use iota::bag::{Self, Bag}; use iota::balance::{Self, Balance}; + use iota::event; use iota::iota::IOTA; - use iota::tx_context::TxContext; - use iota::bag::{Self, Bag}; + use iota::iota::IotaTreasuryCap; use iota::table::{Self, Table}; - use iota::object::ID; - use iota_system::validator::Validator; - use iota_system::validator_wrapper::ValidatorWrapper; + use iota_system::validator::ValidatorV1; + use iota_system::validator_wrapper::Validator; const SYSTEM_STATE_VERSION_V1: u64 = 18446744073709551605; // u64::MAX - 10 - public struct SystemParameters has store { + public struct SystemEpochInfoEventV1 has copy, drop { + epoch: u64, + protocol_version: u64, + reference_gas_price: u64, + total_stake: u64, + storage_charge: u64, + storage_rebate: u64, + storage_fund_balance: u64, + total_gas_fees: u64, + total_stake_rewards_distributed: u64, + burnt_tokens_amount: u64, + minted_tokens_amount: u64, + } + + public struct SystemParametersV1 has store { epoch_duration_ms: u64, extra_fields: Bag, } - public struct ValidatorSet has store { - active_validators: vector, - inactive_validators: Table, + public struct ValidatorSetV1 has store { + active_validators: vector, + inactive_validators: Table, extra_fields: Bag, } - public struct IotaSystemStateInner has store { + public struct IotaSystemStateV1 has store { epoch: u64, protocol_version: u64, system_state_version: u64, - validators: ValidatorSet, + iota_treasury_cap: IotaTreasuryCap, + validators: ValidatorSetV1, storage_fund: Balance, - parameters: SystemParameters, + parameters: SystemParametersV1, reference_gas_price: u64, safe_mode: bool, epoch_start_timestamp_ms: u64, @@ -40,24 +55,26 @@ module iota_system::iota_system_state_inner { } public(package) fun create( - validators: vector, + iota_treasury_cap: IotaTreasuryCap, + validators: vector, storage_fund: Balance, protocol_version: u64, epoch_start_timestamp_ms: u64, epoch_duration_ms: u64, ctx: &mut TxContext, - ): IotaSystemStateInner { - let system_state = IotaSystemStateInner { + ): IotaSystemStateV1 { + let system_state = IotaSystemStateV1 { epoch: 0, protocol_version, system_state_version: genesis_system_state_version(), - validators: ValidatorSet { + iota_treasury_cap, + validators: ValidatorSetV1 { active_validators: validators, inactive_validators: table::new(ctx), extra_fields: bag::new(ctx), }, storage_fund, - parameters: SystemParameters { + parameters: SystemParametersV1 { epoch_duration_ms, extra_fields: bag::new(ctx), }, @@ -70,14 +87,38 @@ module iota_system::iota_system_state_inner { } public(package) fun advance_epoch( - self: &mut IotaSystemStateInner, - storage_charge: Balance, - computation_reward: Balance, - storage_rebate_amount: u64, + self: &mut IotaSystemStateV1, + _validator_target_reward: u64, + mut storage_charge: Balance, + mut computation_reward: Balance, + mut storage_rebate_amount: u64, + mut _non_refundable_storage_fee_amount: u64, + _reward_slashing_rate: u64, + _ctx: &mut TxContext, ) : Balance { + let storage_charge_value = storage_charge.value(); + let total_gas_fees = computation_reward.value(); + balance::join(&mut self.storage_fund, computation_reward); balance::join(&mut self.storage_fund, storage_charge); let storage_rebate = balance::split(&mut self.storage_fund, storage_rebate_amount); + + event::emit( + SystemEpochInfoEventV1 { + epoch: self.epoch, + protocol_version: self.protocol_version, + reference_gas_price: self.reference_gas_price, + total_stake: 0, + storage_charge: storage_charge_value, + storage_rebate: storage_rebate_amount, + storage_fund_balance: self.storage_fund.value(), + total_gas_fees, + total_stake_rewards_distributed: 0, + burnt_tokens_amount: 0, + minted_tokens_amount: 0, + } + ); + storage_rebate } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/validator.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/validator.move index 923cc9f3b27..01a61565bc7 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/validator.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/validator.move @@ -5,13 +5,12 @@ module iota_system::validator { use std::ascii; - use iota::tx_context::TxContext; use std::string::{Self, String}; use iota::bag::{Self, Bag}; use iota::balance::{Self, Balance}; use iota::iota::IOTA; - public struct ValidatorMetadata has store { + public struct ValidatorMetadataV1 has store { iota_address: address, authority_pubkey_bytes: vector, network_pubkey_bytes: vector, @@ -22,8 +21,8 @@ module iota_system::validator { extra_fields: Bag, } - public struct Validator has store { - metadata: ValidatorMetadata, + public struct ValidatorV1 has store { + metadata: ValidatorMetadataV1, voting_power: u64, stake: Balance, extra_fields: Bag, @@ -39,8 +38,8 @@ module iota_system::validator { primary_address: vector, init_stake: Balance, ctx: &mut TxContext - ): Validator { - let metadata = ValidatorMetadata { + ): ValidatorV1 { + let metadata = ValidatorMetadataV1 { iota_address, authority_pubkey_bytes, network_pubkey_bytes, @@ -51,7 +50,7 @@ module iota_system::validator { extra_fields: bag::new(ctx), }; - Validator { + ValidatorV1 { metadata, voting_power: balance::value(&init_stake), stake: init_stake, diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/validator_wrapper.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/validator_wrapper.move index 7729b3d4e77..1593f71ef46 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/validator_wrapper.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/safe_mode/sources/validator_wrapper.move @@ -5,7 +5,7 @@ module iota_system::validator_wrapper { use iota::versioned::Versioned; - public struct ValidatorWrapper has store { + public struct Validator has store { inner: Versioned } } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/genesis.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/genesis.move index e6bff0442aa..f4d69976b8b 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/genesis.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/genesis.move @@ -3,12 +3,11 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::genesis { - use std::vector; - use iota::balance::{Self, Balance}; - use iota::object::UID; - use iota::iota::IOTA; - use iota::tx_context::{Self, TxContext}; - use std::option::Option; + use std::string::String; + + use iota::balance; + use iota::iota::IotaTreasuryCap; + use iota::timelock::SystemTimelockCap; use iota_system::iota_system; use iota_system::validator; @@ -55,15 +54,20 @@ module iota_system::genesis { public struct TokenAllocation has drop { recipient_address: address, amount_nanos: u64, + staked_with_validator: Option
, + staked_with_timelock_expiration: Option, } + #[allow(unused_function)] fun create( iota_system_state_id: UID, - mut iota_supply: Balance, + mut iota_treasury_cap: IotaTreasuryCap, genesis_chain_parameters: GenesisChainParameters, genesis_validators: vector, _token_distribution_schedule: TokenDistributionSchedule, + _timelock_genesis_label: Option, + system_timelock_cap: SystemTimelockCap, ctx: &mut TxContext, ) { assert!(tx_context::epoch(ctx) == 0, 0); @@ -97,7 +101,7 @@ module iota_system::genesis { network_address, p2p_address, primary_address, - balance::split(&mut iota_supply, 2500), + iota_treasury_cap.mint_balance(2500, ctx), ctx ); @@ -108,11 +112,13 @@ module iota_system::genesis { iota_system::create( iota_system_state_id, + iota_treasury_cap, validators, - iota_supply, // storage_fund + balance::zero(), genesis_chain_parameters.protocol_version, genesis_chain_parameters.chain_start_timestamp_ms, genesis_chain_parameters.epoch_duration_ms, + system_timelock_cap, ctx, ); } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/iota_system.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/iota_system.move index d0339bb3b95..549ba9c21a3 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/iota_system.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/iota_system.move @@ -3,17 +3,16 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::iota_system { - use std::vector; - use iota::balance::Balance; - use iota::object::UID; - use iota::iota::IOTA; - use iota::transfer; - use iota::tx_context::{Self, TxContext}; use iota::dynamic_field; + use iota::iota::IOTA; + use iota::iota::IotaTreasuryCap; + use iota::timelock::SystemTimelockCap; - use iota_system::validator::Validator; - use iota_system::iota_system_state_inner::{Self, IotaSystemStateInner, IotaSystemStateInnerV2}; + use iota_system::validator::ValidatorV1; + use iota_system::iota_system_state_inner::{Self, IotaSystemStateV1, IotaSystemStateV2}; + + const SYSTEM_TIMELOCK_CAP_DF_KEY: vector = b"sys_timelock_cap"; public struct IotaSystemState has key { id: UID, @@ -22,14 +21,17 @@ module iota_system::iota_system { public(package) fun create( id: UID, - validators: vector, + iota_treasury_cap: IotaTreasuryCap, + validators: vector, storage_fund: Balance, protocol_version: u64, epoch_start_timestamp_ms: u64, epoch_duration_ms: u64, + system_timelock_cap: SystemTimelockCap, ctx: &mut TxContext, ) { let system_state = iota_system_state_inner::create( + iota_treasury_cap, validators, storage_fund, protocol_version, @@ -43,21 +45,22 @@ module iota_system::iota_system { version, }; dynamic_field::add(&mut self.id, version, system_state); + dynamic_field::add(&mut self.id, SYSTEM_TIMELOCK_CAP_DF_KEY, system_timelock_cap); transfer::share_object(self); } + #[allow(unused_function)] fun advance_epoch( + validator_target_reward: u64, storage_charge: Balance, computation_reward: Balance, wrapper: &mut IotaSystemState, new_epoch: u64, next_protocol_version: u64, storage_rebate: u64, - _non_refundable_storage_fee: u64, - _storage_fund_reinvest_rate: u64, // share of storage fund's rewards that's reinvested - // into storage fund, in basis point. - _reward_slashing_rate: u64, // how much rewards are slashed to punish a validator, in bps. - epoch_start_timestamp_ms: u64, // Timestamp of the epoch start + non_refundable_storage_fee: u64, + reward_slashing_rate: u64, + epoch_start_timestamp_ms: u64, ctx: &mut TxContext, ) : Balance { let self = load_system_state_mut(wrapper); @@ -66,34 +69,38 @@ module iota_system::iota_system { self, new_epoch, next_protocol_version, + validator_target_reward, storage_charge, computation_reward, storage_rebate, + non_refundable_storage_fee, + reward_slashing_rate, epoch_start_timestamp_ms, + ctx ); storage_rebate } - public fun active_validator_addresses(wrapper: &mut IotaSystemState): vector
{ + public fun active_validator_addresses(_wrapper: &mut IotaSystemState): vector
{ vector::empty() } - fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateInnerV2 { + fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateV2 { load_inner_maybe_upgrade(self) } - fun load_inner_maybe_upgrade(self: &mut IotaSystemState): &mut IotaSystemStateInnerV2 { + fun load_inner_maybe_upgrade(self: &mut IotaSystemState): &mut IotaSystemStateV2 { let mut version = self.version; if (version == iota_system_state_inner::genesis_system_state_version()) { - let inner: IotaSystemStateInner = dynamic_field::remove(&mut self.id, version); + let inner: IotaSystemStateV1 = dynamic_field::remove(&mut self.id, version); let new_inner = iota_system_state_inner::v1_to_v2(inner); version = iota_system_state_inner::system_state_version(&new_inner); dynamic_field::add(&mut self.id, version, new_inner); self.version = version; }; - let inner: &mut IotaSystemStateInnerV2 = dynamic_field::borrow_mut(&mut self.id, version); + let inner: &mut IotaSystemStateV2 = dynamic_field::borrow_mut(&mut self.id, version); assert!(iota_system_state_inner::system_state_version(inner) == version, 0); inner } diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/iota_system_state_inner.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/iota_system_state_inner.move index 5b957ebfd10..18c0632784c 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/iota_system_state_inner.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/iota_system_state_inner.move @@ -3,51 +3,67 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::iota_system_state_inner { + use iota::bag::{Self, Bag}; use iota::balance::{Self, Balance}; + use iota::event; use iota::iota::IOTA; - use iota::tx_context::TxContext; - use iota::bag::{Self, Bag}; + use iota::iota::IotaTreasuryCap; use iota::table::{Self, Table}; - use iota::object::ID; - use iota_system::validator::Validator; - use iota_system::validator_wrapper::ValidatorWrapper; + use iota_system::validator::ValidatorV1; + use iota_system::validator_wrapper::Validator; const SYSTEM_STATE_VERSION_V1: u64 = 18446744073709551605; // u64::MAX - 10 const SYSTEM_STATE_VERSION_V2: u64 = 18446744073709551606; // u64::MAX - 9 - public struct SystemParameters has store { + public struct SystemEpochInfoEventV1 has copy, drop { + epoch: u64, + protocol_version: u64, + reference_gas_price: u64, + total_stake: u64, + storage_charge: u64, + storage_rebate: u64, + storage_fund_balance: u64, + total_gas_fees: u64, + total_stake_rewards_distributed: u64, + burnt_tokens_amount: u64, + minted_tokens_amount: u64, + } + + public struct SystemParametersV1 has store { epoch_duration_ms: u64, extra_fields: Bag, } - public struct ValidatorSet has store { - active_validators: vector, - inactive_validators: Table, + public struct ValidatorSetV1 has store { + active_validators: vector, + inactive_validators: Table, extra_fields: Bag, } - public struct IotaSystemStateInner has store { + public struct IotaSystemStateV1 has store { epoch: u64, protocol_version: u64, system_state_version: u64, - validators: ValidatorSet, + iota_treasury_cap: IotaTreasuryCap, + validators: ValidatorSetV1, storage_fund: Balance, - parameters: SystemParameters, + parameters: SystemParametersV1, reference_gas_price: u64, safe_mode: bool, epoch_start_timestamp_ms: u64, extra_fields: Bag, } - public struct IotaSystemStateInnerV2 has store { + public struct IotaSystemStateV2 has store { new_dummy_field: u64, epoch: u64, protocol_version: u64, system_state_version: u64, - validators: ValidatorSet, + iota_treasury_cap: IotaTreasuryCap, + validators: ValidatorSetV1, storage_fund: Balance, - parameters: SystemParameters, + parameters: SystemParametersV1, reference_gas_price: u64, safe_mode: bool, epoch_start_timestamp_ms: u64, @@ -55,21 +71,23 @@ module iota_system::iota_system_state_inner { } public(package) fun create( - validators: vector, + iota_treasury_cap: IotaTreasuryCap, + validators: vector, storage_fund: Balance, protocol_version: u64, epoch_start_timestamp_ms: u64, epoch_duration_ms: u64, ctx: &mut TxContext, - ): IotaSystemStateInner { + ): IotaSystemStateV1 { let validators = new_validator_set(validators, ctx); - let system_state = IotaSystemStateInner { + let system_state = IotaSystemStateV1 { epoch: 0, protocol_version, system_state_version: genesis_system_state_version(), + iota_treasury_cap, validators, storage_fund, - parameters: SystemParameters { + parameters: SystemParametersV1 { epoch_duration_ms, extra_fields: bag::new(ctx), }, @@ -82,13 +100,17 @@ module iota_system::iota_system_state_inner { } public(package) fun advance_epoch( - self: &mut IotaSystemStateInnerV2, + self: &mut IotaSystemStateV2, new_epoch: u64, next_protocol_version: u64, - storage_charge: Balance, - computation_reward: Balance, - storage_rebate_amount: u64, + _validator_target_reward: u64, + mut storage_charge: Balance, + mut computation_reward: Balance, + mut storage_rebate_amount: u64, + mut _non_refundable_storage_fee_amount: u64, + _reward_slashing_rate: u64, epoch_start_timestamp_ms: u64, + _ctx: &mut TxContext, ) : Balance { self.epoch_start_timestamp_ms = epoch_start_timestamp_ms; self.epoch = self.epoch + 1; @@ -96,31 +118,52 @@ module iota_system::iota_system_state_inner { self.safe_mode = false; self.protocol_version = next_protocol_version; + let storage_charge_value = storage_charge.value(); + let total_gas_fees = computation_reward.value(); + balance::join(&mut self.storage_fund, computation_reward); balance::join(&mut self.storage_fund, storage_charge); let storage_rebate = balance::split(&mut self.storage_fund, storage_rebate_amount); + + event::emit( + SystemEpochInfoEventV1 { + epoch: self.epoch, + protocol_version: self.protocol_version, + reference_gas_price: self.reference_gas_price, + total_stake: 0, + storage_charge: storage_charge_value, + storage_rebate: storage_rebate_amount, + storage_fund_balance: self.storage_fund.value(), + total_gas_fees, + total_stake_rewards_distributed: 0, + burnt_tokens_amount: 0, + minted_tokens_amount: 0, + } + ); + storage_rebate } - public(package) fun protocol_version(self: &IotaSystemStateInnerV2): u64 { self.protocol_version } - public(package) fun system_state_version(self: &IotaSystemStateInnerV2): u64 { self.system_state_version } + public(package) fun protocol_version(self: &IotaSystemStateV2): u64 { self.protocol_version } + public(package) fun system_state_version(self: &IotaSystemStateV2): u64 { self.system_state_version } public(package) fun genesis_system_state_version(): u64 { SYSTEM_STATE_VERSION_V1 } - fun new_validator_set(init_active_validators: vector, ctx: &mut TxContext): ValidatorSet { - ValidatorSet { + fun new_validator_set(init_active_validators: vector, ctx: &mut TxContext): ValidatorSetV1 { + ValidatorSetV1 { active_validators: init_active_validators, inactive_validators: table::new(ctx), extra_fields: bag::new(ctx), } } - public(package) fun v1_to_v2(v1: IotaSystemStateInner): IotaSystemStateInnerV2 { - let IotaSystemStateInner { + public(package) fun v1_to_v2(v1: IotaSystemStateV1): IotaSystemStateV2 { + let IotaSystemStateV1 { epoch, protocol_version, system_state_version: old_system_state_version, + iota_treasury_cap, validators, storage_fund, parameters, @@ -130,11 +173,12 @@ module iota_system::iota_system_state_inner { extra_fields, } = v1; assert!(old_system_state_version == SYSTEM_STATE_VERSION_V1, 0); - IotaSystemStateInnerV2 { + IotaSystemStateV2 { new_dummy_field: 100, epoch, protocol_version, system_state_version: SYSTEM_STATE_VERSION_V2, + iota_treasury_cap, validators, storage_fund, parameters, diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/validator.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/validator.move index 923cc9f3b27..01a61565bc7 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/validator.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/validator.move @@ -5,13 +5,12 @@ module iota_system::validator { use std::ascii; - use iota::tx_context::TxContext; use std::string::{Self, String}; use iota::bag::{Self, Bag}; use iota::balance::{Self, Balance}; use iota::iota::IOTA; - public struct ValidatorMetadata has store { + public struct ValidatorMetadataV1 has store { iota_address: address, authority_pubkey_bytes: vector, network_pubkey_bytes: vector, @@ -22,8 +21,8 @@ module iota_system::validator { extra_fields: Bag, } - public struct Validator has store { - metadata: ValidatorMetadata, + public struct ValidatorV1 has store { + metadata: ValidatorMetadataV1, voting_power: u64, stake: Balance, extra_fields: Bag, @@ -39,8 +38,8 @@ module iota_system::validator { primary_address: vector, init_stake: Balance, ctx: &mut TxContext - ): Validator { - let metadata = ValidatorMetadata { + ): ValidatorV1 { + let metadata = ValidatorMetadataV1 { iota_address, authority_pubkey_bytes, network_pubkey_bytes, @@ -51,7 +50,7 @@ module iota_system::validator { extra_fields: bag::new(ctx), }; - Validator { + ValidatorV1 { metadata, voting_power: balance::value(&init_stake), stake: init_stake, diff --git a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/validator_wrapper.move b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/validator_wrapper.move index 10e2b527c62..5a673effe7d 100644 --- a/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/validator_wrapper.move +++ b/crates/iota-e2e-tests/tests/framework_upgrades/mock_iota_systems/shallow_upgrade/sources/validator_wrapper.move @@ -3,45 +3,43 @@ // SPDX-License-Identifier: Apache-2.0 module iota_system::validator_wrapper { - use iota::versioned::Versioned; - use iota::versioned; - use iota::tx_context::TxContext; - use iota_system::validator::Validator; + use iota::versioned::{Self, Versioned}; + use iota_system::validator::ValidatorV1; const EInvalidVersion: u64 = 0; - public struct ValidatorWrapper has store { + public struct Validator has store { inner: Versioned } // Validator corresponds to version 1. - public(package) fun create_v1(validator: Validator, ctx: &mut TxContext): ValidatorWrapper { - ValidatorWrapper { + public(package) fun create_v1(validator: ValidatorV1, ctx: &mut TxContext): Validator { + Validator { inner: versioned::create(1, validator, ctx) } } /// This function should always return the latest supported version. /// If the inner version is old, we upgrade it lazily in-place. - public(package) fun load_validator_maybe_upgrade(self: &mut ValidatorWrapper): &mut Validator { + public(package) fun load_validator_maybe_upgrade(self: &mut Validator): &mut ValidatorV1 { upgrade_to_latest(self); - versioned::load_value_mut(&mut self.inner) + versioned::load_value_mut(&mut self.inner) } /// Destroy the wrapper and retrieve the inner validator object. - public(package) fun destroy(mut self: ValidatorWrapper): Validator { - upgrade_to_latest(&mut self); - let ValidatorWrapper { inner } = self; + public(package) fun destroy(self: Validator): ValidatorV1 { + upgrade_to_latest(&self); + let Validator { inner } = self; versioned::destroy(inner) } - fun upgrade_to_latest(self: &mut ValidatorWrapper) { + fun upgrade_to_latest(self: &Validator) { let version = version(self); // TODO: When new versions are added, we need to explicitly upgrade here. assert!(version == 1, EInvalidVersion); } - fun version(self: &ValidatorWrapper): u64 { + fun version(self: &Validator): u64 { versioned::version(&self.inner) } } diff --git a/crates/iota-types/src/iota_system_state/simtest_iota_system_state_inner.rs b/crates/iota-types/src/iota_system_state/simtest_iota_system_state_inner.rs index fc1c17c9653..2cbba91fb62 100644 --- a/crates/iota-types/src/iota_system_state/simtest_iota_system_state_inner.rs +++ b/crates/iota-types/src/iota_system_state/simtest_iota_system_state_inner.rs @@ -14,6 +14,7 @@ use crate::{ committee::{CommitteeWithNetworkMetadata, NetworkMetadata}, crypto::{AuthorityPublicKey, AuthorityPublicKeyBytes, NetworkPublicKey}, error::IotaError, + gas_coin::IotaTreasuryCap, iota_system_state::{ AdvanceEpochParams, IotaSystemStateTrait, epoch_start_iota_system_state::{EpochStartSystemState, EpochStartValidatorInfoV1}, @@ -27,6 +28,7 @@ pub struct SimTestIotaSystemStateV1 { pub epoch: u64, pub protocol_version: u64, pub system_state_version: u64, + pub iota_treasury_cap: IotaTreasuryCap, pub validators: SimTestValidatorSetV1, pub storage_fund: Balance, pub parameters: SimTestSystemParametersV1, @@ -225,6 +227,7 @@ pub struct SimTestIotaSystemStateShallowV1 { pub epoch: u64, pub protocol_version: u64, pub system_state_version: u64, + pub iota_treasury_cap: IotaTreasuryCap, pub validators: SimTestValidatorSetV1, pub storage_fund: Balance, pub parameters: SimTestSystemParametersV1, @@ -366,6 +369,7 @@ pub struct SimTestIotaSystemStateDeepV1 { pub epoch: u64, pub protocol_version: u64, pub system_state_version: u64, + pub iota_treasury_cap: IotaTreasuryCap, pub validators: SimTestValidatorSetDeepV2, pub storage_fund: Balance, pub parameters: SimTestSystemParametersV1,