Skip to content

Commit

Permalink
Upgrade jsonrpc to upgrade hyper (#804)
Browse files Browse the repository at this point in the history
* Remove unused module

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Upgrade Light Node to jsonrpc v17.0

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Update CHANGELOG

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix panic syntax to be Rust 2021-compatible (fixes nightly coverage check in CI)

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Co-authored-by: Romain Ruetschi <romain@informal.systems>
  • Loading branch information
thanethomson and romac authored Feb 9, 2021
1 parent 95bd6da commit 1a66290
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

* `[tendermint-proto]` Fix panic in evidence serialization in the case where we
receive an empty evidence Protobuf structure ([#782])
* `[light-node]` Upgrade `jsonrpc` dependency to v17.0 to fix security
vulnerability in `hyper` v0.12.35 ([#803])

[#782]: https://github.com/informalsystems/tendermint-rs/issues/782
[#803]: https://github.com/informalsystems/tendermint-rs/issues/803

## v0.18.0

Expand Down
8 changes: 4 additions & 4 deletions light-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ path = "src/bin/tendermint-light-node/main.rs"
anomaly = { version = "0.2", features = ["serializer"] }
async-trait = "0.1"
gumdrop = "0.7"
jsonrpc-core = "14.2"
jsonrpc-core-client = "14.2"
jsonrpc-http-server = "14.2"
jsonrpc-derive = "14.2"
jsonrpc-core = "17.0"
jsonrpc-core-client = "17.0"
jsonrpc-http-server = "17.0"
jsonrpc-derive = "17.0"
serde = { version = "1", features = ["serde_derive"] }
serde_json = "1.0"
thiserror = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions light-node/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ impl Runnable for StartCmd {
fn run(&self) {
if let Err(e) = StartCmd::assert_init_was_run() {
status_err!(&e);
panic!(e);
panic!("{}", e);
}

let supervisor = match self.construct_supervisor() {
Ok(supervisor) => supervisor,
Err(e) => {
status_err!(&e);
panic!(e);
panic!("{}", e);
}
};

Expand Down
33 changes: 18 additions & 15 deletions light-node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ where
}

mod sealed {
use jsonrpc_core::futures::future::{self, FutureResult};
use jsonrpc_core::futures;
use jsonrpc_core::types::Error;
use jsonrpc_core::{BoxFuture, Result};
use jsonrpc_derive::rpc;

use tendermint_light_client::supervisor::Handle;
Expand All @@ -46,11 +47,11 @@ mod sealed {
pub trait Rpc {
/// Returns the latest trusted block.
#[rpc(name = "state")]
fn state(&self) -> FutureResult<Option<LightBlock>, Error>;
fn state(&self) -> BoxFuture<Result<Option<LightBlock>>>;

/// Returns the latest status.
#[rpc(name = "status")]
fn status(&self) -> FutureResult<LatestStatus, Error>;
fn status(&self) -> BoxFuture<Result<LatestStatus>>;
}

pub use self::rpc_impl_Rpc::gen_client::Client;
Expand All @@ -75,34 +76,32 @@ mod sealed {
where
H: Handle + Send + Sync + 'static,
{
fn state(&self) -> FutureResult<Option<LightBlock>, Error> {
fn state(&self) -> BoxFuture<Result<Option<LightBlock>>> {
let res = self.handle.latest_trusted().map_err(|e| {
let mut err = Error::internal_error();
err.message = e.to_string();
err.data = serde_json::to_value(e.kind()).ok();
err
});

future::result(res)
Box::pin(futures::future::ready(res))
}

fn status(&self) -> FutureResult<LatestStatus, Error> {
fn status(&self) -> BoxFuture<Result<LatestStatus>> {
let res = self.handle.latest_status().map_err(|e| {
let mut err = Error::internal_error();
err.message = e.to_string();
err.data = serde_json::to_value(e.kind()).ok();
err
});

future::result(res)
Box::pin(futures::future::ready(res))
}
}
}

#[cfg(test)]
mod test {
use futures::compat::Future01CompatExt as _;
use jsonrpc_core::futures::future::Future;
use jsonrpc_core::IoHandler;
use jsonrpc_core_client::transports::local;
use pretty_assertions::assert_eq;
Expand All @@ -117,13 +116,15 @@ mod test {
#[tokio::test]
async fn state() {
let server = Server::new(MockHandle {});
let fut = {
let have = {
let mut io = IoHandler::new();
io.extend_with(server.to_delegate());
let (client, server) = local::connect::<Client, _, _>(io);
client.state().join(server)
tokio::select! {
result = client.state() => result.unwrap(),
_ = server => panic!("server terminated before client state request completed"),
}
};
let (have, _) = fut.compat().await.unwrap();
let want = serde_json::from_str(LIGHTBLOCK_JSON).unwrap();

assert_eq!(have, want);
Expand All @@ -132,13 +133,15 @@ mod test {
#[tokio::test]
async fn status() {
let server = Server::new(MockHandle {});
let fut = {
let have = {
let mut io = IoHandler::new();
io.extend_with(server.to_delegate());
let (client, server) = local::connect::<Client, _, _>(io);
client.status().join(server)
tokio::select! {
result = client.status() => result.unwrap(),
_ = server => panic!("server terminated before client status request completed"),
}
};
let (have, _) = fut.compat().await.unwrap();
let want = serde_json::from_str(STATUS_JSON).unwrap();

assert_eq!(have, want);
Expand Down
6 changes: 0 additions & 6 deletions tendermint/src/lite.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tendermint/src/public_key/pub_key_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod tests {

match PubKeyRequest::decode(want.as_ref()) {
Ok(have) => assert_eq!(have, msg),
Err(err) => panic!(err.to_string()),
Err(err) => panic!("{}", err.to_string()),
}
}
}

0 comments on commit 1a66290

Please sign in to comment.