Skip to content

Commit

Permalink
changes to abci_info and block_results
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivani912 committed Mar 24, 2020
1 parent d0b9039 commit accb997
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 33 deletions.
2 changes: 1 addition & 1 deletion tendermint/src/abci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod info;
mod log;
mod path;
mod proof;
mod responses;
pub mod responses;
pub mod tag;
pub mod transaction;

Expand Down
18 changes: 10 additions & 8 deletions tendermint/src/abci/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,26 @@ pub struct DeliverTx {
pub info: Option<Info>,

/// Amount of gas wanted
// #[serde(default, rename = "gasWanted")]
pub gas_wanted: Gas,
pub gas_wanted: Option<Gas>,

This comment has been minimized.

Copy link
@greg-szabo

greg-szabo Mar 25, 2020

Member

This breaks the block_results test which expects a regular Gas, instead of an Option in DeliverTx.

This comment has been minimized.

Copy link
@Shivani912

Shivani912 Mar 25, 2020

Author Contributor

That's weird because it doesn't fail when i run it. Anyways, I'll remove the Option there :)

This comment has been minimized.

Copy link
@greg-szabo

greg-szabo Mar 26, 2020

Member

Maybe I had the wrong version or something. Keep it there, let's figure it out if necessary. Compatibility with Go is more important, we should fix the test instead, if it is really broken.


/// Amount of gas used
// #[serde(default, rename = "gasUsed")]
pub gas_used: Gas,
pub gas_used: Option<Gas>,

This comment has been minimized.

Copy link
@greg-szabo

greg-szabo Mar 25, 2020

Member

This breaks the block_results test which expects a regular Gas, instead of an Option in DeliverTx.

This comment has been minimized.

Copy link
@Shivani912

/// Tags
#[serde(default)]
pub events: Vec<Event>,
/// Events
pub events: Option<Vec<Event>>,

This comment has been minimized.

Copy link
@greg-szabo

greg-szabo Mar 25, 2020

Member

This breaks the block_results test which expects a regular Event, instead of an Option in DeliverTx.

This comment has been minimized.

Copy link
@Shivani912

/// Codespace
pub codespace: Option<Codespace>,
}

/// Event
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Event {
/// Event type
#[serde(rename = "type")]
pub type_str: String,

/// Attributes
pub attributes: Vec<Tag>,
}

Expand Down Expand Up @@ -114,7 +116,7 @@ pub struct EndBlock {
}

/// Return an empty vec in the event `validator_updates` is `null`
fn deserialize_validator_updates<'de, D>(
pub fn deserialize_validator_updates<'de, D>(
deserializer: D,
) -> Result<Vec<validator::Update>, D::Error>
where
Expand Down
31 changes: 29 additions & 2 deletions tendermint/src/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,35 @@ pub struct Params {
)]
pub max_age_num_blocks: u64,

/// Max age duration
pub max_age_duration: Duration,
}

#[derive(Clone, Debug)]
struct Duration(u64);
/// Duration
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Duration(u64);

impl<'de> Deserialize<'de> for Duration {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(Duration(
String::deserialize(deserializer)?
.parse()
.map_err(|e| D::Error::custom(format!("{}", e)))?,
))
}
}

impl From<Duration> for std::time::Duration {
fn from(d: Duration) -> std::time::Duration {
std::time::Duration::from_nanos(d.0)
}
}

impl Serialize for Duration {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
format!("{:?}", &self).serialize(serializer)
}
}
8 changes: 4 additions & 4 deletions tendermint/src/rpc/endpoint/block_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ pub struct Response {
pub height: block::Height,

/// Txs results
pub txs_results: abci::DeliverTx,
pub txs_results: Option<Vec<abci::DeliverTx>>,

/// Begin block events
pub begin_block_events: abci::Event,
pub begin_block_events: Option<Vec<abci::Event>>,

/// End block events
pub end_block_events: abci::Event,
pub end_block_events: Option<Vec<abci::Event>>,

/// Validator updates
#[serde(deserialize_with = "deserialize_validator_updates")]
#[serde(deserialize_with = "abci::responses::deserialize_validator_updates")]
pub validator_updates: Vec<validator::Update>,

/// New consensus params
Expand Down
19 changes: 1 addition & 18 deletions tendermint/tests/lite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ use std::{fs, path::PathBuf};
use tendermint::block::{Header, Height};
use tendermint::lite::error::{Error, Kind};
use tendermint::lite::{Requester, TrustThresholdFraction, TrustedState};
use tendermint::{block::signed_header::SignedHeader, lite, validator::Set, Hash, Time};
use tendermint::{block::signed_header::SignedHeader, lite, validator::Set, Hash, Time, evidence::Duration};

#[derive(Clone, Debug)]
struct Duration(u64);

#[derive(Deserialize, Clone, Debug)]
struct TestCases {
Expand Down Expand Up @@ -318,18 +316,3 @@ async fn run_bisection_test(case: TestBisection) {
}
}

impl<'de> Deserialize<'de> for Duration {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(Duration(
String::deserialize(deserializer)?
.parse()
.map_err(|e| D::Error::custom(format!("{}", e)))?,
))
}
}

impl From<Duration> for std::time::Duration {
fn from(d: Duration) -> std::time::Duration {
std::time::Duration::from_nanos(d.0)
}
}

0 comments on commit accb997

Please sign in to comment.