sui_json_rpc_types/
sui_checkpoint.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::Page;
5use fastcrypto::encoding::Base64;
6use schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8use serde_with::serde_as;
9use sui_types::base_types::TransactionDigest;
10use sui_types::committee::EpochId;
11use sui_types::crypto::AggregateAuthoritySignature;
12use sui_types::digests::CheckpointDigest;
13use sui_types::gas::GasCostSummary;
14use sui_types::message_envelope::Message;
15use sui_types::messages_checkpoint::{
16    CheckpointCommitment, CheckpointContents, CheckpointSequenceNumber, CheckpointSummary,
17    CheckpointTimestamp, EndOfEpochData,
18};
19use sui_types::sui_serde::BigInt;
20pub type CheckpointPage = Page<Checkpoint, BigInt<u64>>;
21
22#[serde_as]
23#[derive(Clone, Debug, JsonSchema, Serialize, Deserialize, PartialEq, Eq)]
24#[serde(rename_all = "camelCase")]
25pub struct Checkpoint {
26    /// Checkpoint's epoch ID
27    #[schemars(with = "BigInt<u64>")]
28    #[serde_as(as = "BigInt<u64>")]
29    pub epoch: EpochId,
30    /// Checkpoint sequence number
31    #[schemars(with = "BigInt<u64>")]
32    #[serde_as(as = "BigInt<u64>")]
33    pub sequence_number: CheckpointSequenceNumber,
34    /// Checkpoint digest
35    pub digest: CheckpointDigest,
36    /// Total number of transactions committed since genesis, including those in this
37    /// checkpoint.
38    #[schemars(with = "BigInt<u64>")]
39    #[serde_as(as = "BigInt<u64>")]
40    pub network_total_transactions: u64,
41    /// Digest of the previous checkpoint
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub previous_digest: Option<CheckpointDigest>,
44    /// The running total gas costs of all transactions included in the current epoch so far
45    /// until this checkpoint.
46    pub epoch_rolling_gas_cost_summary: GasCostSummary,
47    /// Timestamp of the checkpoint - number of milliseconds from the Unix epoch
48    /// Checkpoint timestamps are monotonic, but not strongly monotonic - subsequent
49    /// checkpoints can have same timestamp if they originate from the same underlining consensus commit
50    #[schemars(with = "BigInt<u64>")]
51    #[serde_as(as = "BigInt<u64>")]
52    pub timestamp_ms: CheckpointTimestamp,
53    /// Present only on the final checkpoint of the epoch.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub end_of_epoch_data: Option<EndOfEpochData>,
56    /// Transaction digests
57    pub transactions: Vec<TransactionDigest>,
58
59    /// Commitments to checkpoint state
60    pub checkpoint_commitments: Vec<CheckpointCommitment>,
61    /// Validator Signature
62    #[schemars(with = "Base64")]
63    //#[serde_as(as = "Readable<Base64, Bytes>")]
64    pub validator_signature: AggregateAuthoritySignature,
65}
66
67impl
68    From<(
69        CheckpointSummary,
70        CheckpointContents,
71        AggregateAuthoritySignature,
72    )> for Checkpoint
73{
74    fn from(
75        (summary, contents, signature): (
76            CheckpointSummary,
77            CheckpointContents,
78            AggregateAuthoritySignature,
79        ),
80    ) -> Self {
81        let digest = summary.digest();
82        let CheckpointSummary {
83            epoch,
84            sequence_number,
85            network_total_transactions,
86            previous_digest,
87            epoch_rolling_gas_cost_summary,
88            timestamp_ms,
89            end_of_epoch_data,
90            ..
91        } = summary;
92
93        Checkpoint {
94            epoch,
95            sequence_number,
96            digest,
97            network_total_transactions,
98            previous_digest,
99            epoch_rolling_gas_cost_summary,
100            timestamp_ms,
101            end_of_epoch_data,
102            transactions: contents.iter().map(|digest| digest.transaction).collect(),
103            // TODO: populate commitment for rpc clients. Most likely, rpc clients don't need this
104            // info (if they need it, they need to get signed BCS data anyway in order to trust
105            // it).
106            checkpoint_commitments: Default::default(),
107            validator_signature: signature,
108        }
109    }
110}
111
112#[serde_as]
113#[derive(Clone, Copy, Debug, JsonSchema, Serialize, Deserialize)]
114#[serde(untagged)]
115pub enum CheckpointId {
116    SequenceNumber(
117        #[schemars(with = "BigInt<u64>")]
118        #[serde_as(as = "BigInt<u64>")]
119        CheckpointSequenceNumber,
120    ),
121    Digest(CheckpointDigest),
122}
123
124impl From<CheckpointSequenceNumber> for CheckpointId {
125    fn from(seq: CheckpointSequenceNumber) -> Self {
126        Self::SequenceNumber(seq)
127    }
128}
129
130impl From<CheckpointDigest> for CheckpointId {
131    fn from(digest: CheckpointDigest) -> Self {
132        Self::Digest(digest)
133    }
134}