Skip to content

Commit

Permalink
Maciek's review
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Nov 22, 2024
1 parent 3da916e commit bed4174
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 40 deletions.
29 changes: 26 additions & 3 deletions grpc/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use prost::Message;
use tonic::service::Interceptor;
use tonic::transport::Channel;

Expand All @@ -7,8 +8,8 @@ use celestia_proto::cosmos::base::node::v1beta1::service_client::ServiceClient a
use celestia_proto::cosmos::base::tendermint::v1beta1::service_client::ServiceClient as TendermintServiceClient;
use celestia_proto::cosmos::tx::v1beta1::service_client::ServiceClient as TxServiceClient;
use celestia_tendermint::block::Block;
use celestia_types::auth::AuthParams;
use celestia_types::blob::{Blob, BlobParams};
use celestia_types::blob::{Blob, BlobParams, RawBlobTx};
use celestia_types::state::auth::AuthParams;
use celestia_types::state::Address;
use celestia_types::state::{RawTx, TxResponse};

Expand Down Expand Up @@ -74,11 +75,33 @@ where
/// Broadcast Tx
#[grpc_method(TxServiceClient::broadcast_tx)]
async fn broadcast_tx(
&mut self,
tx_bytes: Vec<u8>,
mode: BroadcastMode,
) -> Result<TxResponse, Error>;

pub async fn broadcast_blob_tx(
&mut self,
tx: RawTx,
blobs: Vec<Blob>,
mode: BroadcastMode,
) -> Result<TxResponse, Error>;
) -> Result<TxResponse, Error> {
// From https://github.com/celestiaorg/celestia-core/blob/v1.43.0-tm-v0.34.35/pkg/consts/consts.go#L19
const BLOB_TX_TYPE_ID: &str = "BLOB";

if blobs.is_empty() {
return Err(Error::TxEmptyBlobList);
}

let blobs = blobs.into_iter().map(Into::into).collect();
let blob_tx = RawBlobTx {
tx: tx.encode_to_vec(),
blobs,
type_id: BLOB_TX_TYPE_ID.to_string(),
};

self.broadcast_tx(blob_tx.encode_to_vec(), mode).await
}

/// Get Tx
#[grpc_method(TxServiceClient::get_tx)]
Expand Down
4 changes: 4 additions & 0 deletions grpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ pub enum Error {
/// Unexpected reponse type
#[error("Unexpected response type")]
UnexpectedResponseType(String),

/// Empty blob submission list
#[error("Attempted to submit blob transaction with empty blob list")]
TxEmptyBlobList,
}
2 changes: 1 addition & 1 deletion grpc/src/types/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use celestia_proto::cosmos::auth::v1beta1::{
QueryAccountRequest, QueryAccountResponse, QueryAccountsRequest, QueryAccountsResponse,
QueryParamsRequest as QueryAuthParamsRequest, QueryParamsResponse as QueryAuthParamsResponse,
};
use celestia_types::auth::{
use celestia_types::state::auth::{
AuthParams, BaseAccount, ModuleAccount, RawBaseAccount, RawModuleAccount,
};
use celestia_types::state::Address;
Expand Down
21 changes: 4 additions & 17 deletions grpc/src/types/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use celestia_proto::cosmos::tx::v1beta1::{
};
use celestia_tendermint::public_key::Secp256k1 as VerifyingKey;
use celestia_tendermint_proto::Protobuf;
use celestia_types::auth::BaseAccount;
use celestia_types::blob::{Blob, RawBlob, RawBlobTx};
use celestia_types::state::auth::BaseAccount;
use celestia_types::state::{
AuthInfo, Fee, ModeInfo, RawTx, RawTxBody, SignerInfo, Sum, Tx, TxResponse,
};
Expand Down Expand Up @@ -66,24 +65,12 @@ impl FromGrpcResponse<GetTxResponse> for RawGetTxResponse {
}
}

