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

Update cometbft-proto to protobufs in CometBFT v1.0 (pre-release) #7

Merged
merged 14 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
22 changes: 22 additions & 0 deletions .changelog/unreleased/breaking-changes/7-proto-v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- `[cometbft-proto]` Change to versioned protobufs published by CometBFT 1.0
([\#7](https://github.com/cometbft/cometbft-rs/pull/7)):
* Instead of side-by-side generated outputs in `v0_34`, `v0_37`, and `v0_38`
produced from respective checkouts of the CometBFT repository, use the
single release (currently at 1.0.0-alpha.1) and generate all protobuf
structures at once.
* In the new versioned module structure corresponding to the CometBFT 1.0
protobuf packages, modules represending protocol domains come to the top
level, e.g. `crate::abci`, `crate::types`. Each of these has a `v1` module
corresponding to the protobufs released in 1.0.0, and possibly a series of
`v1beta1`, `v1beta2`, ... modules with earlier revisions of the protocol,
as documented in the [CometBFT protobuf README][proto-readme]
- `[cometbft]` Update to the new version structure in `cometbft-proto` ([\#7](https://github.com/cometbft/cometbft-rs/pull/7)):
* Relocated the modules for version-targeted ABCI support. Now under the
`abci` module, `v1` provides the `Request` and `Response` enum definitions
with the variants valid per CometBFT 1.0, while `v1beta*` modules provide
revisions corresponding to earlier ABCI versions.
- `[cometbft-rpc]` Update to changes in CometBFT 1.0 ([\#7](https://github.com/cometbft/cometbft-rs/pull/7)):
* The version variants in `CompatMode` are `V0_34` and `V1`, to reflect that
the RPC dialect used since 0.37 has graduated into 1.0.

[proto-readme]: https://github.com/cometbft/cometbft/blob/main/proto/README.md
17 changes: 9 additions & 8 deletions cometbft/src/abci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ pub mod request;
pub mod response;
pub mod types;

pub use crate::v0_38::abci::request::Request;
pub use crate::v0_38::abci::request::{
ConsensusRequest, InfoRequest, MempoolRequest, SnapshotRequest,
};
pub use crate::v0_38::abci::response::Response;
pub use crate::v0_38::abci::response::{
ConsensusResponse, InfoResponse, MempoolResponse, SnapshotResponse,
};
pub mod v1;
pub mod v1beta1;
pub mod v1beta2;
pub mod v1beta3;

pub use v1::request::Request;
pub use v1::request::{ConsensusRequest, InfoRequest, MempoolRequest, SnapshotRequest};
pub use v1::response::Response;
pub use v1::response::{ConsensusResponse, InfoResponse, MempoolResponse, SnapshotResponse};

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

Expand Down
8 changes: 4 additions & 4 deletions cometbft/src/abci/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ mod v0_34 {
use crate::prelude::*;
use core::convert::{TryFrom, TryInto};

use cometbft_proto::v0_34::abci as pb;
use cometbft_proto::abci::v1beta1 as pb;
use cometbft_proto::Protobuf;

impl From<EventAttribute> for pb::EventAttribute {
Expand Down Expand Up @@ -268,7 +268,7 @@ mod v0_37 {
use crate::prelude::*;
use core::convert::{TryFrom, TryInto};

use cometbft_proto::v0_37::abci as pb;
use cometbft_proto::abci::v1beta2 as pb;
use cometbft_proto::Protobuf;

impl From<EventAttribute> for pb::EventAttribute {
Expand Down Expand Up @@ -322,12 +322,12 @@ mod v0_37 {
impl Protobuf<pb::Event> for Event {}
}

mod v0_38 {
mod v1 {
use super::{Event, EventAttribute};
use crate::prelude::*;
use core::convert::{TryFrom, TryInto};

use cometbft_proto::v0_38::abci as pb;
use cometbft_proto::abci::v1 as pb;
use cometbft_proto::Protobuf;

impl From<EventAttribute> for pb::EventAttribute {
Expand Down
46 changes: 41 additions & 5 deletions cometbft/src/abci/request/apply_snapshot_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ pub struct ApplySnapshotChunk {
// Protobuf conversions
// =============================================================================

cometbft_pb_modules! {
mod v1 {
use super::ApplySnapshotChunk;
use cometbft_proto::abci::v1 as pb;
use cometbft_proto::Protobuf;

impl From<ApplySnapshotChunk> for pb::abci::RequestApplySnapshotChunk {
impl From<ApplySnapshotChunk> for pb::ApplySnapshotChunkRequest {
fn from(apply_snapshot_chunk: ApplySnapshotChunk) -> Self {
Self {
index: apply_snapshot_chunk.index,
Expand All @@ -53,10 +55,12 @@ cometbft_pb_modules! {
}
}

impl TryFrom<pb::abci::RequestApplySnapshotChunk> for ApplySnapshotChunk {
impl TryFrom<pb::ApplySnapshotChunkRequest> for ApplySnapshotChunk {
type Error = crate::Error;

fn try_from(apply_snapshot_chunk: pb::abci::RequestApplySnapshotChunk) -> Result<Self, Self::Error> {
fn try_from(
apply_snapshot_chunk: pb::ApplySnapshotChunkRequest,
) -> Result<Self, Self::Error> {
Ok(Self {
index: apply_snapshot_chunk.index,
chunk: apply_snapshot_chunk.chunk,
Expand All @@ -65,5 +69,37 @@ cometbft_pb_modules! {
}
}

impl Protobuf<pb::abci::RequestApplySnapshotChunk> for ApplySnapshotChunk {}
impl Protobuf<pb::ApplySnapshotChunkRequest> for ApplySnapshotChunk {}
}

mod v1beta1 {
use super::ApplySnapshotChunk;
use cometbft_proto::abci::v1beta1 as pb;
use cometbft_proto::Protobuf;

impl From<ApplySnapshotChunk> for pb::RequestApplySnapshotChunk {
fn from(apply_snapshot_chunk: ApplySnapshotChunk) -> Self {
Self {
index: apply_snapshot_chunk.index,
chunk: apply_snapshot_chunk.chunk,
sender: apply_snapshot_chunk.sender,
}
}
}

impl TryFrom<pb::RequestApplySnapshotChunk> for ApplySnapshotChunk {
type Error = crate::Error;

fn try_from(
apply_snapshot_chunk: pb::RequestApplySnapshotChunk,
) -> Result<Self, Self::Error> {
Ok(Self {
index: apply_snapshot_chunk.index,
chunk: apply_snapshot_chunk.chunk,
sender: apply_snapshot_chunk.sender,
})
}
}

impl Protobuf<pb::RequestApplySnapshotChunk> for ApplySnapshotChunk {}
}
24 changes: 12 additions & 12 deletions cometbft/src/abci/request/begin_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ pub struct BeginBlock {
// Protobuf conversions
// =============================================================================

mod v0_34 {
mod v1beta1 {
use super::BeginBlock;
use crate::Error;
use cometbft_proto::v0_34 as pb;
use cometbft_proto::abci::v1beta1 as pb;
use cometbft_proto::Protobuf;

impl From<BeginBlock> for pb::abci::RequestBeginBlock {
impl From<BeginBlock> for pb::RequestBeginBlock {
fn from(begin_block: BeginBlock) -> Self {
Self {
hash: begin_block.hash.into(),
Expand All @@ -51,10 +51,10 @@ mod v0_34 {
}
}

impl TryFrom<pb::abci::RequestBeginBlock> for BeginBlock {
impl TryFrom<pb::RequestBeginBlock> for BeginBlock {
type Error = Error;

fn try_from(begin_block: pb::abci::RequestBeginBlock) -> Result<Self, Self::Error> {
fn try_from(begin_block: pb::RequestBeginBlock) -> Result<Self, Self::Error> {
Ok(Self {
hash: begin_block.hash.try_into()?,
header: begin_block
Expand All @@ -74,16 +74,16 @@ mod v0_34 {
}
}

impl Protobuf<pb::abci::RequestBeginBlock> for BeginBlock {}
impl Protobuf<pb::RequestBeginBlock> for BeginBlock {}
}

mod v0_37 {
mod v1beta2 {
use super::BeginBlock;
use crate::Error;
use cometbft_proto::v0_37 as pb;
use cometbft_proto::abci::v1beta2 as pb;
use cometbft_proto::Protobuf;

impl From<BeginBlock> for pb::abci::RequestBeginBlock {
impl From<BeginBlock> for pb::RequestBeginBlock {
fn from(begin_block: BeginBlock) -> Self {
Self {
hash: begin_block.hash.into(),
Expand All @@ -98,10 +98,10 @@ mod v0_37 {
}
}

impl TryFrom<pb::abci::RequestBeginBlock> for BeginBlock {
impl TryFrom<pb::RequestBeginBlock> for BeginBlock {
type Error = Error;

fn try_from(begin_block: pb::abci::RequestBeginBlock) -> Result<Self, Self::Error> {
fn try_from(begin_block: pb::RequestBeginBlock) -> Result<Self, Self::Error> {
Ok(Self {
hash: begin_block.hash.try_into()?,
header: begin_block
Expand All @@ -121,5 +121,5 @@ mod v0_37 {
}
}

impl Protobuf<pb::abci::RequestBeginBlock> for BeginBlock {}
impl Protobuf<pb::RequestBeginBlock> for BeginBlock {}
}
45 changes: 40 additions & 5 deletions cometbft/src/abci/request/check_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ pub enum CheckTxKind {
// Protobuf conversions
// =============================================================================

cometbft_pb_modules! {
mod v1 {
use super::{CheckTx, CheckTxKind};
use cometbft_proto::abci::v1 as pb;
use cometbft_proto::Protobuf;

impl From<CheckTx> for pb::abci::RequestCheckTx {
impl From<CheckTx> for pb::CheckTxRequest {
fn from(check_tx: CheckTx) -> Self {
Self {
tx: check_tx.tx,
Expand All @@ -47,10 +49,10 @@ cometbft_pb_modules! {
}
}

impl TryFrom<pb::abci::RequestCheckTx> for CheckTx {
impl TryFrom<pb::CheckTxRequest> for CheckTx {
type Error = crate::Error;

fn try_from(check_tx: pb::abci::RequestCheckTx) -> Result<Self, Self::Error> {
fn try_from(check_tx: pb::CheckTxRequest) -> Result<Self, Self::Error> {
let kind = match check_tx.r#type {
0 => CheckTxKind::New,
1 => CheckTxKind::Recheck,
Expand All @@ -63,5 +65,38 @@ cometbft_pb_modules! {
}
}

impl Protobuf<pb::abci::RequestCheckTx> for CheckTx {}
impl Protobuf<pb::CheckTxRequest> for CheckTx {}
}

mod v1beta1 {
use super::{CheckTx, CheckTxKind};
use cometbft_proto::abci::v1beta1 as pb;
use cometbft_proto::Protobuf;

impl From<CheckTx> for pb::RequestCheckTx {
fn from(check_tx: CheckTx) -> Self {
Self {
tx: check_tx.tx,
r#type: check_tx.kind as i32,
}
}
}

impl TryFrom<pb::RequestCheckTx> for CheckTx {
type Error = crate::Error;

fn try_from(check_tx: pb::RequestCheckTx) -> Result<Self, Self::Error> {
let kind = match check_tx.r#type {
0 => CheckTxKind::New,
1 => CheckTxKind::Recheck,
_ => return Err(crate::Error::unsupported_check_tx_type()),
};
Ok(Self {
tx: check_tx.tx,
kind,
})
}
}

impl Protobuf<pb::RequestCheckTx> for CheckTx {}
}
34 changes: 6 additions & 28 deletions cometbft/src/abci/request/deliver_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,24 @@ pub struct DeliverTx {
// Protobuf conversions
// =============================================================================

mod v0_34 {
mod v1beta1 {
use super::DeliverTx;
use cometbft_proto::v0_34 as pb;
use cometbft_proto::abci::v1beta1 as pb;
use cometbft_proto::Protobuf;

impl From<DeliverTx> for pb::abci::RequestDeliverTx {
impl From<DeliverTx> for pb::RequestDeliverTx {
fn from(deliver_tx: DeliverTx) -> Self {
Self { tx: deliver_tx.tx }
}
}

impl TryFrom<pb::abci::RequestDeliverTx> for DeliverTx {
impl TryFrom<pb::RequestDeliverTx> for DeliverTx {
type Error = crate::Error;

fn try_from(deliver_tx: pb::abci::RequestDeliverTx) -> Result<Self, Self::Error> {
fn try_from(deliver_tx: pb::RequestDeliverTx) -> Result<Self, Self::Error> {
Ok(Self { tx: deliver_tx.tx })
}
}

impl Protobuf<pb::abci::RequestDeliverTx> for DeliverTx {}
}

mod v0_37 {
use super::DeliverTx;
use cometbft_proto::v0_37 as pb;
use cometbft_proto::Protobuf;

impl From<DeliverTx> for pb::abci::RequestDeliverTx {
fn from(deliver_tx: DeliverTx) -> Self {
Self { tx: deliver_tx.tx }
}
}

impl TryFrom<pb::abci::RequestDeliverTx> for DeliverTx {
type Error = crate::Error;

fn try_from(deliver_tx: pb::abci::RequestDeliverTx) -> Result<Self, Self::Error> {
Ok(Self { tx: deliver_tx.tx })
}
}

impl Protobuf<pb::abci::RequestDeliverTx> for DeliverTx {}
impl Protobuf<pb::RequestDeliverTx> for DeliverTx {}
}
Loading