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

Tendermint/v0.33 #196

Merged
merged 39 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bd3430e
initial new commit struct
Shivani912 Feb 25, 2020
d129ad2
update functions
Shivani912 Mar 10, 2020
b64840b
fixed deserialization for new commit struct
Shivani912 Mar 12, 2020
b893a25
updated links to generator + val_set_test file
Shivani912 Mar 12, 2020
17c3c02
Ismail/commit struct followup (#182)
liamsi Mar 17, 2020
525b419
fix error
Shivani912 Mar 17, 2020
ae3ee39
more json bisection tests
Shivani912 Mar 17, 2020
0e6a073
abci_info struct app_version implemented
greg-szabo Mar 19, 2020
1a9a96e
Fixed fmt
greg-szabo Mar 19, 2020
a3367f3
Updated integration tests to tendermint v0.33 node
greg-szabo Mar 20, 2020
d0b9039
update block result response
Shivani912 Mar 20, 2020
accb997
changes to abci_info and block_results
Shivani912 Mar 24, 2020
e4918c8
Removed CircleCI reference and added codecov reference to Cargo
greg-szabo Mar 24, 2020
e0bce41
removing unwanted Option from DeliverTx struct fields
Shivani912 Mar 25, 2020
06d91d4
last_block_app_hash is now Option<Vec<u8>>
Shivani912 Mar 25, 2020
af430df
AbciInfo.last_block_app_hash is base64 encoded instead of hex
Shivani912 Mar 25, 2020
0ad0537
last_block_app_hash changed to Vec<u8>
Shivani912 Mar 25, 2020
ddbc113
Cherry-pick from 87e888b8a1278297ddeedb3f1823e6cc6f0d4ad7 (Liamsi)
liamsi Dec 12, 2019
323b44a
[88] Fix JSON ID
greg-szabo Mar 29, 2020
95902c6
[192] Fix abci_info compatibility for v0.33
greg-szabo Mar 29, 2020
c0c3ed7
[4] block_results test fix
greg-szabo Mar 29, 2020
3659a30
[184][120] Tendermint v0.33 compatibility fixes + integration tests f…
greg-szabo Mar 29, 2020
6c589c9
Added one abci_query test
greg-szabo Mar 29, 2020
2bf6125
FMT + get rid of warnings
greg-szabo Mar 29, 2020
5e9b62a
Relaxed genesis struct AppHash requirements from strict hex to anything
greg-szabo Mar 29, 2020
0d4952d
Removed unused Protocol struct
greg-szabo Mar 29, 2020
58411ac
Removed unused Protocol struct
greg-szabo Mar 29, 2020
2743f8b
Merge branch 'tendermint/v0.33' of github.com:informalsystems/tenderm…
greg-szabo Mar 29, 2020
7649289
IdType removed and JSON ID made as enum
greg-szabo Mar 29, 2020
f0048c5
Duration looks better now
Shivani912 Mar 30, 2020
a2ae776
fix fmt
Shivani912 Mar 30, 2020
5801875
Update tendermint/src/lite_impl/signed_header.rs
greg-szabo Mar 31, 2020
bceaf4f
Update tendermint/src/lite_impl/signed_header.rs
greg-szabo Mar 31, 2020
624ecae
Removed AsRef from JSON ID
greg-szabo Mar 31, 2020
4e2f2a9
Merge branch 'tendermint/v0.33' of github.com:informalsystems/tenderm…
greg-szabo Mar 31, 2020
ccb7b78
Merge remote-tracking branch 'remotes/origin/master' into tendermint/…
liamsi Apr 8, 2020
51934ba
Update Proof and ProofOp (#206)
liamsi Apr 8, 2020
2993d23
Add missing serializer for TrustThresholdFraction fields (#210)
romac Apr 10, 2020
0eae723
commit followup (#199)
liamsi Apr 10, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
runs-on: ubuntu-latest
services:
tendermint:
image: interchainio/tendermint
image: tendermint/tendermint
ports:
- 26656:26656
- 26657:26657
Expand Down
3 changes: 2 additions & 1 deletion tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ authors = [
all-features = true

[badges]
circle-ci = { repository = "interchainio/tendermint-rs" }
codecov = { repository = "..."}

[dependencies]
anomaly = "0.2"
Expand All @@ -44,6 +44,7 @@ prost-amino = "0.5"
prost-amino-derive = "0.5"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
serde_bytes = "0.11"
sha2 = { version = "0.8", default-features = false }
signatory = { version = "0.18", features = ["ed25519", "ecdsa"] }
signatory-dalek = "0.18"
Expand Down
13 changes: 10 additions & 3 deletions tendermint/src/abci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ mod info;
mod log;
mod path;
mod proof;
mod responses;
pub mod responses;
pub mod tag;
pub mod transaction;

pub use self::{
code::Code, data::Data, gas::Gas, info::Info, log::Log, path::Path, proof::Proof,
responses::Responses, transaction::Transaction,
code::Code,
data::Data,
gas::Gas,
info::Info,
log::Log,
path::Path,
proof::Proof,
responses::{DeliverTx, Event, Responses},
transaction::Transaction,
};
96 changes: 53 additions & 43 deletions tendermint/src/abci/proof.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,61 @@
//! ABCI Merkle proofs

use crate::error::Error;
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};
use std::{
fmt::{self, Display},
str::FromStr,
};
use subtle_encoding::{Encoding, Hex};

/// ABCI Merkle proofs
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Proof(Vec<u8>);

impl AsRef<[u8]> for Proof {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}

impl Display for Proof {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
&Hex::upper_case().encode_to_string(&self.0).unwrap()
)
}
use crate::serializers;
use serde::{Deserialize, Serialize};

/// Proof is Merkle proof defined by the list of ProofOps
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct Proof {
/// The list of ProofOps
pub ops: Vec<ProofOp>,
}

impl FromStr for Proof {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Error> {
let bytes = Hex::upper_case().decode(s)?;
Ok(Proof(bytes))
}
}

impl<'de> Deserialize<'de> for Proof {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let hex = String::deserialize(deserializer)?;
Ok(Self::from_str(&hex).map_err(|e| D::Error::custom(format!("{}", e)))?)
}
/// ProofOp defines an operation used for calculating Merkle root
/// The data could be arbitrary format, providing necessary data
/// for example neighbouring node hash
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ProofOp {
/// Type of the ProofOp
#[serde(alias = "type")]
pub field_type: String,
/// Key of the ProofOp
#[serde(
default,
serialize_with = "serializers::serialize_base64",
deserialize_with = "serializers::parse_base64"
)]
pub key: Vec<u8>,
/// Actual data
#[serde(
default,
serialize_with = "serializers::serialize_base64",
deserialize_with = "serializers::parse_base64"
)]
pub data: Vec<u8>,
}

