Skip to content

Commit f260aa3

Browse files
cyberphysic4lkodemartin
authored andcommitted
feat(protocol): PCR-2 iota-rest-api (#5276)
* iota-rest-api changes * refactor(rest-api): use v2 of system state summary (#5455) --------- Co-authored-by: Konstantinos Demartinos <[email protected]>
1 parent e127e9c commit f260aa3

File tree

3 files changed

+99
-13
lines changed

3 files changed

+99
-13
lines changed

crates/iota-rest-api/openapi/openapi.json

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,76 @@
19221922
}
19231923
}
19241924
},
1925+
{
1926+
"type": "object",
1927+
"required": [
1928+
"computation_charge",
1929+
"computation_charge_burned",
1930+
"epoch",
1931+
"epoch_start_timestamp_ms",
1932+
"kind",
1933+
"non_refundable_storage_fee",
1934+
"protocol_version",
1935+
"storage_charge",
1936+
"storage_rebate",
1937+
"system_packages"
1938+
],
1939+
"properties": {
1940+
"computation_charge": {
1941+
"description": "The total amount of gas charged for computation during the epoch.",
1942+
"type": "string",
1943+
"format": "u64"
1944+
},
1945+
"computation_charge_burned": {
1946+
"description": "The total amount of gas burned for computation during the epoch.",
1947+
"type": "string",
1948+
"format": "u64"
1949+
},
1950+
"epoch": {
1951+
"description": "The next (to become) epoch ID.",
1952+
"type": "string",
1953+
"format": "u64"
1954+
},
1955+
"epoch_start_timestamp_ms": {
1956+
"description": "Unix timestamp when epoch started",
1957+
"type": "string",
1958+
"format": "u64"
1959+
},
1960+
"kind": {
1961+
"type": "string",
1962+
"enum": [
1963+
"change_epoch_v2"
1964+
]
1965+
},
1966+
"non_refundable_storage_fee": {
1967+
"description": "The non-refundable storage fee.",
1968+
"type": "string",
1969+
"format": "u64"
1970+
},
1971+
"protocol_version": {
1972+
"description": "The protocol version in effect in the new epoch.",
1973+
"type": "string",
1974+
"format": "u64"
1975+
},
1976+
"storage_charge": {
1977+
"description": "The total amount of gas charged for storage during the epoch.",
1978+
"type": "string",
1979+
"format": "u64"
1980+
},
1981+
"storage_rebate": {
1982+
"description": "The amount of storage rebate refunded to the txn senders.",
1983+
"type": "string",
1984+
"format": "u64"
1985+
},
1986+
"system_packages": {
1987+
"description": "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.",
1988+
"type": "array",
1989+
"items": {
1990+
"$ref": "#/components/schemas/SystemPackage"
1991+
}
1992+
}
1993+
}
1994+
},
19251995
{
19261996
"type": "object",
19271997
"required": [
@@ -3918,7 +3988,8 @@
39183988
"protocol_version",
39193989
"reference_gas_price",
39203990
"safe_mode",
3921-
"safe_mode_computation_rewards",
3991+
"safe_mode_computation_charges",
3992+
"safe_mode_computation_charges_burned",
39223993
"safe_mode_non_refundable_storage_fee",
39233994
"safe_mode_storage_charges",
39243995
"safe_mode_storage_rebates",
@@ -4054,8 +4125,13 @@
40544125
"description": "Whether the system is running in a downgraded safe mode due to a non-recoverable bug. This is set whenever we failed to execute advance_epoch, and ended up executing advance_epoch_safe_mode. It can be reset once we are able to successfully execute advance_epoch.",
40554126
"type": "boolean"
40564127
},
4057-
"safe_mode_computation_rewards": {
4058-
"description": "Amount of computation rewards accumulated (and not yet distributed) during safe mode.",
4128+
"safe_mode_computation_charges": {
4129+
"description": "Amount of computation charges accumulated (and not yet distributed) during safe mode.",
4130+
"type": "string",
4131+
"format": "u64"
4132+
},
4133+
"safe_mode_computation_charges_burned": {
4134+
"description": "Amount of burned computation charges accumulated during safe mode.",
40594135
"type": "string",
40604136
"format": "u64"
40614137
},

crates/iota-rest-api/src/reader.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,17 @@ impl StateReader {
5555
}
5656

5757
pub fn get_system_state_summary(&self) -> Result<super::system::SystemStateSummary> {
58-
use iota_types::iota_system_state::IotaSystemStateTrait;
58+
use iota_types::iota_system_state::{
59+
IotaSystemStateTrait, iota_system_state_summary::IotaSystemStateSummaryV2,
60+
};
5961

6062
let system_state = iota_types::iota_system_state::get_iota_system_state(self.inner())
6163
.map_err(StorageError::custom)?;
62-
let summary = system_state.into_iota_system_state_summary().into();
64+
let summary =
65+
IotaSystemStateSummaryV2::try_from(system_state.into_iota_system_state_summary())
66+
.map_err(StorageError::custom)?;
6367

64-
Ok(summary)
68+
Ok(summary.into())
6569
}
6670

6771
pub fn get_transaction(

crates/iota-rest-api/src/system.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,15 @@ pub struct SystemStateSummary {
117117
#[serde_as(as = "iota_types::iota_serde::BigInt<u64>")]
118118
#[schemars(with = "crate::_schemars::U64")]
119119
pub safe_mode_storage_charges: u64,
120-
/// Amount of computation rewards accumulated (and not yet distributed)
120+
/// Amount of computation charges accumulated (and not yet distributed)
121121
/// during safe mode.
122122
#[serde_as(as = "iota_types::iota_serde::BigInt<u64>")]
123123
#[schemars(with = "crate::_schemars::U64")]
124-
pub safe_mode_computation_rewards: u64,
124+
pub safe_mode_computation_charges: u64,
125+
/// Amount of burned computation charges accumulated during safe mode.
126+
#[serde_as(as = "iota_types::iota_serde::BigInt<u64>")]
127+
#[schemars(with = "crate::_schemars::U64")]
128+
pub safe_mode_computation_charges_burned: u64,
125129
/// Amount of storage rebates accumulated (and not yet burned) during safe
126130
/// mode.
127131
#[serde_as(as = "iota_types::iota_serde::BigInt<u64>")]
@@ -426,13 +430,13 @@ impl From<iota_types::iota_system_state::iota_system_state_summary::IotaValidato
426430
}
427431
}
428432

429-
impl From<iota_types::iota_system_state::iota_system_state_summary::IotaSystemStateSummary>
433+
impl From<iota_types::iota_system_state::iota_system_state_summary::IotaSystemStateSummaryV2>
430434
for SystemStateSummary
431435
{
432436
fn from(
433-
value: iota_types::iota_system_state::iota_system_state_summary::IotaSystemStateSummary,
437+
value: iota_types::iota_system_state::iota_system_state_summary::IotaSystemStateSummaryV2,
434438
) -> Self {
435-
let iota_types::iota_system_state::iota_system_state_summary::IotaSystemStateSummary {
439+
let iota_types::iota_system_state::iota_system_state_summary::IotaSystemStateSummaryV2 {
436440
epoch,
437441
protocol_version,
438442
system_state_version,
@@ -443,7 +447,8 @@ impl From<iota_types::iota_system_state::iota_system_state_summary::IotaSystemSt
443447
reference_gas_price,
444448
safe_mode,
445449
safe_mode_storage_charges,
446-
safe_mode_computation_rewards,
450+
safe_mode_computation_charges,
451+
safe_mode_computation_charges_burned,
447452
safe_mode_storage_rebates,
448453
safe_mode_non_refundable_storage_fee,
449454
epoch_start_timestamp_ms,
@@ -480,7 +485,8 @@ impl From<iota_types::iota_system_state::iota_system_state_summary::IotaSystemSt
480485
reference_gas_price,
481486
safe_mode,
482487
safe_mode_storage_charges,
483-
safe_mode_computation_rewards,
488+
safe_mode_computation_charges,
489+
safe_mode_computation_charges_burned,
484490
safe_mode_storage_rebates,
485491
safe_mode_non_refundable_storage_fee,
486492
epoch_start_timestamp_ms,

0 commit comments

Comments
 (0)