Skip to content

Commit

Permalink
feat: improved system displays implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriyr committed Nov 13, 2024
1 parent 75765e7 commit aeb0ba0
Show file tree
Hide file tree
Showing 20 changed files with 1,641 additions and 85 deletions.
74 changes: 74 additions & 0 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use iota_types::committee::CommitteeTrait;
use iota_types::{
IOTA_SYSTEM_ADDRESS, TypeTag,
authenticator_state::get_authenticator_state,
balance::Balance,
base_types::*,
committee::{Committee, EpochId, ProtocolVersion},
crypto::{AuthoritySignInfo, AuthoritySignature, RandomnessRound, Signer, default_hash},
Expand All @@ -71,6 +72,8 @@ use iota_types::{
execution_status::ExecutionStatus,
fp_ensure,
gas::{GasCostSummary, IotaGasStatus},
gas_coin::GAS,
governance::StakedIota,
inner_temporary_store::{
InnerTemporaryStore, ObjectMap, PackageStoreWithFallback, TemporaryModuleResolver, TxCoins,
WrittenObjects,
Expand Down Expand Up @@ -100,6 +103,7 @@ use iota_types::{
BackingPackageStore, BackingStore, ObjectKey, ObjectOrTombstone, ObjectStore, WriteKind,
},
supported_protocol_versions::{ProtocolConfig, SupportedProtocolVersions},
timelock::{timelock::TimeLock, timelocked_staked_iota::TimelockedStakedIota},
transaction::*,
};
use itertools::Itertools;
Expand Down Expand Up @@ -4490,6 +4494,73 @@ impl AuthorityState {
Some(tx)
}

#[instrument(level = "debug", skip_all)]
fn create_system_display_txs(
&self,
epoch_store: &Arc<AuthorityPerEpochStore>,
) -> Option<EndOfEpochTransactionKind> {
let txs = [
self.create_staked_iota_display_tx_v1(epoch_store),
self.create_staked_timelocked_iota_display_tx_v1(epoch_store),
self.create_timelock_display_tx_v1(epoch_store),
]
.iter()
.filter_map(|f| f.clone())
.collect::<Vec<_>>();

if txs.is_empty() {
return None;
}

info!("Creating system display tx");
Some(EndOfEpochTransactionKind::system_display(txs))
}

#[instrument(level = "debug", skip_all)]
fn create_staked_iota_display_tx_v1(
&self,
epoch_store: &Arc<AuthorityPerEpochStore>,
) -> Option<SystemDisplayTransactionKind> {
let ty = StakedIota::type_();

if epoch_store.system_display_object_created(ty, 1) {
return None;
}

info!("Creating StakedIota display tx v1");
Some(SystemDisplayTransactionKind::StakedIotaV1)
}

#[instrument(level = "debug", skip_all)]
fn create_staked_timelocked_iota_display_tx_v1(
&self,
epoch_store: &Arc<AuthorityPerEpochStore>,
) -> Option<SystemDisplayTransactionKind> {
let ty = TimelockedStakedIota::type_();

if epoch_store.system_display_object_created(ty, 1) {
return None;
}

info!("Creating TimelockedStakedIota display tx v1");
Some(SystemDisplayTransactionKind::TimelockedStakedIotaV1)
}

#[instrument(level = "debug", skip_all)]
fn create_timelock_display_tx_v1(
&self,
epoch_store: &Arc<AuthorityPerEpochStore>,
) -> Option<SystemDisplayTransactionKind> {
let ty = TimeLock::<Balance>::type_(Balance::type_(GAS::type_().into()).into());

if epoch_store.system_display_object_created(ty, 1) {
return None;
}

info!("Creating TimeLock display tx v1");
Some(SystemDisplayTransactionKind::TimeLockV1)
}

/// Creates and execute the advance epoch transaction to effects without
/// committing it to the database. The effects of the change epoch tx
/// are only written to the database after a certified checkpoint has been
Expand Down Expand Up @@ -4525,6 +4596,9 @@ impl AuthorityState {
if let Some(tx) = self.init_bridge_committee_tx(epoch_store) {
txns.push(tx);
}
if let Some(tx) = self.create_system_display_txs(epoch_store) {
txns.push(tx);
}

let next_epoch = epoch_store.epoch() + 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module iota_system::iota_system {
use iota::dynamic_field;
use iota::vec_map::VecMap;

use iota_system::iota_system_state_inner::{Self, SystemParametersV1, IotaSystemStateV1};
use iota_system::iota_system_state_inner::{Self, SystemParametersV1, IotaSystemStateV1, IotaSystemStateV2};
use iota_system::staking_pool::{PoolTokenExchangeRate, StakedIota};
use iota_system::validator::ValidatorV1;
use iota_system::validator_cap::UnverifiedValidatorOperationCap;
Expand Down Expand Up @@ -597,16 +597,23 @@ module iota_system::iota_system {
storage_rebate
}

fun load_system_state(self: &mut IotaSystemState): &IotaSystemStateV1 {
fun load_system_state(self: &mut IotaSystemState): &IotaSystemStateV2 {
load_inner_maybe_upgrade(self)
}

fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateV1 {
fun load_system_state_mut(self: &mut IotaSystemState): &mut IotaSystemStateV2 {
load_inner_maybe_upgrade(self)
}

fun load_inner_maybe_upgrade(self: &mut IotaSystemState): &mut IotaSystemStateV1 {
let inner: &mut IotaSystemStateV1 = dynamic_field::borrow_mut(
fun load_inner_maybe_upgrade(self: &mut IotaSystemState): &mut IotaSystemStateV2 {
if (self.version == 1) {
let v1: IotaSystemStateV1 = dynamic_field::remove(&mut self.id, self.version);
let v2 = v1.v1_to_v2();
self.version = 2;
dynamic_field::add(&mut self.id, self.version, v2);
};

let inner: &mut IotaSystemStateV2 = dynamic_field::borrow_mut(
&mut self.id,
self.version
);
Expand Down
Loading

0 comments on commit aeb0ba0

Please sign in to comment.