diff --git a/crates/sui-types/src/executable_transaction.rs b/crates/sui-types/src/executable_transaction.rs index 4e4354c1be4a5..964bf9b235947 100644 --- a/crates/sui-types/src/executable_transaction.rs +++ b/crates/sui-types/src/executable_transaction.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use crate::messages_checkpoint::CheckpointSequenceNumber; +use crate::messages_consensus::{AuthorityIndex, Round, TransactionIndex}; use crate::{committee::EpochId, crypto::AuthorityStrongQuorumSignInfo}; use crate::message_envelope::{Envelope, TrustedEnvelope, VerifiedEnvelope}; @@ -23,6 +24,9 @@ pub enum CertificateProof { QuorumExecuted(EpochId), /// Transaction generated by the system, for example Clock update transaction SystemTransaction(EpochId), + /// Validity was proven through consensus. Round, authority and transaction index indicate + /// the position of the transaction in the consensus DAG for debugging. + Consensus(EpochId, Round, AuthorityIndex, TransactionIndex), } impl CertificateProof { @@ -38,11 +42,21 @@ impl CertificateProof { Self::SystemTransaction(epoch) } + pub fn new_from_consensus( + epoch: EpochId, + round: Round, + authority: AuthorityIndex, + transaction_index: TransactionIndex, + ) -> Self { + Self::Consensus(epoch, round, authority, transaction_index) + } + pub fn epoch(&self) -> EpochId { match self { Self::Checkpoint(epoch, _) | Self::QuorumExecuted(epoch) - | Self::SystemTransaction(epoch) => *epoch, + | Self::SystemTransaction(epoch) + | Self::Consensus(epoch, _, _, _) => *epoch, Self::Certified(sig) => sig.epoch, } } @@ -57,13 +71,6 @@ pub type VerifiedExecutableTransaction = VerifiedEnvelope; impl VerifiedExecutableTransaction { - pub fn certificate_sig(&self) -> Option<&AuthorityStrongQuorumSignInfo> { - match self.auth_sig() { - CertificateProof::Certified(sig) => Some(sig), - _ => None, - } - } - pub fn gas_budget(&self) -> u64 { self.data().transaction_data().gas_budget() } diff --git a/crates/sui-types/src/message_envelope.rs b/crates/sui-types/src/message_envelope.rs index 97917c5750ab4..4a15a39ccef97 100644 --- a/crates/sui-types/src/message_envelope.rs +++ b/crates/sui-types/src/message_envelope.rs @@ -10,6 +10,7 @@ use crate::crypto::{ use crate::error::SuiResult; use crate::executable_transaction::CertificateProof; use crate::messages_checkpoint::CheckpointSequenceNumber; +use crate::messages_consensus::{AuthorityIndex, Round, TransactionIndex}; use crate::transaction::SenderSignedData; use fastcrypto::traits::KeyPair; use once_cell::sync::OnceCell; @@ -452,6 +453,31 @@ impl VerifiedEnvelope { }) } + pub fn new_from_consensus( + transaction: VerifiedEnvelope, + epoch: EpochId, + round: Round, + authority: AuthorityIndex, + transaction_index: TransactionIndex, + ) -> Self { + let inner = transaction.into_inner(); + let Envelope { + digest, + data, + auth_signature: _, + } = inner; + VerifiedEnvelope::new_unchecked(Envelope { + digest, + data, + auth_signature: CertificateProof::new_from_consensus( + epoch, + round, + authority, + transaction_index, + ), + }) + } + pub fn epoch(&self) -> EpochId { self.auth_signature.epoch() } diff --git a/crates/sui-types/src/messages_consensus.rs b/crates/sui-types/src/messages_consensus.rs index 4a192ab534595..29a4cc08dcda5 100644 --- a/crates/sui-types/src/messages_consensus.rs +++ b/crates/sui-types/src/messages_consensus.rs @@ -4,9 +4,7 @@ use crate::base_types::{AuthorityName, ObjectRef, TransactionDigest}; use crate::base_types::{ConciseableName, ObjectID, SequenceNumber}; use crate::digests::ConsensusCommitDigest; -use crate::messages_checkpoint::{ - CheckpointSequenceNumber, CheckpointSignatureMessage, CheckpointTimestamp, -}; +use crate::messages_checkpoint::{CheckpointSequenceNumber, CheckpointSignatureMessage}; use crate::supported_protocol_versions::{ Chain, SupportedProtocolVersions, SupportedProtocolVersionsWithHashes, }; @@ -24,16 +22,29 @@ use std::hash::{Hash, Hasher}; use std::sync::Arc; use std::time::{SystemTime, UNIX_EPOCH}; +/// The index of an authority in the consensus committee. +/// The value should be the same in Sui committee. +pub type AuthorityIndex = u32; + +/// Consensus round number. +pub type Round = u32; + +/// The index of a transaction in a consensus block. +pub type TransactionIndex = u16; + +/// Non-decreasing timestamp produced by consensus in ms. +pub type TimestampMs = u64; + /// Only commit_timestamp_ms is passed to the move call currently. /// However we include epoch and round to make sure each ConsensusCommitPrologue has a unique tx digest. #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)] pub struct ConsensusCommitPrologue { /// Epoch of the commit prologue transaction pub epoch: u64, - /// Consensus round of the commit + /// Consensus round of the commit. Using u64 for compatibility. pub round: u64, - /// Unix timestamp from consensus - pub commit_timestamp_ms: CheckpointTimestamp, + /// Unix timestamp from consensus commit. + pub commit_timestamp_ms: TimestampMs, } #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)] @@ -42,8 +53,8 @@ pub struct ConsensusCommitPrologueV2 { pub epoch: u64, /// Consensus round of the commit pub round: u64, - /// Unix timestamp from consensus - pub commit_timestamp_ms: CheckpointTimestamp, + /// Unix timestamp from consensus commit. + pub commit_timestamp_ms: TimestampMs, /// Digest of consensus output pub consensus_commit_digest: ConsensusCommitDigest, } @@ -64,8 +75,8 @@ pub struct ConsensusCommitPrologueV3 { /// The sub DAG index of the consensus commit. This field will be populated if there /// are multiple consensus commits per round. pub sub_dag_index: Option, - /// Unix timestamp from consensus - pub commit_timestamp_ms: CheckpointTimestamp, + /// Unix timestamp from consensus commit. + pub commit_timestamp_ms: TimestampMs, /// Digest of consensus output pub consensus_commit_digest: ConsensusCommitDigest, /// Stores consensus handler determined shared object version assignments.