Skip to content
Merged
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 @@ -13,7 +13,6 @@ CREATE TABLE checkpoints
timestamp_ms BIGINT NOT NULL,
total_gas_cost BIGINT NOT NULL,
computation_cost BIGINT NOT NULL,
computation_cost_burned BIGINT NOT NULL,
storage_cost BIGINT NOT NULL,
storage_rebate BIGINT NOT NULL,
non_refundable_storage_fee BIGINT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE checkpoints
DROP COLUMN computation_cost_burned;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Your SQL goes here
ALTER TABLE checkpoints
ADD COLUMN computation_cost_burned BIGINT;
4 changes: 2 additions & 2 deletions crates/iota-indexer/src/apis/coin_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use iota_types::{
};
use jsonrpsee::{RpcModule, core::RpcResult};

use crate::indexer_reader::IndexerReader;
use crate::{indexer_reader::IndexerReader, types::IotaSystemStateSummaryView};

pub(crate) struct CoinReadApi {
inner: IndexerReader,
Expand Down Expand Up @@ -142,7 +142,7 @@ impl CoinReadApiServer for CoinReadApi {
.inner
.spawn_blocking(|this| this.get_latest_iota_system_state())
.await?
.iota_total_supply,
.iota_total_supply(),
})
} else {
self.inner
Expand Down
58 changes: 37 additions & 21 deletions crates/iota-indexer/src/apis/governance_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ use iota_types::{
governance::StakedIota,
id::ID,
iota_serde::BigInt,
iota_system_state::{PoolTokenExchangeRate, iota_system_state_summary::IotaSystemStateSummary},
iota_system_state::{
PoolTokenExchangeRate,
iota_system_state_summary::{
IotaSystemStateSummary, IotaSystemStateSummaryV1, IotaSystemStateSummaryV2,
},
},
timelock::timelocked_staked_iota::TimelockedStakedIota,
};
use jsonrpsee::{RpcModule, core::RpcResult};
use serde::{Serialize, de::DeserializeOwned};
use tokio::sync::Mutex;

use crate::{errors::IndexerError, indexer_reader::IndexerReader};
use crate::{
errors::IndexerError, indexer_reader::IndexerReader, types::IotaSystemStateSummaryView,
};

/// Maximum amount of staked objects for querying.
const MAX_QUERY_STAKED_OBJECTS: usize = 1000;
Expand Down Expand Up @@ -63,9 +70,8 @@ impl GovernanceReadApi {
}

async fn get_validators_apy(&self) -> Result<ValidatorApys, IndexerError> {
let system_state_summary: IotaSystemStateSummary =
self.get_latest_iota_system_state().await?;
let epoch = system_state_summary.epoch;
let system_state_summary = self.get_latest_iota_system_state().await?;
let epoch = system_state_summary.epoch();

let exchange_rate_table = self.exchange_rates(&system_state_summary).await?;

Expand Down Expand Up @@ -170,7 +176,7 @@ impl GovernanceReadApi {
});

let system_state_summary = self.get_latest_iota_system_state().await?;
let epoch = system_state_summary.epoch;
let epoch = system_state_summary.epoch();

let (candidate_rates, pending_rates) = tokio::try_join!(
self.candidate_validators_exchange_rate(&system_state_summary),
Expand Down Expand Up @@ -236,7 +242,7 @@ impl GovernanceReadApi {
});

let system_state_summary = self.get_latest_iota_system_state().await?;
let epoch = system_state_summary.epoch;
let epoch = system_state_summary.epoch();

let rates = self
.exchange_rates(&system_state_summary)
Expand Down Expand Up @@ -359,7 +365,7 @@ impl GovernanceReadApi {
&self,
system_state_summary: &IotaSystemStateSummary,
) -> Result<Vec<ValidatorExchangeRates>, IndexerError> {
let epoch = system_state_summary.epoch;
let epoch = system_state_summary.epoch();

let mut cache = self.exchange_rates_cache.lock().await;

Expand Down Expand Up @@ -399,7 +405,7 @@ impl GovernanceReadApi {
system_state_summary: &IotaSystemStateSummary,
) -> Result<Vec<ValidatorExchangeRates>, IndexerError> {
let tables = system_state_summary
.active_validators
.active_validators()
.iter()
.map(|validator| {
(
Expand All @@ -422,8 +428,8 @@ impl GovernanceReadApi {
) -> Result<Vec<ValidatorExchangeRates>, IndexerError> {
let tables = self
.validator_summary_from_system_state(
system_state_summary.inactive_pools_id,
system_state_summary.inactive_pools_size,
system_state_summary.inactive_pools_id(),
system_state_summary.inactive_pools_size(),
|df| bcs::from_bytes::<ID>(&df.bcs_name).map_err(Into::into),
)
.await?;
Expand Down Expand Up @@ -470,8 +476,8 @@ impl GovernanceReadApi {
) -> Result<Vec<ValidatorExchangeRates>, IndexerError> {
let tables = self
.validator_summary_from_system_state(
system_state_summary.validator_candidates_id,
system_state_summary.validator_candidates_size,
system_state_summary.validator_candidates_id(),
system_state_summary.validator_candidates_size(),
|df| bcs::from_bytes::<IotaAddress>(&df.bcs_name).map_err(Into::into),
)
.await?;
Expand Down Expand Up @@ -502,9 +508,9 @@ impl GovernanceReadApi {
/// let system_state_summary = self.get_latest_iota_system_state().await?;
/// let _ = self.validator_summary_from_system_state(
/// // ID of the object that maps from a staking pool ID to the inactive validator that has that pool as its staking pool
/// system_state_summary.inactive_pools_id,
/// system_state_summary.inactive_pools_id(),
/// // Number of inactive staking pools
/// system_state_summary.inactive_pools_size,
/// system_state_summary.inactive_pools_size(),
/// // Extract the `ID` of the `Inactive` validator from the `DynamicFieldInfo` in the `system_state_summary.inactive_pools_id` table
/// |df| bcs::from_bytes::<ID>(&df.bcs_name).map_err(Into::into),
/// ).await?;
Expand All @@ -517,9 +523,9 @@ impl GovernanceReadApi {
/// let system_state_summary = self.get_latest_iota_system_state().await?;
/// let _ = self.validator_summary_from_system_state(
/// // ID of the object that stores preactive validators, mapping their addresses to their Validator structs
/// system_state_summary.validator_candidates_id,
/// system_state_summary.validator_candidates_id(),
/// // Number of preactive validators
/// system_state_summary.validator_candidates_size,
/// system_state_summary.validator_candidates_size(),
/// // Extract the `IotaAddress` of the `Candidate` validator from the `DynamicFieldInfo` in the `system_state_summary.validator_candidates_id` table
/// |df| bcs::from_bytes::<IotaAddress>(&df.bcs_name).map_err(Into::into),
/// ).await?;
Expand Down Expand Up @@ -683,10 +689,20 @@ impl GovernanceReadApiServer for GovernanceReadApi {
Ok(epoch.committee().map_err(IndexerError::from)?.into())
}

async fn get_latest_iota_system_state(&self) -> RpcResult<IotaSystemStateSummary> {
self.get_latest_iota_system_state()
.await
.map_err(Into::into)
async fn get_latest_iota_system_state(&self) -> RpcResult<IotaSystemStateSummaryV2> {
Ok(self
.get_latest_iota_system_state()
.await?
.try_into()
.map_err(IndexerError::from)?)
}

async fn get_latest_iota_system_state_v1(&self) -> RpcResult<IotaSystemStateSummaryV1> {
Ok(self
.get_latest_iota_system_state()
.await?
.try_into()
.map_err(IndexerError::from)?)
}

async fn get_reference_gas_price(&self) -> RpcResult<BigInt<u64>> {
Expand Down
24 changes: 10 additions & 14 deletions crates/iota-indexer/src/handlers/checkpoint_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ use iota_types::{
dynamic_field::{DynamicFieldInfo, DynamicFieldName, DynamicFieldType},
effects::TransactionEffectsAPI,
event::{SystemEpochInfoEvent, SystemEpochInfoEventV1, SystemEpochInfoEventV2},
iota_system_state::{
IotaSystemStateTrait, get_iota_system_state,
iota_system_state_summary::IotaSystemStateSummary,
},
iota_system_state::{IotaSystemStateTrait, get_iota_system_state},
messages_checkpoint::{
CertifiedCheckpointSummary, CheckpointContents, CheckpointSequenceNumber,
},
Expand Down Expand Up @@ -55,7 +52,8 @@ use crate::{
},
types::{
EventIndex, IndexedCheckpoint, IndexedDeletedObject, IndexedEpochInfo, IndexedEvent,
IndexedObject, IndexedPackage, IndexedTransaction, IndexerResult, TransactionKind, TxIndex,
IndexedObject, IndexedPackage, IndexedTransaction, IndexerResult,
IotaSystemStateSummaryView, TransactionKind, TxIndex,
},
};

Expand Down Expand Up @@ -205,14 +203,14 @@ impl CheckpointHandler {
} = data;

// Genesis epoch
let system_state =
get_iota_system_state(&checkpoint_object_store)?.into_iota_system_state_summary();
if *checkpoint_summary.sequence_number() == 0 {
info!("Processing genesis epoch");
let system_state: IotaSystemStateSummary =
get_iota_system_state(&checkpoint_object_store)?.into_iota_system_state_summary();
return Ok(Some(EpochToCommit {
last_epoch: None,
new_epoch: IndexedEpochInfo::from_new_system_state_summary(
system_state,
&system_state,
0, // first_checkpoint_id
None,
),
Expand All @@ -225,9 +223,6 @@ impl CheckpointHandler {
return Ok(None);
}

let system_state: IotaSystemStateSummary =
get_iota_system_state(&checkpoint_object_store)?.into_iota_system_state_summary();

let event = transactions
.iter()
.flat_map(|t| t.events.as_ref().map(|e| &e.data))
Expand Down Expand Up @@ -263,11 +258,12 @@ impl CheckpointHandler {
// guarantee that the previous epoch's checkpoints have been written to
// db.

let network_tx_count_prev_epoch = match system_state.epoch {
let epoch = system_state.epoch();
let network_tx_count_prev_epoch = match epoch {
// If first epoch change, this number is 0
1 => Ok(0),
_ => {
let last_epoch = system_state.epoch - 2;
let last_epoch = epoch - 2;
state
.get_network_total_transactions_by_end_of_epoch(last_epoch)
.await
Expand All @@ -282,7 +278,7 @@ impl CheckpointHandler {
network_tx_count_prev_epoch,
)),
new_epoch: IndexedEpochInfo::from_new_system_state_summary(
system_state,
&system_state,
checkpoint_summary.sequence_number + 1, // first_checkpoint_id
Some(&event),
),
Expand Down
9 changes: 6 additions & 3 deletions crates/iota-indexer/src/models/checkpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub struct StoredCheckpoint {
pub timestamp_ms: i64,
pub total_gas_cost: i64,
pub computation_cost: i64,
pub computation_cost_burned: i64,
pub storage_cost: i64,
pub storage_rebate: i64,
pub non_refundable_storage_fee: i64,
Expand All @@ -40,6 +39,7 @@ pub struct StoredCheckpoint {
pub end_of_epoch_data: Option<Vec<u8>>,
pub min_tx_sequence_number: Option<i64>,
pub max_tx_sequence_number: Option<i64>,
pub computation_cost_burned: Option<i64>,
}

impl From<&IndexedCheckpoint> for StoredCheckpoint {
Expand All @@ -61,7 +61,7 @@ impl From<&IndexedCheckpoint> for StoredCheckpoint {
timestamp_ms: c.timestamp_ms as i64,
total_gas_cost: c.total_gas_cost,
computation_cost: c.computation_cost as i64,
computation_cost_burned: c.computation_cost_burned as i64,
computation_cost_burned: Some(c.computation_cost_burned as i64),
storage_cost: c.storage_cost as i64,
storage_rebate: c.storage_rebate as i64,
non_refundable_storage_fee: c.non_refundable_storage_fee as i64,
Expand Down Expand Up @@ -149,6 +149,9 @@ impl TryFrom<StoredCheckpoint> for RpcCheckpoint {
})
.transpose()?;

let computation_cost_burned = checkpoint
.computation_cost_burned
.unwrap_or(checkpoint.computation_cost) as u64;
Ok(RpcCheckpoint {
epoch: checkpoint.epoch as u64,
sequence_number: checkpoint.sequence_number as u64,
Expand All @@ -157,7 +160,7 @@ impl TryFrom<StoredCheckpoint> for RpcCheckpoint {
end_of_epoch_data,
epoch_rolling_gas_cost_summary: GasCostSummary {
computation_cost: checkpoint.computation_cost as u64,
computation_cost_burned: checkpoint.computation_cost_burned as u64,
computation_cost_burned,
storage_cost: checkpoint.storage_cost as u64,
storage_rebate: checkpoint.storage_rebate as u64,
non_refundable_storage_fee: checkpoint.non_refundable_storage_fee as u64,
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-indexer/src/models/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iota_types::iota_system_state::iota_system_state_summary::IotaSystemStateSum
use crate::{
errors::IndexerError,
schema::{epochs, feature_flags, protocol_configs},
types::IndexedEpochInfo,
types::{IndexedEpochInfo, IotaSystemStateSummaryView},
};

#[derive(Queryable, Insertable, Debug, Clone, Default)]
Expand Down Expand Up @@ -165,7 +165,7 @@ impl TryFrom<StoredEpochInfo> for EpochInfo {
Ok(EpochInfo {
epoch: value.epoch as u64,
validators: system_state
.map(|s| s.active_validators)
.map(|s| s.active_validators().to_vec())
.unwrap_or_default(),
epoch_total_transactions: value.epoch_total_transactions.unwrap_or(0) as u64,
first_checkpoint_id: value.first_checkpoint_id as u64,
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-indexer/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ diesel::table! {
timestamp_ms -> Int8,
total_gas_cost -> Int8,
computation_cost -> Int8,
computation_cost_burned -> Int8,
storage_cost -> Int8,
storage_rebate -> Int8,
non_refundable_storage_fee -> Int8,
Expand All @@ -61,6 +60,7 @@ diesel::table! {
end_of_epoch_data -> Nullable<Bytea>,
min_tx_sequence_number -> Nullable<Int8>,
max_tx_sequence_number -> Nullable<Int8>,
computation_cost_burned -> Nullable<Int8>,
}
}

Expand Down
Loading
Loading