Skip to content

Commit

Permalink
Remove VersionedProtocolMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind committed Jun 26, 2024
1 parent 8fafac2 commit 433725f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 58 deletions.
31 changes: 1 addition & 30 deletions crates/sui-types/src/effects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ use crate::crypto::{
use crate::digests::{
ObjectDigest, TransactionDigest, TransactionEffectsDigest, TransactionEventsDigest,
};
use crate::error::{SuiError, SuiResult};
use crate::error::SuiResult;
use crate::event::Event;
use crate::execution::SharedInput;
use crate::execution_status::ExecutionStatus;
use crate::gas::GasCostSummary;
use crate::message_envelope::{Envelope, Message, TrustedEnvelope, VerifiedEnvelope};
use crate::object::Owner;
use crate::storage::WriteKind;
use crate::transaction::VersionedProtocolMessage;
use effects_v1::TransactionEffectsV1;
pub use effects_v2::UnchangedSharedKind;
use enum_dispatch::enum_dispatch;
pub use object_change::{EffectsObjectChange, ObjectIn, ObjectOut};
use serde::{Deserialize, Serialize};
use shared_crypto::intent::{Intent, IntentScope};
use std::collections::BTreeMap;
use sui_protocol_config::ProtocolConfig;
pub use test_effects_builder::TestEffectsBuilder;

mod effects_v1;
Expand Down Expand Up @@ -61,33 +59,6 @@ pub enum TransactionEffects {
V2(TransactionEffectsV2),
}

impl VersionedProtocolMessage for TransactionEffects {
fn message_version(&self) -> Option<u64> {
Some(match self {
Self::V1(_) => 1,
Self::V2(_) => 2,
})
}

fn check_version_and_features_supported(&self, protocol_config: &ProtocolConfig) -> SuiResult {
match self {
Self::V1(_) => Ok(()),
Self::V2(_) => {
if protocol_config.enable_effects_v2() {
Ok(())
} else {
Err(SuiError::WrongMessageVersion {
error: format!(
"TransactionEffectsV2 is not supported at protocol {:?}.",
protocol_config.version
),
})
}
}
}
}
}

impl Message for TransactionEffects {
type DigestType = TransactionEffectsDigest;
const SCOPE: IntentScope = IntentScope::TransactionEffects;
Expand Down
17 changes: 1 addition & 16 deletions crates/sui-types/src/message_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ use crate::crypto::{
use crate::error::SuiResult;
use crate::executable_transaction::CertificateProof;
use crate::messages_checkpoint::CheckpointSequenceNumber;
use crate::transaction::{SenderSignedData, VersionedProtocolMessage};
use crate::transaction::SenderSignedData;
use fastcrypto::traits::KeyPair;
use once_cell::sync::OnceCell;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use shared_crypto::intent::{Intent, IntentScope};
use std::fmt::{Debug, Display, Formatter};
use std::ops::{Deref, DerefMut};
use sui_protocol_config::ProtocolConfig;

pub trait Message {
type DigestType: Clone + Debug;
Expand Down Expand Up @@ -91,13 +90,6 @@ impl<T: Message, S> Envelope<T, S> {
}
}

impl<T: Message + VersionedProtocolMessage, S> VersionedProtocolMessage for Envelope<T, S> {
fn check_version_and_features_supported(&self, protocol_config: &ProtocolConfig) -> SuiResult {
self.data
.check_version_and_features_supported(protocol_config)
}
}

impl<T: Message + PartialEq, S: PartialEq> PartialEq for Envelope<T, S> {
fn eq(&self, other: &Self) -> bool {
self.data == other.data && self.auth_signature == other.auth_signature
Expand Down Expand Up @@ -299,13 +291,6 @@ impl<T: Message, S> VerifiedEnvelope<T, S> {
}
}

impl<T: Message + VersionedProtocolMessage, S> VersionedProtocolMessage for VerifiedEnvelope<T, S> {
fn check_version_and_features_supported(&self, protocol_config: &ProtocolConfig) -> SuiResult {
self.inner()
.check_version_and_features_supported(protocol_config)
}
}

/// After deserialization, a TrustedTransactionEnvelope can be turned back into a
/// VerifiedTransactionEnvelope.
impl<T: Message, S> From<TrustedEnvelope<T, S>> for VerifiedEnvelope<T, S> {
Expand Down
12 changes: 0 additions & 12 deletions crates/sui-types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2732,18 +2732,6 @@ impl CertifiedTransaction {
pub type VerifiedCertificate = VerifiedEnvelope<SenderSignedData, AuthorityStrongQuorumSignInfo>;
pub type TrustedCertificate = TrustedEnvelope<SenderSignedData, AuthorityStrongQuorumSignInfo>;

pub trait VersionedProtocolMessage {
/// Return version of message. Some messages depend on their enclosing messages to know the
/// version number, so not every implementor implements this.
fn message_version(&self) -> Option<u64> {
None
}

/// Check that the version of the message is the correct one to use at this protocol version.
/// Also checks whether the feauures used by the message are supported by the protocol config.
fn check_version_and_features_supported(&self, protocol_config: &ProtocolConfig) -> SuiResult;
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, PartialOrd, Ord, Hash)]
pub enum InputObjectKind {
// A Move package, must be immutable.
Expand Down

0 comments on commit 433725f

Please sign in to comment.