Skip to content

Commit

Permalink
rpc: take over tendermint::abci
Browse files Browse the repository at this point in the history
The existing contents of the `tendermint::abci` module note that they're
only for the purpose of implementing the RPC endpoints, not a general
ABCI implementation.

Moving that code from the `tendermint` crate to the `tendermint-rpc`
crate decouples the RPC interface from improvements to the ABCI domain
modeling. Eventually, it would be good to eliminate this code and align
it with the new ABCI domain types.
  • Loading branch information
hdevalence committed Sep 10, 2021
1 parent d4b9a37 commit c04c29c
Show file tree
Hide file tree
Showing 33 changed files with 89 additions and 82 deletions.
2 changes: 1 addition & 1 deletion light-client/src/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{components::io::IoError, types::PeerId};

use tendermint::abci::transaction::Hash;
use tendermint_rpc::abci::transaction::Hash;

use contracts::contract_trait;

Expand Down
2 changes: 1 addition & 1 deletion light-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use crate::types::{Height, LightBlock, PeerId, SignedHeader, Time, TrustThreshold, ValidatorSet};

use serde::{Deserialize, Serialize};
use tendermint::abci::transaction::Hash;
use tendermint_rpc as rpc;
use tendermint_rpc::abci::transaction::Hash;

use crate::components::clock::Clock;
use crate::components::io::{AtHeight, Io, IoError};
Expand Down
1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ subtle-encoding = { version = "0.5", features = ["bech32-preview"] }
url = "2.2"
walkdir = "2.3"
flex-error = { version = "0.4.1", default-features = false }
subtle = "2"

# Optional dependencies
async-trait = { version = "0.1", optional = true }
Expand Down
34 changes: 34 additions & 0 deletions rpc/src/abci.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! Old ABCI structures, formerly defined in `tendermint::abci`.
//!
//! The original contents of `tendermint::abci` were created only to model RPC
//! responses, not to model ABCI itself:
//!
//! > NOTE: This module contains types for ABCI responses as consumed from RPC
//! endpoints. It does not contain an ABCI protocol implementation.
//!
//! The old types should be eliminated and
//! merged with the new ABCI domain types. Moving them here in the meantime
//! disentangles improving the ABCI domain modeling from changes to the RPC
//! interface.

mod code;
mod data;
mod gas;
mod info;
mod log;
mod path;

pub mod responses;
pub mod tag;
pub mod transaction;

