Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix/consensus-param…
Browse files Browse the repository at this point in the history
…s-json
  • Loading branch information
lklimek committed Mar 1, 2024
2 parents 3c4ecad + 309f589 commit 664adde
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
34 changes: 34 additions & 0 deletions proto-compiler/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,37 @@ pub(crate) fn tenderdash_commitish() -> String {
Err(_) => DEFAULT_TENDERDASH_COMMITISH.to_string(),
}
}

/// Save the commitish of last successful download to a file in a state file,
/// located in the `dir` directory and named `download.state`.
pub(crate) fn save_state(dir: &Path, commitish: &str) {
let state_file = PathBuf::from(&dir).join("download.state");

std::fs::write(&state_file, commitish)
.map_err(|e| {
println!(
"[warn] => Failed to write download.state file {}: {}",
state_file.display(),
e
);
})
.ok();
}

/// Check if the state file contains the same commitish as the one we are trying
/// to download. State file should be located in the `dir` and named
/// `download.state`
pub(crate) fn check_state(dir: &Path, commitish: &str) -> bool {
let state_file = PathBuf::from(&dir).join("download.state");

match read_to_string(state_file) {
Ok(content) => {
println!(
"[info] => Found previously downloaded Tenderdash {}.",
content.trim()
);
content.eq(commitish)
},
Err(_) => false,
}
}
29 changes: 20 additions & 9 deletions proto-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use functions::{
mod constants;
use constants::{CUSTOM_FIELD_ATTRIBUTES, CUSTOM_TYPE_ATTRIBUTES, TENDERDASH_REPO};

use crate::functions::{check_state, save_state};

/// Import and compile protobuf definitions for Tenderdash.
///
/// Checkouts tenderdash repository to ../target/tenderdash and generates
Expand All @@ -25,7 +27,7 @@ pub fn proto_compile() {
.join("src")
.join("tenderdash.rs");

let target_dir = root.join("..").join("proto").join("src").join("prost");
let prost_out_dir = root.join("..").join("proto").join("src").join("prost");

let out_dir = var("OUT_DIR")
.map(PathBuf::from)
Expand All @@ -47,13 +49,21 @@ pub fn proto_compile() {
let thirdparty_dir = root.join("third_party");

let commitish = tenderdash_commitish();
println!("[info] => Fetching {TENDERDASH_REPO} at {commitish} into {tenderdash_dir:?}");
fetch_commitish(
&PathBuf::from(&tenderdash_dir),
&cargo_target_dir,
TENDERDASH_REPO,
&commitish,
); // This panics if it fails.

// check if this commitish is already downloaded
let download = !check_state(&prost_out_dir, &commitish);

if download {
println!("[info] => Fetching {TENDERDASH_REPO} at {commitish} into {tenderdash_dir:?}.");
fetch_commitish(
&PathBuf::from(&tenderdash_dir),
&cargo_target_dir,
TENDERDASH_REPO,
&commitish,
); // This panics if it fails.
} else {
println!("[info] => Skipping download.");
}

// We need all files in proto/tendermint/abci, plus .../types/canonical.proto
// for signature verification
Expand Down Expand Up @@ -100,9 +110,10 @@ pub fn proto_compile() {
pb.compile_protos(&protos, &proto_includes_paths).unwrap();

println!("[info] => Removing old structs and copying new structs.");
copy_files(&out_dir, &target_dir); // This panics if it fails.
copy_files(&out_dir, &prost_out_dir); // This panics if it fails.

generate_tenderdash_lib(&out_dir, &tenderdash_lib_target, &abci_ver, &tenderdash_ver);

save_state(&prost_out_dir, &commitish);
println!("[info] => Done!");
}
2 changes: 1 addition & 1 deletion proto/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module defines the various errors that be raised during Protobuf
//! conversions.

use core::{convert::TryFrom, fmt::Display, num::TryFromIntError};
use core::{fmt::Display, num::TryFromIntError};

use flex_error::{define_error, DisplayOnly};
use prost::{DecodeError, EncodeError};
Expand Down
5 changes: 1 addition & 4 deletions proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ mod error;
#[allow(warnings)]
mod tenderdash;

use core::{
convert::{TryFrom, TryInto},
fmt::Display,
};
use core::fmt::Display;

use bytes::{Buf, BufMut};
pub use error::Error;
Expand Down
2 changes: 1 addition & 1 deletion proto/src/serializers/part_set_header_total.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! from a string-quoted integer value into an integer value without quotes in
//! Tendermint Core v0.34.0. This deserializer allows backwards-compatibility by
//! deserializing both ways. See also: <https://github.com/informalsystems/tendermint-rs/issues/679>
use core::{convert::TryFrom, fmt::Formatter};
use core::fmt::Formatter;

use serde::{
de::{Error, Visitor},
Expand Down

0 comments on commit 664adde

Please sign in to comment.