impl Serialize for Proof {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.to_string().serialize(serializer)
#[cfg(test)]
mod test {
use super::Proof;
use crate::test::test_serialization_roundtrip;

#[test]
fn serialization_roundtrip() {
let payload = r#"
{
"ops": [
{
"type": "iavl:v",
"key": "Y29uc2Vuc3VzU3RhdGUvaWJjb25lY2xpZW50LzIy",
"data": "8QEK7gEKKAgIEAwYHCIgG9RAkJgHlxNjmyzOW6bUAidhiRSja0x6+GXCVENPG1oKKAgGEAUYFyIgwRns+dJvjf1Zk2BaFrXz8inPbvYHB7xx2HCy9ima5f8KKAgEEAMYFyogOr8EGajEV6fG5fzJ2fAAvVMgRLhdMJTzCPlogl9rxlIKKAgCEAIYFyIgcjzX/a+2bFbnNldpawQqZ+kYhIwz5r4wCUzuu1IFW04aRAoeY29uc2Vuc3VzU3RhdGUvaWJjb25lY2xpZW50LzIyEiAZ1uuG60K4NHJZZMuS9QX6o4eEhica5jIHYwflRiYkDBgX"
},
{
"type": "multistore",
"key": "aWJj",
"data": "CvEECjAKBGJhbmsSKAomCIjYAxIg2MEyyonbZButYnvSRkf2bPQg+nqA+Am1MeDxG6F4p1UKLwoDYWNjEigKJgiI2AMSIN2YHczeuXNvyetrSFQpkCcJzfB6PXVCw0i/XShMgPnIChEKB3VwZ3JhZGUSBgoECIjYAwovCgNnb3YSKAomCIjYAxIgYM0TfBli7KxhY4nWgDSDPykhUJwtKFql9RU5l86WinQKLwoDaWJjEigKJgiI2AMSIFp6aJASeInQKF8y824zjmgcFORN6M+ECbgFfJkobKs8CjAKBG1haW4SKAomCIjYAxIgsZzwmLQ7PH1UeZ/vCUSqlQmfgt3CGfoMgJLkUqKCv0EKMwoHc3Rha2luZxIoCiYIiNgDEiCiBZoBLyDGj5euy3n33ik+SpqYK9eB5xbI+iY8ycYVbwo0CghzbGFzaGluZxIoCiYIiNgDEiAJz3gEYuIhdensHU3b5qH5ons2quepd6EaRgCHXab6PQoyCgZzdXBwbHkSKAomCIjYAxIglWLA5/THPTiTxAlaLHOBYFIzEJTmKPznItUwAc8zD+AKEgoIZXZpZGVuY2USBgoECIjYAwowCgRtaW50EigKJgiI2AMSIMS8dZ1j8F6JVVv+hB1rHBZC+gIFJxHan2hM8qDC64n/CjIKBnBhcmFtcxIoCiYIiNgDEiB8VIzExUHX+SvHZFz/P9NM9THnw/gTDDLVReuZX8htLgo4CgxkaXN0cmlidXRpb24SKAomCIjYAxIg3u/Nd4L+8LT8OXJCh14o8PHIJ/GLQwsmE7KYIl1GdSYKEgoIdHJhbnNmZXISBgoECIjYAw=="
}
]
}"#;
test_serialization_roundtrip::<Proof>(payload);
}
}
32 changes: 20 additions & 12 deletions tendermint/src/abci/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,44 @@ where
///
/// This type corresponds to the `ResponseDeliverTx` proto from:
///
/// <https://github.com/tendermint/tendermint/blob/develop/abci/types/types.proto>
/// <https://github.com/tendermint/tendermint/blob/master/abci/types/types.proto>
// TODO(tarcieri): generate this automatically from the proto
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DeliverTx {
/// ABCI application response code
pub code: Option<Code>,
pub code: Code,

/// ABCI application data
pub data: Option<Data>,
pub data: Data,

/// ABCI log data (nondeterministic)
pub log: Option<Log>,
pub log: Log,

/// ABCI info (nondeterministic)
pub info: Option<Info>,
pub info: Info,

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

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

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

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

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

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

/// Begin block response.
Expand Down Expand Up @@ -108,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
2 changes: 1 addition & 1 deletion tendermint/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use subtle::{self, ConstantTimeEq};
use subtle_encoding::hex;

/// Size of an account ID in bytes
const LENGTH: usize = 20;
pub const LENGTH: usize = 20;

/// Account IDs
#[derive(Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
Expand Down
18 changes: 14 additions & 4 deletions tendermint/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Blocks within the chains of a Tendermint network

mod commit;
pub mod commit_sig;
pub mod header;
mod height;
mod id;
Expand All @@ -11,6 +12,7 @@ mod size;

pub use self::{
commit::*,
commit_sig::*,
header::Header,
height::*,
id::{Id, ParseId},
Expand Down Expand Up @@ -46,18 +48,26 @@ where
{
#[derive(Deserialize)]
struct TmpCommit {
pub height: Height,
#[serde(
serialize_with = "serializers::serialize_u64",
deserialize_with = "serializers::parse_u64"
)]
pub round: u64,
#[serde(deserialize_with = "serializers::parse_non_empty_block_id")]
block_id: Option<Id>,
precommits: Option<Precommits>,
pub block_id: Option<Id>,
pub signatures: Option<CommitSigs>,
}

let commit = TmpCommit::deserialize(deserializer)?;
if commit.block_id.is_none() || commit.precommits.is_none() {
if commit.block_id.is_none() || commit.signatures.is_none() {
Ok(None)
} else {
Ok(Some(Commit {
height: commit.height,
round: commit.round,
block_id: commit.block_id.unwrap(),
precommits: commit.precommits.unwrap(),
signatures: commit.signatures.unwrap(),
}))
}
}
58 changes: 35 additions & 23 deletions tendermint/src/block/commit.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,74 @@
//! Commits to a Tendermint blockchain

use crate::{block, Vote};
use crate::block::commit_sig::CommitSig;
use crate::block::{Height, Id};
use crate::serializers;
use serde::{Deserialize, Serialize};
use std::{ops::Deref, slice};

/// Commit contains the justification (ie. a set of signatures) that a block was committed by a set
/// of validators.
///
/// TODO: Update links below!
/// <https://github.com/tendermint/tendermint/blob/51dc810d041eaac78320adc6d53ad8b160b06601/types/block.go#L486-L502>
/// <https://github.com/tendermint/tendermint/blob/master/docs/spec/blockchain/blockchain.md#lastcommit>
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
pub struct Commit {
/// Block ID of the last commit
pub block_id: block::Id,
/// Block height
pub height: Height,

/// Precommits
pub precommits: Precommits,
/// Round
#[serde(
serialize_with = "serializers::serialize_u64",
deserialize_with = "serializers::parse_u64"
)]
pub round: u64,

/// Block ID
pub block_id: Id,

/// Signatures
pub signatures: CommitSigs,
}

