Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: add CheckpointData to bcs sui.yaml description file #19516

Merged
merged 1 commit into from
Sep 24, 2024
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
55 changes: 55 additions & 0 deletions crates/sui-core/src/generate_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@ use move_core_types::language_storage::{ModuleId, StructTag, TypeTag};
use pretty_assertions::assert_str_eq;
use rand::rngs::StdRng;
use rand::SeedableRng;
use roaring::RoaringBitmap;
use serde_reflection::{Registry, Result, Samples, Tracer, TracerConfig};
use shared_crypto::intent::{Intent, IntentMessage, PersonalMessage};
use std::str::FromStr;
use std::{fs::File, io::Write};
use sui_types::base_types::SuiAddress;
use sui_types::crypto::{
AggregateAuthoritySignature, AuthorityQuorumSignInfo, AuthorityStrongQuorumSignInfo,
};
use sui_types::effects::TransactionEvents;
use sui_types::event::Event;
use sui_types::execution_status::{
CommandArgumentError, ExecutionFailureStatus, ExecutionStatus, PackageUpgradeError,
TypeArgumentError,
};
use sui_types::full_checkpoint_content::{CheckpointData, CheckpointTransaction};
use sui_types::messages_checkpoint::CertifiedCheckpointSummary;
use sui_types::messages_grpc::ObjectInfoRequestKind;
use sui_types::move_package::TypeOrigin;
use sui_types::object::Object;
use sui_types::transaction::{SenderSignedData, TransactionData};
use sui_types::type_input::{StructInput, TypeInput};
use sui_types::{
base_types::MoveObjectType_,
Expand Down Expand Up @@ -66,6 +77,9 @@ fn get_registry() -> Result<Registry> {

let m = ModuleId::new(AccountAddress::ZERO, Identifier::new("foo").unwrap());
tracer.trace_value(&mut samples, &m).unwrap();
tracer
.trace_value(&mut samples, &Identifier::new("foo").unwrap())
.unwrap();

let (addr, kp): (_, AuthorityKeyPair) = get_key_pair();
let (s_addr, s_kp): (_, AccountKeyPair) = get_key_pair();
Expand Down Expand Up @@ -221,6 +235,47 @@ fn get_registry() -> Result<Registry> {
tracer.trace_type::<CheckpointContents>(&samples).unwrap();
tracer.trace_type::<CheckpointSummary>(&samples).unwrap();

let sender_data = SenderSignedData::new(
TransactionData::new_with_gas_coins(
TransactionKind::EndOfEpochTransaction(Vec::new()),
SuiAddress::ZERO,
Vec::new(),
0,
0,
),
Vec::new(),
);
tracer.trace_value(&mut samples, &sender_data).unwrap();

let quorum_sig: AuthorityStrongQuorumSignInfo = AuthorityQuorumSignInfo {
epoch: 0,
signature: AggregateAuthoritySignature::default(),
signers_map: RoaringBitmap::default(),
};
tracer.trace_value(&mut samples, &quorum_sig).unwrap();

tracer
.trace_type::<CertifiedCheckpointSummary>(&samples)
.unwrap();

let event = Event {
package_id: ObjectID::random(),
transaction_module: Identifier::new("foo").unwrap(),
sender: SuiAddress::ZERO,
type_: struct_tag.clone(),
contents: vec![0],
};
tracer.trace_value(&mut samples, &event).unwrap();

tracer.trace_type::<Object>(&samples).unwrap();

tracer.trace_type::<TransactionEvents>(&samples).unwrap();
tracer
.trace_type::<CheckpointTransaction>(&samples)
.unwrap();

tracer.trace_type::<CheckpointData>(&samples).unwrap();

tracer.registry()
}

Expand Down
74 changes: 68 additions & 6 deletions crates/sui-core/tests/staged/sui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ AuthenticatorStateUpdate:
TYPENAME: SequenceNumber
AuthorityPublicKeyBytes:
NEWTYPESTRUCT: BYTES
AuthorityQuorumSignInfo:
STRUCT:
- epoch: U64
- signature:
TUPLEARRAY:
CONTENT: U8
SIZE: 48
- signers_map: BYTES
CallArg:
ENUM:
0:
Expand Down Expand Up @@ -97,6 +105,15 @@ CheckpointContentsV1:
SEQ:
SEQ:
TYPENAME: GenericSignature
CheckpointData:
STRUCT:
- checkpoint_summary:
TYPENAME: "sui_types::message_envelope::Envelope<sui_types::messages_checkpoint::CheckpointSummary, sui_types::crypto::AuthorityQuorumSignInfo<true>>"
- checkpoint_contents:
TYPENAME: CheckpointContents
- transactions:
SEQ:
TYPENAME: CheckpointTransaction
CheckpointDigest:
NEWTYPESTRUCT:
TYPENAME: Digest
Expand All @@ -121,6 +138,21 @@ CheckpointSummary:
TYPENAME: EndOfEpochData
- version_specific_data:
SEQ: U8
CheckpointTransaction:
STRUCT:
- transaction:
TYPENAME: "sui_types::message_envelope::Envelope<sui_types::transaction::SenderSignedData, sui_types::crypto::EmptySignInfo>"
- effects:
TYPENAME: TransactionEffects
- events:
OPTION:
TYPENAME: TransactionEvents
- input_objects:
SEQ:
TYPENAME: Object
- output_objects:
SEQ:
TYPENAME: Object
Command:
ENUM:
0:
Expand Down Expand Up @@ -340,16 +372,20 @@ EndOfEpochTransactionKind:
BridgeCommitteeInit:
NEWTYPE:
TYPENAME: SequenceNumber
Envelope:
Event:
STRUCT:
- data:
TYPENAME: SenderSignedData
- auth_signature:
TYPENAME: EmptySignInfo
- package_id:
TYPENAME: ObjectID
- transaction_module: STR
- sender:
TYPENAME: SuiAddress
- type_:
TYPENAME: StructTag
- contents: BYTES
ExecutionData:
STRUCT:
- transaction:
TYPENAME: Envelope
TYPENAME: "sui_types::message_envelope::Envelope<sui_types::transaction::SenderSignedData, sui_types::crypto::EmptySignInfo>"
- effects:
TYPENAME: TransactionEffects
ExecutionDigests:
Expand Down Expand Up @@ -640,6 +676,15 @@ MultiSigPublicKey:
- TYPENAME: PublicKey
- U8
- threshold: U16
Object:
STRUCT:
- data:
TYPENAME: Data
- owner:
TYPENAME: Owner
- previous_transaction:
TYPENAME: TransactionDigest
- storage_rebate: U64
ObjectArg:
ENUM:
0:
Expand Down Expand Up @@ -985,6 +1030,11 @@ TransactionEffectsV2:
- aux_data_digest:
OPTION:
TYPENAME: EffectsAuxDataDigest
TransactionEvents:
STRUCT:
- data:
SEQ:
TYPENAME: Event
TransactionEventsDigest:
NEWTYPESTRUCT:
TYPENAME: Digest
Expand Down Expand Up @@ -1153,4 +1203,16 @@ ZkLoginAuthenticatorAsBytes:
ZkLoginPublicIdentifier:
NEWTYPESTRUCT:
SEQ: U8
"sui_types::message_envelope::Envelope<sui_types::messages_checkpoint::CheckpointSummary, sui_types::crypto::AuthorityQuorumSignInfo<true>>":
STRUCT:
- data:
TYPENAME: CheckpointSummary
- auth_signature:
TYPENAME: AuthorityQuorumSignInfo
"sui_types::message_envelope::Envelope<sui_types::transaction::SenderSignedData, sui_types::crypto::EmptySignInfo>":
STRUCT:
- data:
TYPENAME: SenderSignedData
- auth_signature:
TYPENAME: EmptySignInfo

34 changes: 34 additions & 0 deletions crates/sui-types/src/message_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::transaction::SenderSignedData;
use fastcrypto::traits::KeyPair;
use once_cell::sync::OnceCell;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_name::{DeserializeNameAdapter, SerializeNameAdapter};
use shared_crypto::intent::{Intent, IntentScope};
use std::fmt::{Debug, Display, Formatter};
use std::ops::{Deref, DerefMut};
Expand All @@ -30,6 +31,7 @@ pub trait Message {
}

#[derive(Clone, Debug, Eq, Serialize, Deserialize)]
#[serde(remote = "Envelope")]
pub struct Envelope<T: Message, S> {
#[serde(skip)]
digest: OnceCell<T::DigestType>,
Expand All @@ -38,6 +40,38 @@ pub struct Envelope<T: Message, S> {
auth_signature: S,
}

impl<'de, T, S> Deserialize<'de> for Envelope<T, S>
where
T: Message + Deserialize<'de>,
S: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::de::Deserializer<'de>,
{
Envelope::deserialize(DeserializeNameAdapter::new(
deserializer,
std::any::type_name::<Self>(),
))
}
}

impl<T, Sig> Serialize for Envelope<T, Sig>
where
T: Message + Serialize,
Sig: Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
Envelope::serialize(
self,
SerializeNameAdapter::new(serializer, std::any::type_name::<Self>()),
)
}
}

impl<T: Message, S> Envelope<T, S> {
pub fn new_from_data_and_sig(data: T, sig: S) -> Self {
Self {
Expand Down
1 change: 1 addition & 0 deletions crates/sui-types/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ pub struct ObjectInner {
}

#[derive(Eq, PartialEq, Debug, Clone, Deserialize, Serialize, Hash)]
#[serde(from = "ObjectInner")]
pub struct Object(Arc<ObjectInner>);

impl From<ObjectInner> for Object {
Expand Down
Loading