pub use self::{
code::Code,
data::Data,
gas::Gas,
info::Info,
log::Log,
path::Path,
responses::{DeliverTx, Event, Responses},
transaction::Transaction,
};
File renamed without changes.
2 changes: 1 addition & 1 deletion tendermint/src/abci/data.rs → rpc/src/abci/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
/// application-specific rules.
#[derive(Clone, Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Data(#[serde(with = "crate::serializers::bytes::base64string")] Vec<u8>);
pub struct Data(#[serde(with = "tendermint::serializers::bytes::base64string")] Vec<u8>);

impl From<Vec<u8>> for Data {
fn from(value: Vec<u8>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/abci/gas.rs → rpc/src/abci/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
//!
//! <https://tendermint.com/docs/spec/abci/apps.html#gas>

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

/// Gas: representation of transaction processing resource costs
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tendermint/src/abci/path.rs → rpc/src/abci/path.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Paths to ABCI data

use crate::error::Error;
use serde::{Deserialize, Serialize};
use std::{
fmt::{self, Display},
str::FromStr,
};
use tendermint::error::Error;

/// Path to ABCI data
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! ABCI response types used by the `/block_results` RPC endpoint.

use super::{code::Code, data::Data, gas::Gas, info::Info, log::Log, tag::Tag};
use crate::{consensus, serializers, validator};
use serde::{Deserialize, Deserializer, Serialize};
use std::fmt::{self, Display};
use tendermint::{consensus, serializers, validator};

/// Responses for ABCI calls which occur during block processing.
///
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/abci/tag.rs → rpc/src/abci/tag.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Tags

use crate::error::Error;
use serde::{Deserialize, Serialize};
use std::{fmt, str::FromStr};
use tendermint::error::Error;
use tendermint_proto::serializers::bytes::base64string;

/// Tags
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Transaction hashes

use crate::error::Error;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::{
fmt::{self, Debug, Display},
str::FromStr,
};
use subtle::{self, ConstantTimeEq};
use subtle_encoding::hex;
use tendermint::error::Error;

/// Size of a transaction hash in bytes
pub const LENGTH: usize = 32;
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub use transport::http::{HttpClient, HttpClientUrl};
#[cfg(feature = "websocket-client")]
pub use transport::websocket::{WebSocketClient, WebSocketClientDriver, WebSocketClientUrl};

use crate::abci::{self, Transaction};
use crate::endpoint::validators::DEFAULT_VALIDATORS_PER_PAGE;
use crate::endpoint::*;
use crate::paging::Paging;
use crate::query::Query;
use crate::{Error, Order, SimpleRequest};
use async_trait::async_trait;
use std::time::Duration;
use tendermint::abci::{self, Transaction};
use tendermint::block::Height;
use tendermint::evidence::Evidence;
use tendermint::Genesis;
Expand Down
3 changes: 1 addition & 2 deletions rpc/src/client/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use futures::StreamExt;
use std::str::FromStr;
use structopt::StructOpt;
use tendermint::abci::transaction::Hash;
use tendermint::abci::{Path, Transaction};
use tendermint_rpc::abci::{transaction::Hash, Path, Transaction};
use tendermint_rpc::query::Query;
use tendermint_rpc::{
Client, Error, HttpClient, Order, Paging, Scheme, Subscription, SubscriptionClient, Url,
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/endpoint/abci_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use serde::{Deserialize, Serialize};

use tendermint::abci::{Code, Log, Path};
use crate::abci::{Code, Log, Path};
use tendermint::block;
use tendermint::merkle::proof::Proof;
use tendermint::serializers;
Expand Down
3 changes: 2 additions & 1 deletion rpc/src/endpoint/block_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use serde::{Deserialize, Serialize};

use tendermint::{abci, block, consensus, validator};
use crate::abci;
use tendermint::{block, consensus, validator};

/// Get ABCI results at a given height.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/endpoint/broadcast/tx_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use serde::{Deserialize, Serialize};

use tendermint::abci::{transaction, Code, Data, Log, Transaction};
use crate::abci::{transaction, Code, Data, Log, Transaction};

/// `/broadcast_tx_async`: broadcast a transaction and return immediately.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
Expand Down
8 changes: 3 additions & 5 deletions rpc/src/endpoint/broadcast/tx_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

use serde::{Deserialize, Serialize};

use tendermint::abci::responses::Codespace;
use tendermint::abci::{Event, Gas, Info};
use tendermint::{
abci::{transaction, Code, Data, Log, Transaction},
block,
use crate::abci::{
responses::Codespace, transaction, Code, Data, Event, Gas, Info, Log, Transaction,
};
use tendermint::block;

/// `/broadcast_tx_commit`: only returns error if `mempool.CheckTx()` errs or
/// if we timeout waiting for tx to commit.
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/endpoint/broadcast/tx_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use serde::{Deserialize, Serialize};

use tendermint::abci::{transaction, Code, Data, Log, Transaction};
use crate::abci::{transaction, Code, Data, Log, Transaction};

/// `/broadcast_tx_sync`: returns with the response from `CheckTx`.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
Expand Down
3 changes: 2 additions & 1 deletion rpc/src/endpoint/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

use crate::Method;

use crate::abci::transaction;
use serde::{Deserialize, Serialize};
use tendermint::{abci::transaction, evidence::Evidence};
use tendermint::evidence::Evidence;

/// `/broadcast_evidence`: broadcast an evidence.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
Expand Down
5 changes: 3 additions & 2 deletions rpc/src/endpoint/tx.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! `/tx` endpoint JSON-RPC wrapper

use crate::abci;
use crate::Method;
use serde::{Deserialize, Serialize};
use tendermint::{abci, block};
use tendermint::block;
use tendermint_proto::types::TxProof;

/// Request for finding a transaction by its hash.
Expand All @@ -12,7 +13,7 @@ pub struct Request {
///
/// Serialized internally into a base64-encoded string before sending to
/// the RPC server.
#[serde(with = "tendermint::serializers::hash_base64")]
#[serde(with = "crate::serializers::hash_base64")]
pub hash: abci::transaction::Hash,
/// Whether or not to include the proofs of the transaction's inclusion in
/// the block.
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! RPC subscription event-related data structures.

use crate::abci::responses::{BeginBlock, EndBlock};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tendermint::abci::responses::{BeginBlock, EndBlock};
use tendermint::Block;

use crate::query::EventType;
Expand Down Expand Up @@ -72,5 +72,5 @@ pub struct TxResult {
pub log: Option<String>,
pub gas_wanted: Option<String>,
pub gas_used: Option<String>,
pub events: Vec<tendermint::abci::Event>,
pub events: Vec<crate::abci::Event>,
}
2 changes: 2 additions & 0 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub use client::{HttpClient, HttpClientUrl};
#[cfg(feature = "websocket-client")]
pub use client::{WebSocketClient, WebSocketClientDriver, WebSocketClientUrl};

pub mod abci;
pub mod endpoint;
pub mod error;
pub mod event;
Expand All @@ -50,6 +51,7 @@ pub mod request;
pub mod response;
pub mod response_error;
mod rpc_url;
mod serializers;
mod utils;
mod version;

Expand Down
1 change: 1 addition & 0 deletions rpc/src/serializers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod hash_base64;
File renamed without changes.
Loading

0 comments on commit c04c29c

Please sign in to comment.