Skip to content

Commit

Permalink
SignedHeader should contain commit (#42)
Browse files Browse the repository at this point in the history
* Add commit to SignedHeader type and rename LastCommit to Commit:

 - Commit needed for lite client and RPC endpoint
 - Commit does not always refer to the last commit

* Move integration tests into tendermint; otherwise fixture tests won't run

* fmt

* verify some assumptions on the structure of the response

* Update tendermint/src/block/commit.rs
  • Loading branch information
liamsi authored and ebuchman committed Oct 3, 2019
1 parent e6106d2 commit 9d454d8
Show file tree
Hide file tree
Showing 27 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions tendermint/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod parts;
mod size;

pub use self::{
commit::LastCommit,
commit::Commit,
header::Header,
height::*,
id::{Id, ParseId},
Expand All @@ -35,5 +35,5 @@ pub struct Block {
pub evidence: evidence::Data,

/// Last commit
pub last_commit: LastCommit,
pub last_commit: Commit,
}
5 changes: 3 additions & 2 deletions tendermint/src/block/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use crate::{block, Vote};
use serde::{Deserialize, Serialize};
use std::{ops::Deref, slice};

/// Last commit to a particular blockchain: +2/3 precommit signatures.
/// Commit contains the justification (ie. a set of signatures) that a block was committed by a set of validators.
///
/// <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, Debug)]
pub struct LastCommit {
pub struct Commit {
/// Block ID of the last commit
pub block_id: block::Id,

Expand Down
11 changes: 2 additions & 9 deletions tendermint/src/rpc/endpoint/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use crate::{block, rpc};
use serde::{Deserialize, Serialize};
use std::ops::Deref;

/// Get commit information about a specific block
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
Expand Down Expand Up @@ -44,12 +43,6 @@ impl rpc::Response for Response {}
pub struct SignedHeader {
/// Block header
pub header: block::Header,
}

impl Deref for SignedHeader {
type Target = block::Header;

fn deref(&self) -> &block::Header {
&self.header
}
/// Commit containing signatures for the header
pub commit: block::Commit,
}
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions tests/rpc.rs → tendermint/tests/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ mod endpoints {
let response = endpoint::commit::Response::from_json(&read_json_fixture("commit")).unwrap();
let header = response.signed_header.header;
assert_eq!(header.chain_id.as_ref(), EXAMPLE_CHAIN);
// For now we just want to make sure the commit including precommits and a block_id exist
// in SignedHeader; later we should verify some properties: e.g. block_id.hash matches the
// header etc:
let commit = response.signed_header.commit;
let _block_id = commit.block_id;
let _precommits = commit.precommits;
}

#[test]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9d454d8

Please sign in to comment.