Skip to content

Commit

Permalink
Merge branch 'main' into plafer/track-ibcrs-836
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani committed Nov 27, 2023
2 parents 823f846 + 83a460a commit 8176eda
Show file tree
Hide file tree
Showing 31 changed files with 1,019 additions and 542 deletions.
983 changes: 617 additions & 366 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ base64 = { version = "0.21", default-features = false, features = ["alloc"] }
displaydoc = { version = "0.2", default-features = false }
derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display"] }
ed25519 = { version = "2.1.0", default-features = false }
ibc = { git ="https://github.com/cosmos/ibc-rs", rev = "b7dd19d" }
ibc-query = { git ="https://github.com/cosmos/ibc-rs", rev = "b7dd19d" }
ibc-proto = { version = "0.37.1", default-features = false }
ics23 = { version = "0.11", default-features = false }
ibc = { version = "0.48.1", default-features = false }
ibc-query = { version = "0.48.1", default-features = false }
ibc-proto = { version = "0.38.0", default-features = false }
ics23 = { version = "0.11", default-features = false }
prost = { version = "0.12", default-features = false }
serde = "1.0"
serde_json = "1.0"
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ So far this app has been tested with:
* Rust >v1.52.1
* CometBFT v0.37

## Usage
## How to integrate ibc-rs changes into basecoin
Since basecoin serves as a suite of integration tests against ibc-rs's functionality, each ibc-rs
PR also requires an accompanying basecoin PR. The steps to do this are:
1. In a new branch in basecoin, update ibc [revisions][revs] with the latest commit of the ibc-rs PR.
2. Implement the necessary changes in basecoin in order to get it working with the latest commit revision of ibc-rs.
3. Run `cargo clippy --all-features` and `cargo clippy --no-default-features` and fix any issues that clippy raises.
4. Open a PR in the basecoin-rs repository, making sure to the link to the associated ibc-rs PR.
5. Check to see if the [integration tests][integration-tests] pass.

