-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proto)!: grpc server and client support (#50)
* feat(proto): grpc server and client support * chore: make ServerRuntime public * test(proto): test grpc server with tenderdash in docker * chore(proto): fix imports * chore: build issues * chore: abci grpc-server feature * chore: imports and features * chore: grpc test * chore: re-export tonic * chore: fix missing serde serialization * chore(proto): fix feature flags * chore(proto): fix warn * fix: wrong json serialization of ConsensusParams * fix: wrong json serialization of ConsensusParams * chore: fix build * chore: simplify features * chore: self review, simplify features * chore: comments * test(abci): grpc test uses latest tenderdash tag * chore: bump version to 0.14.0-dev.7 for tenderdash v0.14.0-dev.3, abci 0.26.0 * chore: fix missing serde serialization * fix: wrong json serialization of ConsensusParams * build(deps): update chrono and replace deprecated fn calls --------- Co-authored-by: Ivan Shumkov <[email protected]>
- Loading branch information
Showing
14 changed files
with
285 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
//! Test gRPC server for ABCI protocol. | ||
//! | ||
//! This test verifies that the gRPC server generated with tonic as part of the | ||
//! tenderdash-proto crate can successfully connect to Tenderdash instance. | ||
//! | ||
//! This test should be implemented in the tenderdash-proto crate; however, it | ||
//! is implemented here to use already existing docker container testing | ||
//! logic. | ||
#![cfg(feature = "grpc")] | ||
|
||
use std::sync::Arc; | ||
|
||
use tenderdash_abci::{ | ||
proto::abci::{ | ||
abci_application_server::AbciApplication, RequestEcho, RequestInfo, ResponseInfo, | ||
}, | ||
CancellationToken, | ||
}; | ||
mod common; | ||
use tenderdash_abci::proto; | ||
use tonic::{async_trait, Response, Status}; | ||
|
||
#[cfg(feature = "docker-tests")] | ||
#[tokio::test] | ||
/// Test server listening on ipv4 address. | ||
/// | ||
/// See [tcp_server_test()]. | ||
async fn test_ipv4_server() { | ||
// we assume the host uses default Docker network configuration, with the host | ||
// using 172.17.0.1 | ||
let bind_address = "172.17.0.1:1234".to_string(); | ||
|
||
grpc_server_test("v4", bind_address.as_str()).await; | ||
} | ||
|
||
#[cfg(feature = "docker-tests")] | ||
#[tokio::test] | ||
/// Test server listening on ipv6 address. | ||
/// | ||
/// See [tcp_server_test()]. | ||
async fn test_ipv6_server() { | ||
// we assume the host uses default Docker network configuration, with the host | ||
// using 172.17.0.1. This is IPv6 notation of the IPv4 address. | ||
let bind_address = "[::ffff:ac11:1]:5678".to_string(); | ||
|
||
grpc_server_test("v6", bind_address.as_str()).await; | ||
} | ||
|
||
#[cfg(feature = "docker-tests")] | ||
/// Feature: ABCI App TCO server | ||
/// | ||
/// * Given that we have Tenderdash instance using TCP connection to communicate | ||
/// with ABCI APP | ||
/// * When we estabilish connection with Tenderdash | ||
/// * Then Tenderdash sends Info request | ||
async fn grpc_server_test(test_name: &str, bind_address: &str) { | ||
use core::panic; | ||
|
||
use proto::abci::abci_application_server::AbciApplicationServer; | ||
use tonic::transport::Server; | ||
|
||
tracing_subscriber::fmt() | ||
.with_env_filter(tracing_subscriber::EnvFilter::new("debug")) | ||
.with_ansi(true) | ||
.try_init() | ||
.ok(); | ||
|
||
let cancel = CancellationToken::new(); | ||
let app = TestApp { | ||
cancel: cancel.clone(), | ||
}; | ||
|
||
let addr = bind_address.parse().expect("address must be valid"); | ||
let server_cancel = cancel.clone(); | ||
let server_handle = tokio::spawn(async move { | ||
tracing::debug!("starting gRPC server"); | ||
Server::builder() | ||
.add_service(AbciApplicationServer::new(app)) | ||
.serve_with_shutdown(addr, server_cancel.cancelled()) | ||
.await | ||
.expect("server failed"); | ||
tracing::debug!("gRPC server stopped"); | ||
}); | ||
|
||
let socket_uri = format!("grpc://{}", bind_address); | ||
let container_name = format!("tenderdash_{}", test_name); | ||
|
||
let td = tokio::task::spawn_blocking(move || { | ||
tracing::debug!("starting Tenderdash in Docker container"); | ||
let td = Arc::new(common::docker::TenderdashDocker::new( | ||
&container_name, | ||
None, | ||
&socket_uri, | ||
)); | ||
common::docker::setup_td_logs_panic(&td); | ||
tracing::debug!("started Tenderdash in Docker container"); | ||
|
||
td | ||
}) | ||
.await | ||
.expect("start tenderdash"); | ||
|
||
tokio::select! { | ||
_ = tokio::time::sleep(tokio::time::Duration::from_secs(60)) => { | ||
panic!("Test timed out"); | ||
} | ||
_ = cancel.cancelled() => { | ||
tracing::debug!("CancellationToken cancelled"); | ||
} | ||
ret = server_handle => { | ||
ret.expect("gRPC server failed"); | ||
} | ||
} | ||
|
||
tokio::task::spawn_blocking(move || drop(td)) | ||
.await | ||
.expect("tenderdash cleanup"); | ||
|
||
tracing::info!("Test finished successfully"); | ||
} | ||
|
||
pub struct TestApp { | ||
// when test succeeds, we cancel this token to finish it | ||
cancel: CancellationToken, | ||
} | ||
#[async_trait] | ||
impl AbciApplication for TestApp { | ||
async fn echo( | ||
&self, | ||
request: tonic::Request<RequestEcho>, | ||
) -> Result<tonic::Response<proto::abci::ResponseEcho>, Status> { | ||
tracing::info!(?request, "Echo called"); | ||
Ok(Response::new(proto::abci::ResponseEcho { | ||
message: request.into_inner().message, | ||
})) | ||
} | ||
async fn info( | ||
&self, | ||
_request: tonic::Request<RequestInfo>, | ||
) -> std::result::Result<tonic::Response<ResponseInfo>, tonic::Status> { | ||
tracing::info!("Info called, test successful"); | ||
let resp = ResponseInfo { | ||
..Default::default() | ||
}; | ||
self.cancel.cancel(); | ||
Ok(Response::new(resp)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
version = "0.14.0-dev.6" | ||
version = "0.14.0-dev.7" | ||
name = "tenderdash-proto-compiler" | ||
authors = ["Informal Systems <[email protected]>", "Dash Core Group"] | ||
edition = "2021" | ||
|
@@ -17,3 +17,15 @@ regex = { "version" = "1.7.1" } | |
ureq = { "version" = "2.6.2" } | ||
zip = { version = "0.6.4", default-features = false, features = ["deflate"] } | ||
fs_extra = { version = "1.3.0" } | ||
tonic-build = { version = "0.11.0", optional = true } | ||
|
||
|
||
[features] | ||
default = [] | ||
# Enable gRPC support; needed by server and client features. | ||
# Conflicts with no_std | ||
grpc = ["dep:tonic-build"] | ||
# Build the gRPC server. Requires tenderdash-proto/std feature. | ||
server = ["grpc"] | ||
# Build the gRPC client. Requires tenderdash-proto/std feature. | ||
client = ["grpc"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.