Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce ChangeEpochV2 #22

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,24 @@ async fn main() -> Result<(), anyhow::Error> {
}
IotaTransactionBlockKind::EndOfEpochTransaction(end_of_epoch_tx) => {
for tx_kind in &end_of_epoch_tx.transactions {
if let IotaEndOfEpochTransactionKind::ChangeEpoch(_change_epoch) = tx_kind {
if !got_epoch_change {
write_bs64_tx_to_file(
&raw_tx_bytes_to_transaction_data_bytes(&tx.raw_transaction)?,
"change-epoch",
)?;
got_epoch_change = true;
match tx_kind {
IotaEndOfEpochTransactionKind::ChangeEpoch(_change_epoch) => {
if !got_epoch_change {
write_bs64_tx_to_file(
&raw_tx_bytes_to_transaction_data_bytes(&tx.raw_transaction)?,
"change-epoch",
)?;
got_epoch_change = true;
}
}
IotaEndOfEpochTransactionKind::ChangeEpochV2(_change_epoch_v2) => {
if !got_epoch_change {
write_bs64_tx_to_file(
&raw_tx_bytes_to_transaction_data_bytes(&tx.raw_transaction)?,
"change-epoch-v2",
)?;
got_epoch_change = true;
}
}
}
}
Expand Down
51 changes: 51 additions & 0 deletions crates/iota-rust-sdk/src/types/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub enum TransactionKind {
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub enum EndOfEpochTransactionKind {
ChangeEpoch(ChangeEpoch),
ChangeEpochV2(ChangeEpochV2),
AuthenticatorStateCreate,
AuthenticatorStateExpire(AuthenticatorStateExpire),
BridgeStateCreate {
Expand Down Expand Up @@ -326,6 +327,56 @@ pub struct ChangeEpoch {
pub system_packages: Vec<SystemPackage>,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub struct ChangeEpochV2 {
/// The next (to become) epoch ID.
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub epoch: EpochId,
/// The protocol version in effect in the new epoch.
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub protocol_version: ProtocolVersion,
/// The total amount of gas charged for storage during the epoch.
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub storage_charge: u64,
/// The total amount of gas charged for computation during the epoch.
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub computation_charge: u64,
/// The total amount of gas burned for computation during the epoch.
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub computation_charge_burned: u64,
/// The amount of storage rebate refunded to the txn senders.
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub storage_rebate: u64,
/// The non-refundable storage fee.
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub non_refundable_storage_fee: u64,
/// Unix timestamp when epoch started
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub epoch_start_timestamp_ms: u64,
/// System packages (specifically framework and move stdlib) that are
/// written before the new epoch starts. This tracks framework upgrades
/// on chain. When executing the ChangeEpoch txn, the validator must
/// write out the modules below. Modules are provided with the version they
/// will be upgraded to, their modules in serialized form (which include
/// their package ID), and a list of their transitive dependencies.
#[cfg_attr(test, any(proptest::collection::size_range(0..=2).lift()))]
pub system_packages: Vec<SystemPackage>,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
Expand Down
16 changes: 15 additions & 1 deletion crates/iota-rust-sdk/src/types/transaction/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,16 @@ mod end_of_epoch {
use super::*;
use crate::types::{
CheckpointDigest,
transaction::{AuthenticatorStateExpire, ChangeEpoch, EndOfEpochTransactionKind},
transaction::{
AuthenticatorStateExpire, ChangeEpoch, ChangeEpochV2, EndOfEpochTransactionKind,
},
};

#[derive(serde_derive::Serialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
enum ReadableEndOfEpochTransactionKindRef<'a> {
ChangeEpoch(&'a ChangeEpoch),
ChangeEpochV2(&'a ChangeEpochV2),
AuthenticatorStateCreate,
AuthenticatorStateExpire(&'a AuthenticatorStateExpire),
BridgeStateCreate {
Expand All @@ -303,6 +306,7 @@ mod end_of_epoch {
#[serde(tag = "kind", rename_all = "snake_case")]
enum ReadableEndOfEpochTransactionKind {
ChangeEpoch(ChangeEpoch),
ChangeEpochV2(ChangeEpochV2),
AuthenticatorStateCreate,
AuthenticatorStateExpire(AuthenticatorStateExpire),
BridgeStateCreate {
Expand All @@ -317,6 +321,7 @@ mod end_of_epoch {
#[derive(serde_derive::Serialize)]
enum BinaryEndOfEpochTransactionKindRef<'a> {
ChangeEpoch(&'a ChangeEpoch),
ChangeEpochV2(&'a ChangeEpochV2),
AuthenticatorStateCreate,
AuthenticatorStateExpire(&'a AuthenticatorStateExpire),
BridgeStateCreate { chain_id: &'a CheckpointDigest },
Expand All @@ -326,6 +331,7 @@ mod end_of_epoch {
#[derive(serde_derive::Deserialize)]
enum BinaryEndOfEpochTransactionKind {
ChangeEpoch(ChangeEpoch),
ChangeEpochV2(ChangeEpochV2),
AuthenticatorStateCreate,
AuthenticatorStateExpire(AuthenticatorStateExpire),
BridgeStateCreate { chain_id: CheckpointDigest },
Expand All @@ -340,6 +346,9 @@ mod end_of_epoch {
if serializer.is_human_readable() {
let readable = match self {
Self::ChangeEpoch(k) => ReadableEndOfEpochTransactionKindRef::ChangeEpoch(k),
Self::ChangeEpochV2(k) => {
ReadableEndOfEpochTransactionKindRef::ChangeEpochV2(k)
}
Self::AuthenticatorStateCreate => {
ReadableEndOfEpochTransactionKindRef::AuthenticatorStateCreate
}
Expand All @@ -359,6 +368,7 @@ mod end_of_epoch {
} else {
let binary = match self {
Self::ChangeEpoch(k) => BinaryEndOfEpochTransactionKindRef::ChangeEpoch(k),
Self::ChangeEpochV2(k) => BinaryEndOfEpochTransactionKindRef::ChangeEpochV2(k),
Self::AuthenticatorStateCreate => {
BinaryEndOfEpochTransactionKindRef::AuthenticatorStateCreate
}
Expand Down Expand Up @@ -388,6 +398,9 @@ mod end_of_epoch {
ReadableEndOfEpochTransactionKind::deserialize(deserializer).map(|readable| {
match readable {
ReadableEndOfEpochTransactionKind::ChangeEpoch(k) => Self::ChangeEpoch(k),
ReadableEndOfEpochTransactionKind::ChangeEpochV2(k) => {
Self::ChangeEpochV2(k)
}
ReadableEndOfEpochTransactionKind::AuthenticatorStateCreate => {
Self::AuthenticatorStateCreate
}
Expand All @@ -408,6 +421,7 @@ mod end_of_epoch {
BinaryEndOfEpochTransactionKind::deserialize(deserializer).map(
|binary| match binary {
BinaryEndOfEpochTransactionKind::ChangeEpoch(k) => Self::ChangeEpoch(k),
BinaryEndOfEpochTransactionKind::ChangeEpochV2(k) => Self::ChangeEpochV2(k),
BinaryEndOfEpochTransactionKind::AuthenticatorStateCreate => {
Self::AuthenticatorStateCreate
}
Expand Down
Loading