Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(grpc, types, proto)!: Add tonic gRPC #454

Merged
merged 61 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
5aa288d
feat: Tonic gRPC
fl0rek Oct 24, 2024
79823d2
wip
fl0rek Oct 25, 2024
01e4ad9
Merge remote-tracking branch 'upstream/main' into feat/grpc
fl0rek Oct 29, 2024
f1954d4
wip3
fl0rek Oct 29, 2024
3fc2f83
types cleanup
fl0rek Oct 29, 2024
3198132
missing rpc methods
fl0rek Oct 30, 2024
07c67b4
smh fmt
fl0rek Oct 30, 2024
4a98ffd
patch
fl0rek Oct 30, 2024
d967c5c
fix wasm deps
fl0rek Oct 30, 2024
ca03d4d
fix wasm
fl0rek Oct 30, 2024
2ae6bf1
fix docs
fl0rek Oct 30, 2024
ee3ebcd
new wasm-pack?
fl0rek Oct 31, 2024
6b60e86
fiddling
fl0rek Nov 4, 2024
a299aef
tonic crate
fl0rek Nov 5, 2024
ae8f607
proc macro
fl0rek Nov 6, 2024
5712fbf
cleanup, updates
fl0rek Nov 7, 2024
df97053
fix wasm
fl0rek Nov 8, 2024
648176f
Merge remote-tracking branch 'upstream/main' into feat/grpc
fl0rek Nov 8, 2024
9de6b11
fix wasm
fl0rek Nov 8, 2024
d6ac94a
missed serialisation
fl0rek Nov 8, 2024
9721805
doctests
fl0rek Nov 8, 2024
007eccc
lasts tests
fl0rek Nov 8, 2024
150b007
fix any pubkey
fl0rek Nov 8, 2024
2011a37
refix wasm
fl0rek Nov 8, 2024
6f9f898
deps
fl0rek Nov 12, 2024
8a7086a
fmt
fl0rek Nov 12, 2024
714049d
Merge remote-tracking branch 'upstream/main' into feat/grpc
fl0rek Nov 13, 2024
fc9d6ee
Apply suggestions from code review
fl0rek Nov 14, 2024
1bc3379
pr review
fl0rek Nov 14, 2024
178a091
Merge branch 'feat/grpc' of github.com:fl0rek/celestia-node-rs into f…
fl0rek Nov 14, 2024
e00bd0b
fix
fl0rek Nov 14, 2024
da920c2
types cleanup
fl0rek Nov 15, 2024
e5adde7
revert toml
fl0rek Nov 15, 2024
4df09f7
blob submission
fl0rek Nov 19, 2024
4a735a9
consolidate types
fl0rek Nov 20, 2024
ad5e974
Any->Any
fl0rek Nov 20, 2024
b0f8ace
remove cosmrs, streamline
fl0rek Nov 20, 2024
1ba8a0a
Add missing file
fl0rek Nov 20, 2024
8db565f
CI
fl0rek Nov 20, 2024
2c5589a
CI2
fl0rek Nov 20, 2024
a71eed3
unpublic
fl0rek Nov 20, 2024
299ce05
fix CI keygen
fl0rek Nov 20, 2024
d961f49
fix wasm
fl0rek Nov 21, 2024
6eb1d08
undo wasm-pack
fl0rek Nov 21, 2024
2bdd1c3
key reorg
fl0rek Nov 21, 2024
e33d0ab
Make TxBody conversion dependent on tonic to fix wasm
fl0rek Nov 21, 2024
963450f
Move tx types to types::state::tx
fl0rek Nov 21, 2024
9bb8299
streamline
fl0rek Nov 21, 2024
388dd50
reexport broadcast mode
fl0rek Nov 21, 2024
963a391
fix Ci, more bittests
fl0rek Nov 21, 2024
3c1d7c1
Update grpc/Cargo.toml
fl0rek Nov 21, 2024
9a835ed
cleanup
fl0rek Nov 21, 2024
5224cfd
Yiannis review
fl0rek Nov 22, 2024
8d6e7c9
test
fl0rek Nov 22, 2024
3da916e
test update
fl0rek Nov 22, 2024
9437196
Maciek's review
fl0rek Nov 22, 2024
0bab694
move bitvector
fl0rek Nov 22, 2024
d4722bf
Apply suggestions from code review
fl0rek Nov 25, 2024
4a72049
remove files commited by mistake
fl0rek Nov 25, 2024
0c1a44e
Update Cargo.toml
fl0rek Nov 25, 2024
6bd6feb
update
fl0rek Nov 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ lumina-node-wasm = { version = "0.5.1", path = "node-wasm" }
celestia-proto = { version = "0.4.1", path = "proto" }
celestia-rpc = { version = "0.6.0", path = "rpc", default-features = false }
celestia-types = { version = "0.6.1", path = "types", default-features = false }
libp2p = "0.54.0"
nmt-rs = "0.2.1"
celestia-tendermint = { version = "0.32.2", default-features = false }
celestia-tendermint-proto = "0.32.2"

