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
56 changes: 54 additions & 2 deletions crates/iota-graphql-rpc/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,58 @@ type ChangeEpochTransaction {
systemPackages(first: Int, after: String, last: Int, before: String): MovePackageConnection!
}

"""
A system transaction that updates epoch information on-chain (increments the
current epoch). Executed by the system once per epoch, without using gas.
Epoch change transactions cannot be submitted by users, because validators
will refuse to sign them.
"""
type ChangeEpochTransactionV2 {
"""
The next (to become) epoch.
"""
epoch: Epoch
"""
The protocol version in effect in the new epoch.
"""
protocolVersion: UInt53!
"""
The total amount of gas charged for storage during the previous epoch
(in NANOS).
"""
storageCharge: BigInt!
"""
The total amount of gas charged for computation during the previous
epoch (in NANOS).
"""
computationCharge: BigInt!
"""
The total amount of gas burned for computation during the previous
epoch (in NANOS).
"""
computationChargeBurned: BigInt!
"""
The IOTA returned to transaction senders for cleaning up objects (in
NANOS).
"""
storageRebate: BigInt!
"""
The total gas retained from storage fees, that will not be returned by
storage rebates when the relevant objects are cleaned up (in NANOS).
"""
nonRefundableStorageFee: BigInt!
"""
Time at which the next epoch will start.
"""
startTimestamp: DateTime!
"""
System packages (specifically framework and move stdlib) that are
written before the new epoch starts, to upgrade them on-chain.
Validators write these packages out when running the transaction.
"""
systemPackages(first: Int, after: String, last: Int, before: String): MovePackageConnection!
}

