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 14, 2024
1 parent 75765e7 commit 8f82d05
Show file tree
Hide file tree
Showing 22 changed files with 1,722 additions and 130 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_timelocked_iota_display_tx_v1(epoch_store),
]
.iter()
.filter_map(|f| f.clone())
.collect::<Vec<_>>();

if txs.is_empty() {
return None;
}

info!("Creating system display transactions");
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 tag = StakedIota::type_();

if epoch_store.is_system_display_object_created(tag, 1) {
return None;
}

info!("Creating `StakedIota` system display v1 transaction");
Some(SystemDisplayTransactionKind::StakedIotaV1)
}

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

if epoch_store.is_system_display_object_created(tag, 1) {
return None;
}

info!("Creating `TimelockedStakedIota` system display v1 transaction");
Some(SystemDisplayTransactionKind::TimelockedStakedIotaV1)
}

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

if epoch_store.is_system_display_object_created(tag, 1) {
return None;
}

info!("Creating `TimeLock<Balance<IOTA>>` system display v1 transaction");
Some(SystemDisplayTransactionKind::TimelockedIotaV1)
}

/// 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
6 changes: 3 additions & 3 deletions crates/iota-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use iota_types::{
error::{IotaError, IotaResult},
executable_transaction::{TrustedExecutableTransaction, VerifiedExecutableTransaction},
iota_system_state::{
display_object_key,
epoch_start_iota_system_state::{EpochStartSystemState, EpochStartSystemStateTrait},
system_display_object_key,
},
message_envelope::TrustedEnvelope,
messages_checkpoint::{
Expand Down Expand Up @@ -961,8 +961,8 @@ impl AuthorityPerEpochStore {
self.epoch_start_configuration.bridge_committee_initiated()
}

pub fn system_display_object_created(&self, ty: StructTag, version: u16) -> bool {
let key = display_object_key(ty);
pub fn is_system_display_object_created(&self, tag: StructTag, version: u16) -> bool {
let key = system_display_object_key(tag);

let object_version = self
.epoch_start_configuration
Expand Down
5 changes: 3 additions & 2 deletions crates/iota-core/src/generate_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use iota_types::{
signature::GenericSignature,
storage::DeleteKind,
transaction::{
Argument, CallArg, Command, EndOfEpochTransactionKind, ObjectArg, TransactionExpiration,
TransactionKind,
Argument, CallArg, Command, EndOfEpochTransactionKind, ObjectArg,
SystemDisplayTransactionKind, TransactionExpiration, TransactionKind,
},
utils::DEFAULT_ADDRESS_SEED,
};
Expand Down Expand Up @@ -172,6 +172,7 @@ fn get_registry() -> Result<Registry> {
tracer.trace_type::<TypeArgumentError>(&samples)?;
tracer.trace_type::<PackageUpgradeError>(&samples)?;
tracer.trace_type::<TransactionExpiration>(&samples)?;
tracer.trace_type::<SystemDisplayTransactionKind>(&samples)?;
tracer.trace_type::<EndOfEpochTransactionKind>(&samples)?;

tracer.trace_type::<IDOperation>(&samples)?;
Expand Down
45 changes: 26 additions & 19 deletions crates/iota-framework/packages/iota-system/sources/iota_system.move
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 @@ -507,7 +507,7 @@ module iota_system::iota_system {
self.load_system_state().iota_system_admin_cap()
}

/// Create an empty `Display` object with `IotaSystemAdminCap`.
/// Create an empty system `Display` object with `IotaSystemAdminCap`.
public(package) fun new_system_display<T: key>(
wrapper: &mut IotaSystemState,
ctx: &mut TxContext,
Expand All @@ -516,7 +516,7 @@ module iota_system::iota_system {
self.new_system_display(ctx)
}

/// Create a new `Display<T>` object with a set of fields using `IotaSystemAdminCap`.
/// Create a new system `Display<T>` object with a set of fields using `IotaSystemAdminCap`.
public(package) fun new_system_display_with_fields<T: key>(
wrapper: &mut IotaSystemState,
fields: vector<String>,
Expand All @@ -527,31 +527,31 @@ module iota_system::iota_system {
self.new_system_display_with_fields(fields, values, ctx)
}

/// Insert a display object.
public(package) fun insert_display_object<T: key>(
/// Insert a system display object.
public(package) fun insert_system_display_object<T: key>(
wrapper: &mut IotaSystemState,
display: Display<T>,
) {
let self = wrapper.load_system_state_mut();
self.insert_display_object(display);
self.insert_system_display_object(display);
}

/// Borrow an immutable display object.
public(package) fun borrow_display_object<T: key>(wrapper: &mut IotaSystemState): &Display<T> {
/// Borrow an immutable system display object.
public(package) fun borrow_system_display_object<T: key>(wrapper: &mut IotaSystemState): &Display<T> {
let self = wrapper.load_system_state();
self.borrow_display_object<T>()
self.borrow_system_display_object<T>()
}

/// Borrow a mutable display object.
public(package) fun borrow_display_object_mut<T: key>(wrapper: &mut IotaSystemState): &mut Display<T> {
/// Borrow a mutable system display object.
public(package) fun borrow_system_display_object_mut<T: key>(wrapper: &mut IotaSystemState): &mut Display<T> {
let self = wrapper.load_system_state_mut();
self.borrow_display_object_mut<T>()
self.borrow_system_display_object_mut<T>()
}

/// Returns true if the related display object exists.
public(package) fun contains_display_object<T: key>(wrapper: &mut IotaSystemState): bool {
/// Returns true if the related system display object exists.
public(package) fun contains_system_display_object<T: key>(wrapper: &mut IotaSystemState): bool {
let self = wrapper.load_system_state();
self.contains_display_object<T>()
self.contains_system_display_object<T>()
}

#[allow(unused_function)]
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 8f82d05

Please sign in to comment.