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

chore: move net2 dependency out of tendermint crate #338

Merged
merged 7 commits into from
Jun 17, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RPC:
- `abci_info`, `abci_query`, `block_results`, `genesis` structs
- serialization/deserialization fixes
- Updated/fixed integration tests
- Move into its own crate ([#338](https://github.com/informalsystems/tendermint-rs/pull/338))

CI:
- Moved to GitHub Actions ([#120](https://github.com/informalsystems/tendermint-rs/issues/120))
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[workspace]

members = [
"tendermint",
"light-node",
"light-client",
"light-node",
"rpc",
"tendermint",
]
1 change: 1 addition & 0 deletions light-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2018"

[dependencies]
tendermint = { path = "../tendermint" }
tendermint-rpc = { version = "0.1.0", path = "../rpc" }

anomaly = { version = "0.2.0", features = ["serializer"] }
contracts = "0.4.0"
Expand Down
4 changes: 3 additions & 1 deletion light-client/src/components/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;

use tendermint::{
block::signed_header::SignedHeader as TMSignedHeader, rpc, validator::Set as TMValidatorSet,
block::signed_header::SignedHeader as TMSignedHeader, validator::Set as TMValidatorSet,
};

use tendermint_rpc as rpc;

use crate::{
bail,
types::{Height, LightBlock, PeerId},
Expand Down
21 changes: 11 additions & 10 deletions light-client/tests/light_client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
use std::collections::HashMap;
use std::convert::TryInto;
use std::fs;
use std::{
path::{Path, PathBuf},
time::{Duration, SystemTime},
};

use contracts::contract_trait;

use tendermint_light_client::{
components::{
clock::Clock,
Expand All @@ -13,16 +23,7 @@ use tendermint_light_client::{
types::{Height, LightBlock, PeerId, Time, TrustThreshold},
};

use std::collections::HashMap;
use std::convert::TryInto;
use std::fs;
use std::{
path::{Path, PathBuf},
time::{Duration, SystemTime},
};

use contracts::contract_trait;
use tendermint::rpc;
use tendermint_rpc as rpc;

// Link to the commit that generated below JSON test files:
// https://github.com/Shivani912/tendermint/commit/e02f8fd54a278f0192353e54b84a027c8fe31c1e
Expand Down
7 changes: 4 additions & 3 deletions light-node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
[package]
name = "light_node"
name = "tendermint-light-node"
authors = ["Ethan Buchman <ethan@coinculture.info>", "Ismail Khoffi <Ismail.Khoffi@gmail.com>"]
version = "0.1.0"
edition = "2018"

[dependencies]
abscissa_tokio = "0.5"
async-trait = "0.1"
gumdrop = "0.7"
serde = { version = "1", features = ["serde_derive"] }
tendermint = { version = "0.13.0-dev", path = "../tendermint" }
async-trait = "0.1"
tendermint-rpc = { version = "0.1.0", path = "../rpc" }
tokio = { version = "0.2", features = ["full"] }
abscissa_tokio = "0.5"

[dependencies.abscissa_core]
version = "0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion light-node/src/bin/light_node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![deny(warnings, missing_docs, trivial_casts, unused_qualifications)]
#![forbid(unsafe_code)]

use light_node::application::APPLICATION;
use tendermint_light_node::application::APPLICATION;

/// Boot LightNode
fn main() {
Expand Down
13 changes: 7 additions & 6 deletions light-node/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

/// App-local prelude includes `app_reader()`/`app_writer()`/`app_config()`
/// accessors along with logging macros. Customize as you see fit.
use crate::prelude::*;
use abscissa_core::{config, Command, FrameworkError, Options, Runnable};
use std::process;
use std::time::{Duration, SystemTime};

use tendermint::hash;
use tendermint::lite;
use tendermint::lite::error::Error;
use tendermint::lite::ValidatorSet as _;
use tendermint::lite::{Header, Height, Requester, TrustThresholdFraction};
use tendermint::rpc;
use tendermint::Hash;

use tendermint_rpc as rpc;

use crate::application::APPLICATION;
use crate::config::LightNodeConfig;
use crate::prelude::*;
use crate::requester::RPCRequester;
use crate::store::{MemStore, State};
use abscissa_core::{config, Command, FrameworkError, Options, Runnable};
use std::process;
use std::time::{Duration, SystemTime};
use tendermint::lite::error::Error;

/// `start` subcommand
///
Expand Down
9 changes: 6 additions & 3 deletions light-node/src/requester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use async_trait::async_trait;
use tendermint::block::signed_header::SignedHeader as TMCommit;
use tendermint::block::Header as TMHeader;
use tendermint::lite::{error, Height, SignedHeader};
use tendermint::rpc;
use tendermint::validator;
use tendermint::validator::Set;
use tendermint::{block, lite};

use tendermint_rpc as rpc;

/// RPCRequester wraps the Tendermint rpc::Client.
pub struct RPCRequester {
client: rpc::Client,
Expand Down Expand Up @@ -50,11 +51,13 @@ impl lite::types::Requester<TMCommit, TMHeader> for RPCRequester {

#[cfg(test)]
mod tests {
use super::*;
use tendermint::lite::types::Header as LiteHeader;
use tendermint::lite::types::Requester as LiteRequester;
use tendermint::lite::types::ValidatorSet as LiteValSet;
use tendermint::rpc;

use tendermint_rpc as rpc;

use super::*;

// TODO: integration test
#[tokio::test]
Expand Down
5 changes: 3 additions & 2 deletions light-node/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
)]

use abscissa_core::testing::prelude::*;
use light_node::config::LightNodeConfig;
use once_cell::sync::Lazy;

use tendermint_light_node::config::LightNodeConfig;

/// Executes your application binary via `cargo run`.
///
/// Storing this value as a [`Lazy`] static ensures that all instances of
Expand Down Expand Up @@ -91,5 +92,5 @@ fn start_with_config_and_args() {
fn version_no_args() {
let mut runner = RUNNER.clone();
let mut cmd = runner.arg("version").capture_stdout().run();
cmd.stdout().expect_regex(r"\A\w+ [\d\.\-]+\z");
cmd.stdout().expect_regex(r"\A[\w-]+ [\d\.\-]+\z");
}
20 changes: 20 additions & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "tendermint-rpc"
liamsi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably deserves a short readme (can be done in a followup PR).

version = "0.1.0"
authors = ["Alexander Simmerl <a.simmerl@gmail.com>"]
edition = "2018"

[dependencies]
async-tungstenite = {version="0.5", features = ["tokio-runtime"]}
bytes = "0.5"
futures = "0.3"
getrandom = "0.1"
http = "0.2"
hyper = "0.13"
serde = { version = "1", features = [ "derive" ] }
serde_bytes = "0.11"
serde_json = "1"
tendermint = { version = "0.13.0", path = "../tendermint" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always sceptical of circular dependencies (even if it's just a dev-dependency). Are we confident that this does cannot have weird side-effects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not expect any, but truth be told this was the solution with the least amount of opinionated changes. Would like to get rid of this circle as well, but afraid this goes too far for this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of any problems either 🍀 🤞

thiserror = "1"
tokio = { version = "0.2", features = ["macros"] }
uuid = { version = "0.8", default-features = false }
14 changes: 7 additions & 7 deletions tendermint/src/rpc/client.rs → rpc/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! Tendermint RPC client

use crate::{
abci::{self, Transaction},
block::Height,
net,
rpc::{endpoint::*, Error, Request, Response},
Genesis,
};
use bytes::buf::ext::BufExt;
use hyper::header;

use tendermint::abci::{self, Transaction};
use tendermint::block::Height;
use tendermint::net;
use tendermint::Genesis;

use crate::{endpoint::*, Error, Request, Response};

/// Tendermint RPC client.
///
/// Presently supports JSONRPC via HTTP.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
//! `/abci_info` endpoint JSONRPC wrapper

use crate::serializers;
use crate::{block, rpc};
use serde::{Deserialize, Serialize};

use tendermint::block;
use tendermint::serializers;

/// Request ABCI information from a node
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request;

impl rpc::Request for Request {
impl crate::Request for Request {
type Response = Response;

fn method(&self) -> rpc::Method {
rpc::Method::AbciInfo
fn method(&self) -> crate::Method {
crate::Method::AbciInfo
}
}

Expand All @@ -23,7 +24,7 @@ pub struct Response {
pub response: AbciInfo,
}

impl rpc::Response for Response {}
impl crate::Response for Response {}

/// ABCI information
#[derive(Clone, Debug, Deserialize, Serialize, Default)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! `/abci_query` endpoint JSONRPC wrapper

use crate::{
abci::{Code, Log, Path},
block,
merkle::proof::Proof,
rpc, serializers,
};
use serde::{Deserialize, Serialize};

use tendermint::abci::{Code, Log, Path};
use tendermint::block;
use tendermint::merkle::proof::Proof;
use tendermint::serializers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity: are all these import changes due to a different formatter? Is there a re reason why all the use crate:: ...s are replaced in that fashion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal touch really, optimised for editability and tracebility of dependencies. I usually one liner per top-level module in a crate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me. Ideally, these should be consistent in all our crates though.


/// Query the ABCI application for information
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
Expand Down Expand Up @@ -42,11 +41,11 @@ impl Request {
}
}

impl rpc::Request for Request {
impl crate::Request for Request {
type Response = Response;

fn method(&self) -> rpc::Method {
rpc::Method::AbciQuery
fn method(&self) -> crate::Method {
crate::Method::AbciQuery
}
}

Expand All @@ -57,7 +56,7 @@ pub struct Response {
pub response: AbciQuery,
}

impl rpc::Response for Response {}
impl crate::Response for Response {}

/// ABCI query results
#[derive(Clone, Debug, Deserialize, Serialize, Default)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//! `/block` endpoint JSONRPC wrapper

use crate::{
block::{self, Block},
rpc,
};
use serde::{Deserialize, Serialize};

use tendermint::block::{self, Block};

/// Get information about a specific block
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
Expand All @@ -24,11 +22,11 @@ impl Request {
}
}

impl rpc::Request for Request {
impl crate::Request for Request {
type Response = Response;

fn method(&self) -> rpc::Method {
rpc::Method::Block
fn method(&self) -> crate::Method {
crate::Method::Block
}
}

Expand All @@ -42,4 +40,4 @@ pub struct Response {
pub block: Block,
}

impl rpc::Response for Response {}
impl crate::Response for Response {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! `/block_results` endpoint JSONRPC wrapper

use crate::{abci, block, consensus, rpc, validator};
use serde::{Deserialize, Serialize};

use tendermint::{abci, block, consensus, validator};

/// Get ABCI results at a given height.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
Expand All @@ -21,11 +22,11 @@ impl Request {
}
}

impl rpc::Request for Request {
impl crate::Request for Request {
type Response = Response;

fn method(&self) -> rpc::Method {
rpc::Method::BlockResults
fn method(&self) -> crate::Method {
crate::Method::BlockResults
}
}

Expand All @@ -52,4 +53,4 @@ pub struct Response {
pub consensus_param_updates: Option<consensus::Params>,
}

impl rpc::Response for Response {}
impl crate::Response for Response {}
Loading