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

proto: bootstrap crate #508

Merged
merged 14 commits into from
Aug 7, 2020
5 changes: 4 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ parsers:
conditional: yes
loop: yes
method: yes
macro: no
macro: no

ignore:
- "proto/src/prost" # Rust structs automatically generated from Protobuf definitions
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

[#472]: https://github.com/informalsystems/tendermint-rs/pull/472

### Proto crate

- Created Rust structs from Tendermint Proto files ([#504])

## [0.15.0] (2020-07-17)

This release is mostly about the revamped [light-client] library and the [light-node] command-line interface.
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
members = [
"light-client",
"light-node",
"proto",
"rpc",
"tendermint",
"testgen"
]

exclude = [
"proto-compiler"
]
3 changes: 2 additions & 1 deletion light-client/src/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ impl VerificationPredicates for ProdPredicates {}
/// This enables test implementations to only override a single method rather than
/// have to re-define every predicate.
pub trait VerificationPredicates: Send {
/// Compare the provided validator_set_hash against the hash produced from hashing the validator set.
/// Compare the provided validator_set_hash against the hash produced from hashing the validator
/// set.
fn validator_sets_match(
&self,
light_block: &LightBlock,
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions proto-compiler/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
16 changes: 16 additions & 0 deletions proto-compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "tendermint-proto-compiler"
version = "0.1.0"
authors = ["Greg Szabo <greg@informal.systems>"]
edition = "2018"
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to explicitly mention that this is not meant to be published (yet) via: https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened an issue for that, good point.



[dependencies]
walkdir = { version = "2.3" }

[build-dependencies]
prost-build = { version = "0.6" }
walkdir = { version = "2.3" }
git2 = { version = "0.13" }

[workspace]
7 changes: 7 additions & 0 deletions proto-compiler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## How to compile fresh proto structs

* `git clone https://github.com/tendermint/tendermint` into the repository `target/` folder.
* `cargo run` in the compiler folder.

The resultant structs will be created in the `tendermint-proto/src/prost` folder.
Copy link
Member

@liamsi liamsi Aug 11, 2020

Choose a reason for hiding this comment

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

Wasn't the folder renamed from tendermint-proto to proto? Would be good to double check if the above still makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good point. Opened a quick issue about it.

Build the `tendermint-proto` library.
41 changes: 41 additions & 0 deletions proto-compiler/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use git2::Repository;
use prost_build::compile_protos;
use std::env::var;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;

fn main() {
let tendermint_dir = var("TENDERMINT_DIR").unwrap_or_else(|_| "target/tendermint".to_string());
if !Path::new(&tendermint_dir).exists() {
let url = "https://github.com/tendermint/tendermint";
Repository::clone(url, &tendermint_dir).unwrap();
}
let proto_paths = [format!("{}/proto", tendermint_dir)];
let proto_includes_paths = [
format!("{}/proto", tendermint_dir),
format!("{}/third_party/proto", tendermint_dir),
];

// List available proto files
let mut protos: Vec<PathBuf> = vec![];
for proto_path in &proto_paths {
protos.append(
&mut WalkDir::new(proto_path)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| {
e.file_type().is_file()
&& e.path().extension().is_some()
&& e.path().extension().unwrap() == "proto"
})
.map(|e| e.into_path())
.collect(),
);
}

// List available paths for dependencies
let includes: Vec<PathBuf> = proto_includes_paths.iter().map(PathBuf::from).collect();

// Compile all proto files
compile_protos(&protos, &includes).unwrap();
}
36 changes: 36 additions & 0 deletions proto-compiler/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::fs::remove_dir_all;
use std::fs::{copy, create_dir_all};
use walkdir::WalkDir;

fn main() {
let tendermint_proto_path = "../proto/src/prost";

// Remove old compiled files
remove_dir_all(tendermint_proto_path).unwrap_or_default();
create_dir_all(tendermint_proto_path).unwrap();

// Copy new compiled files (prost does not use folder structures)
let err: Vec<std::io::Error> = WalkDir::new(env!("OUT_DIR"))
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| e.file_type().is_file())
.map(|e| {
copy(
e.path(),
std::path::Path::new(&format!(
"{}/{}",
tendermint_proto_path,
&e.file_name().to_os_string().to_str().unwrap()
)),
)
})
.filter_map(|e| e.err())
.collect();

if !err.is_empty() {
for e in err {
dbg!(e);
}
panic!("error while copying compiled files")
}
}
21 changes: 21 additions & 0 deletions proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "tendermint-proto"
version = "0.1.0"
authors = ["Greg Szabo <greg@informal.systems>"]
edition = "2018"
license = "Apache-2.0"
repository = "https://github.com/informalsystems/tendermint-rs/tree/master/tendermint-proto"
readme = "README.md"
categories = ["cryptography", "cryptography::cryptocurrencies", "database"]
keywords = ["blockchain", "tendermint", "proto"]

description = """
tendermint-proto is a the Rust implementation of the Tendermint proto structs.
"""

[package.metadata.docs.rs]
all-features = true

[dependencies]
prost = { version = "0.6" }
prost-types = { version = "0.6" }
50 changes: 50 additions & 0 deletions proto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## tendermint-proto

[![Crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
[![Build Status][build-image]][build-link]
[![Audit Status][audit-image]][audit-link]
[![Apache 2.0 Licensed][license-image]][license-link]
![Rust 1.39+][rustc-image]

Crate for interacting with Tendermint [proto structs][tendermint-go-proto-link].

[Documentation][docs-link]

## Requirements

- Rust 1.39+

## License

Copyright © 2020 Informal Systems

Licensed under the Apache License, Version 2.0 (the "License");
you may not use the files in this repository except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

[//]: # (badges)

[crate-image]: https://img.shields.io/crates/v/tendermint-proto.svg
[crate-link]: https://crates.io/crates/tendermint-proto
[docs-image]: https://docs.rs/tendermint-proto/badge.svg
[docs-link]: https://docs.rs/tendermint-proto/
[build-image]: https://github.com/informalsystems/tendermint-rs/workflows/Rust/badge.svg
[build-link]: https://github.com/informalsystems/tendermint-rs/actions?query=workflow%3ARust
[audit-image]: https://github.com/informalsystems/tendermint-rs/workflows/Audit-Check/badge.svg
[audit-link]: https://github.com/informalsystems/tendermint-rs/actions?query=workflow%3AAudit-Check
[license-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg
[license-link]: https://github.com/informalsystems/tendermint-rs/blob/master/LICENSE
[rustc-image]: https://img.shields.io/badge/rustc-1.39+-blue.svg

[//]: # (general links)

[tendermint-go-proto-link]: https://github.com/tendermint/tendermint/tree/master/proto/tendermint
88 changes: 88 additions & 0 deletions proto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//! tendermint-proto library gives the developer access to the Tendermint proto-defined structs.

// This module setup is necessary because the generated code contains "super::" calls for
// dependencies. Unfortunately, prost doesn't create this for us automatically.

#![deny(
warnings,
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_import_braces
)]
#![forbid(unsafe_code)]
#![doc(html_root_url = "https://docs.rs/tendermint-proto/0.1.0")]

mod tendermint {
pub mod abci {
#![allow(missing_docs)]
#![allow(clippy::large_enum_variant)]
include!("prost/tendermint.abci.rs");
}
pub mod blockchain {
#![allow(missing_docs)]
#![allow(clippy::large_enum_variant)]
include!("prost/tendermint.blockchain.rs");
}
pub mod consensus {
#![allow(missing_docs)]
include!("prost/tendermint.consensus.rs");
}
pub mod crypto {
#![allow(missing_docs)]
include!("prost/tendermint.crypto.rs");
}
pub mod evidence {
#![allow(missing_docs)]
include!("prost/tendermint.evidence.rs");
}
pub mod libs {
#![allow(missing_docs)]
pub mod bits {
#![allow(missing_docs)]
include!("prost/tendermint.libs.bits.rs");
}
}
pub mod mempool {
#![allow(missing_docs)]
include!("prost/tendermint.mempool.rs");
}
pub mod p2p {
#![allow(missing_docs)]
include!("prost/tendermint.p2p.rs");
}
pub mod privval {
#![allow(missing_docs)]
include!("prost/tendermint.privval.rs");
}
pub mod rpc {
#![allow(missing_docs)]
pub mod grpc {
#![allow(missing_docs)]
include!("prost/tendermint.rpc.grpc.rs");
}
}
pub mod state {
#![allow(missing_docs)]
include!("prost/tendermint.state.rs");
}
pub mod statesync {
#![allow(missing_docs)]
include!("prost/tendermint.statesync.rs");
}
pub mod store {
#![allow(missing_docs)]
include!("prost/tendermint.store.rs");
}
pub mod types {
#![allow(missing_docs)]
#![allow(clippy::large_enum_variant)]
include!("prost/tendermint.types.rs");
}
pub mod version {
#![allow(missing_docs)]
include!("prost/tendermint.version.rs");
}
}

pub use tendermint::*;
Empty file added proto/src/prost/gogoproto.rs
Empty file.
Empty file.
Loading