libp2p = "0.54.0"
nmt-rs = "0.2.1"
prost = "0.13.3"
prost-build = "0.13.3"
prost-types = "0.13.3"

[patch.crates-io]
# Uncomment to apply local changes
#beetswap = { path = "../beetswap" }
Expand Down
6 changes: 3 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ path = "src/main.rs"

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

anyhow = "1.0.86"
axum = "0.7.5"
Expand Down
8 changes: 4 additions & 4 deletions node-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ categories = [
crate-type = ["cdylib", "rlib"]

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

anyhow = "1.0.86"
console_error_panic_hook = "0.1.7"
Expand Down
10 changes: 5 additions & 5 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ categories = [
]

[dependencies]
celestia-proto = { workspace = true }
celestia-tendermint = { workspace = true }
celestia-tendermint-proto = { workspace = true }
celestia-types = { workspace = true }
celestia-proto.workspace = true
celestia-tendermint.workspace = true
celestia-tendermint-proto.workspace = true
celestia-types.workspace = true
libp2p = { workspace = true, features = [
"autonat",
"ping",
Expand All @@ -32,13 +32,13 @@ libp2p = { workspace = true, features = [
"request-response",
"kad",
] }
prost.workspace = true

async-trait = "0.1.80"
beetswap = "0.4.0"
cid = { version = "0.11.1", features = ["serde-codec"] }
dashmap = "5.5.3"
futures = "0.3.30"
prost = "0.12.6"
rand = "0.8.5"
serde = { version = "1.0.203", features = ["derive"] }
smallvec = { version = "1.13.2", features = [
Expand Down
21 changes: 16 additions & 5 deletions proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,28 @@ keywords = ["blockchain", "celestia", "lumina"]
categories = ["encoding", "cryptography::cryptocurrencies"]

[dependencies]
celestia-tendermint-proto = { workspace = true }
prost = "0.12.6"
prost-types = "0.12.6"
celestia-tendermint-proto.workspace = true
prost.workspace = true
prost-types.workspace = true
serde = { version = "1.0.203", features = ["derive"] }
tonic = "0.12.3"
pbjson = "0.7.0"
pbjson-types = "0.7.0"

[build-dependencies]
prost-build = "0.12.6"
protox = "0.6.1"
prost-build.workspace = true
prost-types.workspace = true
protox = "0.7.1"
tempfile = "3.13.0"
tonic-build = "0.12.3"
pbjson-build = "0.7.0"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.42"

[dev-dependencies]
serde_json = "1.0.117"

[features]
default = ["tonic"]
tonic = []
127 changes: 99 additions & 28 deletions proto/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! A build script generating rust types from protobuf definitions.

use prost_types::FileDescriptorSet;

const SERIALIZED: &str = r#"#[derive(::serde::Deserialize, ::serde::Serialize)]"#;
const SERIALIZED_DEFAULT: &str =
r#"#[derive(::serde::Deserialize, ::serde::Serialize)] #[serde(default)]"#;
Expand Down Expand Up @@ -44,7 +46,7 @@ static CUSTOM_TYPE_ATTRIBUTES: &[(&str, &str)] = &[
(".shwap.Sample", SERIALIZED_DEFAULT),
(".shwap.Share", SERIALIZED_DEFAULT),
(".shwap.Share", TRANSPARENT),
];
];
fl0rek marked this conversation as resolved.
Show resolved Hide resolved

#[rustfmt::skip]
static CUSTOM_FIELD_ATTRIBUTES: &[(&str, &str)] = &[
Expand All @@ -63,26 +65,52 @@ static CUSTOM_FIELD_ATTRIBUTES: &[(&str, &str)] = &[
(".shwap.Share", BASE64STRING),
];

#[rustfmt::skip]
static EXTERN_PATHS: &[(&str, &str)] = &[
(".tendermint", "::celestia_tendermint_proto::v0_34"),
(".google.protobuf.Timestamp", "::celestia_tendermint_proto::google::protobuf::Timestamp"),
(".google.protobuf.Duration", "::celestia_tendermint_proto::google::protobuf::Duration"),
];

const PROTO_FILES: &[&str] = &[
"vendor/celestia/blob/v1/params.proto",
"vendor/celestia/blob/v1/query.proto",
"vendor/celestia/blob/v1/tx.proto",
"vendor/celestia/da/data_availability_header.proto",
"vendor/cosmos/auth/v1beta1/auth.proto",
"vendor/cosmos/auth/v1beta1/query.proto",
"vendor/cosmos/base/abci/v1beta1/abci.proto",
"vendor/cosmos/base/node/v1beta1/query.proto",
"vendor/cosmos/base/tendermint/v1beta1/query.proto",
"vendor/cosmos/base/v1beta1/coin.proto",
"vendor/cosmos/crypto/multisig/v1beta1/multisig.proto",
"vendor/cosmos/crypto/secp256k1/keys.proto",
"vendor/cosmos/staking/v1beta1/query.proto",
"vendor/cosmos/tx/v1beta1/service.proto",
"vendor/cosmos/tx/v1beta1/tx.proto",
"vendor/go-header/p2p/pb/header_request.proto",
"vendor/header/pb/extended_header.proto",
"vendor/share/eds/byzantine/pb/share.proto",
"vendor/share/shwap/p2p/bitswap/pb/bitswap.proto",
"vendor/share/shwap/pb/shwap.proto",
"vendor/tendermint/types/types.proto",
];

#[cfg(feature = "tonic")]
const INCLUDES: &[&str] = &["vendor", "vendor/nmt"];

fn main() {
let fds = protox::compile(
[
"vendor/celestia/da/data_availability_header.proto",
"vendor/celestia/blob/v1/tx.proto",
"vendor/header/pb/extended_header.proto",
"vendor/share/eds/byzantine/pb/share.proto",
"vendor/share/shwap/pb/shwap.proto",
"vendor/share/shwap/p2p/bitswap/pb/bitswap.proto",
"vendor/cosmos/base/v1beta1/coin.proto",
"vendor/cosmos/base/abci/v1beta1/abci.proto",
"vendor/cosmos/crypto/multisig/v1beta1/multisig.proto",
"vendor/cosmos/staking/v1beta1/query.proto",
"vendor/cosmos/tx/v1beta1/tx.proto",
"vendor/go-header/p2p/pb/header_request.proto",
],
["vendor", "vendor/nmt"],
)
.expect("protox failed to build");
let fds = protox_compile();
prost_build(fds);
#[cfg(feature = "tonic")]
tonic_build(protox_compile())
fl0rek marked this conversation as resolved.
Show resolved Hide resolved
}

fn protox_compile() -> FileDescriptorSet {
protox::compile(PROTO_FILES, INCLUDES).expect("protox failed to build")
}

fn prost_build(fds: FileDescriptorSet) {
let mut config = prost_build::Config::new();

for (type_path, attr) in CUSTOM_TYPE_ATTRIBUTES {
Expand All @@ -93,19 +121,62 @@ fn main() {
config.field_attribute(field_path, attr);
}

for (proto_path, rust_path) in EXTERN_PATHS {
config.extern_path(proto_path.to_string(), rust_path.to_string());
}

config
.include_file("mod.rs")
.extern_path(".tendermint", "::celestia_tendermint_proto::v0_34")
.extern_path(
".google.protobuf.Timestamp",
"::celestia_tendermint_proto::google::protobuf::Timestamp",
)
.extern_path(
".google.protobuf.Duration",
"::celestia_tendermint_proto::google::protobuf::Duration",
)
// Comments in Google's protobuf are causing issues with cargo-test
.disable_comments([".google"])
.compile_fds(fds)
.expect("prost failed");
}

#[cfg(feature = "tonic")]
fn tonic_build(fds: FileDescriptorSet) {
let buf_img = tempfile::NamedTempFile::new()
.expect("should be able to create a temp file to hold the buf image file descriptor set");

let mut prost_config = prost_build::Config::new();
prost_config.enable_type_names();

let mut tonic_config = tonic_build::configure()
.build_client(true)
.build_server(false)
.use_arc_self(true)
// override prost-types with pbjson-types
.compile_well_known_types(true)
.extern_path(".google.protobuf", "::pbjson_types")
.file_descriptor_set_path(buf_img.path())
.skip_protoc_run();

for (type_path, attr) in CUSTOM_TYPE_ATTRIBUTES {
tonic_config = tonic_config.type_attribute(type_path, attr);
}
for (proto_path, rust_path) in EXTERN_PATHS {
tonic_config = tonic_config.extern_path(proto_path, rust_path);
}
for (field_path, attr) in CUSTOM_FIELD_ATTRIBUTES {
tonic_config = tonic_config.field_attribute(field_path, attr);
}

tonic_config
.compile_fds_with_config(prost_config, fds)
.expect("should be able to compile protobuf using tonic");

let descriptor_set = std::fs::read(buf_img.path())
.expect("the buf image/descriptor set must exist and be readable at this point");

pbjson_build::Builder::new()
.register_descriptors(&descriptor_set)
.unwrap()
.build(&[
".celestia_proto",
".celestia",
".cosmos",
".tendermint",
".google",
])
.unwrap();
}
4 changes: 4 additions & 0 deletions proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@

pub mod serializers;

#[cfg(not(feature = "tonic"))]
include!(concat!(env!("OUT_DIR"), "/mod.rs"));

#[cfg(feature = "tonic")]
::tonic::include_proto!("mod");
zvolin marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 7 additions & 3 deletions proto/src/serializers/option_any.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! [`serde`] serializer for the optional [`Any`].

#[cfg(feature = "tonic")]
use pbjson_types::Any;
#[cfg(not(feature = "tonic"))]
use prost_types::Any;

use serde::{Deserialize, Deserializer, Serialize, Serializer};

/// Deserialize `Option<Any>`.
Expand All @@ -17,7 +21,7 @@ where

let any = Option::<Def>::deserialize(deserializer)?.map(|def| Any {
type_url: def.type_url,
value: def.value,
value: def.value.into(),
});

Ok(any)
Expand Down Expand Up @@ -65,7 +69,7 @@ mod tests {
let msg = TxResponse {
tx: Some(Any {
type_url: "abc".to_string(),
value: vec![1, 2, 3],
value: vec![1, 2, 3].into(),
}),
};
let json = serde_json::to_string(&msg).unwrap();
Expand All @@ -85,7 +89,7 @@ mod tests {
serde_json::from_str(r#"{"tx":{"type_url":"abc","value":"AQID"}}"#).unwrap();
let tx = msg.tx.unwrap();
assert_eq!(tx.type_url, "abc");
assert_eq!(tx.value, &[1, 2, 3])
assert_eq!(tx.value.as_ref(), &[1, 2, 3])
}

#[test]
Expand Down
Loading