Skip to content

Commit

Permalink
Update to tendermint-rs 0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlyCst committed Feb 2, 2021
1 parent a86a651 commit c81a107
Show file tree
Hide file tree
Showing 14 changed files with 656 additions and 812 deletions.
1,181 changes: 459 additions & 722 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ path = "src/bin/main.rs"
# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
prost-types = "0.6.1"
prost = "0.6.1"
prost-types = "0.7"
prost = "0.7"
# Servers (JsonRPC, gRPC, Websocket)
tonic = "0.3.1"
tokio = { version = "0.2", features = ["full"] }
warp = "0.2"
tonic = "0.4"
tokio = { version = "1.0", features = ["full"] }
warp = "0.3"
futures = "0.3.8"
# CLI utilities
colored = "2"
Expand All @@ -27,16 +27,19 @@ ics23 = "0.6.0"
sha2 = "0.9.2"
hex = "0.4.2"

# The `ibc-rs` repo didn't activate tonic server definition (see https://github.com/informalsystems/ibc-rs/blob/03cb9cafec462b3c36ca1c4aa5ef93c278fee9f3/proto-compiler/src/cmd/compile.rs#L85)
# In the meanwhile we rely on a fork
#
# ibc = { git = "https://github.com/informalsystems/ibc-rs" }
# ibc-proto = { git = "https://github.com/informalsystems/ibc-rs" }
ibc = { git = "https://github.com/CharlyCst/ibc-rs", branch="charly/tonic-server" }
ibc-proto = { git = "https://github.com/CharlyCst/ibc-rs", branch="charly/tonic-server" }
ibc = { git = "https://github.com/CharlyCst/ibc-rs", branch="charly/tonic-server-definitions" }
ibc-proto = { git = "https://github.com/CharlyCst/ibc-rs", branch="charly/tonic-server-definitions" }

tendermint = "0.17.0-rc2"
tendermint-testgen = "0.17.0-rc2"
tendermint-rpc = "0.17.0-rc2"
tendermint-proto = "0.17.0-rc2"
tendermint-light-client = "0.17.0-rc2"
tendermint = "0.18.0"
tendermint-testgen = "0.18.0"
tendermint-rpc = "0.18.0"
tendermint-proto = "0.18.0"
tendermint-light-client = "0.18.0"

[dependencies.clap]
version = "3.0.0-beta.1"
Expand Down
2 changes: 1 addition & 1 deletion src/abci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn get_info<S: Storage>(node: &Node<S>) -> AbciInfo {
version: "v0.17.0".to_string(),
app_version: 1,
last_block_height: tendermint::block::Height::from(
chain.get_height().version_height as u32,
chain.get_height().revision_height as u32,
),
last_block_app_hash: vec![],
}
Expand Down
3 changes: 2 additions & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tendermock::Tendermock;

