Skip to content

Commit

Permalink
[Fastpath] Support transactions certified through consensus (#19601)
Browse files Browse the repository at this point in the history
## Description 

The fields in the `CertificateProof::Consensus` variant is chosen to
enhance debuggability (including the transaction's position in the DAG:
round, authority index, transaction index), without unnecessary data
(consensus block digest is excluded).

## Test plan 

CI

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
mwtian authored Sep 30, 2024
1 parent 5505e62 commit dffc298
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 18 deletions.
23 changes: 15 additions & 8 deletions crates/sui-types/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 {
Expand All @@ -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,
}
}
Expand All @@ -57,13 +71,6 @@ pub type VerifiedExecutableTransaction = VerifiedEnvelope<SenderSignedData, Cert
pub type TrustedExecutableTransaction = TrustedEnvelope<SenderSignedData, CertificateProof>;

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()
}
Expand Down
26 changes: 26 additions & 0 deletions crates/sui-types/src/message_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -452,6 +453,31 @@ impl<T: Message> VerifiedEnvelope<T, CertificateProof> {
})
}

pub fn new_from_consensus(
transaction: VerifiedEnvelope<T, EmptySignInfo>,
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()
}
Expand Down
31 changes: 21 additions & 10 deletions crates/sui-types/src/messages_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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)]
Expand All @@ -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,
}
Expand All @@ -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<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,
/// Stores consensus handler determined shared object version assignments.
Expand Down

0 comments on commit dffc298

Please sign in to comment.