impl IntoGrpcParam<BroadcastTxRequest> for (RawTx, Vec<Blob>, BroadcastMode) {
impl IntoGrpcParam<BroadcastTxRequest> for (Vec<u8>, BroadcastMode) {
fn into_parameter(self) -> BroadcastTxRequest {
let (tx, blobs, mode) = self;
let (tx_bytes, mode) = self;

// From https://github.com/celestiaorg/celestia-core/blob/v1.43.0-tm-v0.34.35/pkg/consts/consts.go#L19
const BLOB_TX_TYPE_ID: &str = "BLOB";

// empty blob list causes error response, but this is already checked when creating MsgPayForBlobs
debug_assert!(!blobs.is_empty());

let blobs = blobs.into_iter().map(RawBlob::from).collect();
let blob_tx = RawBlobTx {
tx: tx.encode_to_vec(),
blobs,
type_id: BLOB_TX_TYPE_ID.to_string(),
};
BroadcastTxRequest {
tx_bytes: blob_tx.encode_to_vec(),
tx_bytes,
mode: mode.into(),
}
}
Expand Down
2 changes: 0 additions & 2 deletions proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const BASE64STRING: &str =
const QUOTED: &str = r#"#[serde(with = "celestia_tendermint_proto::serializers::from_str")]"#;
const VEC_BASE64STRING: &str =
r#"#[serde(with = "celestia_tendermint_proto::serializers::bytes::vec_base64string")]"#;
#[cfg(not(feature = "tonic"))]
const OPTION_ANY: &str = r#"#[serde(with = "crate::serializers::option_any")]"#;
const OPTION_TIMESTAMP: &str = r#"#[serde(with = "crate::serializers::option_timestamp")]"#;
const NULL_DEFAULT: &str = r#"#[serde(with = "crate::serializers::null_default")]"#;
Expand Down Expand Up @@ -53,7 +52,6 @@ static CUSTOM_TYPE_ATTRIBUTES: &[(&str, &str)] = &[
static CUSTOM_FIELD_ATTRIBUTES: &[(&str, &str)] = &[
(".celestia.core.v1.da.DataAvailabilityHeader.row_roots", VEC_BASE64STRING),
(".celestia.core.v1.da.DataAvailabilityHeader.column_roots", VEC_BASE64STRING),
#[cfg(not(feature = "tonic"))]
(".cosmos.base.abci.v1beta1.TxResponse.tx", OPTION_ANY),
(".cosmos.base.abci.v1beta1.TxResponse.logs", NULL_DEFAULT),
(".cosmos.base.abci.v1beta1.TxResponse.events", NULL_DEFAULT),
Expand Down
1 change: 0 additions & 1 deletion proto/src/serializers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Custom serializers to be used with [`serde`].

pub mod null_default;
#[cfg(not(feature = "tonic"))]
pub mod option_any;
pub mod option_timestamp;
1 change: 0 additions & 1 deletion types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("../README.md")]

pub mod auth;
mod bit_array;
pub mod blob;
mod block;
Expand Down
1 change: 1 addition & 0 deletions types/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Types and interfaces for accessing Celestia's state-relevant information.

mod address;
pub mod auth;
mod balance;
mod query_delegation;
mod tx;
Expand Down
16 changes: 1 addition & 15 deletions types/src/auth.rs → types/src/state/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,11 @@ use crate::Error;

pub use celestia_proto::cosmos::auth::v1beta1::BaseAccount as RawBaseAccount;
pub use celestia_proto::cosmos::auth::v1beta1::ModuleAccount as RawModuleAccount;
pub use celestia_proto::cosmos::auth::v1beta1::Params as AuthParams;

const COSMOS_ED25519_PUBKEY: &str = "/cosmos.crypto.ed25519.PubKey";
const COSMOS_SECP256K1_PUBKEY: &str = "/cosmos.crypto.secp256k1.PubKey";

/// Params defines the parameters for the auth module.
#[derive(Debug)]
pub struct AuthParams {
/// Maximum number of memo characters
pub max_memo_characters: u64,
/// Maximum nubmer of signatures
pub tx_sig_limit: u64,
/// Cost per transaction byte
pub tx_size_cost_per_byte: u64,
/// Cost to verify ed25519 signature
pub sig_verify_cost_ed25519: u64,
/// Cost to verify secp255k1 signature
pub sig_verify_cost_secp256k1: u64,
}

/// [`BaseAccount`] defines a base account type.
///
/// It contains all the necessary fields for basic account functionality.
Expand Down

0 comments on commit bed4174

Please sign in to comment.