Skip to content

Commit

Permalink
[Protobuf] Support validator transaction type in protobuf (#13897) (#…
Browse files Browse the repository at this point in the history
…14019)

* format and add new transaction type.

* format  + cleanup + new transaciton type.

* update.

* fix the validator transaction.

* upgrade protobuf.

* grpc support validator transaction.

Co-authored-by: larry-aptos <[email protected]>
  • Loading branch information
ying-w and larry-aptos authored Jul 16, 2024
1 parent 6d3beea commit 1ce3930
Show file tree
Hide file tree
Showing 24 changed files with 5,465 additions and 2,503 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions api/types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,13 @@ impl ValidatorTransaction {
ValidatorTransaction::DkgResult(t) => t.timestamp,
}
}

pub fn events(&self) -> &[Event] {
match self {
ValidatorTransaction::ObservedJwkUpdate(t) => &t.events,
ValidatorTransaction::DkgResult(t) => &t.events,
}
}
}

impl
Expand Down Expand Up @@ -690,9 +697,9 @@ impl From<QuorumCertifiedUpdate> for ExportedQuorumCertifiedUpdate {
/// 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<usize>,
pub signer_indices: Vec<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
sig: Option<HexEncodedBytes>,
pub sig: Option<HexEncodedBytes>,
}

impl From<AggregateSignature> for ExportedAggregateSignature {
Expand Down Expand Up @@ -744,9 +751,9 @@ pub struct DKGResultTransaction {

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Object)]
pub struct ExportedDKGTranscript {
epoch: U64,
author: Address,
payload: HexEncodedBytes,
pub epoch: U64,
pub author: Address,
pub payload: HexEncodedBytes,
}

impl From<DKGTranscript> for ExportedDKGTranscript {
Expand Down
109 changes: 97 additions & 12 deletions ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
// SPDX-License-Identifier: Apache-2.0

use aptos_api_types::{
AccountSignature, DeleteModule, DeleteResource, Ed25519Signature, EntryFunctionId,
EntryFunctionPayload, Event, GenesisPayload, MoveAbility, MoveFunction,
MoveFunctionGenericTypeParam, MoveFunctionVisibility, MoveModule, MoveModuleBytecode,
MoveModuleId, MoveScriptBytecode, MoveStruct, MoveStructField, MoveStructTag, MoveType,
MultiEd25519Signature, MultiKeySignature, MultisigPayload, MultisigTransactionPayload,
PublicKey, ScriptPayload, Signature, SingleKeySignature, Transaction, TransactionInfo,
TransactionPayload, TransactionSignature, WriteSet, WriteSetChange,
transaction::ValidatorTransaction as ApiValidatorTransactionEnum, AccountSignature,
DeleteModule, DeleteResource, Ed25519Signature, EntryFunctionId, EntryFunctionPayload, Event,
GenesisPayload, MoveAbility, MoveFunction, MoveFunctionGenericTypeParam,
MoveFunctionVisibility, MoveModule, MoveModuleBytecode, MoveModuleId, MoveScriptBytecode,
MoveStruct, MoveStructField, MoveStructTag, MoveType, MultiEd25519Signature, MultiKeySignature,
MultisigPayload, MultisigTransactionPayload, PublicKey, ScriptPayload, Signature,
SingleKeySignature, Transaction, TransactionInfo, TransactionPayload, TransactionSignature,
WriteSet, WriteSetChange,
};
use aptos_bitvec::BitVec;
use aptos_logger::warn;
use aptos_protos::{
transaction::{
v1 as transaction,
v1::{any_signature, Ed25519, Keyless, Secp256k1Ecdsa, TransactionSizeInfo, WebAuthn},
transaction::v1::{
self as transaction, any_signature, validator_transaction,
validator_transaction::observed_jwk_update::exported_provider_jw_ks::{
jwk::{JwkType, Rsa, UnsupportedJwk},
Jwk as ProtoJwk,
},
Ed25519, Keyless, Secp256k1Ecdsa, TransactionSizeInfo, WebAuthn,
},
util::timestamp,
};
use aptos_types::jwks::jwk::JWK;
use hex;
use move_binary_format::file_format::Ability;
use std::time::Duration;
Expand Down Expand Up @@ -826,8 +832,8 @@ pub fn convert_transaction(
)
},
Transaction::PendingTransaction(_) => panic!("PendingTransaction not supported"),
Transaction::ValidatorTransaction(_) => {
transaction::transaction::TxnData::Validator(transaction::ValidatorTransaction {})
Transaction::ValidatorTransaction(api_validator_txn) => {
convert_validator_transaction(api_validator_txn)
},
};

Expand Down Expand Up @@ -856,3 +862,82 @@ pub fn convert_transaction(
size_info: Some(size_info),
}
}

