Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use iota_types::{
TransactionEvents, VerifiedCertifiedTransactionEffects, VerifiedSignedTransactionEffects,
},
error::{ExecutionError, IotaError, IotaResult, UserInputError},
event::{Event, EventID, SystemEpochInfoEvent, SystemEpochInfoEventV1, SystemEpochInfoEventV2},
event::{Event, EventID, SystemEpochInfoEvent},
executable_transaction::VerifiedExecutableTransaction,
execution_config_utils::to_binary_config,
execution_status::ExecutionStatus,
Expand Down Expand Up @@ -4714,9 +4714,9 @@ impl AuthorityState {
let system_epoch_info_event = temporary_store
.events
.data
.iter()
.into_iter()
.find(|event| event.is_system_epoch_info_event())
.map(|event| SystemEpochInfoEvent::from(event));
.map(SystemEpochInfoEvent::from);
// 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());
Expand Down
9 changes: 6 additions & 3 deletions crates/iota-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use iota_types::{
error::UserInputError,
execution::TypeLayoutStore,
fp_bail, fp_ensure,
iota_system_state::get_iota_system_state,
iota_system_state::{
get_iota_system_state, iota_system_state_summary::IotaSystemStateSummaryV2,
},
message_envelope::Message,
storage::{
BackingPackageStore, MarkerValue, ObjectKey, ObjectOrTombstone, ObjectStore, get_module,
Expand Down Expand Up @@ -1592,10 +1594,11 @@ impl AuthorityStore {

// It is safe to call this function because we are in the middle of
// reconfiguration.
let system_state = self
let system_state: IotaSystemStateSummaryV2 = self
.get_iota_system_state_object_unsafe()
.expect("Reading iota system state object cannot fail")
.into_iota_system_state_summary();
.into_iota_system_state_summary()
.try_into()?;
let storage_fund_balance = system_state.storage_fund_total_object_storage_rebates;
info!(
"Total IOTA amount in the network: {}, storage fund balance: {}, total storage rebate: {} at beginning of epoch {}",
Expand Down
185 changes: 184 additions & 1 deletion crates/iota-types/src/iota_system_state/iota_system_state_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{

/// This is the JSON-RPC type for IOTA system state objects.
/// It is an enum type that can represent either V1 or V2 system state objects.
#[non_exhaustive]
pub enum IotaSystemStateSummary {
V1(IotaSystemStateSummaryV1),
V2(IotaSystemStateSummaryV2),
Expand Down Expand Up @@ -192,7 +193,7 @@ pub struct IotaSystemStateSummaryV1 {
}

/// This is the JSON-RPC type for the
/// [`IotaSystemStateV2`](super::iota_system_state_inner_v2::IotaSystemStateV1)
/// [`IotaSystemStateV2`](super::iota_system_state_inner_v2::IotaSystemStateV2)
/// object. It flattens all fields to make them top-level fields such that it as
/// minimum dependencies to the internal data structures of the IOTA system
/// state type.
Expand Down Expand Up @@ -418,6 +419,188 @@ impl IotaSystemStateSummaryV2 {
}
}

// Conversion traits to make usage and access easier in calling scopes.

impl From<IotaSystemStateSummaryV1> for IotaSystemStateSummaryV2 {
fn from(v1: IotaSystemStateSummaryV1) -> Self {
let IotaSystemStateSummaryV1 {
epoch,
protocol_version,
system_state_version,
iota_total_supply,
iota_treasury_cap_id,
storage_fund_total_object_storage_rebates,
storage_fund_non_refundable_balance,
reference_gas_price,
safe_mode,
safe_mode_storage_charges,
safe_mode_computation_rewards,
safe_mode_storage_rebates,
safe_mode_non_refundable_storage_fee,
epoch_start_timestamp_ms,
epoch_duration_ms,
min_validator_count,
max_validator_count,
min_validator_joining_stake,
validator_low_stake_threshold,
validator_very_low_stake_threshold,
validator_low_stake_grace_period,
total_stake,
active_validators,
pending_active_validators_id,
pending_active_validators_size,
pending_removals,
staking_pool_mappings_id,
staking_pool_mappings_size,
inactive_pools_id,
inactive_pools_size,
validator_candidates_id,
validator_candidates_size,
at_risk_validators,
validator_report_records,
} = v1;
Self {
epoch,
protocol_version,
system_state_version,
iota_total_supply,
iota_treasury_cap_id,
storage_fund_total_object_storage_rebates,
storage_fund_non_refundable_balance,
reference_gas_price,
safe_mode,
safe_mode_storage_charges,
safe_mode_computation_charges: safe_mode_computation_rewards,
safe_mode_computation_charges_burned: safe_mode_computation_rewards,
safe_mode_storage_rebates,
safe_mode_non_refundable_storage_fee,
epoch_start_timestamp_ms,
epoch_duration_ms,
min_validator_count,
max_validator_count,
min_validator_joining_stake,
validator_low_stake_threshold,
validator_very_low_stake_threshold,
validator_low_stake_grace_period,
total_stake,
active_validators,
pending_active_validators_id,
pending_active_validators_size,
pending_removals,
staking_pool_mappings_id,
staking_pool_mappings_size,
inactive_pools_id,
inactive_pools_size,
validator_candidates_id,
validator_candidates_size,
at_risk_validators,
validator_report_records,
}
}
}

impl From<IotaSystemStateSummaryV2> for IotaSystemStateSummaryV1 {
fn from(v2: IotaSystemStateSummaryV2) -> Self {
let IotaSystemStateSummaryV2 {
epoch,
protocol_version,
system_state_version,
iota_total_supply,
iota_treasury_cap_id,
storage_fund_total_object_storage_rebates,
storage_fund_non_refundable_balance,
reference_gas_price,
safe_mode,
safe_mode_storage_charges,
safe_mode_computation_charges,
safe_mode_computation_charges_burned: _,
safe_mode_storage_rebates,
safe_mode_non_refundable_storage_fee,
epoch_start_timestamp_ms,
epoch_duration_ms,
min_validator_count,
max_validator_count,
min_validator_joining_stake,
validator_low_stake_threshold,
validator_very_low_stake_threshold,
validator_low_stake_grace_period,
total_stake,
active_validators,
pending_active_validators_id,
pending_active_validators_size,
pending_removals,
staking_pool_mappings_id,
staking_pool_mappings_size,
inactive_pools_id,
inactive_pools_size,
validator_candidates_id,
validator_candidates_size,
at_risk_validators,
validator_report_records,
} = v2;
Self {
epoch,
protocol_version,
system_state_version,
iota_total_supply,
iota_treasury_cap_id,
storage_fund_total_object_storage_rebates,
storage_fund_non_refundable_balance,
reference_gas_price,
safe_mode,
safe_mode_storage_charges,
safe_mode_computation_rewards: safe_mode_computation_charges,
safe_mode_storage_rebates,
safe_mode_non_refundable_storage_fee,
epoch_start_timestamp_ms,
epoch_duration_ms,
min_validator_count,
max_validator_count,
min_validator_joining_stake,
validator_low_stake_threshold,
validator_very_low_stake_threshold,
validator_low_stake_grace_period,
total_stake,
active_validators,
pending_active_validators_id,
pending_active_validators_size,
pending_removals,
staking_pool_mappings_id,
staking_pool_mappings_size,
inactive_pools_id,
inactive_pools_size,
validator_candidates_id,
validator_candidates_size,
at_risk_validators,
validator_report_records,
}
}
}

// Conversions from `IotaSystemState` might be fallible in the future.

impl TryFrom<IotaSystemStateSummary> for IotaSystemStateSummaryV1 {
type Error = IotaError;

fn try_from(summary: IotaSystemStateSummary) -> Result<Self, Self::Error> {
Ok(match summary {
IotaSystemStateSummary::V1(v1) => v1,
IotaSystemStateSummary::V2(v2) => v2.into(),
})
}
}

impl TryFrom<IotaSystemStateSummary> for IotaSystemStateSummaryV2 {
type Error = IotaError;

fn try_from(summary: IotaSystemStateSummary) -> Result<Self, Self::Error> {
Ok(match summary {
IotaSystemStateSummary::V1(v1) => v1.into(),
IotaSystemStateSummary::V2(v2) => v2,
})
}
}

/// This is the JSON-RPC type for the IOTA validator. It flattens all inner
/// structures to top-level fields so that they are decoupled from the internal
/// definitions.
Expand Down
Loading