From b0c6a3144d8ea62ac09632dd9f2346e11f2d4897 Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Fri, 14 Jun 2024 20:00:29 -0700 Subject: [PATCH 1/9] api fix initial --- api/types/src/convert.rs | 43 ++++--- api/types/src/transaction.rs | 230 +++++++++++++++++++++++++++-------- 2 files changed, 210 insertions(+), 63 deletions(-) diff --git a/api/types/src/convert.rs b/api/types/src/convert.rs index 0b464c9369019..5c6f21634abb9 100644 --- a/api/types/src/convert.rs +++ b/api/types/src/convert.rs @@ -4,15 +4,16 @@ use crate::{ transaction::{ - BlockEpilogueTransaction, DecodedTableData, DeleteModule, DeleteResource, DeleteTableItem, - DeletedTableData, MultisigPayload, MultisigTransactionPayload, StateCheckpointTransaction, - UserTransactionRequestInner, WriteModule, WriteResource, WriteTableItem, + BlockEpilogueTransaction, BlockMetadataExtTransaction, DecodedTableData, DeleteModule, + DeleteResource, DeleteTableItem, DeletedTableData, MultisigPayload, + MultisigTransactionPayload, StateCheckpointTransaction, UserTransactionRequestInner, + ValidatorTransaction, WriteModule, WriteResource, WriteTableItem, }, view::{ViewFunction, ViewRequest}, - Address, Bytecode, DirectWriteSet, EntryFunctionId, EntryFunctionPayload, Event, - HexEncodedBytes, MoveFunction, MoveModuleBytecode, MoveResource, MoveScriptBytecode, MoveType, - MoveValue, PendingTransaction, ResourceGroup, ScriptPayload, ScriptWriteSet, - SubmitTransactionRequest, Transaction, TransactionInfo, TransactionOnChainData, + Address, BlockMetadataTransaction, Bytecode, DirectWriteSet, EntryFunctionId, + EntryFunctionPayload, Event, HexEncodedBytes, MoveFunction, MoveModuleBytecode, MoveResource, + MoveScriptBytecode, MoveType, MoveValue, PendingTransaction, ResourceGroup, ScriptPayload, + ScriptWriteSet, SubmitTransactionRequest, Transaction, TransactionInfo, TransactionOnChainData, TransactionPayload, UserTransactionRequest, VersionedEvent, WriteSet, WriteSetChange, WriteSetPayload, }; @@ -176,7 +177,6 @@ impl<'a, S: StateView> MoveConverter<'a, S> { timestamp: u64, data: TransactionOnChainData, ) -> Result { - use aptos_types::transaction::Transaction::*; let aux_data = self .db .get_transaction_auxiliary_data_by_version(data.version)?; @@ -189,23 +189,32 @@ impl<'a, S: StateView> MoveConverter<'a, S> { ); let events = self.try_into_events(&data.events)?; Ok(match data.transaction { - UserTransaction(txn) => { + aptos_types::transaction::Transaction::UserTransaction(txn) => { let payload = self.try_into_transaction_payload(txn.payload().clone())?; (&txn, info, payload, events, timestamp).into() }, - GenesisTransaction(write_set) => { + aptos_types::transaction::Transaction::GenesisTransaction(write_set) => { let payload = self.try_into_write_set_payload(write_set)?; (info, payload, events).into() }, - BlockMetadata(txn) => (&txn, info, events).into(), - BlockMetadataExt(txn) => (&txn, info, events).into(), - StateCheckpoint(_) => { + aptos_types::transaction::Transaction::BlockMetadata(txn) => { + Transaction::BlockMetadataTransaction(BlockMetadataTransaction::from_internal_repr( + txn, info, events, + )) + // (&txn, info, events).into() + }, + aptos_types::transaction::Transaction::BlockMetadataExt(txn) => { + Transaction::BlockMetadataExtTransaction( + BlockMetadataExtTransaction::from_internal_repr(txn, info, events), + ) + }, + aptos_types::transaction::Transaction::StateCheckpoint(_) => { Transaction::StateCheckpointTransaction(StateCheckpointTransaction { info, timestamp: timestamp.into(), }) }, - BlockEpilogue(block_epilogue_payload) => { + aptos_types::transaction::Transaction::BlockEpilogue(block_epilogue_payload) => { Transaction::BlockEpilogueTransaction(BlockEpilogueTransaction { info, timestamp: timestamp.into(), @@ -228,7 +237,11 @@ impl<'a, S: StateView> MoveConverter<'a, S> { }, }) }, - ValidatorTransaction(_txn) => (info, events, timestamp).into(), + aptos_types::transaction::Transaction::ValidatorTransaction(txn) => { + Transaction::ValidatorTransaction(ValidatorTransaction::from_internal_repr( + txn, info, events, timestamp, + )) + }, }) } diff --git a/api/types/src/transaction.rs b/api/types/src/transaction.rs index 108e62a67bf62..317f95b693aa3 100755 --- a/api/types/src/transaction.rs +++ b/api/types/src/transaction.rs @@ -18,7 +18,7 @@ use aptos_crypto::{ use aptos_types::{ account_address::AccountAddress, block_metadata::BlockMetadata, - block_metadata_ext::BlockMetadataExt, + block_metadata_ext::{BlockMetadataExt, BlockMetadataWithRandomness}, contract_event::{ContractEvent, EventWithVersion}, keyless, transaction::{ @@ -179,6 +179,7 @@ pub enum Transaction { StateCheckpointTransaction(StateCheckpointTransaction), BlockEpilogueTransaction(BlockEpilogueTransaction), ValidatorTransaction(ValidatorTransaction), + BlockMetadataExtTransaction(BlockMetadataExtTransaction), } impl Transaction { @@ -190,7 +191,8 @@ impl Transaction { Transaction::GenesisTransaction(_) => 0, Transaction::StateCheckpointTransaction(txn) => txn.timestamp.0, Transaction::BlockEpilogueTransaction(txn) => txn.timestamp.0, - Transaction::ValidatorTransaction(txn) => txn.timestamp.0, + Transaction::ValidatorTransaction(txn) => txn.timestamp().0, + Transaction::BlockMetadataExtTransaction(txn) => txn.timestamp().0, } } @@ -202,7 +204,10 @@ impl Transaction { Transaction::GenesisTransaction(txn) => Some(txn.info.version.into()), Transaction::StateCheckpointTransaction(txn) => Some(txn.info.version.into()), Transaction::BlockEpilogueTransaction(txn) => Some(txn.info.version.into()), - Transaction::ValidatorTransaction(txn) => Some(txn.info.version.into()), + Transaction::ValidatorTransaction(txn) => Some(txn.transaction_info().version.into()), + Transaction::BlockMetadataExtTransaction(txn) => { + Some(txn.transaction_info().version.into()) + }, } } @@ -214,7 +219,8 @@ impl Transaction { Transaction::GenesisTransaction(txn) => txn.info.success, Transaction::StateCheckpointTransaction(txn) => txn.info.success, Transaction::BlockEpilogueTransaction(txn) => txn.info.success, - Transaction::ValidatorTransaction(txn) => txn.info.success, + Transaction::ValidatorTransaction(txn) => txn.transaction_info().success, + Transaction::BlockMetadataExtTransaction(txn) => txn.transaction_info().success, } } @@ -230,7 +236,10 @@ impl Transaction { Transaction::GenesisTransaction(txn) => txn.info.vm_status.clone(), Transaction::StateCheckpointTransaction(txn) => txn.info.vm_status.clone(), Transaction::BlockEpilogueTransaction(txn) => txn.info.vm_status.clone(), - Transaction::ValidatorTransaction(txn) => txn.info.vm_status.clone(), + Transaction::ValidatorTransaction(txn) => txn.transaction_info().vm_status.clone(), + Transaction::BlockMetadataExtTransaction(txn) => { + txn.transaction_info().vm_status.clone() + }, } } @@ -243,6 +252,7 @@ impl Transaction { Transaction::StateCheckpointTransaction(_) => "state_checkpoint_transaction", Transaction::BlockEpilogueTransaction(_) => "block_epilogue_transaction", Transaction::ValidatorTransaction(_) => "validator_transaction", + Transaction::BlockMetadataExtTransaction(_) => "block_metadata_ext_transaction", } } @@ -256,7 +266,8 @@ impl Transaction { Transaction::GenesisTransaction(txn) => &txn.info, Transaction::StateCheckpointTransaction(txn) => &txn.info, Transaction::BlockEpilogueTransaction(txn) => &txn.info, - Transaction::ValidatorTransaction(txn) => &txn.info, + Transaction::ValidatorTransaction(txn) => txn.transaction_info(), + Transaction::BlockMetadataExtTransaction(txn) => txn.transaction_info(), }) } } @@ -308,38 +319,6 @@ impl From<(TransactionInfo, WriteSetPayload, Vec)> for Transaction { } } -impl From<(&BlockMetadata, TransactionInfo, Vec)> for Transaction { - fn from((txn, info, events): (&BlockMetadata, TransactionInfo, Vec)) -> Self { - Transaction::BlockMetadataTransaction(BlockMetadataTransaction { - info, - id: txn.id().into(), - epoch: txn.epoch().into(), - round: txn.round().into(), - events, - previous_block_votes_bitvec: txn.previous_block_votes_bitvec().clone(), - proposer: txn.proposer().into(), - failed_proposer_indices: txn.failed_proposer_indices().clone(), - timestamp: txn.timestamp_usecs().into(), - }) - } -} - -impl From<(&BlockMetadataExt, TransactionInfo, Vec)> for Transaction { - fn from((txn, info, events): (&BlockMetadataExt, TransactionInfo, Vec)) -> Self { - Transaction::BlockMetadataTransaction(BlockMetadataTransaction { - info, - id: txn.id().into(), - epoch: txn.epoch().into(), - round: txn.round().into(), - events, - previous_block_votes_bitvec: txn.previous_block_votes_bitvec().clone(), - proposer: txn.proposer().into(), - failed_proposer_indices: txn.failed_proposer_indices().clone(), - timestamp: txn.timestamp_usecs().into(), - }) - } -} - impl From<(&SignedTransaction, TransactionPayload)> for UserTransactionRequest { fn from((txn, payload): (&SignedTransaction, TransactionPayload)) -> Self { Self { @@ -354,15 +333,15 @@ impl From<(&SignedTransaction, TransactionPayload)> for UserTransactionRequest { } } -impl From<(TransactionInfo, Vec, u64)> for Transaction { - fn from((info, events, timestamp): (TransactionInfo, Vec, u64)) -> Self { - Transaction::ValidatorTransaction(ValidatorTransaction { - info, - events, - timestamp: timestamp.into(), - }) - } -} +// impl From<(TransactionInfo, Vec, u64)> for Transaction { +// fn from((info, events, timestamp): (TransactionInfo, Vec, u64)) -> Self { +// Transaction::ValidatorTransaction(ValidatorTransaction { +// info, +// events, +// timestamp: timestamp.into(), +// }) +// } +// } /// Information related to how a transaction affected the state of the blockchain #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] @@ -586,8 +565,163 @@ pub struct BlockMetadataTransaction { pub timestamp: U64, } +impl BlockMetadataTransaction { + pub fn from_internal_repr( + internal: BlockMetadata, + info: TransactionInfo, + events: Vec, + ) -> Self { + Self { + info, + id: internal.id().into(), + epoch: internal.epoch().into(), + round: internal.round().into(), + events, + previous_block_votes_bitvec: internal.previous_block_votes_bitvec().clone(), + proposer: internal.proposer().into(), + failed_proposer_indices: internal.failed_proposer_indices().clone(), + timestamp: internal.timestamp_usecs().into(), + } + } +} + +/// A block metadata transaction +/// +/// This signifies the beginning of a block, and contains information +/// about the specific block +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] +pub struct BlockMetadataWithRandomnessTransaction { + #[serde(flatten)] + #[oai(flatten)] + pub info: TransactionInfo, + pub id: HashValue, + pub epoch: U64, + pub round: U64, + /// The events emitted at the block creation + pub events: Vec, + /// Previous block votes + pub previous_block_votes_bitvec: Vec, + pub proposer: Address, + /// The indices of the proposers who failed to propose + pub failed_proposer_indices: Vec, + pub timestamp: U64, + pub randomness: Option>, +} + +impl BlockMetadataWithRandomnessTransaction { + pub fn from_internal_repr( + internal: BlockMetadataWithRandomness, + info: TransactionInfo, + events: Vec, + ) -> Self { + Self { + info, + id: internal.id.into(), + epoch: internal.epoch.into(), + round: internal.round.into(), + events, + previous_block_votes_bitvec: internal.previous_block_votes_bitvec.clone(), + proposer: internal.proposer.into(), + failed_proposer_indices: internal.failed_proposer_indices.clone(), + timestamp: internal.timestamp_usecs.into(), + randomness: internal.randomness.map(|r| r.randomness().to_vec()), + } + } +} +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] +pub enum BlockMetadataExtTransaction { + V0(BlockMetadataTransaction), + V1(BlockMetadataWithRandomnessTransaction), +} + +impl BlockMetadataExtTransaction { + pub fn from_internal_repr( + internal: BlockMetadataExt, + info: TransactionInfo, + events: Vec, + ) -> Self { + match internal { + BlockMetadataExt::V0(v0) => Self::V0(BlockMetadataTransaction::from_internal_repr( + v0, info, events, + )), + BlockMetadataExt::V1(v1) => Self::V1( + BlockMetadataWithRandomnessTransaction::from_internal_repr(v1, info, events), + ), + } + } + + pub fn transaction_info(&self) -> &TransactionInfo { + match self { + BlockMetadataExtTransaction::V0(t) => &t.info, + BlockMetadataExtTransaction::V1(t) => &t.info, + } + } + + pub fn timestamp(&self) -> U64 { + match self { + BlockMetadataExtTransaction::V0(t) => t.timestamp, + BlockMetadataExtTransaction::V1(t) => t.timestamp, + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] +pub enum ValidatorTransaction { + ObservedJWKUpdate(JWKUpdateTransaction), + DKGResult(DKGResultTransaction), +} + +impl ValidatorTransaction { + pub fn transaction_info(&self) -> &TransactionInfo { + match self { + ValidatorTransaction::ObservedJWKUpdate(t) => &t.info, + ValidatorTransaction::DKGResult(t) => &t.info, + } + } + + pub fn timestamp(&self) -> U64 { + match self { + ValidatorTransaction::ObservedJWKUpdate(t) => t.timestamp, + ValidatorTransaction::DKGResult(t) => t.timestamp, + } + } + + pub fn from_internal_repr( + internal: aptos_types::validator_txn::ValidatorTransaction, + info: TransactionInfo, + events: Vec, + timestamp: u64, + ) -> Self { + match internal { + aptos_types::validator_txn::ValidatorTransaction::DKGResult(_) => { + Self::DKGResult(DKGResultTransaction { + info, + events, + timestamp: U64::from(timestamp), + }) + }, + aptos_types::validator_txn::ValidatorTransaction::ObservedJWKUpdate(_) => { + Self::ObservedJWKUpdate(JWKUpdateTransaction { + info, + events, + timestamp: U64::from(timestamp), + }) + }, + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] +pub struct JWKUpdateTransaction { + #[serde(flatten)] + #[oai(flatten)] + pub info: TransactionInfo, + pub events: Vec, + pub timestamp: U64, +} + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] -pub struct ValidatorTransaction { +pub struct DKGResultTransaction { #[serde(flatten)] #[oai(flatten)] pub info: TransactionInfo, From 45880e4adb943696d7b48b40c3e3a11efd6544ea Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Sat, 15 Jun 2024 00:30:30 -0700 Subject: [PATCH 2/9] include raw input --- Cargo.lock | 3 + api/types/Cargo.toml | 1 + api/types/src/transaction.rs | 139 ++++++++++++++++-- .../indexer-grpc-fullnode/src/convert.rs | 6 + .../src/stream_coordinator.rs | 12 +- types/Cargo.toml | 2 + types/src/block_metadata_ext.rs | 7 + types/src/jwks/jwk/mod.rs | 3 +- types/src/jwks/rsa/mod.rs | 4 +- types/src/jwks/unsupported/mod.rs | 3 +- types/src/transaction/mod.rs | 4 +- types/src/validator_txn.rs | 7 + 12 files changed, 170 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44d7536b9fe37..506fc8c59b8ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -531,6 +531,7 @@ dependencies = [ "poem-openapi", "poem-openapi-derive", "serde", + "serde_bytes", "serde_json", ] @@ -4108,6 +4109,8 @@ dependencies = [ "passkey-authenticator", "passkey-client", "passkey-types", + "poem-openapi", + "poem-openapi-derive", "proptest", "proptest-derive", "quick_cache", diff --git a/api/types/Cargo.toml b/api/types/Cargo.toml index 1ff09c771eed3..709109522a2f0 100644 --- a/api/types/Cargo.toml +++ b/api/types/Cargo.toml @@ -37,6 +37,7 @@ poem-openapi = { workspace = true } poem-openapi-derive = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } +serde_bytes = { workspace = true } [package.metadata.cargo-machete] ignored = ["async-trait", "poem", "poem-openapi-derive"] diff --git a/api/types/src/transaction.rs b/api/types/src/transaction.rs index 317f95b693aa3..78fc778639b34 100755 --- a/api/types/src/transaction.rs +++ b/api/types/src/transaction.rs @@ -40,6 +40,11 @@ use std::{ str::FromStr, time::{SystemTime, UNIX_EPOCH}, }; +use aptos_types::aggregate_signature::AggregateSignature; +use aptos_types::dkg::{DKGTranscript, DKGTranscriptMetadata}; +use aptos_types::jwks::{ProviderJWKs, QuorumCertifiedUpdate}; +use aptos_types::jwks::jwk::JWK; +use aptos_types::jwks::unsupported::UnsupportedJWK; static DUMMY_GUID: Lazy = Lazy::new(|| EventGuid { creation_number: U64::from(0u64), @@ -251,8 +256,8 @@ impl Transaction { Transaction::BlockMetadataTransaction(_) => "block_metadata_transaction", Transaction::StateCheckpointTransaction(_) => "state_checkpoint_transaction", Transaction::BlockEpilogueTransaction(_) => "block_epilogue_transaction", - Transaction::ValidatorTransaction(_) => "validator_transaction", - Transaction::BlockMetadataExtTransaction(_) => "block_metadata_ext_transaction", + Transaction::ValidatorTransaction(vt) => vt.type_str(), + Transaction::BlockMetadataExtTransaction(bmet) => bmet.type_str(), } } @@ -629,6 +634,8 @@ impl BlockMetadataWithRandomnessTransaction { } } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] +#[serde(tag = "block_metadata_ext_transaction_type", rename_all = "snake_case")] +#[oai(one_of, discriminator_name = "block_metadata_ext_transaction_type", rename_all = "snake_case")] pub enum BlockMetadataExtTransaction { V0(BlockMetadataTransaction), V1(BlockMetadataWithRandomnessTransaction), @@ -650,6 +657,13 @@ impl BlockMetadataExtTransaction { } } + pub fn type_str(&self) -> &'static str { + match self { + BlockMetadataExtTransaction::V0(_) => "block_metadata_ext_transaction__v0", + BlockMetadataExtTransaction::V1(_) => "block_metadata_ext_transaction__v1", + } + } + pub fn transaction_info(&self) -> &TransactionInfo { match self { BlockMetadataExtTransaction::V0(t) => &t.info, @@ -657,6 +671,13 @@ impl BlockMetadataExtTransaction { } } + pub fn transaction_info_mut(&mut self) -> &mut TransactionInfo { + match self { + BlockMetadataExtTransaction::V0(t) => &mut t.info, + BlockMetadataExtTransaction::V1(t) => &mut t.info, + } + } + pub fn timestamp(&self) -> U64 { match self { BlockMetadataExtTransaction::V0(t) => t.timestamp, @@ -666,23 +687,39 @@ impl BlockMetadataExtTransaction { } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] +#[serde(tag = "validator_transaction_type", rename_all = "snake_case")] +#[oai(one_of, discriminator_name = "validator_transaction_type", rename_all = "snake_case")] pub enum ValidatorTransaction { - ObservedJWKUpdate(JWKUpdateTransaction), - DKGResult(DKGResultTransaction), + ObservedJwkUpdate(JWKUpdateTransaction), + DkgResult(DKGResultTransaction), } impl ValidatorTransaction { + pub fn type_str(&self) -> &'static str { + match self { + ValidatorTransaction::ObservedJwkUpdate(_) => "validator_transaction__observed_jwk_update", + ValidatorTransaction::DkgResult(_) => "validator_transaction__dkg_result", + } + } + pub fn transaction_info(&self) -> &TransactionInfo { match self { - ValidatorTransaction::ObservedJWKUpdate(t) => &t.info, - ValidatorTransaction::DKGResult(t) => &t.info, + ValidatorTransaction::ObservedJwkUpdate(t) => &t.info, + ValidatorTransaction::DkgResult(t) => &t.info, + } + } + + pub fn transaction_info_mut(&mut self) -> &mut TransactionInfo { + match self { + ValidatorTransaction::ObservedJwkUpdate(t) => &mut t.info, + ValidatorTransaction::DkgResult(t) => &mut t.info, } } pub fn timestamp(&self) -> U64 { match self { - ValidatorTransaction::ObservedJWKUpdate(t) => t.timestamp, - ValidatorTransaction::DKGResult(t) => t.timestamp, + ValidatorTransaction::ObservedJwkUpdate(t) => t.timestamp, + ValidatorTransaction::DkgResult(t) => t.timestamp, } } @@ -693,18 +730,20 @@ impl ValidatorTransaction { timestamp: u64, ) -> Self { match internal { - aptos_types::validator_txn::ValidatorTransaction::DKGResult(_) => { - Self::DKGResult(DKGResultTransaction { + aptos_types::validator_txn::ValidatorTransaction::DKGResult(dkg_transcript) => { + Self::DkgResult(DKGResultTransaction { info, events, timestamp: U64::from(timestamp), + dkg_transcript: ExportedDKGTranscript::from_internal_repr(dkg_transcript), }) }, - aptos_types::validator_txn::ValidatorTransaction::ObservedJWKUpdate(_) => { - Self::ObservedJWKUpdate(JWKUpdateTransaction { + aptos_types::validator_txn::ValidatorTransaction::ObservedJWKUpdate(quorum_certified_update) => { + Self::ObservedJwkUpdate(JWKUpdateTransaction { info, events, timestamp: U64::from(timestamp), + quorum_certified_update: ExportedQuorumCertifiedUpdate::from_internal_repr(quorum_certified_update), }) }, } @@ -718,6 +757,61 @@ pub struct JWKUpdateTransaction { pub info: TransactionInfo, pub events: Vec, pub timestamp: U64, + pub quorum_certified_update: ExportedQuorumCertifiedUpdate, +} + +/// A more API-friendly representation of the on-chain `aptos_types::jwks::QuorumCertifiedUpdate`. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] +pub struct ExportedQuorumCertifiedUpdate { + pub update: ExportedProviderJWKs, + pub multi_sig: ExportedAggregateSignature, +} + +impl ExportedQuorumCertifiedUpdate { + pub fn from_internal_repr(internal: QuorumCertifiedUpdate) -> Self { + let QuorumCertifiedUpdate { update, multi_sig } = internal; + Self { + update: ExportedProviderJWKs::from_internal_repr(update), + multi_sig: ExportedAggregateSignature::from_internal_repr(multi_sig), + } + } +} + +/// A more API-friendly representation of the on-chain `aptos_types::aggregate_signature::AggregateSignature`. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] +pub struct ExportedAggregateSignature { + signer_indices: Vec, + sig: Option>, +} + +impl ExportedAggregateSignature { + pub fn from_internal_repr(internal: AggregateSignature) -> Self { + Self { + signer_indices: internal.get_signers_bitvec().iter_ones().collect(), + sig: internal.sig().as_ref().map(|s|s.to_bytes().to_vec()), + } + } +} + +/// A more API-friendly representation of the on-chain `aptos_types::jwks::ProviderJWKs`. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] +pub struct ExportedProviderJWKs { + pub issuer: String, + pub version: u64, + pub jwks: Vec, +} + +impl ExportedProviderJWKs { + pub fn from_internal_repr(internal: ProviderJWKs) -> Self { + let ProviderJWKs { issuer, version, jwks } = internal; + Self { + issuer: String::from_utf8(issuer).unwrap_or("non_utf8_issuer".to_string()), + version, + jwks: jwks.iter().map(|on_chain_jwk|{ + JWK::try_from(on_chain_jwk).expect("conversion from on-chain representation to human-friendly representation should work") + }).collect(), + } + } } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] @@ -727,6 +821,27 @@ pub struct DKGResultTransaction { pub info: TransactionInfo, pub events: Vec, pub timestamp: U64, + pub dkg_transcript: ExportedDKGTranscript, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] +pub struct ExportedDKGTranscript { + epoch: U64, + author: Address, + #[serde(with = "serde_bytes")] + payload: Vec, +} + +impl ExportedDKGTranscript { + pub fn from_internal_repr(internal: DKGTranscript) -> Self { + let DKGTranscript { metadata, transcript_bytes } = internal; + let DKGTranscriptMetadata { epoch, author } = metadata; + Self { + epoch: epoch.into(), + author: author.into(), + payload: transcript_bytes, + } + } } /// An event from a transaction diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs index 1f66751e94871..40f73c380cfa2 100644 --- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs +++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs @@ -760,6 +760,9 @@ pub fn convert_transaction( Transaction::ValidatorTransaction(_) => { transaction::transaction::TransactionType::Validator }, + Transaction::BlockMetadataExtTransaction(_) => { + todo!() + } }; let txn_data = match &transaction { @@ -829,6 +832,9 @@ pub fn convert_transaction( Transaction::ValidatorTransaction(_) => { transaction::transaction::TxnData::Validator(transaction::ValidatorTransaction {}) }, + Transaction::BlockMetadataExtTransaction(_) => { + todo!() + } }; transaction::Transaction { diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs index c6bce7af37f02..288d078f24ce1 100644 --- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs +++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs @@ -7,7 +7,7 @@ use crate::{ runtime::{DEFAULT_NUM_RETRIES, RETRY_TIME_MILLIS}, }; use aptos_api::context::Context; -use aptos_api_types::{AsConverter, Transaction as APITransaction, TransactionOnChainData}; +use aptos_api_types::{AsConverter, Transaction as APITransaction, Transaction, TransactionOnChainData}; use aptos_indexer_grpc_utils::{ chunk_transactions, constants::MESSAGE_SIZE_LIMIT, @@ -409,9 +409,15 @@ impl IndexerStreamCoordinator { bet.info.epoch = Some(epoch_bcs); }, APITransaction::ValidatorTransaction(ref mut vt) => { - vt.info.block_height = Some(block_height_bcs); - vt.info.epoch = Some(epoch_bcs); + let info = vt.transaction_info_mut(); + info.block_height = Some(block_height_bcs); + info.epoch = Some(epoch_bcs); }, + Transaction::BlockMetadataExtTransaction(ref mut bmet) => { + let info = bmet.transaction_info_mut(); + info.block_height = Some(block_height_bcs); + info.epoch = Some(epoch_bcs); + } }; txn }) { diff --git a/types/Cargo.toml b/types/Cargo.toml index 85fdf0dc195f4..9c029afec4299 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -61,6 +61,8 @@ serde_yaml = { workspace = true } strum = { workspace = true } strum_macros = { workspace = true } thiserror = { workspace = true } +poem-openapi = { workspace = true } +poem-openapi-derive = { workspace = true } [dev-dependencies] ahash = { workspace = true } diff --git a/types/src/block_metadata_ext.rs b/types/src/block_metadata_ext.rs index 89be0c95cb7e9..b28ed18be8479 100644 --- a/types/src/block_metadata_ext.rs +++ b/types/src/block_metadata_ext.rs @@ -104,6 +104,13 @@ impl BlockMetadataExt { BlockMetadataExt::V1(obj) => obj.round, } } + + pub fn type_name(&self) -> &'static str { + match self { + BlockMetadataExt::V0(_) => "block_metadata_ext_transaction__v0", + BlockMetadataExt::V1(_) => "block_metadata_ext_transaction__v1", + } + } } impl From for BlockMetadataExt { diff --git a/types/src/jwks/jwk/mod.rs b/types/src/jwks/jwk/mod.rs index f5d692162b815..d47ca7d9ff76f 100644 --- a/types/src/jwks/jwk/mod.rs +++ b/types/src/jwks/jwk/mod.rs @@ -14,6 +14,7 @@ use std::{ cmp::Ordering, fmt::{Debug, Formatter}, }; +use poem_openapi_derive::Union; /// Reflection of Move type `0x1::jwks::JWK`. /// When you load an on-chain config that contains some JWK(s), the JWK will be of this type. @@ -47,7 +48,7 @@ impl From for JWKMoveStruct { } /// The JWK type that can be converted from/to `JWKMoveStruct` but easier to use in rust. -#[derive(Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] pub enum JWK { RSA(RSA_JWK), Unsupported(UnsupportedJWK), diff --git a/types/src/jwks/rsa/mod.rs b/types/src/jwks/rsa/mod.rs index a08012ad23cf5..337a4c2579dc5 100644 --- a/types/src/jwks/rsa/mod.rs +++ b/types/src/jwks/rsa/mod.rs @@ -11,11 +11,11 @@ use once_cell::sync::Lazy; use ring::signature::RsaKeyPair; use rsa::{pkcs1::EncodeRsaPrivateKey, pkcs8::DecodePrivateKey}; use serde::{Deserialize, Serialize}; - +use poem_openapi_derive::Object; /// Move type `0x1::jwks::RSA_JWK` in rust. /// See its doc in Move for more details. #[allow(non_camel_case_types)] -#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, Object)] pub struct RSA_JWK { pub kid: String, pub kty: String, diff --git a/types/src/jwks/unsupported/mod.rs b/types/src/jwks/unsupported/mod.rs index 6a6c15e2fc6f3..f92d179becabe 100644 --- a/types/src/jwks/unsupported/mod.rs +++ b/types/src/jwks/unsupported/mod.rs @@ -6,10 +6,11 @@ use aptos_crypto::HashValue; use move_core_types::value::{MoveStruct, MoveValue}; use serde::{Deserialize, Serialize}; use std::fmt::{Debug, Formatter}; +use poem_openapi_derive::Object; /// Move type `0x1::jwks::UnsupportedJWK` in rust. /// See its doc in Move for more details. -#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Object)] pub struct UnsupportedJWK { pub id: Vec, pub payload: Vec, diff --git a/types/src/transaction/mod.rs b/types/src/transaction/mod.rs index ee1900b0eaf3e..6d60b927da3c3 100644 --- a/types/src/transaction/mod.rs +++ b/types/src/transaction/mod.rs @@ -2000,8 +2000,8 @@ impl Transaction { Transaction::BlockMetadata(_) => "block_metadata", Transaction::StateCheckpoint(_) => "state_checkpoint", Transaction::BlockEpilogue(_) => "block_epilogue", - Transaction::ValidatorTransaction(_) => "validator_transaction", - Transaction::BlockMetadataExt(_) => "block_metadata_ext", + Transaction::ValidatorTransaction(vt) => vt.type_name(), + Transaction::BlockMetadataExt(bmet) => bmet.type_name(), } } diff --git a/types/src/validator_txn.rs b/types/src/validator_txn.rs index d99b43a96a1d2..8a8e6ad5e2ca2 100644 --- a/types/src/validator_txn.rs +++ b/types/src/validator_txn.rs @@ -40,6 +40,13 @@ impl ValidatorTransaction { }, } } + + pub fn type_name(&self) -> &'static str { + match self { + ValidatorTransaction::DKGResult(_) => "validator_transaction__dkg_result", + ValidatorTransaction::ObservedJWKUpdate(_) => "validator_transaction__observed_jwk_update", + } + } } #[derive(Clone, Debug, Eq, Hash, PartialEq)] From 8d0ea434ce905b058b6457a2e395722000834f8e Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Sat, 15 Jun 2024 19:19:13 -0700 Subject: [PATCH 3/9] lint --- Cargo.lock | 1 - api/types/Cargo.toml | 1 - api/types/src/convert.rs | 22 ++++---- api/types/src/transaction.rs | 56 ++++++++++++------- crates/aptos/src/common/types.rs | 22 ++++++-- crates/indexer/src/indexer/fetcher.rs | 10 +++- crates/indexer/src/models/transactions.rs | 5 +- .../indexer-grpc-fullnode/src/convert.rs | 4 +- .../src/stream_coordinator.rs | 6 +- types/Cargo.toml | 7 ++- types/src/jwks/jwk/mod.rs | 4 +- types/src/jwks/rsa/mod.rs | 2 +- types/src/jwks/unsupported/mod.rs | 2 +- types/src/validator_txn.rs | 4 +- 14 files changed, 96 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 506fc8c59b8ef..0ac84028808eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -531,7 +531,6 @@ dependencies = [ "poem-openapi", "poem-openapi-derive", "serde", - "serde_bytes", "serde_json", ] diff --git a/api/types/Cargo.toml b/api/types/Cargo.toml index 709109522a2f0..1ff09c771eed3 100644 --- a/api/types/Cargo.toml +++ b/api/types/Cargo.toml @@ -37,7 +37,6 @@ poem-openapi = { workspace = true } poem-openapi-derive = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } -serde_bytes = { workspace = true } [package.metadata.cargo-machete] ignored = ["async-trait", "poem", "poem-openapi-derive"] diff --git a/api/types/src/convert.rs b/api/types/src/convert.rs index 5c6f21634abb9..68936a34c6ab2 100644 --- a/api/types/src/convert.rs +++ b/api/types/src/convert.rs @@ -177,6 +177,10 @@ impl<'a, S: StateView> MoveConverter<'a, S> { timestamp: u64, data: TransactionOnChainData, ) -> Result { + use aptos_types::transaction::Transaction::{ + BlockEpilogue, BlockMetadata, BlockMetadataExt, GenesisTransaction, StateCheckpoint, + UserTransaction, + }; let aux_data = self .db .get_transaction_auxiliary_data_by_version(data.version)?; @@ -189,32 +193,30 @@ impl<'a, S: StateView> MoveConverter<'a, S> { ); let events = self.try_into_events(&data.events)?; Ok(match data.transaction { - aptos_types::transaction::Transaction::UserTransaction(txn) => { + UserTransaction(txn) => { let payload = self.try_into_transaction_payload(txn.payload().clone())?; (&txn, info, payload, events, timestamp).into() }, - aptos_types::transaction::Transaction::GenesisTransaction(write_set) => { + GenesisTransaction(write_set) => { let payload = self.try_into_write_set_payload(write_set)?; (info, payload, events).into() }, - aptos_types::transaction::Transaction::BlockMetadata(txn) => { + BlockMetadata(txn) => { Transaction::BlockMetadataTransaction(BlockMetadataTransaction::from_internal_repr( txn, info, events, )) // (&txn, info, events).into() }, - aptos_types::transaction::Transaction::BlockMetadataExt(txn) => { - Transaction::BlockMetadataExtTransaction( - BlockMetadataExtTransaction::from_internal_repr(txn, info, events), - ) - }, - aptos_types::transaction::Transaction::StateCheckpoint(_) => { + BlockMetadataExt(txn) => Transaction::BlockMetadataExtTransaction( + BlockMetadataExtTransaction::from_internal_repr(txn, info, events), + ), + StateCheckpoint(_) => { Transaction::StateCheckpointTransaction(StateCheckpointTransaction { info, timestamp: timestamp.into(), }) }, - aptos_types::transaction::Transaction::BlockEpilogue(block_epilogue_payload) => { + BlockEpilogue(block_epilogue_payload) => { Transaction::BlockEpilogueTransaction(BlockEpilogueTransaction { info, timestamp: timestamp.into(), diff --git a/api/types/src/transaction.rs b/api/types/src/transaction.rs index 78fc778639b34..e4ff2c223c14a 100755 --- a/api/types/src/transaction.rs +++ b/api/types/src/transaction.rs @@ -17,9 +17,12 @@ use aptos_crypto::{ }; use aptos_types::{ account_address::AccountAddress, + aggregate_signature::AggregateSignature, block_metadata::BlockMetadata, block_metadata_ext::{BlockMetadataExt, BlockMetadataWithRandomness}, contract_event::{ContractEvent, EventWithVersion}, + dkg::{DKGTranscript, DKGTranscriptMetadata}, + jwks::{jwk::JWK, ProviderJWKs, QuorumCertifiedUpdate}, keyless, transaction::{ authenticator::{ @@ -40,11 +43,6 @@ use std::{ str::FromStr, time::{SystemTime, UNIX_EPOCH}, }; -use aptos_types::aggregate_signature::AggregateSignature; -use aptos_types::dkg::{DKGTranscript, DKGTranscriptMetadata}; -use aptos_types::jwks::{ProviderJWKs, QuorumCertifiedUpdate}; -use aptos_types::jwks::jwk::JWK; -use aptos_types::jwks::unsupported::UnsupportedJWK; static DUMMY_GUID: Lazy = Lazy::new(|| EventGuid { creation_number: U64::from(0u64), @@ -635,7 +633,11 @@ impl BlockMetadataWithRandomnessTransaction { } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] #[serde(tag = "block_metadata_ext_transaction_type", rename_all = "snake_case")] -#[oai(one_of, discriminator_name = "block_metadata_ext_transaction_type", rename_all = "snake_case")] +#[oai( + one_of, + discriminator_name = "block_metadata_ext_transaction_type", + rename_all = "snake_case" +)] pub enum BlockMetadataExtTransaction { V0(BlockMetadataTransaction), V1(BlockMetadataWithRandomnessTransaction), @@ -688,7 +690,11 @@ impl BlockMetadataExtTransaction { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] #[serde(tag = "validator_transaction_type", rename_all = "snake_case")] -#[oai(one_of, discriminator_name = "validator_transaction_type", rename_all = "snake_case")] +#[oai( + one_of, + discriminator_name = "validator_transaction_type", + rename_all = "snake_case" +)] pub enum ValidatorTransaction { ObservedJwkUpdate(JWKUpdateTransaction), DkgResult(DKGResultTransaction), @@ -697,7 +703,9 @@ pub enum ValidatorTransaction { impl ValidatorTransaction { pub fn type_str(&self) -> &'static str { match self { - ValidatorTransaction::ObservedJwkUpdate(_) => "validator_transaction__observed_jwk_update", + ValidatorTransaction::ObservedJwkUpdate(_) => { + "validator_transaction__observed_jwk_update" + }, ValidatorTransaction::DkgResult(_) => "validator_transaction__dkg_result", } } @@ -738,14 +746,16 @@ impl ValidatorTransaction { dkg_transcript: ExportedDKGTranscript::from_internal_repr(dkg_transcript), }) }, - aptos_types::validator_txn::ValidatorTransaction::ObservedJWKUpdate(quorum_certified_update) => { - Self::ObservedJwkUpdate(JWKUpdateTransaction { - info, - events, - timestamp: U64::from(timestamp), - quorum_certified_update: ExportedQuorumCertifiedUpdate::from_internal_repr(quorum_certified_update), - }) - }, + aptos_types::validator_txn::ValidatorTransaction::ObservedJWKUpdate( + quorum_certified_update, + ) => Self::ObservedJwkUpdate(JWKUpdateTransaction { + info, + events, + timestamp: U64::from(timestamp), + quorum_certified_update: ExportedQuorumCertifiedUpdate::from_internal_repr( + quorum_certified_update, + ), + }), } } } @@ -788,7 +798,7 @@ impl ExportedAggregateSignature { pub fn from_internal_repr(internal: AggregateSignature) -> Self { Self { signer_indices: internal.get_signers_bitvec().iter_ones().collect(), - sig: internal.sig().as_ref().map(|s|s.to_bytes().to_vec()), + sig: internal.sig().as_ref().map(|s| s.to_bytes().to_vec()), } } } @@ -803,7 +813,11 @@ pub struct ExportedProviderJWKs { impl ExportedProviderJWKs { pub fn from_internal_repr(internal: ProviderJWKs) -> Self { - let ProviderJWKs { issuer, version, jwks } = internal; + let ProviderJWKs { + issuer, + version, + jwks, + } = internal; Self { issuer: String::from_utf8(issuer).unwrap_or("non_utf8_issuer".to_string()), version, @@ -828,13 +842,15 @@ pub struct DKGResultTransaction { pub struct ExportedDKGTranscript { epoch: U64, author: Address, - #[serde(with = "serde_bytes")] payload: Vec, } impl ExportedDKGTranscript { pub fn from_internal_repr(internal: DKGTranscript) -> Self { - let DKGTranscript { metadata, transcript_bytes } = internal; + let DKGTranscript { + metadata, + transcript_bytes, + } = internal; let DKGTranscriptMetadata { epoch, author } = metadata; Self { epoch: epoch.into(), diff --git a/crates/aptos/src/common/types.rs b/crates/aptos/src/common/types.rs index 057e84ad47371..3010485a924fd 100644 --- a/crates/aptos/src/common/types.rs +++ b/crates/aptos/src/common/types.rs @@ -1365,16 +1365,28 @@ impl From<&Transaction> for TransactionSummary { sequence_number: None, }, Transaction::ValidatorTransaction(txn) => TransactionSummary { - transaction_hash: txn.info.hash, + transaction_hash: txn.transaction_info().hash, gas_used: None, gas_unit_price: None, pending: None, sender: None, sequence_number: None, - success: Some(txn.info.success), - timestamp_us: Some(txn.timestamp.0), - version: Some(txn.info.version.0), - vm_status: Some(txn.info.vm_status.clone()), + success: Some(txn.transaction_info().success), + timestamp_us: Some(txn.timestamp().0), + version: Some(txn.transaction_info().version.0), + vm_status: Some(txn.transaction_info().vm_status.clone()), + }, + Transaction::BlockMetadataExtTransaction(txn) => TransactionSummary { + transaction_hash: txn.transaction_info().hash, + gas_used: None, + gas_unit_price: None, + pending: None, + sender: None, + sequence_number: None, + success: Some(txn.transaction_info().success), + timestamp_us: Some(txn.timestamp().0), + version: Some(txn.transaction_info().version.0), + vm_status: Some(txn.transaction_info().vm_status.clone()), }, } } diff --git a/crates/indexer/src/indexer/fetcher.rs b/crates/indexer/src/indexer/fetcher.rs index 9e4d68e916851..758a6065d7b5f 100644 --- a/crates/indexer/src/indexer/fetcher.rs +++ b/crates/indexer/src/indexer/fetcher.rs @@ -292,8 +292,14 @@ async fn fetch_nexts( bet.info.epoch = Some(epoch_bcs); }, Transaction::ValidatorTransaction(ref mut st) => { - st.info.block_height = Some(block_height_bcs); - st.info.epoch = Some(epoch_bcs); + let info = st.transaction_info_mut(); + info.block_height = Some(block_height_bcs); + info.epoch = Some(epoch_bcs); + }, + Transaction::BlockMetadataExtTransaction(ref mut bmet) => { + let info = bmet.transaction_info_mut(); + info.block_height = Some(block_height_bcs); + info.epoch = Some(epoch_bcs); }, }; txn diff --git a/crates/indexer/src/models/transactions.rs b/crates/indexer/src/models/transactions.rs index 2ee3e093fe032..50f6f7b615354 100644 --- a/crates/indexer/src/models/transactions.rs +++ b/crates/indexer/src/models/transactions.rs @@ -238,7 +238,7 @@ impl Transaction { }, APITransaction::ValidatorTransaction(validator_txn) => ( Self::from_transaction_info( - &validator_txn.info, + validator_txn.transaction_info(), None, transaction.type_str().to_string(), 0, @@ -250,6 +250,9 @@ impl Transaction { vec![], vec![], ), + APITransaction::BlockMetadataExtTransaction(_block_metadata_ext_txn) => { + todo!() + }, } } diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs index 40f73c380cfa2..d245d35d08635 100644 --- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs +++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs @@ -762,7 +762,7 @@ pub fn convert_transaction( }, Transaction::BlockMetadataExtTransaction(_) => { todo!() - } + }, }; let txn_data = match &transaction { @@ -834,7 +834,7 @@ pub fn convert_transaction( }, Transaction::BlockMetadataExtTransaction(_) => { todo!() - } + }, }; transaction::Transaction { diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs index 288d078f24ce1..e9cf71b17b7bb 100644 --- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs +++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs @@ -7,7 +7,9 @@ use crate::{ runtime::{DEFAULT_NUM_RETRIES, RETRY_TIME_MILLIS}, }; use aptos_api::context::Context; -use aptos_api_types::{AsConverter, Transaction as APITransaction, Transaction, TransactionOnChainData}; +use aptos_api_types::{ + AsConverter, Transaction as APITransaction, Transaction, TransactionOnChainData, +}; use aptos_indexer_grpc_utils::{ chunk_transactions, constants::MESSAGE_SIZE_LIMIT, @@ -417,7 +419,7 @@ impl IndexerStreamCoordinator { let info = bmet.transaction_info_mut(); info.block_height = Some(block_height_bcs); info.epoch = Some(epoch_bcs); - } + }, }; txn }) { diff --git a/types/Cargo.toml b/types/Cargo.toml index 9c029afec4299..79c5b17de97c1 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -45,6 +45,8 @@ num-derive = { workspace = true } num-traits = { workspace = true } once_cell = { workspace = true } passkey-types = { workspace = true } +poem-openapi = { workspace = true } +poem-openapi-derive = { workspace = true } proptest = { workspace = true, optional = true } proptest-derive = { workspace = true, optional = true } quick_cache = { workspace = true } @@ -61,8 +63,6 @@ serde_yaml = { workspace = true } strum = { workspace = true } strum_macros = { workspace = true } thiserror = { workspace = true } -poem-openapi = { workspace = true } -poem-openapi-derive = { workspace = true } [dev-dependencies] ahash = { workspace = true } @@ -97,3 +97,6 @@ harness = false [[bench]] name = "state_key" harness = false + +[package.metadata.cargo-machete] +ignored = ['poem-openapi'] diff --git a/types/src/jwks/jwk/mod.rs b/types/src/jwks/jwk/mod.rs index d47ca7d9ff76f..4d45eac86fa33 100644 --- a/types/src/jwks/jwk/mod.rs +++ b/types/src/jwks/jwk/mod.rs @@ -1,6 +1,8 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 +#![allow(clippy::match_result_ok)] + use crate::{ jwks::{rsa::RSA_JWK, unsupported::UnsupportedJWK}, move_any::{Any as MoveAny, AsMoveAny}, @@ -9,12 +11,12 @@ use crate::{ use anyhow::anyhow; use aptos_crypto_derive::{BCSCryptoHash, CryptoHasher}; use move_core_types::value::{MoveStruct, MoveValue}; +use poem_openapi_derive::Union; use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, fmt::{Debug, Formatter}, }; -use poem_openapi_derive::Union; /// Reflection of Move type `0x1::jwks::JWK`. /// When you load an on-chain config that contains some JWK(s), the JWK will be of this type. diff --git a/types/src/jwks/rsa/mod.rs b/types/src/jwks/rsa/mod.rs index 337a4c2579dc5..23a9cd6fba819 100644 --- a/types/src/jwks/rsa/mod.rs +++ b/types/src/jwks/rsa/mod.rs @@ -8,10 +8,10 @@ use base64::URL_SAFE_NO_PAD; use jsonwebtoken::{Algorithm, DecodingKey, TokenData, Validation}; use move_core_types::value::{MoveStruct, MoveValue}; use once_cell::sync::Lazy; +use poem_openapi_derive::Object; use ring::signature::RsaKeyPair; use rsa::{pkcs1::EncodeRsaPrivateKey, pkcs8::DecodePrivateKey}; use serde::{Deserialize, Serialize}; -use poem_openapi_derive::Object; /// Move type `0x1::jwks::RSA_JWK` in rust. /// See its doc in Move for more details. #[allow(non_camel_case_types)] diff --git a/types/src/jwks/unsupported/mod.rs b/types/src/jwks/unsupported/mod.rs index f92d179becabe..813747b4aee10 100644 --- a/types/src/jwks/unsupported/mod.rs +++ b/types/src/jwks/unsupported/mod.rs @@ -4,9 +4,9 @@ use crate::{move_any::AsMoveAny, move_utils::as_move_value::AsMoveValue}; use aptos_crypto::HashValue; use move_core_types::value::{MoveStruct, MoveValue}; +use poem_openapi_derive::Object; use serde::{Deserialize, Serialize}; use std::fmt::{Debug, Formatter}; -use poem_openapi_derive::Object; /// Move type `0x1::jwks::UnsupportedJWK` in rust. /// See its doc in Move for more details. diff --git a/types/src/validator_txn.rs b/types/src/validator_txn.rs index 8a8e6ad5e2ca2..ad6481b36f52f 100644 --- a/types/src/validator_txn.rs +++ b/types/src/validator_txn.rs @@ -44,7 +44,9 @@ impl ValidatorTransaction { pub fn type_name(&self) -> &'static str { match self { ValidatorTransaction::DKGResult(_) => "validator_transaction__dkg_result", - ValidatorTransaction::ObservedJWKUpdate(_) => "validator_transaction__observed_jwk_update", + ValidatorTransaction::ObservedJWKUpdate(_) => { + "validator_transaction__observed_jwk_update" + }, } } } From 7a4dc4c7c2bfcdf8c16291443386d5441e768fd8 Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Sat, 15 Jun 2024 19:29:32 -0700 Subject: [PATCH 4/9] update --- api/types/src/transaction.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/api/types/src/transaction.rs b/api/types/src/transaction.rs index e4ff2c223c14a..34b1c646d37f7 100755 --- a/api/types/src/transaction.rs +++ b/api/types/src/transaction.rs @@ -336,16 +336,6 @@ impl From<(&SignedTransaction, TransactionPayload)> for UserTransactionRequest { } } -// impl From<(TransactionInfo, Vec, u64)> for Transaction { -// fn from((info, events, timestamp): (TransactionInfo, Vec, u64)) -> Self { -// Transaction::ValidatorTransaction(ValidatorTransaction { -// info, -// events, -// timestamp: timestamp.into(), -// }) -// } -// } - /// Information related to how a transaction affected the state of the blockchain #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] pub struct TransactionInfo { From 90a42a95bbfb0aad62a328432cb6856db066af93 Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Mon, 17 Jun 2024 17:52:14 -0700 Subject: [PATCH 5/9] revert bmet --- api/types/src/convert.rs | 27 ++-- api/types/src/transaction.rs | 146 ++++-------------- crates/aptos/src/common/types.rs | 12 -- crates/indexer/src/indexer/fetcher.rs | 5 - crates/indexer/src/models/transactions.rs | 3 - .../indexer-grpc-fullnode/src/convert.rs | 6 - .../src/stream_coordinator.rs | 9 +- 7 files changed, 45 insertions(+), 163 deletions(-) diff --git a/api/types/src/convert.rs b/api/types/src/convert.rs index 68936a34c6ab2..bcfd522eb6e1a 100644 --- a/api/types/src/convert.rs +++ b/api/types/src/convert.rs @@ -4,16 +4,16 @@ use crate::{ transaction::{ - BlockEpilogueTransaction, BlockMetadataExtTransaction, DecodedTableData, DeleteModule, - DeleteResource, DeleteTableItem, DeletedTableData, MultisigPayload, - MultisigTransactionPayload, StateCheckpointTransaction, UserTransactionRequestInner, - ValidatorTransaction, WriteModule, WriteResource, WriteTableItem, + BlockEpilogueTransaction, DecodedTableData, DeleteModule, DeleteResource, DeleteTableItem, + DeletedTableData, MultisigPayload, MultisigTransactionPayload, StateCheckpointTransaction, + UserTransactionRequestInner, ValidatorTransaction, WriteModule, WriteResource, + WriteTableItem, }, view::{ViewFunction, ViewRequest}, - Address, BlockMetadataTransaction, Bytecode, DirectWriteSet, EntryFunctionId, - EntryFunctionPayload, Event, HexEncodedBytes, MoveFunction, MoveModuleBytecode, MoveResource, - MoveScriptBytecode, MoveType, MoveValue, PendingTransaction, ResourceGroup, ScriptPayload, - ScriptWriteSet, SubmitTransactionRequest, Transaction, TransactionInfo, TransactionOnChainData, + Address, Bytecode, DirectWriteSet, EntryFunctionId, EntryFunctionPayload, Event, + HexEncodedBytes, MoveFunction, MoveModuleBytecode, MoveResource, MoveScriptBytecode, MoveType, + MoveValue, PendingTransaction, ResourceGroup, ScriptPayload, ScriptWriteSet, + SubmitTransactionRequest, Transaction, TransactionInfo, TransactionOnChainData, TransactionPayload, UserTransactionRequest, VersionedEvent, WriteSet, WriteSetChange, WriteSetPayload, }; @@ -201,15 +201,8 @@ impl<'a, S: StateView> MoveConverter<'a, S> { let payload = self.try_into_write_set_payload(write_set)?; (info, payload, events).into() }, - BlockMetadata(txn) => { - Transaction::BlockMetadataTransaction(BlockMetadataTransaction::from_internal_repr( - txn, info, events, - )) - // (&txn, info, events).into() - }, - BlockMetadataExt(txn) => Transaction::BlockMetadataExtTransaction( - BlockMetadataExtTransaction::from_internal_repr(txn, info, events), - ), + BlockMetadata(txn) => (&txn, info, events).into(), + BlockMetadataExt(txn) => (&txn, info, events).into(), StateCheckpoint(_) => { Transaction::StateCheckpointTransaction(StateCheckpointTransaction { info, diff --git a/api/types/src/transaction.rs b/api/types/src/transaction.rs index 34b1c646d37f7..7c499eadf7dce 100755 --- a/api/types/src/transaction.rs +++ b/api/types/src/transaction.rs @@ -19,7 +19,7 @@ use aptos_types::{ account_address::AccountAddress, aggregate_signature::AggregateSignature, block_metadata::BlockMetadata, - block_metadata_ext::{BlockMetadataExt, BlockMetadataWithRandomness}, + block_metadata_ext::BlockMetadataExt, contract_event::{ContractEvent, EventWithVersion}, dkg::{DKGTranscript, DKGTranscriptMetadata}, jwks::{jwk::JWK, ProviderJWKs, QuorumCertifiedUpdate}, @@ -182,7 +182,6 @@ pub enum Transaction { StateCheckpointTransaction(StateCheckpointTransaction), BlockEpilogueTransaction(BlockEpilogueTransaction), ValidatorTransaction(ValidatorTransaction), - BlockMetadataExtTransaction(BlockMetadataExtTransaction), } impl Transaction { @@ -195,7 +194,6 @@ impl Transaction { Transaction::StateCheckpointTransaction(txn) => txn.timestamp.0, Transaction::BlockEpilogueTransaction(txn) => txn.timestamp.0, Transaction::ValidatorTransaction(txn) => txn.timestamp().0, - Transaction::BlockMetadataExtTransaction(txn) => txn.timestamp().0, } } @@ -208,9 +206,6 @@ impl Transaction { Transaction::StateCheckpointTransaction(txn) => Some(txn.info.version.into()), Transaction::BlockEpilogueTransaction(txn) => Some(txn.info.version.into()), Transaction::ValidatorTransaction(txn) => Some(txn.transaction_info().version.into()), - Transaction::BlockMetadataExtTransaction(txn) => { - Some(txn.transaction_info().version.into()) - }, } } @@ -223,7 +218,6 @@ impl Transaction { Transaction::StateCheckpointTransaction(txn) => txn.info.success, Transaction::BlockEpilogueTransaction(txn) => txn.info.success, Transaction::ValidatorTransaction(txn) => txn.transaction_info().success, - Transaction::BlockMetadataExtTransaction(txn) => txn.transaction_info().success, } } @@ -240,9 +234,6 @@ impl Transaction { Transaction::StateCheckpointTransaction(txn) => txn.info.vm_status.clone(), Transaction::BlockEpilogueTransaction(txn) => txn.info.vm_status.clone(), Transaction::ValidatorTransaction(txn) => txn.transaction_info().vm_status.clone(), - Transaction::BlockMetadataExtTransaction(txn) => { - txn.transaction_info().vm_status.clone() - }, } } @@ -255,7 +246,6 @@ impl Transaction { Transaction::StateCheckpointTransaction(_) => "state_checkpoint_transaction", Transaction::BlockEpilogueTransaction(_) => "block_epilogue_transaction", Transaction::ValidatorTransaction(vt) => vt.type_str(), - Transaction::BlockMetadataExtTransaction(bmet) => bmet.type_str(), } } @@ -270,7 +260,6 @@ impl Transaction { Transaction::StateCheckpointTransaction(txn) => &txn.info, Transaction::BlockEpilogueTransaction(txn) => &txn.info, Transaction::ValidatorTransaction(txn) => txn.transaction_info(), - Transaction::BlockMetadataExtTransaction(txn) => txn.transaction_info(), }) } } @@ -322,6 +311,38 @@ impl From<(TransactionInfo, WriteSetPayload, Vec)> for Transaction { } } +impl From<(&BlockMetadata, TransactionInfo, Vec)> for Transaction { + fn from((txn, info, events): (&BlockMetadata, TransactionInfo, Vec)) -> Self { + Transaction::BlockMetadataTransaction(BlockMetadataTransaction { + info, + id: txn.id().into(), + epoch: txn.epoch().into(), + round: txn.round().into(), + events, + previous_block_votes_bitvec: txn.previous_block_votes_bitvec().clone(), + proposer: txn.proposer().into(), + failed_proposer_indices: txn.failed_proposer_indices().clone(), + timestamp: txn.timestamp_usecs().into(), + }) + } +} + +impl From<(&BlockMetadataExt, TransactionInfo, Vec)> for Transaction { + fn from((txn, info, events): (&BlockMetadataExt, TransactionInfo, Vec)) -> Self { + Transaction::BlockMetadataTransaction(BlockMetadataTransaction { + info, + id: txn.id().into(), + epoch: txn.epoch().into(), + round: txn.round().into(), + events, + previous_block_votes_bitvec: txn.previous_block_votes_bitvec().clone(), + proposer: txn.proposer().into(), + failed_proposer_indices: txn.failed_proposer_indices().clone(), + timestamp: txn.timestamp_usecs().into(), + }) + } +} + impl From<(&SignedTransaction, TransactionPayload)> for UserTransactionRequest { fn from((txn, payload): (&SignedTransaction, TransactionPayload)) -> Self { Self { @@ -578,106 +599,6 @@ impl BlockMetadataTransaction { } } -/// A block metadata transaction -/// -/// This signifies the beginning of a block, and contains information -/// about the specific block -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] -pub struct BlockMetadataWithRandomnessTransaction { - #[serde(flatten)] - #[oai(flatten)] - pub info: TransactionInfo, - pub id: HashValue, - pub epoch: U64, - pub round: U64, - /// The events emitted at the block creation - pub events: Vec, - /// Previous block votes - pub previous_block_votes_bitvec: Vec, - pub proposer: Address, - /// The indices of the proposers who failed to propose - pub failed_proposer_indices: Vec, - pub timestamp: U64, - pub randomness: Option>, -} - -impl BlockMetadataWithRandomnessTransaction { - pub fn from_internal_repr( - internal: BlockMetadataWithRandomness, - info: TransactionInfo, - events: Vec, - ) -> Self { - Self { - info, - id: internal.id.into(), - epoch: internal.epoch.into(), - round: internal.round.into(), - events, - previous_block_votes_bitvec: internal.previous_block_votes_bitvec.clone(), - proposer: internal.proposer.into(), - failed_proposer_indices: internal.failed_proposer_indices.clone(), - timestamp: internal.timestamp_usecs.into(), - randomness: internal.randomness.map(|r| r.randomness().to_vec()), - } - } -} -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] -#[serde(tag = "block_metadata_ext_transaction_type", rename_all = "snake_case")] -#[oai( - one_of, - discriminator_name = "block_metadata_ext_transaction_type", - rename_all = "snake_case" -)] -pub enum BlockMetadataExtTransaction { - V0(BlockMetadataTransaction), - V1(BlockMetadataWithRandomnessTransaction), -} - -impl BlockMetadataExtTransaction { - pub fn from_internal_repr( - internal: BlockMetadataExt, - info: TransactionInfo, - events: Vec, - ) -> Self { - match internal { - BlockMetadataExt::V0(v0) => Self::V0(BlockMetadataTransaction::from_internal_repr( - v0, info, events, - )), - BlockMetadataExt::V1(v1) => Self::V1( - BlockMetadataWithRandomnessTransaction::from_internal_repr(v1, info, events), - ), - } - } - - pub fn type_str(&self) -> &'static str { - match self { - BlockMetadataExtTransaction::V0(_) => "block_metadata_ext_transaction__v0", - BlockMetadataExtTransaction::V1(_) => "block_metadata_ext_transaction__v1", - } - } - - pub fn transaction_info(&self) -> &TransactionInfo { - match self { - BlockMetadataExtTransaction::V0(t) => &t.info, - BlockMetadataExtTransaction::V1(t) => &t.info, - } - } - - pub fn transaction_info_mut(&mut self) -> &mut TransactionInfo { - match self { - BlockMetadataExtTransaction::V0(t) => &mut t.info, - BlockMetadataExtTransaction::V1(t) => &mut t.info, - } - } - - pub fn timestamp(&self) -> U64 { - match self { - BlockMetadataExtTransaction::V0(t) => t.timestamp, - BlockMetadataExtTransaction::V1(t) => t.timestamp, - } - } -} - #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] #[serde(tag = "validator_transaction_type", rename_all = "snake_case")] #[oai( @@ -781,6 +702,7 @@ impl ExportedQuorumCertifiedUpdate { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)] pub struct ExportedAggregateSignature { signer_indices: Vec, + #[serde(skip_serializing_if = "Option::is_none")] sig: Option>, } diff --git a/crates/aptos/src/common/types.rs b/crates/aptos/src/common/types.rs index 3010485a924fd..496bc523dae72 100644 --- a/crates/aptos/src/common/types.rs +++ b/crates/aptos/src/common/types.rs @@ -1376,18 +1376,6 @@ impl From<&Transaction> for TransactionSummary { version: Some(txn.transaction_info().version.0), vm_status: Some(txn.transaction_info().vm_status.clone()), }, - Transaction::BlockMetadataExtTransaction(txn) => TransactionSummary { - transaction_hash: txn.transaction_info().hash, - gas_used: None, - gas_unit_price: None, - pending: None, - sender: None, - sequence_number: None, - success: Some(txn.transaction_info().success), - timestamp_us: Some(txn.timestamp().0), - version: Some(txn.transaction_info().version.0), - vm_status: Some(txn.transaction_info().vm_status.clone()), - }, } } } diff --git a/crates/indexer/src/indexer/fetcher.rs b/crates/indexer/src/indexer/fetcher.rs index 758a6065d7b5f..7340ae1a13474 100644 --- a/crates/indexer/src/indexer/fetcher.rs +++ b/crates/indexer/src/indexer/fetcher.rs @@ -296,11 +296,6 @@ async fn fetch_nexts( info.block_height = Some(block_height_bcs); info.epoch = Some(epoch_bcs); }, - Transaction::BlockMetadataExtTransaction(ref mut bmet) => { - let info = bmet.transaction_info_mut(); - info.block_height = Some(block_height_bcs); - info.epoch = Some(epoch_bcs); - }, }; txn }) { diff --git a/crates/indexer/src/models/transactions.rs b/crates/indexer/src/models/transactions.rs index 50f6f7b615354..52a1f2bca5c5e 100644 --- a/crates/indexer/src/models/transactions.rs +++ b/crates/indexer/src/models/transactions.rs @@ -250,9 +250,6 @@ impl Transaction { vec![], vec![], ), - APITransaction::BlockMetadataExtTransaction(_block_metadata_ext_txn) => { - todo!() - }, } } diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs index d245d35d08635..1f66751e94871 100644 --- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs +++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs @@ -760,9 +760,6 @@ pub fn convert_transaction( Transaction::ValidatorTransaction(_) => { transaction::transaction::TransactionType::Validator }, - Transaction::BlockMetadataExtTransaction(_) => { - todo!() - }, }; let txn_data = match &transaction { @@ -832,9 +829,6 @@ pub fn convert_transaction( Transaction::ValidatorTransaction(_) => { transaction::transaction::TxnData::Validator(transaction::ValidatorTransaction {}) }, - Transaction::BlockMetadataExtTransaction(_) => { - todo!() - }, }; transaction::Transaction { diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs index e9cf71b17b7bb..45b8b7282257d 100644 --- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs +++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs @@ -7,9 +7,7 @@ use crate::{ runtime::{DEFAULT_NUM_RETRIES, RETRY_TIME_MILLIS}, }; use aptos_api::context::Context; -use aptos_api_types::{ - AsConverter, Transaction as APITransaction, Transaction, TransactionOnChainData, -}; +use aptos_api_types::{AsConverter, Transaction as APITransaction, TransactionOnChainData}; use aptos_indexer_grpc_utils::{ chunk_transactions, constants::MESSAGE_SIZE_LIMIT, @@ -415,11 +413,6 @@ impl IndexerStreamCoordinator { info.block_height = Some(block_height_bcs); info.epoch = Some(epoch_bcs); }, - Transaction::BlockMetadataExtTransaction(ref mut bmet) => { - let info = bmet.transaction_info_mut(); - info.block_height = Some(block_height_bcs); - info.epoch = Some(epoch_bcs); - }, }; txn }) { From 71739f891b05372747af9fb6dbbfdcf855cbdc54 Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Tue, 18 Jun 2024 05:42:22 -0700 Subject: [PATCH 6/9] clean up --- api/types/src/convert.rs | 7 +-- api/types/src/transaction.rs | 88 ++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 53 deletions(-) diff --git a/api/types/src/convert.rs b/api/types/src/convert.rs index bcfd522eb6e1a..a38118d0edba4 100644 --- a/api/types/src/convert.rs +++ b/api/types/src/convert.rs @@ -6,8 +6,7 @@ use crate::{ transaction::{ BlockEpilogueTransaction, DecodedTableData, DeleteModule, DeleteResource, DeleteTableItem, DeletedTableData, MultisigPayload, MultisigTransactionPayload, StateCheckpointTransaction, - UserTransactionRequestInner, ValidatorTransaction, WriteModule, WriteResource, - WriteTableItem, + UserTransactionRequestInner, WriteModule, WriteResource, WriteTableItem, }, view::{ViewFunction, ViewRequest}, Address, Bytecode, DirectWriteSet, EntryFunctionId, EntryFunctionPayload, Event, @@ -233,9 +232,7 @@ impl<'a, S: StateView> MoveConverter<'a, S> { }) }, aptos_types::transaction::Transaction::ValidatorTransaction(txn) => { - Transaction::ValidatorTransaction(ValidatorTransaction::from_internal_repr( - txn, info, events, timestamp, - )) + Transaction::ValidatorTransaction((txn, info, events, timestamp).into()) }, }) } diff --git a/api/types/src/transaction.rs b/api/types/src/transaction.rs index 7c499eadf7dce..cd05df936b21e 100755 --- a/api/types/src/transaction.rs +++ b/api/types/src/transaction.rs @@ -579,26 +579,6 @@ pub struct BlockMetadataTransaction { pub timestamp: U64, } -impl BlockMetadataTransaction { - pub fn from_internal_repr( - internal: BlockMetadata, - info: TransactionInfo, - events: Vec, - ) -> Self { - Self { - info, - id: internal.id().into(), - epoch: internal.epoch().into(), - round: internal.round().into(), - events, - previous_block_votes_bitvec: internal.previous_block_votes_bitvec().clone(), - proposer: internal.proposer().into(), - failed_proposer_indices: internal.failed_proposer_indices().clone(), - timestamp: internal.timestamp_usecs().into(), - } - } -} - #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Union)] #[serde(tag = "validator_transaction_type", rename_all = "snake_case")] #[oai( @@ -641,20 +621,31 @@ impl ValidatorTransaction { ValidatorTransaction::DkgResult(t) => t.timestamp, } } +} - pub fn from_internal_repr( - internal: aptos_types::validator_txn::ValidatorTransaction, - info: TransactionInfo, - events: Vec, - timestamp: u64, +impl + From<( + aptos_types::validator_txn::ValidatorTransaction, + TransactionInfo, + Vec, + u64, + )> for ValidatorTransaction +{ + fn from( + (txn, info, events, timestamp): ( + aptos_types::validator_txn::ValidatorTransaction, + TransactionInfo, + Vec, + u64, + ), ) -> Self { - match internal { + match txn { aptos_types::validator_txn::ValidatorTransaction::DKGResult(dkg_transcript) => { Self::DkgResult(DKGResultTransaction { info, events, timestamp: U64::from(timestamp), - dkg_transcript: ExportedDKGTranscript::from_internal_repr(dkg_transcript), + dkg_transcript: dkg_transcript.into(), }) }, aptos_types::validator_txn::ValidatorTransaction::ObservedJWKUpdate( @@ -663,9 +654,7 @@ impl ValidatorTransaction { info, events, timestamp: U64::from(timestamp), - quorum_certified_update: ExportedQuorumCertifiedUpdate::from_internal_repr( - quorum_certified_update, - ), + quorum_certified_update: quorum_certified_update.into(), }), } } @@ -688,12 +677,12 @@ pub struct ExportedQuorumCertifiedUpdate { pub multi_sig: ExportedAggregateSignature, } -impl ExportedQuorumCertifiedUpdate { - pub fn from_internal_repr(internal: QuorumCertifiedUpdate) -> Self { - let QuorumCertifiedUpdate { update, multi_sig } = internal; +impl From for ExportedQuorumCertifiedUpdate { + fn from(value: QuorumCertifiedUpdate) -> Self { + let QuorumCertifiedUpdate { update, multi_sig } = value; Self { - update: ExportedProviderJWKs::from_internal_repr(update), - multi_sig: ExportedAggregateSignature::from_internal_repr(multi_sig), + update: update.into(), + multi_sig: multi_sig.into(), } } } @@ -703,14 +692,17 @@ impl ExportedQuorumCertifiedUpdate { pub struct ExportedAggregateSignature { signer_indices: Vec, #[serde(skip_serializing_if = "Option::is_none")] - sig: Option>, + sig: Option, } -impl ExportedAggregateSignature { - pub fn from_internal_repr(internal: AggregateSignature) -> Self { +impl From for ExportedAggregateSignature { + fn from(value: AggregateSignature) -> Self { Self { - signer_indices: internal.get_signers_bitvec().iter_ones().collect(), - sig: internal.sig().as_ref().map(|s| s.to_bytes().to_vec()), + signer_indices: value.get_signers_bitvec().iter_ones().collect(), + sig: value + .sig() + .as_ref() + .map(|s| HexEncodedBytes::from(s.to_bytes().to_vec())), } } } @@ -723,13 +715,13 @@ pub struct ExportedProviderJWKs { pub jwks: Vec, } -impl ExportedProviderJWKs { - pub fn from_internal_repr(internal: ProviderJWKs) -> Self { +impl From for ExportedProviderJWKs { + fn from(value: ProviderJWKs) -> Self { let ProviderJWKs { issuer, version, jwks, - } = internal; + } = value; Self { issuer: String::from_utf8(issuer).unwrap_or("non_utf8_issuer".to_string()), version, @@ -754,20 +746,20 @@ pub struct DKGResultTransaction { pub struct ExportedDKGTranscript { epoch: U64, author: Address, - payload: Vec, + payload: HexEncodedBytes, } -impl ExportedDKGTranscript { - pub fn from_internal_repr(internal: DKGTranscript) -> Self { +impl From for ExportedDKGTranscript { + fn from(value: DKGTranscript) -> Self { let DKGTranscript { metadata, transcript_bytes, - } = internal; + } = value; let DKGTranscriptMetadata { epoch, author } = metadata; Self { epoch: epoch.into(), author: author.into(), - payload: transcript_bytes, + payload: HexEncodedBytes::from(transcript_bytes), } } } From bcd30dcbb7a79f8a92dbda4fd4636b317a50d35c Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Tue, 18 Jun 2024 05:46:08 -0700 Subject: [PATCH 7/9] revert BlockMetadatExt type name --- types/src/block_metadata_ext.rs | 7 ------- types/src/transaction/mod.rs | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/types/src/block_metadata_ext.rs b/types/src/block_metadata_ext.rs index b28ed18be8479..89be0c95cb7e9 100644 --- a/types/src/block_metadata_ext.rs +++ b/types/src/block_metadata_ext.rs @@ -104,13 +104,6 @@ impl BlockMetadataExt { BlockMetadataExt::V1(obj) => obj.round, } } - - pub fn type_name(&self) -> &'static str { - match self { - BlockMetadataExt::V0(_) => "block_metadata_ext_transaction__v0", - BlockMetadataExt::V1(_) => "block_metadata_ext_transaction__v1", - } - } } impl From for BlockMetadataExt { diff --git a/types/src/transaction/mod.rs b/types/src/transaction/mod.rs index 6d60b927da3c3..2418671247655 100644 --- a/types/src/transaction/mod.rs +++ b/types/src/transaction/mod.rs @@ -2001,7 +2001,7 @@ impl Transaction { Transaction::StateCheckpoint(_) => "state_checkpoint", Transaction::BlockEpilogue(_) => "block_epilogue", Transaction::ValidatorTransaction(vt) => vt.type_name(), - Transaction::BlockMetadataExt(bmet) => bmet.type_name(), + Transaction::BlockMetadataExt(_) => "block_metadata_ext", } } From 1d02284771c9bc1078e3f44b2fae2bfda0bdb063 Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Sat, 22 Jun 2024 12:32:46 -0700 Subject: [PATCH 8/9] fix spec --- api/doc/spec.json | 377 +++++++++++++++++++++++++++++++++++++++------- api/doc/spec.yaml | 271 +++++++++++++++++++++++++++------ 2 files changed, 550 insertions(+), 98 deletions(-) diff --git a/api/doc/spec.json b/api/doc/spec.json index 9757337ae35e5..d36e4a6a0100d 100644 --- a/api/doc/spec.json +++ b/api/doc/spec.json @@ -14330,6 +14330,73 @@ } } }, + "DKGResultTransaction": { + "type": "object", + "required": [ + "version", + "hash", + "state_change_hash", + "event_root_hash", + "gas_used", + "success", + "vm_status", + "accumulator_root_hash", + "changes", + "events", + "timestamp", + "dkg_transcript" + ], + "properties": { + "version": { + "$ref": "#/components/schemas/U64" + }, + "hash": { + "$ref": "#/components/schemas/HashValue" + }, + "state_change_hash": { + "$ref": "#/components/schemas/HashValue" + }, + "event_root_hash": { + "$ref": "#/components/schemas/HashValue" + }, + "state_checkpoint_hash": { + "$ref": "#/components/schemas/HashValue" + }, + "gas_used": { + "$ref": "#/components/schemas/U64" + }, + "success": { + "type": "boolean", + "description": "Whether the transaction was successful" + }, + "vm_status": { + "type": "string", + "description": "The VM status of the transaction, can tell useful information in a failure" + }, + "accumulator_root_hash": { + "$ref": "#/components/schemas/HashValue" + }, + "changes": { + "type": "array", + "description": "Final state of resources changed by the transaction", + "items": { + "$ref": "#/components/schemas/WriteSetChange" + } + }, + "events": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Event" + } + }, + "timestamp": { + "$ref": "#/components/schemas/U64" + }, + "dkg_transcript": { + "$ref": "#/components/schemas/ExportedDKGTranscript" + } + } + }, "DecodedTableData": { "type": "object", "description": "Decoded table data", @@ -14598,6 +14665,84 @@ } } }, + "ExportedAggregateSignature": { + "type": "object", + "description": "A more API-friendly representation of the on-chain `aptos_types::aggregate_signature::AggregateSignature`.", + "required": [ + "signer_indices" + ], + "properties": { + "signer_indices": { + "type": "array", + "items": { + "type": "integer", + "format": "uint64" + } + }, + "sig": { + "$ref": "#/components/schemas/HexEncodedBytes" + } + } + }, + "ExportedDKGTranscript": { + "type": "object", + "required": [ + "epoch", + "author", + "payload" + ], + "properties": { + "epoch": { + "$ref": "#/components/schemas/U64" + }, + "author": { + "$ref": "#/components/schemas/Address" + }, + "payload": { + "$ref": "#/components/schemas/HexEncodedBytes" + } + } + }, + "ExportedProviderJWKs": { + "type": "object", + "description": "A more API-friendly representation of the on-chain `aptos_types::jwks::ProviderJWKs`.", + "required": [ + "issuer", + "version", + "jwks" + ], + "properties": { + "issuer": { + "type": "string" + }, + "version": { + "type": "integer", + "format": "uint64" + }, + "jwks": { + "type": "array", + "items": { + "$ref": "#/components/schemas/JWK" + } + } + } + }, + "ExportedQuorumCertifiedUpdate": { + "type": "object", + "description": "A more API-friendly representation of the on-chain `aptos_types::jwks::QuorumCertifiedUpdate`.", + "required": [ + "update", + "multi_sig" + ], + "properties": { + "update": { + "$ref": "#/components/schemas/ExportedProviderJWKs" + }, + "multi_sig": { + "$ref": "#/components/schemas/ExportedAggregateSignature" + } + } + }, "FeePayerSignature": { "type": "object", "description": "Fee payer signature for fee payer transactions\n\nThis allows you to have transactions across multiple accounts and with a fee payer", @@ -14857,6 +15002,85 @@ } } }, + "JWK": { + "type": "object", + "description": "The JWK type that can be converted from/to `JWKMoveStruct` but easier to use in rust.", + "anyOf": [ + { + "$ref": "#/components/schemas/RSA_JWK" + }, + { + "$ref": "#/components/schemas/UnsupportedJWK" + } + ] + }, + "JWKUpdateTransaction": { + "type": "object", + "required": [ + "version", + "hash", + "state_change_hash", + "event_root_hash", + "gas_used", + "success", + "vm_status", + "accumulator_root_hash", + "changes", + "events", + "timestamp", + "quorum_certified_update" + ], + "properties": { + "version": { + "$ref": "#/components/schemas/U64" + }, + "hash": { + "$ref": "#/components/schemas/HashValue" + }, + "state_change_hash": { + "$ref": "#/components/schemas/HashValue" + }, + "event_root_hash": { + "$ref": "#/components/schemas/HashValue" + }, + "state_checkpoint_hash": { + "$ref": "#/components/schemas/HashValue" + }, + "gas_used": { + "$ref": "#/components/schemas/U64" + }, + "success": { + "type": "boolean", + "description": "Whether the transaction was successful" + }, + "vm_status": { + "type": "string", + "description": "The VM status of the transaction, can tell useful information in a failure" + }, + "accumulator_root_hash": { + "$ref": "#/components/schemas/HashValue" + }, + "changes": { + "type": "array", + "description": "Final state of resources changed by the transaction", + "items": { + "$ref": "#/components/schemas/WriteSetChange" + } + }, + "events": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Event" + } + }, + "timestamp": { + "$ref": "#/components/schemas/U64" + }, + "quorum_certified_update": { + "$ref": "#/components/schemas/ExportedQuorumCertifiedUpdate" + } + } + }, "Keyless": { "type": "object", "required": [ @@ -15465,6 +15689,34 @@ } ] }, + "RSA_JWK": { + "type": "object", + "description": "Move type `0x1::jwks::RSA_JWK` in rust.\nSee its doc in Move for more details.", + "required": [ + "kid", + "kty", + "alg", + "e", + "n" + ], + "properties": { + "kid": { + "type": "string" + }, + "kty": { + "type": "string" + }, + "alg": { + "type": "string" + }, + "e": { + "type": "string" + }, + "n": { + "type": "string" + } + } + }, "RawTableItemRequest": { "type": "object", "description": "Table Item request for the GetTableItemRaw API", @@ -16236,6 +16488,30 @@ "description": "A string containing a 64-bit unsigned integer.\n\nWe represent u64 values as a string to ensure compatibility with languages such\nas JavaScript that do not parse u64s in JSON natively.\n", "example": "32425224034" }, + "UnsupportedJWK": { + "type": "object", + "description": "Move type `0x1::jwks::UnsupportedJWK` in rust.\nSee its doc in Move for more details.", + "required": [ + "id", + "payload" + ], + "properties": { + "id": { + "type": "array", + "items": { + "type": "integer", + "format": "uint8" + } + }, + "payload": { + "type": "array", + "items": { + "type": "integer", + "format": "uint8" + } + } + } + }, "UserTransaction": { "type": "object", "description": "A transaction submitted by a user to change the state of the blockchain", @@ -16330,66 +16606,59 @@ }, "ValidatorTransaction": { "type": "object", - "required": [ - "version", - "hash", - "state_change_hash", - "event_root_hash", - "gas_used", - "success", - "vm_status", - "accumulator_root_hash", - "changes", - "events", - "timestamp" - ], - "properties": { - "version": { - "$ref": "#/components/schemas/U64" - }, - "hash": { - "$ref": "#/components/schemas/HashValue" - }, - "state_change_hash": { - "$ref": "#/components/schemas/HashValue" - }, - "event_root_hash": { - "$ref": "#/components/schemas/HashValue" - }, - "state_checkpoint_hash": { - "$ref": "#/components/schemas/HashValue" - }, - "gas_used": { - "$ref": "#/components/schemas/U64" - }, - "success": { - "type": "boolean", - "description": "Whether the transaction was successful" - }, - "vm_status": { - "type": "string", - "description": "The VM status of the transaction, can tell useful information in a failure" - }, - "accumulator_root_hash": { - "$ref": "#/components/schemas/HashValue" + "oneOf": [ + { + "$ref": "#/components/schemas/ValidatorTransaction_JWKUpdateTransaction" }, - "changes": { - "type": "array", - "description": "Final state of resources changed by the transaction", - "items": { - "$ref": "#/components/schemas/WriteSetChange" + { + "$ref": "#/components/schemas/ValidatorTransaction_DKGResultTransaction" + } + ], + "discriminator": { + "propertyName": "validator_transaction_type", + "mapping": { + "observed_jwk_update": "#/components/schemas/ValidatorTransaction_JWKUpdateTransaction", + "dkg_result": "#/components/schemas/ValidatorTransaction_DKGResultTransaction" + } + } + }, + "ValidatorTransaction_DKGResultTransaction": { + "allOf": [ + { + "type": "object", + "required": [ + "validator_transaction_type" + ], + "properties": { + "validator_transaction_type": { + "type": "string", + "example": "dkg_result" + } } }, - "events": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Event" + { + "$ref": "#/components/schemas/DKGResultTransaction" + } + ] + }, + "ValidatorTransaction_JWKUpdateTransaction": { + "allOf": [ + { + "type": "object", + "required": [ + "validator_transaction_type" + ], + "properties": { + "validator_transaction_type": { + "type": "string", + "example": "observed_jwk_update" + } } }, - "timestamp": { - "$ref": "#/components/schemas/U64" + { + "$ref": "#/components/schemas/JWKUpdateTransaction" } - } + ] }, "VersionedEvent": { "type": "object", diff --git a/api/doc/spec.yaml b/api/doc/spec.yaml index d7d2aab1b221b..9e22e463b078d 100644 --- a/api/doc/spec.yaml +++ b/api/doc/spec.yaml @@ -10725,6 +10725,55 @@ components: format: uint32 timestamp: $ref: '#/components/schemas/U64' + DKGResultTransaction: + type: object + required: + - version + - hash + - state_change_hash + - event_root_hash + - gas_used + - success + - vm_status + - accumulator_root_hash + - changes + - events + - timestamp + - dkg_transcript + properties: + version: + $ref: '#/components/schemas/U64' + hash: + $ref: '#/components/schemas/HashValue' + state_change_hash: + $ref: '#/components/schemas/HashValue' + event_root_hash: + $ref: '#/components/schemas/HashValue' + state_checkpoint_hash: + $ref: '#/components/schemas/HashValue' + gas_used: + $ref: '#/components/schemas/U64' + success: + type: boolean + description: Whether the transaction was successful + vm_status: + type: string + description: The VM status of the transaction, can tell useful information in a failure + accumulator_root_hash: + $ref: '#/components/schemas/HashValue' + changes: + type: array + description: Final state of resources changed by the transaction + items: + $ref: '#/components/schemas/WriteSetChange' + events: + type: array + items: + $ref: '#/components/schemas/Event' + timestamp: + $ref: '#/components/schemas/U64' + dkg_transcript: + $ref: '#/components/schemas/ExportedDKGTranscript' DecodedTableData: type: object description: Decoded table data @@ -10919,6 +10968,60 @@ components: $ref: '#/components/schemas/U64' account_address: $ref: '#/components/schemas/Address' + ExportedAggregateSignature: + type: object + description: A more API-friendly representation of the on-chain `aptos_types::aggregate_signature::AggregateSignature`. + required: + - signer_indices + properties: + signer_indices: + type: array + items: + type: integer + format: uint64 + sig: + $ref: '#/components/schemas/HexEncodedBytes' + ExportedDKGTranscript: + type: object + required: + - epoch + - author + - payload + properties: + epoch: + $ref: '#/components/schemas/U64' + author: + $ref: '#/components/schemas/Address' + payload: + $ref: '#/components/schemas/HexEncodedBytes' + ExportedProviderJWKs: + type: object + description: A more API-friendly representation of the on-chain `aptos_types::jwks::ProviderJWKs`. + required: + - issuer + - version + - jwks + properties: + issuer: + type: string + version: + type: integer + format: uint64 + jwks: + type: array + items: + $ref: '#/components/schemas/JWK' + ExportedQuorumCertifiedUpdate: + type: object + description: A more API-friendly representation of the on-chain `aptos_types::jwks::QuorumCertifiedUpdate`. + required: + - update + - multi_sig + properties: + update: + $ref: '#/components/schemas/ExportedProviderJWKs' + multi_sig: + $ref: '#/components/schemas/ExportedAggregateSignature' FeePayerSignature: type: object description: |- @@ -11110,6 +11213,61 @@ components: format: uint8 signature: $ref: '#/components/schemas/Signature' + JWK: + type: object + description: The JWK type that can be converted from/to `JWKMoveStruct` but easier to use in rust. + anyOf: + - $ref: '#/components/schemas/RSA_JWK' + - $ref: '#/components/schemas/UnsupportedJWK' + JWKUpdateTransaction: + type: object + required: + - version + - hash + - state_change_hash + - event_root_hash + - gas_used + - success + - vm_status + - accumulator_root_hash + - changes + - events + - timestamp + - quorum_certified_update + properties: + version: + $ref: '#/components/schemas/U64' + hash: + $ref: '#/components/schemas/HashValue' + state_change_hash: + $ref: '#/components/schemas/HashValue' + event_root_hash: + $ref: '#/components/schemas/HashValue' + state_checkpoint_hash: + $ref: '#/components/schemas/HashValue' + gas_used: + $ref: '#/components/schemas/U64' + success: + type: boolean + description: Whether the transaction was successful + vm_status: + type: string + description: The VM status of the transaction, can tell useful information in a failure + accumulator_root_hash: + $ref: '#/components/schemas/HashValue' + changes: + type: array + description: Final state of resources changed by the transaction + items: + $ref: '#/components/schemas/WriteSetChange' + events: + type: array + items: + $ref: '#/components/schemas/Event' + timestamp: + $ref: '#/components/schemas/U64' + quorum_certified_update: + $ref: '#/components/schemas/ExportedQuorumCertifiedUpdate' Keyless: type: object required: @@ -11603,6 +11761,28 @@ components: type: string example: secp256r1_ecdsa - $ref: '#/components/schemas/Secp256r1Ecdsa' + RSA_JWK: + type: object + description: |- + Move type `0x1::jwks::RSA_JWK` in rust. + See its doc in Move for more details. + required: + - kid + - kty + - alg + - e + - n + properties: + kid: + type: string + kty: + type: string + alg: + type: string + e: + type: string + n: + type: string RawTableItemRequest: type: object description: Table Item request for the GetTableItemRaw API @@ -12081,6 +12261,25 @@ components: We represent u64 values as a string to ensure compatibility with languages such as JavaScript that do not parse u64s in JSON natively. example: '32425224034' + UnsupportedJWK: + type: object + description: |- + Move type `0x1::jwks::UnsupportedJWK` in rust. + See its doc in Move for more details. + required: + - id + - payload + properties: + id: + type: array + items: + type: integer + format: uint8 + payload: + type: array + items: + type: integer + format: uint8 UserTransaction: type: object description: A transaction submitted by a user to change the state of the blockchain @@ -12151,50 +12350,34 @@ components: $ref: '#/components/schemas/U64' ValidatorTransaction: type: object - required: - - version - - hash - - state_change_hash - - event_root_hash - - gas_used - - success - - vm_status - - accumulator_root_hash - - changes - - events - - timestamp - properties: - version: - $ref: '#/components/schemas/U64' - hash: - $ref: '#/components/schemas/HashValue' - state_change_hash: - $ref: '#/components/schemas/HashValue' - event_root_hash: - $ref: '#/components/schemas/HashValue' - state_checkpoint_hash: - $ref: '#/components/schemas/HashValue' - gas_used: - $ref: '#/components/schemas/U64' - success: - type: boolean - description: Whether the transaction was successful - vm_status: - type: string - description: The VM status of the transaction, can tell useful information in a failure - accumulator_root_hash: - $ref: '#/components/schemas/HashValue' - changes: - type: array - description: Final state of resources changed by the transaction - items: - $ref: '#/components/schemas/WriteSetChange' - events: - type: array - items: - $ref: '#/components/schemas/Event' - timestamp: - $ref: '#/components/schemas/U64' + oneOf: + - $ref: '#/components/schemas/ValidatorTransaction_JWKUpdateTransaction' + - $ref: '#/components/schemas/ValidatorTransaction_DKGResultTransaction' + discriminator: + propertyName: validator_transaction_type + mapping: + observed_jwk_update: '#/components/schemas/ValidatorTransaction_JWKUpdateTransaction' + dkg_result: '#/components/schemas/ValidatorTransaction_DKGResultTransaction' + ValidatorTransaction_DKGResultTransaction: + allOf: + - type: object + required: + - validator_transaction_type + properties: + validator_transaction_type: + type: string + example: dkg_result + - $ref: '#/components/schemas/DKGResultTransaction' + ValidatorTransaction_JWKUpdateTransaction: + allOf: + - type: object + required: + - validator_transaction_type + properties: + validator_transaction_type: + type: string + example: observed_jwk_update + - $ref: '#/components/schemas/JWKUpdateTransaction' VersionedEvent: type: object description: An event from a transaction with a version From 25421b3195d4d779277f4f23e6fab0a357e98719 Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Sat, 22 Jun 2024 12:51:13 -0700 Subject: [PATCH 9/9] trigger ci