Skip to content

Commit

Permalink
Resolve conflict in #986 (#1004)
Browse files Browse the repository at this point in the history
* Fix `cargo test` and add check to CI (#990)

* Relocate ABCI test to fix broken doctest

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Use tokio_test for mock client doctest

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add CI test for default features

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add `block_search` RPC endpoint (#991)

* Add block_search RPC endpoint and tests

* Add .changelog entry

* Fix comments

* tools: Fix `block_search` endpoint integration tests (#999)

Closes #998

* Bump integration test tendermint to v0.34.13
* Fix kvstore integration tests
* Bump tendermint version to v0.34.13 in CI

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* ci: Build and check tools (#997)

So far only the kvstore tests ran as part of the Github workfows. This
would leave opportunity for changes to introduce breakage to the builds
of the tools. In this change the same build and clippy stages are
introduced for the tools workspace that currently run for the top-level
one.

Signed-off-by: xla <self@xla.is>

* tools: Add `block_search` method to RPC probe (#1002)

* Add missing block_search endpoint
* Bump tendermint version to v0.34.13

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Co-authored-by: Shoaib Ahmed <sufialhussaini@gmail.com>
Co-authored-by: xla <a.simmerl@gmail.com>
  • Loading branch information
3 people authored Oct 6, 2021
1 parent ddd7d40 commit 540e37f
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 67 deletions.
1 change: 1 addition & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build-all = "build --workspace --all-targets --"
build-wasm-tendermint = "build -p tendermint --manifest-path tendermint/Cargo.toml --target wasm32-unknown-unknown --release --no-default-features --"
build-wasm-light-client = "build -p tendermint-light-client --manifest-path light-client/Cargo.toml --target wasm32-unknown-unknown --release --no-default-features --"
build-abci = "build --manifest-path abci/Cargo.toml --bin kvstore-rs --features binary,kvstore-app"
build-tools = "build --manifest-path tools/Cargo.toml --all-features --all-targets --workspace"
test-all-features = "test --all-features --no-fail-fast"
3 changes: 3 additions & 0 deletions .changelog/unreleased/features/832-block-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `[tendermint-rpc]` Add support for the `/block_search` RPC endpoint. See
<https://docs.tendermint.com/master/rpc/\#/Info/block_search> for details
([#832](https://github.com/informalsystems/tendermint-rs/issues/832))
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: build-wasm-light-client

tools:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: build-tools
15 changes: 15 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -Dwarnings -Drust-2018-idioms

clippy-tools-output:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true
- uses: actions-rs/clippy-check@v1
with:
name: clippy-tools-results
token: ${{ secrets.GITHUB_TOKEN }}
args: --manifest-path tools/kvstore-test/Cargo.toml --all-features --all-targets -- -Dwarnings -Drust-2018-idioms

docs:
runs-on: ubuntu-latest
steps:
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ jobs:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"

default-features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test

# TODO(shonfeder): remove duplication once GitHub addresses one of these
# - https://git.luolix.topmunity/t/support-for-yaml-anchors/16128/15
# - https://git.luolix.topmunity/t/reusing-sharing-inheriting-steps-between-jobs-declarations/16851/13
Expand All @@ -33,6 +45,7 @@ jobs:
with:
command: test-all-features
args: -p tendermint

tendermint-rpc:
runs-on: ubuntu-latest
steps:
Expand All @@ -45,6 +58,7 @@ jobs:
with:
command: test-all-features
args: -p tendermint-rpc

tendermint-proto:
runs-on: ubuntu-latest
steps:
Expand All @@ -57,6 +71,7 @@ jobs:
with:
command: test-all-features
args: -p tendermint-proto

tendermint-light-client:
runs-on: ubuntu-latest
steps:
Expand All @@ -69,6 +84,7 @@ jobs:
with:
command: test-all-features
args: -p tendermint-light-client

# From https://rustwasm.github.io/docs/wasm-bindgen/wasm-bindgen-test/continuous-integration.html#github-actions
tendermint-light-client-js:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -109,7 +125,7 @@ jobs:
runs-on: ubuntu-latest
services:
tendermint:
image: informaldev/tendermint:0.34.0
image: informaldev/tendermint:0.34.13
ports:
- 26656:26656
- 26657:26657
Expand Down
45 changes: 45 additions & 0 deletions abci/src/application/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,51 @@ use tracing::{debug, info};
///
/// This structure effectively just serves as a handle to the actual key/value
/// store - the [`KeyValueStoreDriver`].
///
/// ## Example
/// ```rust
/// use tendermint_abci::{KeyValueStoreApp, ServerBuilder, ClientBuilder};
/// use tendermint_proto::abci::{RequestEcho, RequestDeliverTx, RequestQuery};
///
/// // Create our key/value store application
/// let (app, driver) = KeyValueStoreApp::new();
/// // Create our server, binding it to TCP port 26658 on localhost and
/// // supplying it with our key/value store application
/// let server = ServerBuilder::default().bind("127.0.0.1:26658", app).unwrap();
/// let server_addr = server.local_addr();
///
/// // We want the driver and the server to run in the background while we
/// // interact with them via the client in the foreground
/// std::thread::spawn(move || driver.run());
/// std::thread::spawn(move || server.listen());
///
/// let mut client = ClientBuilder::default().connect(server_addr).unwrap();
/// let res = client
/// .echo(RequestEcho {
/// message: "Hello ABCI!".to_string(),
/// })
/// .unwrap();
/// assert_eq!(res.message, "Hello ABCI!");
///
/// // Deliver a transaction and then commit the transaction
/// client
/// .deliver_tx(RequestDeliverTx {
/// tx: "test-key=test-value".as_bytes().to_owned(),
/// })
/// .unwrap();
/// client.commit().unwrap();
///
/// // We should be able to query for the data we just delivered above
/// let res = client
/// .query(RequestQuery {
/// data: "test-key".as_bytes().to_owned(),
/// path: "".to_string(),
/// height: 0,
/// prove: false,
/// })
/// .unwrap();
/// assert_eq!(res.value, "test-value".as_bytes().to_owned());
/// ```
#[derive(Debug, Clone)]
pub struct KeyValueStoreApp {
cmd_tx: Sender<Command>,
Expand Down
51 changes: 0 additions & 51 deletions abci/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,6 @@
//! ABCI framework for building [Tendermint] applications in Rust.
//!
//! [Tendermint]: https://tendermint.com
//!
//! ## Example
//!
//! The following example is adapted from our integration test suite to
//! demonstrate how to instantiate an ABCI application, server and client and
//! have them interact. In practice, the client interaction will be performed
//! by a full Tendermint node.
//!
//! ```
//! use tendermint_abci::{KeyValueStoreApp, ServerBuilder, ClientBuilder};
//! use tendermint_proto::abci::{RequestEcho, RequestDeliverTx, RequestQuery};
//!
//! // Create our key/value store application
//! let (app, driver) = KeyValueStoreApp::new();
//! // Create our server, binding it to TCP port 26658 on localhost and
//! // supplying it with our key/value store application
//! let server = ServerBuilder::default().bind("127.0.0.1:26658", app).unwrap();
//! let server_addr = server.local_addr();
//!
//! // We want the driver and the server to run in the background while we
//! // interact with them via the client in the foreground
//! std::thread::spawn(move || driver.run());
//! std::thread::spawn(move || server.listen());
//!
//! let mut client = ClientBuilder::default().connect(server_addr).unwrap();
//! let res = client
//! .echo(RequestEcho {
//! message: "Hello ABCI!".to_string(),
//! })
//! .unwrap();
//! assert_eq!(res.message, "Hello ABCI!");
//!
//! // Deliver a transaction and then commit the transaction
//! client
//! .deliver_tx(RequestDeliverTx {
//! tx: "test-key=test-value".as_bytes().to_owned(),
//! })
//! .unwrap();
//! client.commit().unwrap();
//!
//! // We should be able to query for the data we just delivered above
//! let res = client
//! .query(RequestQuery {
//! data: "test-key".as_bytes().to_owned(),
//! path: "".to_string(),
//! height: 0,
//! prove: false,
//! })
//! .unwrap();
//! assert_eq!(res.value, "test-value".as_bytes().to_owned());
//! ```
mod application;
#[cfg(feature = "client")]
Expand Down
1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ tracing-subscriber = { version = "0.2", optional = true }

[dev-dependencies]
lazy_static = "1.4.0"
tokio-test = "0.4"
12 changes: 12 additions & 0 deletions rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ pub trait Client {
self.perform(block_results::Request::default()).await
}

/// `/block_search`: search for blocks by BeginBlock and EndBlock events.
async fn block_search(
&self,
query: Query,
page: u32,
per_page: u8,
order: Order,
) -> Result<block_search::Response, Error> {
self.perform(block_search::Request::new(query, page, per_page, order))
.await
}

/// `/blockchain`: get block headers for `min` <= `height` <= `max`.
///
/// Block headers are returned in descending order (highest first).
Expand Down
21 changes: 21 additions & 0 deletions rpc/src/client/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ enum ClientRequest {
/// The height of the block you want.
height: u32,
},
/// Search for a block by way of a specific query. Uses the same
/// query syntax as the `subscribe` endpoint.
BlockSearch {
/// The query against which blocks should be matched.
query: Query,
#[structopt(long, default_value = "1")]
page: u32,
#[structopt(long, default_value = "10")]
per_page: u8,
#[structopt(long, default_value = "asc")]
order: Order,
},
// TODO(thane): Implement evidence broadcast
/// Broadcast a transaction asynchronously (without waiting for the ABCI
/// app to check it or for it to be committed).
Expand Down Expand Up @@ -313,6 +325,15 @@ where
serde_json::to_string_pretty(&client.block_results(height).await?)
.map_err(Error::serde)?
}
ClientRequest::BlockSearch {
query,
page,
per_page,
order,
} => {
serde_json::to_string_pretty(&client.block_search(query, page, per_page, order).await?)
.map_err(Error::serde)?
}
ClientRequest::BroadcastTxAsync { tx } => serde_json::to_string_pretty(
&client
.broadcast_tx_async(Transaction::from(tx.into_bytes()))
Expand Down
5 changes: 2 additions & 3 deletions rpc/src/client/transport/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ use std::collections::HashMap;
/// }
/// }"#;
///
/// #[tokio::main]
/// async fn main() {
/// tokio_test::block_on(async {
/// let matcher = MockRequestMethodMatcher::default()
/// .map(Method::AbciInfo, Ok(ABCI_INFO_RESPONSE.to_string()));
/// let (client, driver) = MockClient::new(matcher);
Expand All @@ -44,7 +43,7 @@ use std::collections::HashMap;
///
/// client.close();
/// driver_hdl.await.unwrap();
/// }
/// });
/// ```
#[derive(Debug)]
pub struct MockClient<M: MockRequestMatcher> {
Expand Down
1 change: 1 addition & 0 deletions rpc/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod abci_info;
pub mod abci_query;
pub mod block;
pub mod block_results;
pub mod block_search;
pub mod blockchain;
pub mod broadcast;
pub mod commit;
Expand Down
48 changes: 48 additions & 0 deletions rpc/src/endpoint/block_search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! `/block_search` endpoint JSON-RPC wrapper
pub use super::{block, block_results};

use crate::{Method, Order};
use serde::{Deserialize, Serialize};

/// Request for searching for blocks by their BeginBlock and EndBlock events.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
pub query: String,
#[serde(with = "tendermint_proto::serializers::from_str")]
pub page: u32,
#[serde(with = "tendermint_proto::serializers::from_str")]
pub per_page: u8,
pub order_by: Order,
}

impl Request {
/// Constructor.
pub fn new(query: impl ToString, page: u32, per_page: u8, order_by: Order) -> Self {
Self {
query: query.to_string(),
page,
per_page,
order_by,
}
}
}

impl crate::Request for Request {
type Response = Response;

fn method(&self) -> Method {
Method::BlockSearch
}
}

impl crate::SimpleRequest for Request {}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub blocks: Vec<block::Response>,
#[serde(with = "tendermint_proto::serializers::from_str")]
pub total_count: u32,
}

impl crate::Response for Response {}
5 changes: 5 additions & 0 deletions rpc/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub enum Method {
/// Get ABCI results for a particular block
BlockResults,

/// Search for blocks by their BeginBlock and EndBlock events
BlockSearch,

/// Get blockchain info
Blockchain,

Expand Down Expand Up @@ -84,6 +87,7 @@ impl Method {
Method::AbciQuery => "abci_query",
Method::Block => "block",
Method::BlockResults => "block_results",
Method::BlockSearch => "block_search",
Method::Blockchain => "blockchain",
Method::BroadcastEvidence => "broadcast_evidence",
Method::BroadcastTxAsync => "broadcast_tx_async",
Expand Down Expand Up @@ -114,6 +118,7 @@ impl FromStr for Method {
"abci_query" => Method::AbciQuery,
"block" => Method::Block,
"block_results" => Method::BlockResults,
"block_search" => Method::BlockSearch,
"blockchain" => Method::Blockchain,
"broadcast_evidence" => Method::BroadcastEvidence,
"broadcast_tx_async" => Method::BroadcastTxAsync,
Expand Down
Loading

0 comments on commit 540e37f

Please sign in to comment.