// Define the CLI interface (see Clap doc)
#[derive(Clap)]
#[clap(version = "0.0.2")]
#[clap(version = "0.1.0")]
#[clap(verbatim_doc_comment)]
/// Tendermock - a mocked Tendermint node
pub struct Args {
Expand All @@ -15,6 +15,7 @@ pub struct Args {
#[clap(short, long, default_value = "26657")]
pub json_port: u16,

/// gRPC port
#[clap(short, long, default_value = "50051")]
pub grpc_port: u16,

Expand Down
8 changes: 5 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ impl Tendermock {
log!(Log::Chain, "Warning: no interface configured");
}
for (jrpc_addr, grpc_addr) in &self.interfaces {
log!(Log::GRPC, "Listening on: {}", &grpc_addr);
log!(Log::JRPC, "Listening on: {}", &jrpc_addr);
if self.verbose {
log!(Log::GRPC, "Listening on: {}", &grpc_addr);
log!(Log::JRPC, "Listening on: {}", &jrpc_addr);
}
let jrpc_server = jrpc::serve(node.clone(), self.verbose, jrpc_addr.clone());
let grpc_server = grpc::serve(node.clone(), self.verbose, grpc_addr.clone());
jrpc_servers.push(jrpc_server);
Expand Down Expand Up @@ -126,7 +128,7 @@ async fn schedule_growth<S: store::Storage>(
return Ok(());
}
loop {
tokio::time::delay_for(std::time::Duration::from_secs(interval)).await;
tokio::time::sleep(std::time::Duration::from_secs(interval)).await;
let node_ref = node.write();
node_ref.get_chain().grow();
drop(node_ref);
Expand Down
6 changes: 3 additions & 3 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ mod test {
let height = chain.get_height();

// Chain is expected to start at height 1 (same as Storage)
assert_eq!(height.version_height, 1);
assert_eq!(height.revision_height, 1);
chain.grow();
let height = chain.get_height();
assert_eq!(height.version_height, 2);
assert_eq!(height.revision_height, 2);
let block = chain.get_block(3);
assert!(block.is_some()); // The third block is not yet valid, but we can retrieve it anyway
chain.grow();
let height = chain.get_height();
assert_eq!(height.version_height, 3); // Now the third block is valid
assert_eq!(height.revision_height, 3); // Now the third block is valid
}
}
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn default_params() -> tendermint::consensus::Params {
max_gas: 1000,
},
evidence: tendermint::evidence::Params {
max_num: 10000,
max_bytes: 10000,
max_age_duration: tendermint::evidence::Duration(std::time::Duration::from_secs(3600)),
max_age_num_blocks: 10000,
},
Expand Down
13 changes: 7 additions & 6 deletions src/grpc/auth.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! # gRPC Auth
//!
//! The auth tendermint gRPC API.
use crate::node;
use crate::logger::Log;
use crate::node;
use crate::store::Storage;
use ibc_proto::cosmos::auth::v1beta1;
use ibc_proto::cosmos::auth::v1beta1::query_server::{Query, QueryServer};
use prost::Message;
use prost_types::Any;
use tonic::{Request, Response, Status};

pub fn get_service<S: 'static + Storage + Sync + Send>(
node: node::SharedNode<S>,
Expand Down Expand Up @@ -35,8 +36,8 @@ impl<S: Storage> QueryService<S> {
impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {
async fn account(
&self,
request: tonic::Request<v1beta1::QueryAccountRequest>,
) -> Result<tonic::Response<v1beta1::QueryAccountResponse>, tonic::Status> {
request: Request<v1beta1::QueryAccountRequest>,
) -> Result<Response<v1beta1::QueryAccountResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/auth/account {:?}", request);
}
Expand All @@ -55,13 +56,13 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {
}),
};
//let response = v1beta1::QueryAccountResponse { account: None };
Ok(tonic::Response::new(response))
Ok(Response::new(response))
}

async fn params(
&self,
request: tonic::Request<v1beta1::QueryParamsRequest>,
) -> Result<tonic::Response<v1beta1::QueryParamsResponse>, tonic::Status> {
request: Request<v1beta1::QueryParamsRequest>,
) -> Result<Response<v1beta1::QueryParamsResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/auth/params {:?}", request);
}
Expand Down
59 changes: 30 additions & 29 deletions src/grpc/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::logger::Log;
use crate::node;
use crate::store::Storage;
use ibc_proto::cosmos::staking::v1beta1;
use tonic::{Status, Response, Request};
use ibc_proto::cosmos::staking::v1beta1::query_server::{Query, QueryServer};

