Skip to content

Commit

Permalink
Merge 7d9572c into 6379c82
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabaluev authored Mar 1, 2023
2 parents 6379c82 + 7d9572c commit b40a935
Show file tree
Hide file tree
Showing 334 changed files with 18,909 additions and 5,543 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- [`tendermint`] Version-specific definitions for ABCI `Request` and `Response`
enums under `v0_34::abci` and `v0_37::abci`, containing only the method variants
present in each of the respective protocol versions.
`Request` and `Response` defined under `v0_37` are re-exported under
the non-versioned `abci` module name, but the `SetOption` variant is not present
in these latest versions of the enums.
([#1193](https://github.com/informalsystems/tendermint-rs/pull/1193))
- [`tendermint-abci`] Change the frame length encoding in the ABCI wire protocol
to unsigned varint, to correspond to the changes in Tendermint Core 0.37.
No compatibility with 0.34 is provided at the moment.
([#1193](https://github.com/informalsystems/tendermint-rs/pull/1193))
- [`tendermint-rpc`] Changed the signature of `WebSocketClient::new_with_config`
to accept a `WebSocketConfig` struct value rather than an `Option`.
([#1193](https://github.com/informalsystems/tendermint-rs/pull/1193))
- [`tendermint-proto`] The `serializers::evidence` module has been made private.
([#1193](https://github.com/informalsystems/tendermint-rs/pull/1193))
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- [`tendermint-proto`] Generate prost bindings for Tendermint 0.34 and 0.37 side by side.
The version-specific structs are placed under the `tendermint::v0_34` and
`tendermint::v0_37` module namespaces, respectively. The names under
`tendermint::v0_37` are also re-exported under `tendermint`.
([#1193](https://github.com/informalsystems/tendermint-rs/pull/1193))
- [`tendermint`] New and updated ABCI domain types for Tendermint Core v0.37
([#1193](https://github.com/informalsystems/tendermint-rs/pull/1193)).
- [`tendermint`] Protobuf conversions provided for both `v0_34` and `v0_37`
versions of the generated [`tendermint-proto`] structs, where applicable.
([#1193](https://github.com/informalsystems/tendermint-rs/pull/1193)).
- [`tendermint-rpc`] Introduce `client::CompatMode`, enumerating protocol
compatibility modes specifying the RPC data encoding used by the client.
An `HttpClient` can be created with a selected mode specified in the new
`builder` API, or have the mode changed afterwards (usually after
version discovery) by the added `set_compat_mode` method.
For `WebSocketClient`, the mode can only be specified at creation via the new
`builder` API.
([#1193](https://github.com/informalsystems/tendermint-rs/pull/1193))
- [`tendermint-abci`] Port ABCI application support to 0.37 Tendermint Core API.
No legacy support for 0.34 is provided at the moment.
([#1193](https://github.com/informalsystems/tendermint-rs/pull/1193)).
72 changes: 63 additions & 9 deletions abci/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ pub mod echo;
#[cfg(feature = "kvstore-app")]
pub mod kvstore;

use tendermint_proto::abci::{
request::Value, response, Request, RequestApplySnapshotChunk, RequestBeginBlock,
RequestCheckTx, RequestDeliverTx, RequestEcho, RequestEndBlock, RequestInfo, RequestInitChain,
RequestLoadSnapshotChunk, RequestOfferSnapshot, RequestQuery, Response,
ResponseApplySnapshotChunk, ResponseBeginBlock, ResponseCheckTx, ResponseCommit,
ResponseDeliverTx, ResponseEcho, ResponseEndBlock, ResponseFlush, ResponseInfo,
ResponseInitChain, ResponseListSnapshots, ResponseLoadSnapshotChunk, ResponseOfferSnapshot,
ResponseQuery,
use tendermint_proto::v0_37::abci::{
request::Value, response, response_process_proposal, Request, RequestApplySnapshotChunk,
RequestBeginBlock, RequestCheckTx, RequestDeliverTx, RequestEcho, RequestEndBlock, RequestInfo,
RequestInitChain, RequestLoadSnapshotChunk, RequestOfferSnapshot, RequestPrepareProposal,
RequestProcessProposal, RequestQuery, Response, ResponseApplySnapshotChunk, ResponseBeginBlock,
ResponseCheckTx, ResponseCommit, ResponseDeliverTx, ResponseEcho, ResponseEndBlock,
ResponseFlush, ResponseInfo, ResponseInitChain, ResponseListSnapshots,
ResponseLoadSnapshotChunk, ResponseOfferSnapshot, ResponsePrepareProposal,
ResponseProcessProposal, ResponseQuery,
};

/// An ABCI application.
Expand Down Expand Up @@ -98,6 +99,54 @@ pub trait Application: Send + Clone + 'static {
) -> ResponseApplySnapshotChunk {
Default::default()
}

/// A stage where the application can modify the list of transactions
/// in the preliminary proposal.
///
/// The default implementation implements the required behavior in a
/// very naive way, removing transactions off the end of the list
/// until the limit on the total size of the transaction is met as
/// specified in the `max_tx_bytes` field of the request, or there are
/// no more transactions. It's up to the application to implement
/// more elaborate removal strategies.
///
/// This method is introduced in ABCI++.
fn prepare_proposal(&self, request: RequestPrepareProposal) -> ResponsePrepareProposal {
// Per the ABCI++ spec: if the size of RequestPrepareProposal.txs is
// greater than RequestPrepareProposal.max_tx_bytes, the Application
// MUST remove transactions to ensure that the
// RequestPrepareProposal.max_tx_bytes limit is respected by those
// transactions returned in ResponsePrepareProposal.txs.
let RequestPrepareProposal {
mut txs,
max_tx_bytes,
..
} = request;
let max_tx_bytes: usize = max_tx_bytes.try_into().unwrap_or(0);
let mut total_tx_bytes: usize = txs
.iter()
.map(|tx| tx.len())
.fold(0, |acc, len| acc.saturating_add(len));
while total_tx_bytes > max_tx_bytes {
if let Some(tx) = txs.pop() {
total_tx_bytes = total_tx_bytes.saturating_sub(tx.len());
} else {
break;
}
}
ResponsePrepareProposal { txs }
}

/// A stage where the application can accept or reject the proposed block.
///
/// The default implementation returns the status value of `ACCEPT`.
///
/// This method is introduced in ABCI++.
fn process_proposal(&self, _request: RequestProcessProposal) -> ResponseProcessProposal {
ResponseProcessProposal {
status: response_process_proposal::ProposalStatus::Accept as i32,
}
}
}

/// Provides a mechanism for the [`Server`] to execute incoming requests while
Expand Down Expand Up @@ -134,7 +183,12 @@ impl<A: Application> RequestDispatcher for A {
Value::ApplySnapshotChunk(req) => {
response::Value::ApplySnapshotChunk(self.apply_snapshot_chunk(req))
},
Value::SetOption(_) => response::Value::SetOption(Default::default()),
Value::PrepareProposal(req) => {
response::Value::PrepareProposal(self.prepare_proposal(req))
},
Value::ProcessProposal(req) => {
response::Value::ProcessProposal(self.process_proposal(req))
},
}),
}
}
Expand Down
14 changes: 7 additions & 7 deletions abci/src/application/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use bytes::BytesMut;
use tendermint_proto::abci::{
use tendermint_proto::v0_37::abci::{
Event, EventAttribute, RequestCheckTx, RequestDeliverTx, RequestInfo, RequestQuery,
ResponseCheckTx, ResponseCommit, ResponseDeliverTx, ResponseInfo, ResponseQuery,
};
Expand Down Expand Up @@ -199,18 +199,18 @@ impl Application for KeyValueStoreApp {
r#type: "app".to_string(),
attributes: vec![
EventAttribute {
key: "key".to_string().into_bytes().into(),
value: key.to_string().into_bytes().into(),
key: "key".to_owned(),
value: key.to_owned(),
index: true,
},
EventAttribute {
key: "index_key".to_string().into_bytes().into(),
value: "index is working".to_string().into_bytes().into(),
key: "index_key".to_owned(),
value: "index is working".to_owned(),
index: true,
},
EventAttribute {
key: "noindex_key".to_string().into_bytes().into(),
value: "index is working".to_string().into_bytes().into(),
key: "noindex_key".to_owned(),
value: "index is working".to_owned(),
index: false,
},
],
Expand Down
19 changes: 5 additions & 14 deletions abci/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
use std::net::{TcpStream, ToSocketAddrs};

use tendermint_proto::abci::{
use tendermint_proto::v0_37::abci::{
request, response, Request, RequestApplySnapshotChunk, RequestBeginBlock, RequestCheckTx,
RequestCommit, RequestDeliverTx, RequestEcho, RequestEndBlock, RequestFlush, RequestInfo,
RequestInitChain, RequestListSnapshots, RequestLoadSnapshotChunk, RequestOfferSnapshot,
RequestQuery, RequestSetOption, ResponseApplySnapshotChunk, ResponseBeginBlock,
ResponseCheckTx, ResponseCommit, ResponseDeliverTx, ResponseEcho, ResponseEndBlock,
ResponseFlush, ResponseInfo, ResponseInitChain, ResponseListSnapshots,
ResponseLoadSnapshotChunk, ResponseOfferSnapshot, ResponseQuery, ResponseSetOption,
RequestQuery, ResponseApplySnapshotChunk, ResponseBeginBlock, ResponseCheckTx, ResponseCommit,
ResponseDeliverTx, ResponseEcho, ResponseEndBlock, ResponseFlush, ResponseInfo,
ResponseInitChain, ResponseListSnapshots, ResponseLoadSnapshotChunk, ResponseOfferSnapshot,
ResponseQuery,
};

use crate::{codec::ClientCodec, Error};
Expand Down Expand Up @@ -113,15 +113,6 @@ impl Client {
perform!(self, Commit, RequestCommit {})
}

/// Request that the application set an option to a particular value.
///
/// This request lacks specification and should not be used.
/// It will be removed in Tendermint Core v0.37.
#[deprecated(note = "The set_option ABCI method will be removed in Tendermint Core v0.37")]
pub fn set_option(&mut self, req: RequestSetOption) -> Result<ResponseSetOption, Error> {
perform!(self, SetOption, req)
}

/// Used during state sync to discover available snapshots on peers.
pub fn list_snapshots(&mut self) -> Result<ResponseListSnapshots, Error> {
perform!(self, ListSnapshots, RequestListSnapshots {})
Expand Down
19 changes: 4 additions & 15 deletions abci/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{

use bytes::{Buf, BufMut, BytesMut};
use prost::Message;
use tendermint_proto::abci::{Request, Response};
use tendermint_proto::v0_37::abci::{Request, Response};

use crate::error::Error;

Expand Down Expand Up @@ -130,7 +130,7 @@ where
message.encode(&mut buf).map_err(Error::encode)?;

let buf = buf.freeze();
encode_varint(buf.len() as u64, &mut dst);
prost::encoding::encode_varint(buf.len() as u64, &mut dst);
dst.put(buf);
Ok(())
}
Expand All @@ -142,11 +142,11 @@ where
{
let src_len = src.len();
let mut tmp = src.clone().freeze();
let encoded_len = match decode_varint(&mut tmp) {
let encoded_len = match prost::encoding::decode_varint(&mut tmp) {
Ok(len) => len,
// We've potentially only received a partial length delimiter
Err(_) if src_len <= MAX_VARINT_LENGTH => return Ok(None),
Err(e) => return Err(e),
Err(e) => return Err(Error::decode(e)),
};
let remaining = tmp.remaining() as u64;
if remaining < encoded_len {
Expand All @@ -164,14 +164,3 @@ where
Ok(Some(res))
}
}

// encode_varint and decode_varint will be removed once
// https://github.com/tendermint/tendermint/issues/5783 lands in Tendermint.
pub fn encode_varint<B: BufMut>(val: u64, mut buf: &mut B) {
prost::encoding::encode_varint(val << 1, &mut buf);
}

pub fn decode_varint<B: Buf>(mut buf: &mut B) -> Result<u64, Error> {
let len = prost::encoding::decode_varint(&mut buf).map_err(Error::decode)?;
Ok(len >> 1)
}
2 changes: 1 addition & 1 deletion abci/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! tendermint-abci errors
use flex_error::{define_error, DisplayError};
use tendermint_proto::abci::response::Value;
use tendermint_proto::v0_37::abci::response::Value;

define_error! {
Error {
Expand Down
2 changes: 1 addition & 1 deletion abci/tests/echo_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(all(feature = "client", feature = "echo-app"))]
mod echo_app_integration {
use tendermint_abci::{ClientBuilder, EchoApp, ServerBuilder};
use tendermint_proto::abci::RequestEcho;
use tendermint_proto::v0_37::abci::RequestEcho;

#[test]
fn echo() {
Expand Down
2 changes: 1 addition & 1 deletion abci/tests/kvstore_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod kvstore_app_integration {
use std::thread;

use tendermint_abci::{ClientBuilder, KeyValueStoreApp, ServerBuilder};
use tendermint_proto::abci::{RequestDeliverTx, RequestEcho, RequestQuery};
use tendermint_proto::v0_37::abci::{RequestDeliverTx, RequestEcho, RequestQuery};

#[test]
fn happy_path() {
Expand Down
14 changes: 5 additions & 9 deletions light-client/src/supervisor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Supervisor and Handle implementation.
use crossbeam_channel as channel;
use tendermint::evidence::{ConflictingHeadersEvidence, Evidence};
use tendermint::evidence::Evidence;

use crate::{
errors::Error,
Expand Down Expand Up @@ -284,19 +284,15 @@ impl Supervisor {
}

/// Report the given evidence of a fork.
// TODO: rework to supply LightClientAttackEvidence data
fn report_evidence(
&mut self,
provider: PeerId,
primary: &LightBlock,
witness: &LightBlock,
_primary: &LightBlock,
_witness: &LightBlock,
) -> Result<(), Error> {
let evidence = ConflictingHeadersEvidence::new(
primary.signed_header.clone(),
witness.signed_header.clone(),
);

self.evidence_reporter
.report(Evidence::ConflictingHeaders(Box::new(evidence)), provider)
.report(Evidence::LightClientAttackEvidence, provider)
.map_err(Error::io)?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion p2p/src/secret_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use chacha20poly1305::{
use merlin::Transcript;
use rand_core::OsRng;
use subtle::ConstantTimeEq;
use tendermint_proto as proto;
use tendermint_proto::v0_37 as proto;
use tendermint_std_ext::TryClone;
use x25519_dalek::{EphemeralSecret, PublicKey as EphemeralPublic};

Expand Down
4 changes: 2 additions & 2 deletions p2p/src/secret_connection/amino_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use core::convert::TryFrom;
use prost_derive::Message;
use tendermint_proto as proto;
use tendermint_proto::v0_37 as proto;

use crate::error::Error;

Expand Down Expand Up @@ -36,7 +36,7 @@ impl AuthSigMessage {
}
}

impl TryFrom<AuthSigMessage> for tendermint_proto::p2p::AuthSigMessage {
impl TryFrom<AuthSigMessage> for proto::p2p::AuthSigMessage {
type Error = Error;

fn try_from(amino_msg: AuthSigMessage) -> Result<Self, Error> {
Expand Down
2 changes: 1 addition & 1 deletion p2p/src/secret_connection/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::convert::TryInto;

use prost::Message as _;
use tendermint_proto as proto;
use tendermint_proto::v0_37 as proto;
use x25519_dalek::PublicKey as EphemeralPublic;

#[cfg(feature = "amino")]
Expand Down
Loading

0 comments on commit b40a935

Please sign in to comment.