Skip to content

Commit

Permalink
chore(proto,types,node,grpc)!: Use tendermint-rs instead of `celest…
Browse files Browse the repository at this point in the history
…ia-tendermint-rs` fork (#463)
  • Loading branch information
oblique authored Nov 27, 2024
1 parent 7f28d96 commit 61ef061
Show file tree
Hide file tree
Showing 75 changed files with 1,455 additions and 739 deletions.
218 changes: 63 additions & 155 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ celestia-proto = { version = "0.5.0", path = "proto" }
celestia-grpc = { version = "0.1.0", path = "grpc" }
celestia-rpc = { version = "0.7.1", path = "rpc", default-features = false }
celestia-types = { version = "0.8.0", path = "types", default-features = false }
celestia-tendermint = { version = "0.33.0", default-features = false }
celestia-tendermint-proto = "0.33.0"
tendermint = { version = "0.40.0", default-features = false }
tendermint-proto = "0.40.0"

libp2p = "0.54.0"
nmt-rs = "0.2.1"
Expand All @@ -23,8 +23,6 @@ prost-types = "0.13.3"
# Uncomment to apply local changes
#beetswap = { path = "../beetswap" }
#blockstore = { path = "../blockstore" }
#celestia-tendermint = { path = "../celestia-tendermint-rs/tendermint" }
#celestia-tendermint-proto = { path = "../celestia-tendermint-rs/proto" }
#nmt-rs = { path = "../nmt-rs" }
#libp2p = { path = "../../rust-libp2p/libp2p" }
#libp2p-core = { path = "../../rust-libp2p/core" }
Expand Down
11 changes: 5 additions & 6 deletions grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ categories = [
]

[dependencies]
celestia-tendermint-proto.workspace = true
celestia-types = { workspace = true, features = [ "tonic" ] }
celestia-proto = { workspace = true, features = [ "tonic" ] }
celestia-tendermint.workspace = true
prost.workspace = true
celestia-grpc-macros = { version = "0.1.0", path = "grpc-macros" }
celestia-proto = { workspace = true, features = ["tonic"] }
celestia-types.workspace = true
prost.workspace = true
tendermint-proto.workspace = true
tendermint.workspace = true

hex = "0.4.3"
k256 = "0.13.4"
pbjson-types = "0.7.0"
serde = "1.0.215"
thiserror = "1.0.61"
tonic = { version = "0.12.3", default-features = false, features = [
Expand Down
9 changes: 4 additions & 5 deletions grpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ use prost::Message;
use tonic::service::Interceptor;
use tonic::transport::Channel;

use celestia_grpc_macros::grpc_method;
use celestia_proto::celestia::blob::v1::query_client::QueryClient as BlobQueryClient;
use celestia_proto::cosmos::auth::v1beta1::query_client::QueryClient as AuthQueryClient;
use celestia_proto::cosmos::base::node::v1beta1::service_client::ServiceClient as ConfigServiceClient;
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_proto::cosmos::tx::v1beta1::Tx as RawTx;
use celestia_types::blob::{Blob, BlobParams, RawBlobTx};
use celestia_types::block::Block;
use celestia_types::state::auth::AuthParams;
use celestia_types::state::Address;
use celestia_types::state::{RawTx, TxResponse};

use celestia_grpc_macros::grpc_method;
use celestia_types::state::{Address, TxResponse};

use crate::types::auth::Account;
use crate::types::tx::GetTxResponse;
Expand Down
4 changes: 2 additions & 2 deletions grpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ pub enum Error {

/// Tendermint Error
#[error(transparent)]
TendermintError(#[from] celestia_tendermint::Error),
TendermintError(#[from] tendermint::Error),

/// Celestia types error
#[error(transparent)]
CelestiaTypesError(#[from] celestia_types::Error),

/// Tendermint Proto Error
#[error(transparent)]
TendermintProtoError(#[from] celestia_tendermint_proto::Error),
TendermintProtoError(#[from] tendermint_proto::Error),

/// Failed to parse gRPC response
#[error("Failed to parse response")]
Expand Down
2 changes: 1 addition & 1 deletion grpc/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use celestia_proto::cosmos::base::tendermint::v1beta1::{
GetBlockByHeightRequest, GetBlockByHeightResponse, GetLatestBlockRequest,
GetLatestBlockResponse,
};
use celestia_tendermint::block::Block;
use celestia_types::blob::BlobParams;
use celestia_types::block::Block;

use crate::Error;

Expand Down
2 changes: 1 addition & 1 deletion grpc/src/types/auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use pbjson_types::Any;
use prost::{Message, Name};

use celestia_proto::cosmos::auth::v1beta1::{
Expand All @@ -9,6 +8,7 @@ use celestia_types::state::auth::{
AuthParams, BaseAccount, ModuleAccount, RawBaseAccount, RawModuleAccount,
};
use celestia_types::state::Address;
use tendermint_proto::google::protobuf::Any;

use crate::types::make_empty_params;
use crate::types::{FromGrpcResponse, IntoGrpcParam};
Expand Down
13 changes: 5 additions & 8 deletions grpc/src/types/tx.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use std::convert::Infallible;

use k256::ecdsa::{signature::Signer, Signature};
use pbjson_types::Any;
use prost::{Message, Name};

use celestia_proto::cosmos::crypto::secp256k1;
use celestia_proto::cosmos::tx::v1beta1::{
BroadcastTxRequest, BroadcastTxResponse, GetTxRequest as RawGetTxRequest,
GetTxResponse as RawGetTxResponse, SignDoc,
};
use celestia_tendermint::public_key::Secp256k1 as VerifyingKey;
use celestia_tendermint_proto::Protobuf;
use celestia_types::state::auth::BaseAccount;
use celestia_types::state::{
AuthInfo, Fee, ModeInfo, RawTx, RawTxBody, SignerInfo, Sum, Tx, TxResponse,
};
use tendermint::public_key::Secp256k1 as VerifyingKey;
use tendermint_proto::google::protobuf::Any;
use tendermint_proto::Protobuf;

use crate::types::{FromGrpcResponse, IntoGrpcParam};
use crate::Error;
Expand Down Expand Up @@ -102,7 +100,7 @@ pub fn sign_tx(
};
let public_key_as_any = Any {
type_url: secp256k1::PubKey::type_url(),
value: public_key.encode_to_vec().into(),
value: public_key.encode_to_vec(),
};

let auth_info = AuthInfo {
Expand All @@ -113,11 +111,10 @@ pub fn sign_tx(
}],
fee: Fee::new(fee, gas_limit),
};
let auth_info_bytes: Result<_, Infallible> = auth_info.encode_vec();

let bytes_to_sign = SignDoc {
body_bytes: tx_body.encode_to_vec(),
auth_info_bytes: auth_info_bytes.expect("Result to be Infallible"),
auth_info_bytes: auth_info.clone().encode_vec(),
chain_id,
account_number: base_account.account_number,
}
Expand Down
4 changes: 2 additions & 2 deletions grpc/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use tonic::transport::Channel;
use tonic::{Request, Status};

use celestia_grpc::GrpcClient;
use celestia_tendermint::crypto::default::ecdsa_secp256k1::SigningKey;
use celestia_tendermint::public_key::Secp256k1 as VerifyingKey;
use celestia_types::state::Address;
use tendermint::crypto::default::ecdsa_secp256k1::SigningKey;
use tendermint::public_key::Secp256k1 as VerifyingKey;

const CELESTIA_GRPC_URL: &str = "http://localhost:19090";

Expand Down
2 changes: 1 addition & 1 deletion node-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ crate-type = ["cdylib", "rlib"]

[target.'cfg(target_arch = "wasm32")'.dependencies]
blockstore.workspace = true
celestia-tendermint.workspace = true
celestia-types.workspace = true
libp2p = { workspace = true, features = ["serde"] }
lumina-node.workspace = true
tendermint.workspace = true

anyhow = "1.0.86"
console_error_panic_hook = "0.1.7"
Expand Down
2 changes: 1 addition & 1 deletion node-wasm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ from_js_value! {

from_display! {
blockstore::Error,
celestia_tendermint::error::Error,
tendermint::error::Error,
libp2p::identity::ParseError,
libp2p::multiaddr::Error,
lumina_node::node::NodeError,
Expand Down
4 changes: 2 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ categories = [

[dependencies]
celestia-proto.workspace = true
celestia-tendermint.workspace = true
celestia-tendermint-proto.workspace = true
celestia-types.workspace = true
libp2p = { workspace = true, features = [
"autonat",
Expand All @@ -33,6 +31,8 @@ libp2p = { workspace = true, features = [
"kad",
] }
prost.workspace = true
tendermint-proto.workspace = true
tendermint.workspace = true

async-trait = "0.1.80"
beetswap = "0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion node/src/daser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ use std::cmp::min;
use std::collections::HashSet;
use std::sync::Arc;

use celestia_tendermint::Time;
use futures::future::BoxFuture;
use futures::stream::FuturesUnordered;
use futures::{FutureExt, StreamExt};
use rand::Rng;
use tendermint::Time;
use tokio::select;
use tokio_util::sync::CancellationToken;
use tracing::{debug, error, warn};
Expand Down
9 changes: 5 additions & 4 deletions node/src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use std::time::Duration;

use blockstore::Blockstore;
use celestia_proto::p2p::pb::{header_request, HeaderRequest};
use celestia_tendermint_proto::Protobuf;
use celestia_types::fraud_proof::BadEncodingFraudProof;
use celestia_types::hash::Hash;
use celestia_types::nmt::{Namespace, NamespacedSha2Hasher};
use celestia_types::row::{Row, RowId};
use celestia_types::row_namespace_data::{RowNamespaceData, RowNamespaceDataId};
use celestia_types::sample::{Sample, SampleId};
use celestia_types::{fraud_proof::BadEncodingFraudProof, hash::Hash};
use celestia_types::{Blob, ExtendedHeader, FraudProof};
use cid::Cid;
use futures::stream::FuturesOrdered;
Expand All @@ -48,6 +48,7 @@ use libp2p::{
Multiaddr, PeerId,
};
use smallvec::SmallVec;
use tendermint_proto::Protobuf;
use tokio::select;
use tokio::sync::{mpsc, oneshot, watch};
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -131,7 +132,7 @@ pub enum P2pError {

/// ProtoBuf message failed to be decoded.
#[error("ProtoBuf decoding error: {0}")]
ProtoDecodeFailed(#[from] celestia_tendermint_proto::Error),
ProtoDecodeFailed(#[from] tendermint_proto::Error),

/// An error propagated from [`celestia_types`] that is related to [`Cid`].
#[error("CID error: {0}")]
Expand Down Expand Up @@ -182,7 +183,7 @@ impl From<oneshot::error::RecvError> for P2pError {

impl From<prost::DecodeError> for P2pError {
fn from(value: prost::DecodeError) -> Self {
P2pError::ProtoDecodeFailed(celestia_tendermint_proto::Error::decode_message(value))
P2pError::ProtoDecodeFailed(tendermint_proto::Error::decode_message(value))
}
}

Expand Down
2 changes: 1 addition & 1 deletion node/src/p2p/header_ex/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ mod tests {
use crate::test_utils::{async_test, gen_filled_store};
use celestia_proto::p2p::pb::header_request::Data;
use celestia_proto::p2p::pb::StatusCode;
use celestia_tendermint_proto::Protobuf;
use celestia_types::ExtendedHeader;
use std::future::poll_fn;
use tendermint_proto::Protobuf;
use tokio::select;
use tokio::sync::oneshot;

Expand Down
4 changes: 2 additions & 2 deletions node/src/p2p/header_ex/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use celestia_proto::p2p::pb::header_request::Data;
use celestia_proto::p2p::pb::{HeaderRequest, HeaderResponse, StatusCode};
use celestia_tendermint_proto::Protobuf;
use celestia_types::consts::HASH_SIZE;
use celestia_types::hash::Hash;
use celestia_types::ExtendedHeader;
use tendermint_proto::Protobuf;

use crate::p2p::header_ex::HeaderExError;

Expand Down Expand Up @@ -88,7 +88,7 @@ pub(super) trait ExtendedHeaderExt {
impl ExtendedHeaderExt for ExtendedHeader {
fn to_header_response(&self) -> HeaderResponse {
HeaderResponse {
body: self.encode_vec().unwrap(),
body: self.clone().encode_vec(),
status_code: StatusCode::Ok.into(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion node/src/pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::sync::Arc;
use std::time::Duration;

use blockstore::Blockstore;
use celestia_tendermint::Time;
use celestia_types::ExtendedHeader;
use tendermint::Time;
use tokio::select;
use tokio_util::sync::CancellationToken;
use tracing::{debug, error, warn};
Expand Down
2 changes: 1 addition & 1 deletion node/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::io::Cursor;
use std::ops::{Bound, RangeBounds, RangeInclusive};

use async_trait::async_trait;
use celestia_tendermint_proto::Protobuf;
use celestia_types::hash::Hash;
use celestia_types::ExtendedHeader;
use cid::Cid;
use prost::Message;
use serde::{Deserialize, Serialize};
use tendermint_proto::Protobuf;
use thiserror::Error;

pub use crate::block_ranges::{BlockRange, BlockRanges, BlockRangesError};
Expand Down
23 changes: 12 additions & 11 deletions node/src/store/indexed_db_store.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::cell::RefCell;
use std::convert::Infallible;
use std::fmt::Display;
use std::pin::pin;

use async_trait::async_trait;
use celestia_tendermint_proto::Protobuf;
use celestia_types::hash::Hash;
use celestia_types::ExtendedHeader;
use cid::Cid;
Expand All @@ -14,6 +12,7 @@ use send_wrapper::SendWrapper;
use serde::{Deserialize, Serialize};
use serde_wasm_bindgen::{from_value, to_value};
use smallvec::smallvec;
use tendermint_proto::Protobuf;
use tokio::sync::Notify;
use tracing::warn;
use wasm_bindgen::JsValue;
Expand Down Expand Up @@ -45,6 +44,7 @@ const VERSION_KEY: &str = "version";
struct ExtendedHeaderEntry {
// We use those fields as indexes, names need to match ones in `add_index`
height: u64,
#[serde(with = "celestia_types::serializers::hash")]
hash: Hash,
header: Vec<u8>,
}
Expand Down Expand Up @@ -593,7 +593,11 @@ async fn insert_tx_op(
headers: VerifiedExtendedHeaders,
) -> Result<ExtendedHeader> {
let head = headers.as_ref().first().expect("headers to not be empty");
let tail = headers.as_ref().last().expect("headers to not be empty");
let tail = headers
.as_ref()
.last()
.cloned()
.expect("headers to not be empty");

let header_store = tx.store(HEADER_STORE_NAME)?;
let ranges_store = tx.store(RANGES_STORE_NAME)?;
Expand All @@ -609,11 +613,11 @@ async fn insert_tx_op(
verify_against_neighbours(
&header_store,
prev_exists.then_some(head),
next_exists.then_some(tail),
next_exists.then_some(&tail),
)
.await?;

for header in headers.as_ref() {
for header in headers {
let hash = header.hash();
let hash_index = header_store.index(HASH_INDEX_NAME)?;
let jsvalue_hash_key = KeyRange::only(&to_value(&hash)?).map_err(rexie::Error::IdbError)?;
Expand All @@ -624,14 +628,11 @@ async fn insert_tx_op(
return Err(StoreInsertionError::HashExists(hash).into());
}

// make sure Result is Infallible, we unwrap it later
let serialized_header: std::result::Result<_, Infallible> = header.encode_vec();

let height = header.height().value();
let header_entry = ExtendedHeaderEntry {
height,
hash,
header: serialized_header.unwrap(),
header: header.encode_vec(),
};

let jsvalue_header = to_value(&header_entry)?;
Expand All @@ -644,7 +645,7 @@ async fn insert_tx_op(
.expect("invalid range");
set_ranges(&ranges_store, HEADER_RANGES_KEY, &header_ranges).await?;

Ok(tail.clone())
Ok(tail)
}

async fn update_sampling_metadata_tx_op(
Expand Down Expand Up @@ -959,7 +960,7 @@ pub mod tests {
let header_entry = ExtendedHeaderEntry {
height: header.height().value(),
hash: header.hash(),
header: header.encode_vec().unwrap(),
header: header.encode_vec(),
};

header_store
Expand Down
Loading

0 comments on commit 61ef061

Please sign in to comment.