pub fn get_service<S: 'static + Storage + Sync + Send>(
Expand Down Expand Up @@ -33,8 +34,8 @@ impl<S: Storage> QueryService<S> {
impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {
async fn validator(
&self,
request: tonic::Request<v1beta1::QueryValidatorRequest>,
) -> Result<tonic::Response<v1beta1::QueryValidatorResponse>, tonic::Status> {
request: Request<v1beta1::QueryValidatorRequest>,
) -> Result<Response<v1beta1::QueryValidatorResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/validator {:?}", request);
}
Expand All @@ -43,8 +44,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn validators(
&self,
request: tonic::Request<v1beta1::QueryValidatorsRequest>,
) -> Result<tonic::Response<v1beta1::QueryValidatorsResponse>, tonic::Status> {
request: Request<v1beta1::QueryValidatorsRequest>,
) -> Result<Response<v1beta1::QueryValidatorsResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/validators {:?}", request);
}
Expand All @@ -53,8 +54,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn validator_delegations(
&self,
request: tonic::Request<v1beta1::QueryValidatorDelegationsRequest>,
) -> Result<tonic::Response<v1beta1::QueryValidatorDelegationsResponse>, tonic::Status> {
request: Request<v1beta1::QueryValidatorDelegationsRequest>,
) -> Result<Response<v1beta1::QueryValidatorDelegationsResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/validator_delegations {:?}", request);
}
Expand All @@ -63,8 +64,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn validator_unbonding_delegations(
&self,
request: tonic::Request<v1beta1::QueryValidatorUnbondingDelegationsRequest>,
) -> Result<tonic::Response<v1beta1::QueryValidatorUnbondingDelegationsResponse>, tonic::Status>
request: Request<v1beta1::QueryValidatorUnbondingDelegationsRequest>,
) -> Result<Response<v1beta1::QueryValidatorUnbondingDelegationsResponse>, Status>
{
if self.verbose {
log!(
Expand All @@ -78,8 +79,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn delegation(
&self,
request: tonic::Request<v1beta1::QueryDelegationRequest>,
) -> Result<tonic::Response<v1beta1::QueryDelegationResponse>, tonic::Status> {
request: Request<v1beta1::QueryDelegationRequest>,
) -> Result<Response<v1beta1::QueryDelegationResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/delegation {:?}", request);
}
Expand All @@ -88,8 +89,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn unbonding_delegation(
&self,
request: tonic::Request<v1beta1::QueryUnbondingDelegationRequest>,
) -> Result<tonic::Response<v1beta1::QueryUnbondingDelegationResponse>, tonic::Status> {
request: Request<v1beta1::QueryUnbondingDelegationRequest>,
) -> Result<Response<v1beta1::QueryUnbondingDelegationResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/unbounding_delegation {:?}", request);
}
Expand All @@ -98,8 +99,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn delegator_validator(
&self,
request: tonic::Request<v1beta1::QueryDelegatorValidatorRequest>,
) -> Result<tonic::Response<v1beta1::QueryDelegatorValidatorResponse>, tonic::Status> {
request: Request<v1beta1::QueryDelegatorValidatorRequest>,
) -> Result<Response<v1beta1::QueryDelegatorValidatorResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/delegator_validator {:?}", request);
}
Expand All @@ -108,8 +109,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn delegator_delegations(
&self,
request: tonic::Request<v1beta1::QueryDelegatorDelegationsRequest>,
) -> Result<tonic::Response<v1beta1::QueryDelegatorDelegationsResponse>, tonic::Status> {
request: Request<v1beta1::QueryDelegatorDelegationsRequest>,
) -> Result<Response<v1beta1::QueryDelegatorDelegationsResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/delegator_delegations {:?}", request);
}
Expand All @@ -118,8 +119,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn delegator_unbonding_delegations(
&self,
request: tonic::Request<v1beta1::QueryDelegatorUnbondingDelegationsRequest>,
) -> Result<tonic::Response<v1beta1::QueryDelegatorUnbondingDelegationsResponse>, tonic::Status>
request: Request<v1beta1::QueryDelegatorUnbondingDelegationsRequest>,
) -> Result<Response<v1beta1::QueryDelegatorUnbondingDelegationsResponse>, Status>
{
if self.verbose {
log!(
Expand All @@ -133,8 +134,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn redelegations(
&self,
request: tonic::Request<v1beta1::QueryRedelegationsRequest>,
) -> Result<tonic::Response<v1beta1::QueryRedelegationsResponse>, tonic::Status> {
request: Request<v1beta1::QueryRedelegationsRequest>,
) -> Result<Response<v1beta1::QueryRedelegationsResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/redelegations {:?}", request);
}
Expand All @@ -143,8 +144,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn delegator_validators(
&self,
request: tonic::Request<v1beta1::QueryDelegatorValidatorsRequest>,
) -> Result<tonic::Response<v1beta1::QueryDelegatorValidatorsResponse>, tonic::Status> {
request: Request<v1beta1::QueryDelegatorValidatorsRequest>,
) -> Result<Response<v1beta1::QueryDelegatorValidatorsResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/delegator_validators {:?}", request);
}
Expand All @@ -153,8 +154,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn historical_info(
&self,
request: tonic::Request<v1beta1::QueryHistoricalInfoRequest>,
) -> Result<tonic::Response<v1beta1::QueryHistoricalInfoResponse>, tonic::Status> {
request: Request<v1beta1::QueryHistoricalInfoRequest>,
) -> Result<Response<v1beta1::QueryHistoricalInfoResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/historical_info {:?}", request);
}
Expand All @@ -163,8 +164,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn pool(
&self,
request: tonic::Request<v1beta1::QueryPoolRequest>,
) -> Result<tonic::Response<v1beta1::QueryPoolResponse>, tonic::Status> {
request: Request<v1beta1::QueryPoolRequest>,
) -> Result<Response<v1beta1::QueryPoolResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/pool {:?}", request);
}
Expand All @@ -173,8 +174,8 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {

async fn params(
&self,
request: tonic::Request<v1beta1::QueryParamsRequest>,
) -> Result<tonic::Response<v1beta1::QueryParamsResponse>, tonic::Status> {
request: Request<v1beta1::QueryParamsRequest>,
) -> Result<Response<v1beta1::QueryParamsResponse>, Status> {
if self.verbose {
log!(Log::GRPC, "/staking/params {:?}", request);
}
Expand All @@ -187,6 +188,6 @@ impl<S: 'static + Storage + Sync + Send> Query for QueryService<S> {
unbonding_time: Some(std::time::Duration::new(3600 * 24 * 30, 0).into()),
}),
};
Ok(tonic::Response::new(response))
Ok(Response::new(response))
}
}
3 changes: 1 addition & 2 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ fn new_client_state(config: &Config) -> AnyClientState {
max_clock_drift: duration,
frozen_height: height.clone(),
latest_height: height,
upgrade_path: String::from("path"),
upgrade_path: vec![String::from("path")],
allow_update_after_expiry: false,
allow_update_after_misbehaviour: false,
consensus_params: config.consensus_params.clone(),
};
AnyClientState::Tendermint(client_state)
}
8 changes: 7 additions & 1 deletion src/jrpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use ibc::ics26_routing::handler::deliver;
use ibc_proto::cosmos::tx::v1beta1::{TxBody, TxRaw};
use prost::Message;
use tendermint::abci::{transaction::Hash, Code};
use tendermint::abci::{transaction::Hash, Code, Info};
use tendermint::abci::responses::Codespace;
use tendermint_rpc::endpoint::{
abci_info::Request as AbciInfoRequest, abci_info::Response as AbciInfoResponse,
abci_query::Request as AbciQueryRequest, abci_query::Response as AbciQueryResponse,
Expand Down Expand Up @@ -228,6 +229,11 @@ where
code: Code::Ok,
data: None,
log: "Success".into(),
codespace: Codespace::default(),
gas_used: 10.into(),
gas_wanted: 10.into(),
info: Info::default(),
events: vec![],
};
Ok(BroadcastTxCommitResponse {
check_tx: tx_result.clone(),
Expand Down
Loading

0 comments on commit c81a107

Please sign in to comment.