Skip to content

Commit

Permalink
Local chain implementation & basic tests (#422)
Browse files Browse the repository at this point in the history
* Attemptin integration at the level of Chain trait

* Removed rpc client from trait Chain

* Removed ChainConfig from trait Chain

* Minor fixes as follow-up from #364

* Impl generic runtime instantiation.

* Migrated CLIs to use generic runtime spawn.

* Added mock light client. First test (incomplete impl).

* Almost ready to send_tx (mock has to be mutable).

* Added chain executor.

* Mutable chain in send_tx, simplified spawn.After review w/ Anca & Romain

* impl CosmosSDKChain cleanup

* Adapted mock context, ICS18 & 26 to correct abstractions.

* Cleaned up Msg trait, added const TYPE_URL.

* Basic light client impl to complete create client test.

* Removed clippy allow exception

* Updated changelog

* Revert "Updated changelog"

This reverts commit 43bd008.
In anticipation of merging master into this dev branch..

* Redid the changelog

* After Anca's comments
  • Loading branch information
adizere authored Dec 3, 2020
1 parent be001eb commit 8ddc688
Show file tree
Hide file tree
Showing 47 changed files with 697 additions and 356 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased Changes

### FEATURES

### IMPROVEMENTS

- Mock chain (implementing IBC handlers) and integration against CLI ([#158])

[#158]: https://github.com/informalsystems/ibc-rs/issues/158

## v0.0.5
*December 2, 2020*
Expand Down
4 changes: 2 additions & 2 deletions modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ version = "=0.17.0-rc3"
version = "=0.17.0-rc3"

[dependencies.tendermint-testgen]
version = "0.17.0-rc2"
version = "0.17.0-rc3"
optional = true

[dev-dependencies]
tokio = { version = "0.2", features = ["macros"] }
subtle-encoding = { version = "0.5" }
tendermint-testgen = { version = "0.17.0-rc2" } # Needed for generating (synthetic) light blocks.
tendermint-testgen = { version = "0.17.0-rc3" } # Needed for generating (synthetic) light blocks.
5 changes: 2 additions & 3 deletions modules/src/ics02_client/client_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::ics02_client::error::{Error, Kind};
use crate::ics02_client::header::Header;
use crate::ics02_client::state::{ClientState, ConsensusState};
use crate::ics03_connection::connection::ConnectionEnd;
use crate::ics07_tendermint as tendermint;
use crate::ics07_tendermint::client_def::TendermintClient;
use crate::ics07_tendermint::client_state::ClientState as TendermintClientState;
use crate::ics07_tendermint::consensus_state::ConsensusState as TendermintConsensusState;
Expand Down Expand Up @@ -93,7 +92,7 @@ pub trait ClientDef: Clone {
#[derive(Clone, Debug, PartialEq)] // TODO: Add Eq bound once possible
#[allow(clippy::large_enum_variant)]
pub enum AnyHeader {
Tendermint(tendermint::header::Header),
Tendermint(TendermintHeader),

#[cfg(any(test, feature = "mocks"))]
Mock(MockHeader),
Expand Down Expand Up @@ -258,7 +257,7 @@ impl ClientState for AnyClientState {

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AnyConsensusState {
Tendermint(crate::ics07_tendermint::consensus_state::ConsensusState),
Tendermint(TendermintConsensusState),

#[cfg(any(test, feature = "mocks"))]
Mock(MockConsensusState),
Expand Down
3 changes: 3 additions & 0 deletions modules/src/ics02_client/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use ibc_proto::ibc::core::client::v1::Height as RawHeight;

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Height {
/// Previously known as "epoch", and will be renamed to "revision" soon
pub version_number: u64,

/// The height of a block
pub version_height: u64,
}

Expand Down
8 changes: 2 additions & 6 deletions modules/src/ics02_client/msgs/create_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::ics02_client::error::{Error, Kind};
use crate::ics24_host::identifier::ClientId;
use crate::tx_msg::Msg;

const TYPE_MSG_CREATE_CLIENT: &str = "create_client";
pub const TYPE_URL: &str = "/ibc.core.client.v1.MsgCreateClient";

/// A type of message that triggers the creation of a new on-chain (IBC) client.
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -69,17 +69,13 @@ impl Msg for MsgCreateAnyClient {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_CREATE_CLIENT.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
// Nothing to validate since all fields are validated on creation.
Ok(())
}

fn type_url(&self) -> String {
"/ibc.core.client.v1.MsgCreateClient".to_string()
TYPE_URL.to_string()
}

fn get_signers(&self) -> Vec<AccountId> {
Expand Down
14 changes: 5 additions & 9 deletions modules/src/ics02_client/msgs/update_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::ics02_client::error::{Error, Kind};
use crate::ics24_host::identifier::ClientId;
use crate::tx_msg::Msg;

const TYPE_MSG_UPDATE_CLIENT: &str = "update_client";
pub const TYPE_URL: &str = "/ibc.core.client.v1.MsgUpdateClient";

/// A type of message that triggers the update of an on-chain (IBC) client with new headers.
#[derive(Clone, Debug, PartialEq)] // TODO: Add Eq bound when possible
Expand All @@ -44,21 +44,17 @@ impl Msg for MsgUpdateAnyClient {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_UPDATE_CLIENT.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
// Nothing to validate since all fields are validated on creation.
Ok(())
}

fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
fn type_url(&self) -> String {
TYPE_URL.to_string()
}

fn type_url(&self) -> String {
"/ibc.core.client.v1.MsgUpdateClient".to_string()
fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
}
}

Expand Down
15 changes: 5 additions & 10 deletions modules/src/ics03_connection/msgs/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use crate::proofs::{ConsensusProof, Proofs};
use crate::tx_msg::Msg;
use crate::Height;

/// Message type for the `MsgConnectionOpenAck` message.
pub const TYPE_MSG_CONNECTION_OPEN_ACK: &str = "connection_open_ack";
pub const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenAck";

/// Message definition `MsgConnectionOpenAck` (i.e., `ConnOpenAck` datagram).
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -73,20 +72,16 @@ impl Msg for MsgConnectionOpenAck {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_CONNECTION_OPEN_ACK.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
Ok(())
}

fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
fn type_url(&self) -> String {
TYPE_URL.to_string()
}

fn type_url(&self) -> String {
"/ibc.core.connection.v1.MsgConnectionOpenAck".to_string()
fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
}
}

Expand Down
15 changes: 5 additions & 10 deletions modules/src/ics03_connection/msgs/conn_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use crate::ics03_connection::error::{Error, Kind};
use crate::ics24_host::identifier::ConnectionId;
use crate::{proofs::Proofs, tx_msg::Msg};

/// Message type for the `MsgConnectionOpenConfirm` message.
pub const TYPE_MSG_CONNECTION_OPEN_CONFIRM: &str = "connection_open_confirm";
pub const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenConfirm";

///
/// Message definition for `MsgConnectionOpenConfirm` (i.e., `ConnOpenConfirm` datagram).
Expand Down Expand Up @@ -42,20 +41,16 @@ impl Msg for MsgConnectionOpenConfirm {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_CONNECTION_OPEN_CONFIRM.to_string()
}

fn validate_basic(&self) -> Result<(), Error> {
Ok(())
}

fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
fn type_url(&self) -> String {
TYPE_URL.to_string()
}

fn type_url(&self) -> String {
"/ibc.core.connection.v1.MsgConnectionOpenConfirm".to_string()
fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
}
}

Expand Down
16 changes: 6 additions & 10 deletions modules/src/ics03_connection/msgs/conn_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::ics03_connection::version::validate_version;
use crate::ics24_host::identifier::{ClientId, ConnectionId};
use crate::tx_msg::Msg;

/// Message type for the `MsgConnectionOpenInit` message.
pub const TYPE_MSG_CONNECTION_OPEN_INIT: &str = "connection_open_init";
pub const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenInit";

///
/// Message definition `MsgConnectionOpenInit` (i.e., the `ConnOpenInit` datagram).
///
Expand Down Expand Up @@ -55,23 +55,19 @@ impl Msg for MsgConnectionOpenInit {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_CONNECTION_OPEN_INIT.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
// All the validation is performed on creation
self.counterparty
.validate_basic()
.map_err(|e| Kind::InvalidCounterparty.context(e).into())
}

fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
fn type_url(&self) -> String {
TYPE_URL.to_string()
}

fn type_url(&self) -> String {
"/ibc.core.connection.v1.MsgConnectionOpenInit".to_string()
fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
}
}

Expand Down
15 changes: 5 additions & 10 deletions modules/src/ics03_connection/msgs/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use crate::proofs::{ConsensusProof, Proofs};
use crate::tx_msg::Msg;
use crate::Height;

/// Message type for the `MsgConnectionOpenTry` message.
pub const TYPE_MSG_CONNECTION_OPEN_TRY: &str = "connection_open_try";
pub const TYPE_URL: &str = "/ibc.core.connection.v1.MsgConnectionOpenTry";

///
/// Message definition `MsgConnectionOpenTry` (i.e., `ConnOpenTry` datagram).
Expand Down Expand Up @@ -88,22 +87,18 @@ impl Msg for MsgConnectionOpenTry {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_CONNECTION_OPEN_TRY.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
self.counterparty
.validate_basic()
.map_err(|e| Kind::InvalidCounterparty.context(e).into())
}

fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
fn type_url(&self) -> String {
TYPE_URL.to_string()
}

fn type_url(&self) -> String {
"/ibc.core.connection.v1.MsgConnectionOpenTry".to_string()
fn get_signers(&self) -> Vec<AccountId> {
vec![self.signer]
}
}

Expand Down
7 changes: 0 additions & 7 deletions modules/src/ics04_channel/msgs/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ use crate::ics04_channel::packet::Packet;
use crate::ics23_commitment::commitment::CommitmentProof;
use crate::{proofs::Proofs, tx_msg::Msg, Height};

/// Message type for the `MsgAcknowledgement` message.
const TYPE_MSG_ACKNOWLEDGEMENT: &str = "ics04/opaque";

///
/// Message definition for packet acknowledgements.
///
Expand Down Expand Up @@ -56,10 +53,6 @@ impl Msg for MsgAcknowledgement {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_ACKNOWLEDGEMENT.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
// Nothing to validate
// All the validation is performed on creation
Expand Down
7 changes: 0 additions & 7 deletions modules/src/ics04_channel/msgs/chan_close_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use tendermint_proto::Protobuf;

use std::convert::{TryFrom, TryInto};

/// Message type for the `MsgChannelCloseConfirm` message.
const TYPE_MSG_CHANNEL_CLOSE_CONFIRM: &str = "channel_close_confirm";

///
/// Message definition for the second step in the channel close handshake (the `ChanCloseConfirm`
/// datagram).
Expand Down Expand Up @@ -56,10 +53,6 @@ impl Msg for MsgChannelCloseConfirm {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_CHANNEL_CLOSE_CONFIRM.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
// Nothing to validate
// All the validation is performed on creation
Expand Down
7 changes: 0 additions & 7 deletions modules/src/ics04_channel/msgs/chan_close_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use tendermint_proto::Protobuf;

use std::convert::TryFrom;

/// Message type for the `MsgChannelCloseInit` message.
const TYPE_MSG_CHANNEL_CLOSE_INIT: &str = "channel_close_init";

///
/// Message definition for the first step in the channel close handshake (`ChanCloseInit` datagram).
///
Expand Down Expand Up @@ -49,10 +46,6 @@ impl Msg for MsgChannelCloseInit {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_CHANNEL_CLOSE_INIT.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
// Nothing to validate
// All the validation is performed on creation
Expand Down
10 changes: 3 additions & 7 deletions modules/src/ics04_channel/msgs/chan_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use tendermint_proto::Protobuf;

use std::convert::{TryFrom, TryInto};

/// Message type for the `MsgChannelOpenAck` message.
const TYPE_MSG_CHANNEL_OPEN_ACK: &str = "channel_open_ack";
pub const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenAck";

///
/// Message definition for the third step in the channel open handshake (`ChanOpenAck` datagram).
Expand Down Expand Up @@ -62,17 +61,14 @@ impl Msg for MsgChannelOpenAck {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_CHANNEL_OPEN_ACK.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
// Nothing to validate
// All the validation is performed on creation
Ok(())
}

fn type_url(&self) -> String {
"/ibc.core.channel.v1.MsgChannelOpenAck".to_string()
TYPE_URL.to_string()
}

fn get_signers(&self) -> Vec<AccountId> {
Expand Down
9 changes: 2 additions & 7 deletions modules/src/ics04_channel/msgs/chan_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use tendermint_proto::Protobuf;

use std::convert::{TryFrom, TryInto};

/// Message type for the `MsgChannelOpenConfirm` message.
const TYPE_MSG_CHANNEL_OPEN_CONFIRM: &str = "channel_open_confirm";
pub const TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenConfirm";

///
/// Message definition for the fourth step in the channel open handshake (`ChanOpenConfirm`
Expand Down Expand Up @@ -56,18 +55,14 @@ impl Msg for MsgChannelOpenConfirm {
crate::keys::ROUTER_KEY.to_string()
}

fn get_type(&self) -> String {
TYPE_MSG_CHANNEL_OPEN_CONFIRM.to_string()
}

fn validate_basic(&self) -> Result<(), Self::ValidationError> {
// Nothing to validate
// All the validation is performed on creation
Ok(())
}

fn type_url(&self) -> String {
"/ibc.core.channel.v1.MsgChannelOpenConfirm".to_string()
TYPE_URL.to_string()
}

fn get_signers(&self) -> Vec<AccountId> {
Expand Down
Loading

0 comments on commit 8ddc688

Please sign in to comment.