"""
Checkpoints contain finalized transactions and are used for node
synchronization and global transaction ordering.
Expand Down Expand Up @@ -1029,7 +1081,7 @@ type EndOfEpochTransaction {
transactions(first: Int, before: String, last: Int, after: String): EndOfEpochTransactionKindConnection!
}

union EndOfEpochTransactionKind = ChangeEpochTransaction | AuthenticatorStateCreateTransaction | AuthenticatorStateExpireTransaction | BridgeStateCreateTransaction | BridgeCommitteeInitTransaction
union EndOfEpochTransactionKind = ChangeEpochTransaction | ChangeEpochTransactionV2 | AuthenticatorStateCreateTransaction | AuthenticatorStateExpireTransaction | BridgeStateCreateTransaction | BridgeCommitteeInitTransaction

type EndOfEpochTransactionKindConnection {
"""
Expand Down Expand Up @@ -1385,7 +1437,7 @@ type GasCostSummary {
"""
computationCost: BigInt
"""
Gas burned for executing this transactions (in NANOS).
Gas burned for executing this transaction (in NANOS).
"""
computationCostBurned: BigInt
"""
Expand Down
48 changes: 3 additions & 45 deletions crates/iota-graphql-rpc/src/context_data/db_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::{collections::BTreeMap, time::Duration};
use std::time::Duration;

use iota_indexer::{
apis::GovernanceReadApi, db::ConnectionPoolConfig, indexer_reader::IndexerReader,
Expand All @@ -13,10 +13,7 @@ use iota_types::{
iota_system_state::iota_system_state_summary::IotaSystemStateSummary as NativeIotaSystemStateSummary,
};

use crate::{
error::Error,
types::{address::Address, iota_address::IotaAddress, validator::Validator},
};
use crate::{error::Error, types::system_state_summary::SystemStateSummaryView};

pub(crate) struct PgManager {
pub inner: IndexerReader,
Expand Down Expand Up @@ -55,7 +52,7 @@ impl PgManager {
.spawn_blocking(move |this| this.get_latest_iota_system_state())
.await?;

if epoch_id.is_none() || epoch_id.is_some_and(|id| id == latest_iota_system_state.epoch) {
if epoch_id.is_none() || epoch_id.is_some_and(|id| id == latest_iota_system_state.epoch()) {
Ok(latest_iota_system_state)
} else {
Ok(self
Expand Down Expand Up @@ -94,42 +91,3 @@ impl PgManager {
Ok(stake)
}
}

/// `checkpoint_viewed_at` represents the checkpoint sequence number at which
/// the set of `IotaValidatorSummary` was queried for. Each `Validator` will
/// inherit this checkpoint, so that when viewing the `Validator`'s state, it
/// will be as if it was read at the same checkpoint.
pub(crate) fn convert_to_validators(
system_state_at_requested_epoch: NativeIotaSystemStateSummary,
checkpoint_viewed_at: u64,
requested_for_epoch: u64,
) -> Vec<Validator> {
let at_risk = BTreeMap::from_iter(system_state_at_requested_epoch.at_risk_validators);
let reports = BTreeMap::from_iter(system_state_at_requested_epoch.validator_report_records);

system_state_at_requested_epoch
.active_validators
.into_iter()
.map(move |validator_summary| {
let at_risk = at_risk.get(&validator_summary.iota_address).copied();
let report_records = reports.get(&validator_summary.iota_address).map(|addrs| {
addrs
.iter()
.cloned()
.map(|a| Address {
address: IotaAddress::from(a),
checkpoint_viewed_at,
})
.collect()
});

Validator {
validator_summary,
at_risk,
report_records,
checkpoint_viewed_at,
requested_for_epoch,
}
})
.collect()
}
2 changes: 1 addition & 1 deletion crates/iota-graphql-rpc/src/types/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Checkpoint {
async fn rolling_gas_summary(&self) -> Option<GasCostSummary> {
Some(GasCostSummary {
computation_cost: self.stored.computation_cost as u64,
computation_cost_burned: self.stored.computation_cost as u64,
computation_cost_burned: self.stored.computation_cost_burned(),
storage_cost: self.stored.storage_cost as u64,
storage_rebate: self.stored.storage_rebate as u64,
non_refundable_storage_fee: self.stored.non_refundable_storage_fee as u64,
Expand Down
3 changes: 2 additions & 1 deletion crates/iota-graphql-rpc/src/types/coin_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::{
object::{self, Object, ObjectFilter, ObjectImpl, ObjectOwner, ObjectStatus},
owner::OwnerImpl,
stake::StakedIota,
system_state_summary::SystemStateSummaryView,
transaction_block::{self, TransactionBlock, TransactionBlockFilter},
type_filter::ExactTypeFilter,
uint53::UInt53,
Expand Down Expand Up @@ -381,7 +382,7 @@ impl CoinMetadata {

let state = pg_manager.fetch_iota_system_state(None).await?;

state.iota_total_supply
state.iota_total_supply()
} else {
let cap_type = TreasuryCap::type_(*coin_struct);

Expand Down
22 changes: 4 additions & 18 deletions crates/iota-graphql-rpc/src/types/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use iota_types::messages_checkpoint::CheckpointCommitment as EpochCommitment;

use crate::{
connection::ScanConnection,
context_data::db_data_provider::{PgManager, convert_to_validators},
context_data::db_data_provider::PgManager,
data::{DataLoader, Db, DbConnection, QueryExecutor},
error::Error,
server::watermark_task::Watermark,
Expand All @@ -22,7 +22,7 @@ use crate::{
cursor::Page,
date_time::DateTime,
protocol_config::ProtocolConfigs,
system_state_summary::SystemStateSummary,
system_state_summary::{NativeStateValidatorInfo, SystemStateSummary},
transaction_block::{self, TransactionBlock, TransactionBlockFilter},
uint53::UInt53,
validator_set::ValidatorSet,
Expand Down Expand Up @@ -71,25 +71,11 @@ impl Epoch {
.fetch_iota_system_state(Some(self.stored.epoch as u64))
.await?;

let active_validators = convert_to_validators(
system_state.clone(),
let validator_set = NativeStateValidatorInfo::from(system_state).into_validator_set(
self.stored.total_stake as u64,
self.checkpoint_viewed_at,
self.stored.epoch as u64,
);
let validator_set = ValidatorSet {
total_stake: Some(BigInt::from(self.stored.total_stake)),
active_validators: Some(active_validators),
pending_removals: Some(system_state.pending_removals),
pending_active_validators_id: Some(system_state.pending_active_validators_id.into()),
pending_active_validators_size: Some(system_state.pending_active_validators_size),
staking_pool_mappings_id: Some(system_state.staking_pool_mappings_id.into()),
staking_pool_mappings_size: Some(system_state.staking_pool_mappings_size),
inactive_pools_id: Some(system_state.inactive_pools_id.into()),
inactive_pools_size: Some(system_state.inactive_pools_size),
validator_candidates_id: Some(system_state.validator_candidates_id.into()),
validator_candidates_size: Some(system_state.validator_candidates_size),
checkpoint_viewed_at: self.checkpoint_viewed_at,
};
Ok(Some(validator_set))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/iota-graphql-rpc/src/types/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl GasCostSummary {
Some(BigInt::from(self.computation_cost))
}

/// Gas burned for executing this transactions (in NANOS).
/// Gas burned for executing this transaction (in NANOS).
async fn computation_cost_burned(&self) -> Option<BigInt> {
Some(BigInt::from(self.computation_cost_burned))
}
Expand Down
Loading
Loading