@@ -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 ) ]
4445pub ( 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 ) ]
5356pub ( 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 ) ]
6174pub ( 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 ]
230350impl 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 }
0 commit comments