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)!: enable celestia-grpc usage within wasm #474

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ jobs:
- name: Run rpc wasm test
run: wasm-pack test --headless --chrome rpc --features=wasm-bindgen

- name: Run grpc wasm test
run: wasm-pack test --headless --chrome grpc

- name: Test node-wasm crate
# We're running node-wasm tests in release mode to get around a failing debug assertion
# https://github.com/libp2p/rust-libp2p/issues/5618
Expand Down
107 changes: 78 additions & 29 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions ci/Dockerfile.grpcwebproxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM docker.io/alpine:3.19.1

RUN apk update && apk add --no-cache wget unzip

RUN wget -O grpcwebproxy.zip https://github.com/improbable-eng/grpc-web/releases/download/v0.15.0/grpcwebproxy-v0.15.0-linux-x86_64.zip && \
unzip grpcwebproxy.zip && \
mv dist/grpcwebproxy* /usr/local/bin/grpcwebproxy && \
rm grpcwebproxy.zip

ENTRYPOINT ["/usr/local/bin/grpcwebproxy"]
5 changes: 3 additions & 2 deletions ci/credentials/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/*
!/.gitignore
*
!/bridge-0.*
/bridge-0.jwt
1 change: 1 addition & 0 deletions ci/credentials/bridge-0.addr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
celestia1t52q7uqgnjfzdh3wx5m5phvma3umrq8k6tq2p9
9 changes: 9 additions & 0 deletions ci/credentials/bridge-0.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN TENDERMINT PRIVATE KEY-----
type: secp256k1
kdf: bcrypt
salt: 2D070635EBDE45AD8845CE82FB6D5A89

PboW9MooV09RX733cy55wuciTKhveZdY2H5NhJ0DIhfHxfyR11viqxy4wJ917rkG
OfsQph8JPYp315ZRYq7vUIsbTreMgnlRSdqPmL0=
=SLpn
-----END TENDERMINT PRIVATE KEY-----
1 change: 1 addition & 0 deletions ci/credentials/bridge-0.plaintext-key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
393fdb5def075819de55756b45c9e2c8531a8c78dd6eede483d3440e9457d839
10 changes: 10 additions & 0 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ services:
- credentials:/credentials
- genesis:/genesis

grpcwebproxy:
image: grpcwebproxy
platform: "linux/amd64"
build:
context: .
dockerfile: Dockerfile.grpcwebproxy
command: --backend_addr=validator:9090 --run_tls_server=false --allow_all_origins
ports:
- 18080:8080

bridge-0:
image: bridge
platform: "linux/amd64"
Expand Down
24 changes: 22 additions & 2 deletions grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,36 @@ prost.workspace = true
tendermint-proto.workspace = true
tendermint.workspace = true

bytes = "1.8"
hex = "0.4.3"
http-body = "1"
k256 = "0.13.4"
regex = { version = "1.11", default-features = false }
serde = "1.0.215"
thiserror = "1.0.61"
tokio = { version = "1.38.0", features = ["sync"] }
tonic = { version = "0.12.3", default-features = false, features = [
"codegen", "prost"
]}

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
anyhow = "1.0.86"
tokio = { version = "1.38.0", features = ["time"] }
tonic = { version = "0.12.3", default-features = false, features = [ "transport" ] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
futures = "0.3.30"
getrandom = { version = "0.2.15", features = ["js"] }
gloo-timers = { version = "0.3.0", features = ["futures"] }
send_wrapper = { version = "0.6.0", features = ["futures"] }
tonic-web-wasm-client = "0.6"

[dev-dependencies]
rand_core = "0.6.4"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
dotenvy = "0.15.7"
tokio = { version = "1.38.0", features = ["rt", "macros"] }
tonic = { version = "0.12.3", optional = true, default-features = false, features = [ "transport" ] }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-futures = "0.4.43"
wasm-bindgen-test = "0.3.42"
11 changes: 6 additions & 5 deletions grpc/grpc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ impl GrpcMethod {
let method = quote! {
#doc_hash #doc_group
pub #signature {
let mut client = #grpc_client_struct :: with_interceptor(
self.grpc_channel.clone(),
self.auth_interceptor.clone(),
let mut client = #grpc_client_struct :: new(
self.transport.clone(),
);
let request = ::tonic::Request::new(( #( #params ),* ).into_parameter());

let param = crate::grpc::IntoGrpcParam::into_parameter(( #( #params ),* ));
let request = ::tonic::Request::new(param);
let response = client. #grpc_method_name (request).await;
response?.into_inner().try_from_response()
crate::grpc::FromGrpcResponse::try_from_response(response?.into_inner())
}
};

Expand Down
Loading
Loading