/// Precommits which certify that a block is valid
/// CommitSigs which certify that a block is valid
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct Precommits(Vec<Option<Vote>>);
pub struct CommitSigs(Vec<CommitSig>);

impl Precommits {
/// Create a new precommit collection
pub fn new<I>(into_precommits: I) -> Self
impl CommitSigs {
/// Create a new CommitSig collection
pub fn new<I>(into_commit_sigs: I) -> Self
where
I: Into<Vec<Option<Vote>>>,
I: Into<Vec<CommitSig>>,
{
Self(into_precommits.into())
Self(into_commit_sigs.into())
}

/// Convert this collection of precommits into a vector
pub fn into_vec(self) -> Vec<Option<Vote>> {
/// Convert this collection of CommitSigs into a vector
pub fn into_vec(self) -> Vec<CommitSig> {
self.0
}

/// Iterate over the precommits in the collection
pub fn iter(&self) -> slice::Iter<'_, Option<Vote>> {
/// Iterate over the CommitSigs in the collection
pub fn iter(&self) -> slice::Iter<'_, CommitSig> {
self.0.iter()
}
}

impl AsRef<[Option<Vote>]> for Precommits {
fn as_ref(&self) -> &[Option<Vote>] {
impl AsRef<[CommitSig]> for CommitSigs {
fn as_ref(&self) -> &[CommitSig] {
self.0.as_slice()
}
}

impl Deref for Precommits {
type Target = [Option<Vote>];
impl Deref for CommitSigs {
type Target = [CommitSig];

fn deref(&self) -> &[Option<Vote>] {
fn deref(&self) -> &[CommitSig] {
self.as_ref()
}
}

impl PartialEq for Precommits {
impl PartialEq for CommitSigs {
fn eq(&self, other: &Self) -> bool {
// Note: this is used for asserts in tests:
self.0.clone().into_iter().eq(other.0.clone().into_iter())
Expand Down
Loading