Skip to content

Commit

Permalink
tendermint: v0.38 ABCI requests and responses
Browse files Browse the repository at this point in the history
Add the v0_38::abci::{Request,Response} enums and the new domain types
representing request and response messages added in CometBFT 0.38.
  • Loading branch information
mzabaluev committed May 5, 2023
1 parent 431db0f commit 36eca7a
Show file tree
Hide file tree
Showing 30 changed files with 1,214 additions and 165 deletions.
4 changes: 2 additions & 2 deletions tendermint/src/abci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub mod request;
pub mod response;
pub mod types;

pub use crate::v0_37::abci::request::Request;
pub use crate::v0_37::abci::response::Response;
pub use crate::v0_38::abci::request::Request;
pub use crate::v0_38::abci::response::Response;

pub use event::{Event, EventAttribute, EventAttributeIndexExt, TypedEvent};

Expand Down
1 change: 1 addition & 0 deletions tendermint/src/abci/doc/request-extendvote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ABCI documentation](https://github.com/cometbft/cometbft/blob/v0.38.x/spec/abci/abci++_methods.md#extendvote)
1 change: 1 addition & 0 deletions tendermint/src/abci/doc/request-finalizeblock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ABCI documentation](https://github.com/cometbft/cometbft/blob/v0.38.x/spec/abci/abci++_methods.md#finalizeblock)
1 change: 1 addition & 0 deletions tendermint/src/abci/doc/request-verifyvoteextension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ABCI documentation](https://github.com/cometbft/cometbft/blob/v0.38.x/spec/abci/abci++_methods.md#verifyvoteextension)
1 change: 1 addition & 0 deletions tendermint/src/abci/doc/response-extendvote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ABCI documentation](https://github.com/cometbft/cometbft/blob/v0.38.x/spec/abci/abci++_methods.md#extendvote)
1 change: 1 addition & 0 deletions tendermint/src/abci/doc/response-finalizeblock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ABCI documentation](https://github.com/cometbft/cometbft/blob/v0.38.x/spec/abci/abci++_methods.md#finalizeblock)
1 change: 1 addition & 0 deletions tendermint/src/abci/doc/response-verifyvoteextension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ABCI documentation](https://github.com/cometbft/cometbft/blob/v0.38.x/spec/abci/abci++_methods.md#verifyvoteextension)
12 changes: 12 additions & 0 deletions tendermint/src/abci/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub(super) mod check_tx;
pub(super) mod deliver_tx;
pub(super) mod echo;
pub(super) mod end_block;
pub(super) mod extend_vote;
pub(super) mod finalize_block;
pub(super) mod info;
pub(super) mod init_chain;
pub(super) mod load_snapshot_chunk;
Expand All @@ -34,13 +36,16 @@ pub(super) mod prepare_proposal;
pub(super) mod process_proposal;
pub(super) mod query;
pub(super) mod set_option;
pub(super) mod verify_vote_extension;

pub use apply_snapshot_chunk::ApplySnapshotChunk;
pub use begin_block::BeginBlock;
pub use check_tx::{CheckTx, CheckTxKind};
pub use deliver_tx::DeliverTx;
pub use echo::Echo;
pub use end_block::EndBlock;
pub use extend_vote::ExtendVote;
pub use finalize_block::FinalizeBlock;
pub use info::Info;
pub use init_chain::InitChain;
pub use load_snapshot_chunk::LoadSnapshotChunk;
Expand All @@ -49,6 +54,7 @@ pub use prepare_proposal::PrepareProposal;
pub use process_proposal::ProcessProposal;
pub use query::Query;
pub use set_option::SetOption;
pub use verify_vote_extension::VerifyVoteExtension;

/// The consensus category of ABCI requests.
#[allow(clippy::large_enum_variant)]
Expand All @@ -68,6 +74,12 @@ pub enum ConsensusRequest {
EndBlock(EndBlock),
#[doc = include_str!("doc/request-commit.md")]
Commit,
#[doc = include_str!("doc/request-extendvote.md")]
ExtendVote(ExtendVote),
#[doc = include_str!("doc/request-verifyvoteextension.md")]
VerifyVoteExtension(VerifyVoteExtension),
#[doc = include_str!("doc/request-finalizeblock.md")]
FinalizeBlock(FinalizeBlock),
}

/// The mempool category of ABCI requests.
Expand Down
40 changes: 40 additions & 0 deletions tendermint/src/abci/request/extend_vote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::{block, Hash};

#[doc = include_str!("../doc/request-extendvote.md")]
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct ExtendVote {
pub hash: Hash,
pub height: block::Height,
}

// =============================================================================
// Protobuf conversions
// =============================================================================

mod v0_38 {
use super::ExtendVote;
use tendermint_proto::v0_38 as pb;
use tendermint_proto::Protobuf;

impl From<ExtendVote> for pb::abci::RequestExtendVote {
fn from(extend_vote: ExtendVote) -> Self {
Self {
hash: extend_vote.hash.into(),
height: extend_vote.height.into(),
}
}
}

impl TryFrom<pb::abci::RequestExtendVote> for ExtendVote {
type Error = crate::Error;

fn try_from(message: pb::abci::RequestExtendVote) -> Result<Self, Self::Error> {
Ok(Self {
hash: message.hash.try_into()?,
height: message.height.try_into()?,
})
}
}

impl Protobuf<pb::abci::RequestExtendVote> for ExtendVote {}
}
85 changes: 85 additions & 0 deletions tendermint/src/abci/request/finalize_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use crate::prelude::*;
use crate::{
abci::types::{CommitInfo, Misbehavior},
account, block, Hash, Time,
};
use bytes::Bytes;

#[doc = include_str!("../doc/request-finalizeblock.md")]
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct FinalizeBlock {
/// List of transactions committed as part of the block.
pub txs: Vec<Bytes>,
/// Information about the last commit, obtained from the block that was just decided.
///
/// This includes the round, the list of validators, and which validators
/// signed the last block.
pub decided_last_commit: CommitInfo,
/// Evidence of validator misbehavior.
pub misbehavior: Vec<Misbehavior>,
/// Merkle root hash of the fields of the decided block.
pub hash: Hash,
/// The height of the finalized block.
pub height: block::Height,
/// Timestamp of the finalized block.
pub time: Time,
/// Merkle root of the next validator set.
pub next_validators_hash: Hash,
/// The address of the public key of the original proposer of the block.
pub proposer_address: account::Id,
}

// =============================================================================
// Protobuf conversions
// =============================================================================

mod v0_38 {
use super::FinalizeBlock;
use crate::Error;
use tendermint_proto::v0_38 as pb;
use tendermint_proto::Protobuf;

impl From<FinalizeBlock> for pb::abci::RequestFinalizeBlock {
fn from(value: FinalizeBlock) -> Self {
Self {
txs: value.txs,
decided_last_commit: Some(value.decided_last_commit.into()),
misbehavior: value.misbehavior.into_iter().map(Into::into).collect(),
hash: value.hash.into(),
height: value.height.into(),
time: Some(value.time.into()),
next_validators_hash: value.next_validators_hash.into(),
proposer_address: value.proposer_address.into(),
}
}
}

impl TryFrom<pb::abci::RequestFinalizeBlock> for FinalizeBlock {
type Error = Error;

fn try_from(message: pb::abci::RequestFinalizeBlock) -> Result<Self, Self::Error> {
Ok(Self {
txs: message.txs,
decided_last_commit: message
.decided_last_commit
.ok_or_else(Error::missing_last_commit_info)?
.try_into()?,
misbehavior: message
.misbehavior
.into_iter()
.map(TryInto::try_into)
.collect::<Result<_, _>>()?,
hash: message.hash.try_into()?,
height: message.height.try_into()?,
time: message
.time
.ok_or_else(Error::missing_timestamp)?
.try_into()?,
next_validators_hash: message.next_validators_hash.try_into()?,
proposer_address: message.proposer_address.try_into()?,
})
}
}

impl Protobuf<pb::abci::RequestFinalizeBlock> for FinalizeBlock {}
}
136 changes: 95 additions & 41 deletions tendermint/src/abci/request/prepare_proposal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::*;
use crate::{
abci::types::{CommitInfo, Misbehavior},
account, block, Error, Hash, Time,
account, block, Hash, Time,
};

use bytes::Bytes;
Expand All @@ -27,52 +27,106 @@ pub struct PrepareProposal {
// Protobuf conversions
// =============================================================================

// The PrepareProposal request has been added in 0.37.
mod v0_37 {
use super::PrepareProposal;
use crate::{prelude::*, Error};
use tendermint_proto::v0_37::abci as pb;
use tendermint_proto::Protobuf;

use tendermint_proto::v0_37::abci as pb;
use tendermint_proto::Protobuf;
impl From<PrepareProposal> for pb::RequestPrepareProposal {
fn from(value: PrepareProposal) -> Self {
Self {
max_tx_bytes: value.max_tx_bytes,
txs: value.txs,
local_last_commit: value.local_last_commit.map(Into::into),
misbehavior: value.misbehavior.into_iter().map(Into::into).collect(),
height: value.height.into(),
time: Some(value.time.into()),
next_validators_hash: value.next_validators_hash.into(),
proposer_address: value.proposer_address.into(),
}
}
}

impl TryFrom<pb::RequestPrepareProposal> for PrepareProposal {
type Error = Error;

impl From<PrepareProposal> for pb::RequestPrepareProposal {
fn from(value: PrepareProposal) -> Self {
Self {
max_tx_bytes: value.max_tx_bytes,
txs: value.txs,
local_last_commit: value.local_last_commit.map(Into::into),
misbehavior: value.misbehavior.into_iter().map(Into::into).collect(),
height: value.height.into(),
time: Some(value.time.into()),
next_validators_hash: value.next_validators_hash.into(),
proposer_address: value.proposer_address.into(),
fn try_from(message: pb::RequestPrepareProposal) -> Result<Self, Self::Error> {
let req = Self {
max_tx_bytes: message.max_tx_bytes,
txs: message.txs,
local_last_commit: message
.local_last_commit
.map(TryInto::try_into)
.transpose()?,
misbehavior: message
.misbehavior
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?,
height: message.height.try_into()?,
time: message
.time
.ok_or_else(Error::missing_timestamp)?
.try_into()?,
next_validators_hash: message.next_validators_hash.try_into()?,
proposer_address: message.proposer_address.try_into()?,
};
Ok(req)
}
}

impl Protobuf<pb::RequestPrepareProposal> for PrepareProposal {}
}

impl TryFrom<pb::RequestPrepareProposal> for PrepareProposal {
type Error = Error;
mod v0_38 {
use super::PrepareProposal;
use crate::{prelude::*, Error};
use tendermint_proto::v0_38::abci as pb;
use tendermint_proto::Protobuf;

fn try_from(message: pb::RequestPrepareProposal) -> Result<Self, Self::Error> {
let req = Self {
max_tx_bytes: message.max_tx_bytes,
txs: message.txs,
local_last_commit: message
.local_last_commit
.map(TryInto::try_into)
.transpose()?,
misbehavior: message
.misbehavior
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?,
height: message.height.try_into()?,
time: message
.time
.ok_or_else(Error::missing_timestamp)?
.try_into()?,
next_validators_hash: message.next_validators_hash.try_into()?,
proposer_address: message.proposer_address.try_into()?,
};
Ok(req)
impl From<PrepareProposal> for pb::RequestPrepareProposal {
fn from(value: PrepareProposal) -> Self {
Self {
max_tx_bytes: value.max_tx_bytes,
txs: value.txs,
local_last_commit: value.local_last_commit.map(Into::into),
misbehavior: value.misbehavior.into_iter().map(Into::into).collect(),
height: value.height.into(),
time: Some(value.time.into()),
next_validators_hash: value.next_validators_hash.into(),
proposer_address: value.proposer_address.into(),
}
}
}
}

impl Protobuf<pb::RequestPrepareProposal> for PrepareProposal {}
impl TryFrom<pb::RequestPrepareProposal> for PrepareProposal {
type Error = Error;

fn try_from(message: pb::RequestPrepareProposal) -> Result<Self, Self::Error> {
let req = Self {
max_tx_bytes: message.max_tx_bytes,
txs: message.txs,
local_last_commit: message
.local_last_commit
.map(TryInto::try_into)
.transpose()?,
misbehavior: message
.misbehavior
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?,
height: message.height.try_into()?,
time: message
.time
.ok_or_else(Error::missing_timestamp)?
.try_into()?,
next_validators_hash: message.next_validators_hash.try_into()?,
proposer_address: message.proposer_address.try_into()?,
};
Ok(req)
}
}

impl Protobuf<pb::RequestPrepareProposal> for PrepareProposal {}
}
Loading

0 comments on commit 36eca7a

Please sign in to comment.