Skip to content

Commit

Permalink
feat(grpc)!: add wasm support and transaction client (#474)
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Zwoliński <[email protected]>
Co-authored-by: Mikołaj Florkiewicz <[email protected]>
  • Loading branch information
zvolin and fl0rek authored Jan 14, 2025
1 parent b4936ac commit 4c2187c
Show file tree
Hide file tree
Showing 43 changed files with 2,308 additions and 533 deletions.
5 changes: 5 additions & 0 deletions .github/actions/local-devnet/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ runs:
"cache-from": ["type=gha,scope=bridge-1"],
"cache-to": ["type=gha,mode=max,scope=bridge-1"],
"output": ["type=docker"]
},
"grpcwebproxy": {
"cache-from": ["type=gha,scope=grpcwebproxy"],
"cache-to": ["type=gha,mode=max,scope=grpcwebproxy"],
"output": ["type=docker"]
}
}
}
Expand Down
51 changes: 48 additions & 3 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"]
4 changes: 3 additions & 1 deletion ci/credentials/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/*
*
!/.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
23 changes: 19 additions & 4 deletions grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,34 @@ prost.workspace = true
tendermint-proto.workspace = true
tendermint.workspace = true

bytes = "1.8"
hex = "0.4.3"
http-body = "1"
k256 = "0.13.4"
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"
dotenvy = "0.15.7"
tokio = { version = "1.38.0", features = ["rt", "macros"] }
tonic = { version = "0.12.3", optional = true, default-features = false, features = [ "transport" ] }
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]
tokio = { version = "1.38.0", features = ["rt", "macros"] }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-futures = "0.4.43"
wasm-bindgen-test.workspace = true
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
109 changes: 0 additions & 109 deletions grpc/src/client.rs

This file was deleted.

27 changes: 26 additions & 1 deletion grpc/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use celestia_types::{hash::Hash, state::ErrorCode};
use tonic::Status;

/// Alias for a `Result` with the error type [`celestia_tonic::Error`].
///
/// [`celestia_tonic::Error`]: crate::Error
pub type Result<T> = std::result::Result<T, Error>;
pub type Result<T, E = Error> = std::result::Result<T, E>;

/// Representation of all the errors that can occur when interacting with [`celestia_tonic`].
///
Expand All @@ -14,6 +15,10 @@ pub enum Error {
#[error(transparent)]
TonicError(#[from] Status),

/// Transport error
#[error("Transport: {0}")]
TransportError(String),

/// Tendermint Error
#[error(transparent)]
TendermintError(#[from] tendermint::Error),
Expand All @@ -37,4 +42,24 @@ pub enum Error {
/// Empty blob submission list
#[error("Attempted to submit blob transaction with empty blob list")]
TxEmptyBlobList,

/// Broadcasting transaction failed
#[error("Broadcasting transaction {0} failed; code: {1}, error: {2}")]
TxBroadcastFailed(Hash, ErrorCode, String),

/// Executing transaction failed
#[error("Transaction {0} execution failed; code: {1}, error: {2}")]
TxExecutionFailed(Hash, ErrorCode, String),

/// Transaction was evicted from the mempool
#[error("Transaction {0} was evicted from the mempool")]
TxEvicted(Hash),

/// Transaction wasn't found, it was likely rejected
#[error("Transaction {0} wasn't found, it was likely rejected")]
TxNotFound(Hash),

/// Provided public key differs from one associated with account
#[error("Provided public key differs from one associated with account")]
PublicKeyMismatch,
}
Loading

0 comments on commit 4c2187c

Please sign in to comment.