Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 as u64,
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
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
5 changes: 2 additions & 3 deletions crates/iota-graphql-rpc/src/types/system_state_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ impl SystemStateSummary {
Some(SafeMode {
enabled: Some(self.native.safe_mode),
gas_summary: Some(GasCostSummary {
computation_cost: self.native.safe_mode_computation_rewards,
// All computation costs are burned in protocol v1.
computation_cost_burned: self.native.safe_mode_computation_rewards,
computation_cost: self.native.safe_mode_computation_charges,
computation_cost_burned: self.native.safe_mode_computation_charges_burned,
storage_cost: self.native.safe_mode_storage_charges,
storage_rebate: self.native.safe_mode_storage_rebates,
non_refundable_storage_fee: self.native.safe_mode_non_refundable_storage_fee,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use iota_types::{
transaction::{
AuthenticatorStateExpire as NativeAuthenticatorStateExpireTransaction,
ChangeEpoch as NativeChangeEpochTransaction,
ChangeEpochV2 as NativeChangeEpochTransactionV2,
EndOfEpochTransactionKind as NativeEndOfEpochTransactionKind,
},
};
Expand Down Expand Up @@ -43,19 +44,31 @@ pub(crate) struct EndOfEpochTransaction {
#[derive(Union, Clone, PartialEq, Eq)]
pub(crate) enum EndOfEpochTransactionKind {
ChangeEpoch(ChangeEpochTransaction),
ChangeEpochV2(ChangeEpochTransactionV2),
AuthenticatorStateCreate(AuthenticatorStateCreateTransaction),
AuthenticatorStateExpire(AuthenticatorStateExpireTransaction),
BridgeStateCreate(BridgeStateCreateTransaction),
BridgeCommitteeInit(BridgeCommitteeInitTransaction),
}

// System transaction for advancing the epoch.
#[derive(Clone, PartialEq, Eq)]
pub(crate) struct ChangeEpochTransaction {
pub native: NativeChangeEpochTransaction,
/// The checkpoint sequence number this was viewed at.
pub checkpoint_viewed_at: u64,
}

// System transaction for advancing the epoch.
// This version includes the computation_charge_burned field for when
// protocol_defined_base_fee is enabled in the protocol config.
#[derive(Clone, PartialEq, Eq)]
pub(crate) struct ChangeEpochTransactionV2 {
pub native: NativeChangeEpochTransactionV2,
/// The checkpoint sequence number this was viewed at.
pub checkpoint_viewed_at: u64,
}

/// System transaction for creating the on-chain state used by zkLogin.
#[derive(SimpleObject, Clone, PartialEq, Eq)]
pub(crate) struct AuthenticatorStateCreateTransaction {
Expand Down Expand Up @@ -226,6 +239,113 @@ impl ChangeEpochTransaction {
}
}

/// 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.
#[Object]
impl ChangeEpochTransactionV2 {
/// The next (to become) epoch.
async fn epoch(&self, ctx: &Context<'_>) -> Result<Option<Epoch>> {
Epoch::query(ctx, Some(self.native.epoch), self.checkpoint_viewed_at)
.await
.extend()
}

/// The protocol version in effect in the new epoch.
async fn protocol_version(&self) -> UInt53 {
self.native.protocol_version.as_u64().into()
}

/// The total amount of gas charged for storage during the previous epoch
/// (in NANOS).
async fn storage_charge(&self) -> BigInt {
BigInt::from(self.native.storage_charge)
}

/// The total amount of gas charged for computation during the previous
/// epoch (in NANOS).
async fn computation_charge(&self) -> BigInt {
BigInt::from(self.native.computation_charge)
}

/// The total amount of gas burned for computation during the previous
/// epoch (in NANOS).
async fn computation_charge_burned(&self) -> BigInt {
BigInt::from(self.native.computation_charge_burned)
}

/// The IOTA returned to transaction senders for cleaning up objects (in
/// NANOS).
async fn storage_rebate(&self) -> BigInt {
BigInt::from(self.native.storage_rebate)
}

/// The total gas retained from storage fees, that will not be returned by
/// storage rebates when the relevant objects are cleaned up (in NANOS).
async fn non_refundable_storage_fee(&self) -> BigInt {
BigInt::from(self.native.non_refundable_storage_fee)
}

/// Time at which the next epoch will start.
async fn start_timestamp(&self) -> Result<DateTime, Error> {
DateTime::from_ms(self.native.epoch_start_timestamp_ms as i64)
}

/// 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.
async fn system_packages(
&self,
ctx: &Context<'_>,
first: Option<u64>,
after: Option<CPackage>,
last: Option<u64>,
before: Option<CPackage>,
) -> Result<Connection<String, MovePackage>> {
let page = Page::from_params(ctx.data_unchecked(), first, after, last, before)?;

let mut connection = Connection::new(false, false);
let Some((prev, next, _, cs)) = page.paginate_consistent_indices(
self.native.system_packages.len(),
self.checkpoint_viewed_at,
)?
else {
return Ok(connection);
};

connection.has_previous_page = prev;
connection.has_next_page = next;

for c in cs {
let (version, modules, deps) = &self.native.system_packages[c.ix];
let compiled_modules = modules
.iter()
.map(|bytes| CompiledModule::deserialize_with_defaults(bytes))
.collect::<PartialVMResult<Vec<_>>>()
.map_err(|e| Error::Internal(format!("Failed to deserialize system modules: {e}")))
.extend()?;

let native = NativeObject::new_system_package(
&compiled_modules,
*version,
deps.clone(),
TransactionDigest::ZERO,
);

let runtime_id = native.id();
let object = Object::from_native(IotaAddress::from(runtime_id), native, c.c, None);
let package = MovePackage::try_from(&object)
.map_err(|_| Error::Internal("Failed to create system package".to_string()))
.extend()?;

connection.edges.push(Edge::new(c.encode_cursor(), package));
}

Ok(connection)
}
}

#[Object]
impl AuthenticatorStateExpireTransaction {
/// Expire JWKs that have a lower epoch than this.
Expand Down Expand Up @@ -268,6 +388,10 @@ impl EndOfEpochTransactionKind {
native: ce,
checkpoint_viewed_at,
}),
N::ChangeEpochV2(ce) => K::ChangeEpochV2(ChangeEpochTransactionV2 {
native: ce,
checkpoint_viewed_at,
}),
N::AuthenticatorStateCreate => {
K::AuthenticatorStateCreate(AuthenticatorStateCreateTransaction { dummy: None })
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/iota-graphql-rpc/tests/snapshot_tests.rs
expression: sdl
snapshot_kind: text
---
type ActiveJwk {
"""
Expand Down Expand Up @@ -393,6 +394,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 @@ -1033,7 +1086,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 @@ -1389,7 +1442,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
Loading