fn convert_validator_transaction(
api_validator_txn: &aptos_api_types::transaction::ValidatorTransaction,
) -> transaction::transaction::TxnData {
transaction::transaction::TxnData::Validator(transaction::ValidatorTransaction {
validator_transaction_type: match api_validator_txn {
ApiValidatorTransactionEnum::DkgResult(dgk_result) => {
Some(
validator_transaction::ValidatorTransactionType::DkgUpdate(
validator_transaction::DkgUpdate {
dkg_transcript: Some(validator_transaction::dkg_update::DkgTranscript {
author: dgk_result.dkg_transcript.author.to_string(),
epoch: dgk_result.dkg_transcript.epoch.0,
payload: dgk_result.dkg_transcript.payload.0.clone(),
}),
},
)
)
},
ApiValidatorTransactionEnum::ObservedJwkUpdate(observed_jwk_update) => {
Some(
validator_transaction::ValidatorTransactionType::ObservedJwkUpdate(
validator_transaction::ObservedJwkUpdate {
quorum_certified_update: Some(
validator_transaction::observed_jwk_update::QuorumCertifiedUpdate {
update: Some(
validator_transaction::observed_jwk_update::ExportedProviderJwKs {
issuer: observed_jwk_update.quorum_certified_update.update.issuer.clone(),
version: observed_jwk_update.quorum_certified_update.update.version,
jwks: observed_jwk_update.quorum_certified_update.update.jwks.iter().map(|jwk| {
match jwk {
JWK::RSA(rsa) => {
ProtoJwk {
jwk_type: Some(
JwkType::Rsa(
Rsa {
kid: rsa.kid.clone(),
n: rsa.n.clone(),
e: rsa.e.clone(),
kty: rsa.kty.clone(),
alg: rsa.alg.clone(),
}
)
)
}
},
JWK::Unsupported(unsupported) => {
ProtoJwk {
jwk_type: Some(
JwkType::UnsupportedJwk(
UnsupportedJwk {
id: unsupported.id.clone(),
payload: unsupported.payload.clone()
}
)
)
}
}
}
}).collect(),
}
),
multi_sig: Some(aptos_protos::transaction::v1::validator_transaction::observed_jwk_update::ExportedAggregateSignature {
signer_indices: observed_jwk_update.quorum_certified_update.multi_sig.signer_indices.clone().into_iter().map(|i| i as u64).collect(),
sig: match &observed_jwk_update.quorum_certified_update.multi_sig.sig {
Some(sig) => sig.0.clone(),
None => vec![],
},
}),
}
)
},
)
)
},
},
events: convert_events(api_validator_txn.events()),
})
}
33 changes: 0 additions & 33 deletions protos/proto/aptos/bigquery_schema/v1/transaction.proto

This file was deleted.

18 changes: 9 additions & 9 deletions protos/proto/aptos/indexer/v1/raw_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "aptos/transaction/v1/transaction.proto";
// This is for storage only.
message TransactionsInStorage {
// Required; transactions data.
repeated aptos.transaction.v1.Transaction transactions = 1;
repeated aptos.transaction.v1.Transaction transactions = 1;
// Required; chain id.
optional uint64 starting_version = 2;
}
Expand All @@ -30,14 +30,14 @@ message GetTransactionsRequest {

// TransactionsResponse is a batch of transactions.
message TransactionsResponse {
// Required; transactions data.
repeated aptos.transaction.v1.Transaction transactions = 1;
// Required; chain id.
optional uint64 chain_id = 2 [jstype = JS_STRING];
// Required; transactions data.
repeated aptos.transaction.v1.Transaction transactions = 1;

// Required; chain id.
optional uint64 chain_id = 2 [jstype = JS_STRING];
}

service RawData {
// Get transactions batch without any filtering from starting version and end if transaction count is present.
rpc GetTransactions(GetTransactionsRequest) returns (stream TransactionsResponse);
}
// Get transactions batch without any filtering from starting version and end if transaction count is present.
rpc GetTransactions(GetTransactionsRequest) returns (stream TransactionsResponse);
}
6 changes: 3 additions & 3 deletions protos/proto/aptos/internal/fullnode/v1/fullnode_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import "aptos/transaction/v1/transaction.proto";
// StreamStatus: BATCH_END with version x + (k + 1) * n - 1

message TransactionsOutput {
repeated aptos.transaction.v1.Transaction transactions = 1;
repeated aptos.transaction.v1.Transaction transactions = 1;
}

message StreamStatus {
Expand Down Expand Up @@ -53,5 +53,5 @@ message TransactionsFromNodeResponse {
}

service FullnodeData {
rpc GetTransactionsFromNode(GetTransactionsFromNodeRequest) returns (stream TransactionsFromNodeResponse);
}
rpc GetTransactionsFromNode(GetTransactionsFromNodeRequest) returns (stream TransactionsFromNodeResponse);
}
12 changes: 5 additions & 7 deletions protos/proto/aptos/remote_executor/v1/network_msg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ syntax = "proto3";
package aptos.remote_executor.v1;

message NetworkMessage {
bytes message = 1;
string message_type = 2;
bytes message = 1;
string message_type = 2;
}

message Empty {

}
message Empty {}

service NetworkMessageService {
rpc SimpleMsgExchange(NetworkMessage) returns (Empty);
}
rpc SimpleMsgExchange(NetworkMessage) returns (Empty);
}
Loading

0 comments on commit 1ce3930

Please sign in to comment.