## Starting up an instance of basecoin
### Step 1: Reset your local CometBFT node
```shell
$ cometbft init
Expand Down Expand Up @@ -69,3 +78,6 @@ $ cometbft node
![class diagram](docs/images/class-diagram.png)
---
![activity diagram - DeliverTx](docs/images/activity-diagram-deliverTx.png)

[revs]: https://github.com/informalsystems/basecoin-rs/blob/9610b29067ba122808d1d14354a32e2005b54517/Cargo.toml#L15-L16
[integration-tests]: https://github.com/informalsystems/basecoin-rs/blob/8f744c8356569d5f87a546f46d1ade247ebe5256/.github/workflows/integration.yml#L1
2 changes: 1 addition & 1 deletion ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG COMETBFT_VERSION=0.37.1
ARG GAIA_VERSION=6.0.0
ARG HERMES_VERSION=1.4.0
ARG HERMES_VERSION=1.7.0
ARG RUST_VERSION=1.65

FROM cometbft/cometbft:v${COMETBFT_VERSION} AS cometbft
Expand Down
2 changes: 1 addition & 1 deletion ci/cometbft-config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ enable = false
rpc_servers = ""
trust_height = 0
trust_hash = ""
trust_period = "168h0m0s"
trust_period = "3m"

# Time to spend discovering snapshots before initiating a restore.
discovery_time = "15s"
Expand Down
6 changes: 4 additions & 2 deletions ci/hermes-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ key_name = 'testkey'
store_prefix = 'ibc'
gas_price = { price = 0.001, denom = 'stake' }
clock_drift = '5s'
trusting_period = '14days'
# `trusting_period` default value is '14days', but for the purpose of testing
# the consensus state pruning mechanism of Tendermint client it is set to '3m'
trusting_period = '3m'

[chains.trust_threshold]
numerator = '1'
Expand All @@ -29,7 +31,7 @@ key_name = 'testkey'
store_prefix = 'ibc'
gas_price = { price = 0.001, denom = 'basecoin' }
clock_drift = '5s'
trusting_period = '14days'
trusting_period = '3m'
proof_specs = '''
[
{
Expand Down
2 changes: 2 additions & 0 deletions ci/one-chain
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ if [ $platform = 'linux' ]; then
sed -i 's#"localhost:6060"#"localhost:'"$PROF_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's/trust_period = "168h0m0s"/trust_period = "3m"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
else
Expand All @@ -135,6 +136,7 @@ else
sed -i '' 's#"localhost:6060"#"localhost:'"$PROF_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's/trust_period = "168h0m0s"/trust_period = "3m"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
# sed -i '' 's/min-retain-blocks = 0/min-retain-blocks = 100/g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/abci/v0_37/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use basecoin_store::utils::SharedRwExt;
use cosmrs::tx::SignerInfo;
use cosmrs::tx::SignerPublicKey;
use cosmrs::Tx;
use ibc::proto::Any;
use ibc::primitives::proto::Any;
use prost::Message;
use serde_json::Value;
use std::fmt::{Debug, Write};
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/modules/auth/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Account for AuthAccount {
}
}

impl ibc_proto::protobuf::Protobuf<BaseAccount> for AuthAccount {}
impl ibc_proto::Protobuf<BaseAccount> for AuthAccount {}

impl TryFrom<BaseAccount> for AuthAccount {
type Error = String;
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/modules/bank/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::types::error::Error;

use basecoin_store::types::Path;
use ibc_proto::{cosmos::base::v1beta1::Coin as ProtoCoin, protobuf::Protobuf};
use ibc_proto::{cosmos::base::v1beta1::Coin as ProtoCoin, Protobuf};

use cosmrs::{AccountId, Coin as MsgCoin};
use primitive_types::U256;
Expand Down
6 changes: 3 additions & 3 deletions crates/app/src/modules/gov/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use basecoin_store::impls::SharedStore;
use basecoin_store::types::{Height, Path, ProtobufStore, TypedStore};
use basecoin_store::utils::{SharedRw, SharedRwExt};

use ibc::hosts::tendermint::upgrade_proposal::upgrade_client_proposal_handler;
use ibc::hosts::tendermint::upgrade_proposal::UpgradeProposal;
use ibc::cosmos_host::upgrade_proposal::upgrade_client_proposal_handler;
use ibc::cosmos_host::upgrade_proposal::UpgradeProposal;
use ibc_proto::cosmos::gov::v1beta1::query_server::QueryServer;
use ibc_proto::google::protobuf::Any;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;

use cosmrs::AccountId;
use std::fmt::Debug;
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/modules/gov/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use displaydoc::Display;
use ibc_proto::cosmos::gov::v1beta1::MsgSubmitProposal as RawMsgSubmitProposal;
use ibc_proto::cosmos::gov::v1beta1::ProposalStatus;
use ibc_proto::google::protobuf::Any;
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;

use crate::modules::bank::util::Coin;
use crate::types::error::Error;
Expand Down
4 changes: 2 additions & 2 deletions crates/app/src/modules/gov/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ibc_proto::cosmos::gov::v1beta1::Proposal as RawProposal;
use ibc_proto::cosmos::gov::v1beta1::ProposalStatus;
use ibc_proto::cosmos::gov::v1beta1::TallyResult;
use ibc_proto::google::protobuf::{Any, Timestamp};
use ibc_proto::protobuf::Protobuf;
use ibc_proto::Protobuf;

use super::error::Error;
use crate::modules::bank::util::Coin;
Expand Down Expand Up @@ -107,7 +107,7 @@ impl From<Proposal> for Any {
fn from(value: Proposal) -> Self {
Self {
type_url: TYPE_URL.to_string(),
value: Protobuf::<RawProposal>::encode_vec(&value),
value: Protobuf::<RawProposal>::encode_vec(value),
}
}
}
87 changes: 73 additions & 14 deletions crates/app/src/modules/ibc/client_contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ use super::impls::{AnyConsensusState, IbcContext};
use basecoin_store::context::Store;
use basecoin_store::types::Height;

use ibc::clients::ics07_tendermint::client_state::ClientState as TmClientState;
use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState;
use ibc::clients::ics07_tendermint::{CommonContext, ValidationContext as TmValidationContext};
use ibc::core::ics02_client::error::ClientError;
use ibc::core::ics02_client::{ClientExecutionContext, ClientValidationContext};
use ibc::core::ics24_host::identifier::ClientId;
use ibc::core::ics24_host::path::{ClientConsensusStatePath, ClientStatePath, Path};
use ibc::core::timestamp::Timestamp;
use ibc::core::{ContextError, ValidationContext};
use ibc::Height as IbcHeight;
use ibc::clients::tendermint::client_state::ClientState as TmClientState;
use ibc::clients::tendermint::consensus_state::ConsensusState as TmConsensusState;
use ibc::clients::tendermint::context::{CommonContext, ValidationContext as TmValidationContext};
use ibc::core::client::context::{ClientExecutionContext, ClientValidationContext};
use ibc::core::client::types::error::ClientError;
use ibc::core::client::types::Height as IbcHeight;
use ibc::core::handler::types::error::ContextError;
use ibc::core::host::types::identifiers::ClientId;
use ibc::core::host::types::path::{ClientConsensusStatePath, ClientStatePath, Path};
use ibc::core::host::ValidationContext;
use ibc::primitives::Timestamp;

use std::fmt::Debug;

Expand Down Expand Up @@ -125,6 +126,34 @@ where
.insert((client_id, height), host_height);
Ok(())
}

/// Delete the update time associated with the client at the specified height.
fn delete_update_time(
&mut self,
client_id: ClientId,
height: IbcHeight,
) -> Result<(), ContextError> {
self.client_processed_times.remove(&(client_id, height));
Ok(())
}

/// Delete the update height associated with the client at the specified height.
fn delete_update_height(
&mut self,
client_id: ClientId,
height: IbcHeight,
) -> Result<(), ContextError> {
self.client_processed_heights.remove(&(client_id, height));
Ok(())
}

fn delete_consensus_state(
&mut self,
consensus_state_path: ClientConsensusStatePath,
) -> Result<(), ContextError> {
self.consensus_state_store.delete(consensus_state_path);
Ok(())
}
}

impl<S> CommonContext for IbcContext<S>
Expand All @@ -148,6 +177,36 @@ where
) -> Result<Self::AnyConsensusState, ContextError> {
ValidationContext::consensus_state(self, client_cons_state_path)
}

fn consensus_state_heights(
&self,
client_id: &ClientId,
) -> Result<Vec<IbcHeight>, ContextError> {
let path = format!("clients/{}/consensusStates", client_id)
.try_into()
.map_err(|_| ClientError::Other {
description: "Invalid consensus state path".into(),
})?;

self.consensus_state_store
.get_keys(&path)
.into_iter()
.flat_map(|path| {
if let Ok(Path::ClientConsensusState(consensus_path)) = path.try_into() {
Some(consensus_path)
} else {
None
}
})
.map(|consensus_path| {
let height = IbcHeight::new(
consensus_path.revision_number,
consensus_path.revision_height,
)?;
Ok(height)
})
.collect()
}
}

impl<S> TmValidationContext for IbcContext<S>
Expand All @@ -157,7 +216,7 @@ where
fn next_consensus_state(
&self,
client_id: &ClientId,
height: &ibc::Height,
height: &IbcHeight,
) -> Result<Option<Self::AnyConsensusState>, ContextError> {
let path = format!("clients/{client_id}/consensusStates")
.try_into()
Expand All @@ -166,7 +225,7 @@ where
let keys = self.store.get_keys(&path);
let found_path = keys.into_iter().find_map(|path| {
if let Ok(Path::ClientConsensusState(path)) = Path::try_from(path) {
if height > &ibc::Height::new(path.epoch, path.height).unwrap() {
if height > &IbcHeight::new(path.revision_number, path.revision_height).unwrap() {
return Some(path);
}
}
Expand All @@ -191,7 +250,7 @@ where
fn prev_consensus_state(
&self,
client_id: &ClientId,
height: &ibc::Height,
height: &IbcHeight,
) -> Result<Option<Self::AnyConsensusState>, ContextError> {
let path = format!("clients/{client_id}/consensusStates")
.try_into()
Expand All @@ -200,7 +259,7 @@ where
let keys = self.store.get_keys(&path);
let pos = keys.iter().position(|path| {
if let Ok(Path::ClientConsensusState(path)) = Path::try_from(path.clone()) {
height >= &ibc::Height::new(path.epoch, path.height).unwrap()
height >= &IbcHeight::new(path.revision_number, path.revision_height).unwrap()
} else {
false
}
Expand Down
5 changes: 3 additions & 2 deletions crates/app/src/modules/ibc/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use ibc::core::handler::types::error::ContextError;

pub use crate::types::error::Error as AppError;
use ibc::core::RouterError;

pub type Error = RouterError;
pub type Error = ContextError;

impl From<Error> for AppError {
fn from(e: Error) -> Self {
Expand Down
Loading

0 comments on commit 8176eda

Please sign in to comment.