Skip to content

Commit 44fd8b6

Browse files
cyberphysic4lkodemartin
authored andcommitted
iota-graphql-rpc changes
1 parent de97fe2 commit 44fd8b6

File tree

6 files changed

+237
-9
lines changed

6 files changed

+237
-9
lines changed

crates/iota-graphql-rpc/schema.graphql

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,58 @@ type ChangeEpochTransaction {
389389
systemPackages(first: Int, after: String, last: Int, before: String): MovePackageConnection!
390390
}
391391

392+
"""
393+
A system transaction that updates epoch information on-chain (increments the
394+
current epoch). Executed by the system once per epoch, without using gas.
395+
Epoch change transactions cannot be submitted by users, because validators
396+
will refuse to sign them.
397+
"""
398+
type ChangeEpochTransactionV2 {
399+
"""
400+
The next (to become) epoch.
401+
"""
402+
epoch: Epoch
403+
"""
404+
The protocol version in effect in the new epoch.
405+
"""
406+
protocolVersion: UInt53!
407+
"""
408+
The total amount of gas charged for storage during the previous epoch
409+
(in NANOS).
410+
"""
411+
storageCharge: BigInt!
412+
"""
413+
The total amount of gas charged for computation during the previous
414+
epoch (in NANOS).
415+
"""
416+
computationCharge: BigInt!
417+
"""
418+
The total amount of gas burned for computation during the previous
419+
epoch (in NANOS).
420+
"""
421+
computationChargeBurned: BigInt!
422+
"""
423+
The IOTA returned to transaction senders for cleaning up objects (in
424+
NANOS).
425+
"""
426+
storageRebate: BigInt!
427+
"""
428+
The total gas retained from storage fees, that will not be returned by
429+
storage rebates when the relevant objects are cleaned up (in NANOS).
430+
"""
431+
nonRefundableStorageFee: BigInt!
432+
"""
433+
Time at which the next epoch will start.
434+
"""
435+
startTimestamp: DateTime!
436+
"""
437+
System packages (specifically framework and move stdlib) that are
438+
written before the new epoch starts, to upgrade them on-chain.
439+
Validators write these packages out when running the transaction.
440+
"""
441+
systemPackages(first: Int, after: String, last: Int, before: String): MovePackageConnection!
442+
}
443+
392444
"""
393445
Checkpoints contain finalized transactions and are used for node
394446
synchronization and global transaction ordering.
@@ -1029,7 +1081,7 @@ type EndOfEpochTransaction {
10291081
transactions(first: Int, before: String, last: Int, after: String): EndOfEpochTransactionKindConnection!
10301082
}
10311083

1032-
union EndOfEpochTransactionKind = ChangeEpochTransaction | AuthenticatorStateCreateTransaction | AuthenticatorStateExpireTransaction | BridgeStateCreateTransaction | BridgeCommitteeInitTransaction
1084+
union EndOfEpochTransactionKind = ChangeEpochTransaction | ChangeEpochTransactionV2 | AuthenticatorStateCreateTransaction | AuthenticatorStateExpireTransaction | BridgeStateCreateTransaction | BridgeCommitteeInitTransaction
10331085

10341086
type EndOfEpochTransactionKindConnection {
10351087
"""
@@ -1385,7 +1437,7 @@ type GasCostSummary {
13851437
"""
13861438
computationCost: BigInt
13871439
"""
1388-
Gas burned for executing this transactions (in NANOS).
1440+
Gas burned for executing this transaction (in NANOS).
13891441
"""
13901442
computationCostBurned: BigInt
13911443
"""

crates/iota-graphql-rpc/src/types/checkpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl Checkpoint {
136136
async fn rolling_gas_summary(&self) -> Option<GasCostSummary> {
137137
Some(GasCostSummary {
138138
computation_cost: self.stored.computation_cost as u64,
139-
computation_cost_burned: self.stored.computation_cost as u64,
139+
computation_cost_burned: self.stored.computation_cost_burned as u64,
140140
storage_cost: self.stored.storage_cost as u64,
141141
storage_rebate: self.stored.storage_rebate as u64,
142142
non_refundable_storage_fee: self.stored.non_refundable_storage_fee as u64,

crates/iota-graphql-rpc/src/types/gas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl GasCostSummary {
111111
Some(BigInt::from(self.computation_cost))
112112
}
113113

114-
/// Gas burned for executing this transactions (in NANOS).
114+
/// Gas burned for executing this transaction (in NANOS).
115115
async fn computation_cost_burned(&self) -> Option<BigInt> {
116116
Some(BigInt::from(self.computation_cost_burned))
117117
}

crates/iota-graphql-rpc/src/types/system_state_summary.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ impl SystemStateSummary {
3838
Some(SafeMode {
3939
enabled: Some(self.native.safe_mode),
4040
gas_summary: Some(GasCostSummary {
41-
computation_cost: self.native.safe_mode_computation_rewards,
42-
// All computation costs are burned in protocol v1.
43-
computation_cost_burned: self.native.safe_mode_computation_rewards,
41+
computation_cost: self.native.safe_mode_computation_charges,
42+
computation_cost_burned: self.native.safe_mode_computation_charges_burned,
4443
storage_cost: self.native.safe_mode_storage_charges,
4544
storage_rebate: self.native.safe_mode_storage_rebates,
4645
non_refundable_storage_fee: self.native.safe_mode_non_refundable_storage_fee,

crates/iota-graphql-rpc/src/types/transaction_block_kind/end_of_epoch.rs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use iota_types::{
1313
transaction::{
1414
AuthenticatorStateExpire as NativeAuthenticatorStateExpireTransaction,
1515
ChangeEpoch as NativeChangeEpochTransaction,
16+
ChangeEpochV2 as NativeChangeEpochTransactionV2,
1617
EndOfEpochTransactionKind as NativeEndOfEpochTransactionKind,
1718
},
1819
};
@@ -43,19 +44,31 @@ pub(crate) struct EndOfEpochTransaction {
4344
#[derive(Union, Clone, PartialEq, Eq)]
4445
pub(crate) enum EndOfEpochTransactionKind {
4546
ChangeEpoch(ChangeEpochTransaction),
47+
ChangeEpochV2(ChangeEpochTransactionV2),
4648
AuthenticatorStateCreate(AuthenticatorStateCreateTransaction),
4749
AuthenticatorStateExpire(AuthenticatorStateExpireTransaction),
4850
BridgeStateCreate(BridgeStateCreateTransaction),
4951
BridgeCommitteeInit(BridgeCommitteeInitTransaction),
5052
}
5153

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

62+
// System transaction for advancing the epoch.
63+
// This version includes the computation_charge_burned field for when
64+
// protocol_defined_base_fee is enabled in the protocol config.
65+
#[derive(Clone, PartialEq, Eq)]
66+
pub(crate) struct ChangeEpochTransactionV2 {
67+
pub native: NativeChangeEpochTransactionV2,
68+
/// The checkpoint sequence number this was viewed at.
69+
pub checkpoint_viewed_at: u64,
70+
}
71+
5972
/// System transaction for creating the on-chain state used by zkLogin.
6073
#[derive(SimpleObject, Clone, PartialEq, Eq)]
6174
pub(crate) struct AuthenticatorStateCreateTransaction {
@@ -226,6 +239,113 @@ impl ChangeEpochTransaction {
226239
}
227240
}
228241

242+
/// A system transaction that updates epoch information on-chain (increments the
243+
/// current epoch). Executed by the system once per epoch, without using gas.
244+
/// Epoch change transactions cannot be submitted by users, because validators
245+
/// will refuse to sign them.
246+
#[Object]
247+
impl ChangeEpochTransactionV2 {
248+
/// The next (to become) epoch.
249+
async fn epoch(&self, ctx: &Context<'_>) -> Result<Option<Epoch>> {
250+
Epoch::query(ctx, Some(self.native.epoch), self.checkpoint_viewed_at)
251+
.await
252+
.extend()
253+
}
254+
255+
/// The protocol version in effect in the new epoch.
256+
async fn protocol_version(&self) -> UInt53 {
257+
self.native.protocol_version.as_u64().into()
258+
}
259+
260+
/// The total amount of gas charged for storage during the previous epoch
261+
/// (in NANOS).
262+
async fn storage_charge(&self) -> BigInt {
263+
BigInt::from(self.native.storage_charge)
264+
}
265+
266+
/// The total amount of gas charged for computation during the previous
267+
/// epoch (in NANOS).
268+
async fn computation_charge(&self) -> BigInt {
269+
BigInt::from(self.native.computation_charge)
270+
}
271+
272+
/// The total amount of gas burned for computation during the previous
273+
/// epoch (in NANOS).
274+
async fn computation_charge_burned(&self) -> BigInt {
275+
BigInt::from(self.native.computation_charge_burned)
276+
}
277+
278+
/// The IOTA returned to transaction senders for cleaning up objects (in
279+
/// NANOS).
280+
async fn storage_rebate(&self) -> BigInt {
281+
BigInt::from(self.native.storage_rebate)
282+
}
283+
284+
/// The total gas retained from storage fees, that will not be returned by
285+
/// storage rebates when the relevant objects are cleaned up (in NANOS).
286+
async fn non_refundable_storage_fee(&self) -> BigInt {
287+
BigInt::from(self.native.non_refundable_storage_fee)
288+
}
289+
290+
/// Time at which the next epoch will start.
291+
async fn start_timestamp(&self) -> Result<DateTime, Error> {
292+
DateTime::from_ms(self.native.epoch_start_timestamp_ms as i64)
293+
}
294+
295+
/// System packages (specifically framework and move stdlib) that are
296+
/// written before the new epoch starts, to upgrade them on-chain.
297+
/// Validators write these packages out when running the transaction.
298+
async fn system_packages(
299+
&self,
300+
ctx: &Context<'_>,
301+
first: Option<u64>,
302+
after: Option<CPackage>,
303+
last: Option<u64>,
304+
before: Option<CPackage>,
305+
) -> Result<Connection<String, MovePackage>> {
306+
let page = Page::from_params(ctx.data_unchecked(), first, after, last, before)?;
307+
308+
let mut connection = Connection::new(false, false);
309+
let Some((prev, next, _, cs)) = page.paginate_consistent_indices(
310+
self.native.system_packages.len(),
311+
self.checkpoint_viewed_at,
312+
)?
313+
else {
314+
return Ok(connection);
315+
};
316+
317+
connection.has_previous_page = prev;
318+
connection.has_next_page = next;
319+
320+
for c in cs {
321+
let (version, modules, deps) = &self.native.system_packages[c.ix];
322+
let compiled_modules = modules
323+
.iter()
324+
.map(|bytes| CompiledModule::deserialize_with_defaults(bytes))
325+
.collect::<PartialVMResult<Vec<_>>>()
326+
.map_err(|e| Error::Internal(format!("Failed to deserialize system modules: {e}")))
327+
.extend()?;
328+
329+
let native = NativeObject::new_system_package(
330+
&compiled_modules,
331+
*version,
332+
deps.clone(),
333+
TransactionDigest::ZERO,
334+
);
335+
336+
let runtime_id = native.id();
337+
let object = Object::from_native(IotaAddress::from(runtime_id), native, c.c, None);
338+
let package = MovePackage::try_from(&object)
339+
.map_err(|_| Error::Internal("Failed to create system package".to_string()))
340+
.extend()?;
341+
342+
connection.edges.push(Edge::new(c.encode_cursor(), package));
343+
}
344+
345+
Ok(connection)
346+
}
347+
}
348+
229349
#[Object]
230350
impl AuthenticatorStateExpireTransaction {
231351
/// Expire JWKs that have a lower epoch than this.
@@ -268,6 +388,10 @@ impl EndOfEpochTransactionKind {
268388
native: ce,
269389
checkpoint_viewed_at,
270390
}),
391+
N::ChangeEpochV2(ce) => K::ChangeEpochV2(ChangeEpochTransactionV2 {
392+
native: ce,
393+
checkpoint_viewed_at,
394+
}),
271395
N::AuthenticatorStateCreate => {
272396
K::AuthenticatorStateCreate(AuthenticatorStateCreateTransaction { dummy: None })
273397
}

crates/iota-graphql-rpc/tests/snapshots/snapshot_tests__schema_sdl_export.snap

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
source: crates/iota-graphql-rpc/tests/snapshot_tests.rs
33
expression: sdl
4+
snapshot_kind: text
45
---
56
type ActiveJwk {
67
"""
@@ -393,6 +394,58 @@ type ChangeEpochTransaction {
393394
systemPackages(first: Int, after: String, last: Int, before: String): MovePackageConnection!
394395
}
395396
397+
"""
398+
A system transaction that updates epoch information on-chain (increments the
399+
current epoch). Executed by the system once per epoch, without using gas.
400+
Epoch change transactions cannot be submitted by users, because validators
401+
will refuse to sign them.
402+
"""
403+
type ChangeEpochTransactionV2 {
404+
"""
405+
The next (to become) epoch.
406+
"""
407+
epoch: Epoch
408+
"""
409+
The protocol version in effect in the new epoch.
410+
"""
411+
protocolVersion: UInt53!
412+
"""
413+
The total amount of gas charged for storage during the previous epoch
414+
(in NANOS).
415+
"""
416+
storageCharge: BigInt!
417+
"""
418+
The total amount of gas charged for computation during the previous
419+
epoch (in NANOS).
420+
"""
421+
computationCharge: BigInt!
422+
"""
423+
The total amount of gas burned for computation during the previous
424+
epoch (in NANOS).
425+
"""
426+
computationChargeBurned: BigInt!
427+
"""
428+
The IOTA returned to transaction senders for cleaning up objects (in
429+
NANOS).
430+
"""
431+
storageRebate: BigInt!
432+
"""
433+
The total gas retained from storage fees, that will not be returned by
434+
storage rebates when the relevant objects are cleaned up (in NANOS).
435+
"""
436+
nonRefundableStorageFee: BigInt!
437+
"""
438+
Time at which the next epoch will start.
439+
"""
440+
startTimestamp: DateTime!
441+
"""
442+
System packages (specifically framework and move stdlib) that are
443+
written before the new epoch starts, to upgrade them on-chain.
444+
Validators write these packages out when running the transaction.
445+
"""
446+
systemPackages(first: Int, after: String, last: Int, before: String): MovePackageConnection!
447+
}
448+
396449
"""
397450
Checkpoints contain finalized transactions and are used for node
398451
synchronization and global transaction ordering.
@@ -1033,7 +1086,7 @@ type EndOfEpochTransaction {
10331086
transactions(first: Int, before: String, last: Int, after: String): EndOfEpochTransactionKindConnection!
10341087
}
10351088
1036-
union EndOfEpochTransactionKind = ChangeEpochTransaction | AuthenticatorStateCreateTransaction | AuthenticatorStateExpireTransaction | BridgeStateCreateTransaction | BridgeCommitteeInitTransaction
1089+
union EndOfEpochTransactionKind = ChangeEpochTransaction | ChangeEpochTransactionV2 | AuthenticatorStateCreateTransaction | AuthenticatorStateExpireTransaction | BridgeStateCreateTransaction | BridgeCommitteeInitTransaction
10371090
10381091
type EndOfEpochTransactionKindConnection {
10391092
"""
@@ -1389,7 +1442,7 @@ type GasCostSummary {
13891442
"""
13901443
computationCost: BigInt
13911444
"""
1392-
Gas burned for executing this transactions (in NANOS).
1445+
Gas burned for executing this transaction (in NANOS).
13931446
"""
13941447
computationCostBurned: BigInt
13951448
"""

0 commit comments

Comments
 (0)