Skip to content

Commit

Permalink
Connection worker (informalsystems#1019)
Browse files Browse the repository at this point in the history
* under construction

* under construction

* identified connection end

* compiles up to supervisor

* Update supervisor.rs

* compiles

* Update counterparty.rs

* without fmt and without clippy

* fmt and clippy

* option for counterparty in conn open try

* Update connection.rs

* Update connection.rs

* Update supervisor.rs

* added some telemetry to connection

* update supervisor with connection

* Update supervisor.rs

* on going

* conenction updates

* Update supervisor.rs

* e2e

* Update connection.py

* Update connection.py

* Update connection.py

* update e2e

* merge

* Review comments

* Add user2 to CI

* Added new files for gaia 4.2.0 to fix CI

* Added config path info to e2e script (informalsystems#1019)

* Fix output of hermes query connections

* Move binding down to declaration site

* Update relayer/src/chain/counterparty.rs

Co-authored-by: Romain Ruetschi <romain@informal.systems>

* Added reporting for the underlying error in counterparty_state()

* Better import of IdentifiedConnectionEnd in cosmos.rs

* Masked tonic::Code::NotFound result for query_client_connections.

* Remove unwraps

* Nit: fix comment & log output

* Cleanup

* Update changelog

* Enable handshake completion on CI

Co-authored-by: Anca Zamfir <zamfiranca@gmail.com>
Co-authored-by: Andy Nogueira <me@andynogueira.dev>
Co-authored-by: Romain Ruetschi <romain@informal.systems>
Co-authored-by: Adi Seredinschi <adi@informal.systems>
  • Loading branch information
5 people authored Jun 22, 2021
1 parent 43a6672 commit c37c4c3
Show file tree
Hide file tree
Showing 30 changed files with 880 additions and 115 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
derivation path when importing keys ([#1049])

- [ibc-relayer]
- Event-based handshake completion for IBC connections ([#821])
- Enable TLS support for gRPC client ([#877])

### IMPROVEMENTS
Expand Down Expand Up @@ -40,6 +41,7 @@
- Removed `--coin-type` option from `keys restore` command. Use `--hd-path` instead ([#1049])

[#673]: https://github.com/informalsystems/ibc-rs/issues/673
[#821]: https://github.com/informalsystems/ibc-rs/issues/821
[#877]: https://github.com/informalsystems/ibc-rs/issues/877
[#919]: https://github.com/informalsystems/ibc-rs/issues/919
[#930]: https://github.com/informalsystems/ibc-rs/issues/930
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion ci/chains/gaia/v4.2.0/ibc-0/key_seed.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion ci/chains/gaia/v4.2.0/ibc-1/key_seed.json

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion ci/simple_config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[global]
strategy = 'packets'
strategy = 'all'
log_level = 'info'

[[chains]]
Expand Down
91 changes: 91 additions & 0 deletions e2e/e2e/connection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from typing import Tuple
import toml

from .cmd import *
from .common import *

import e2e.relayer as relayer



@dataclass
class TxConnInitRes:
Expand Down Expand Up @@ -250,3 +254,90 @@ def query_connection_end(c: Config, chain_id: ChainId, conn_id: ConnectionId) ->
l.debug(f'Status of connection end {conn_id}: {res}')

return res

# =============================================================================
# Passive CONNECTION relayer tests
# =============================================================================

def verify_state(c: Config,
ibc1: ChainId, ibc0: ChainId,
ibc1_conn_id: ConnectionId):

strategy = toml.load(c.config_file)['global']['strategy']
l.debug(f'Using strategy: {strategy}')

# verify connection state on both chains, should be 'Open' for 'all' strategy, 'Init' otherwise
if strategy == 'all':
sleep(10.0)
for i in range(20):
sleep(2.0)
ibc1_conn_end = query_connection_end(c, ibc1, ibc1_conn_id)
ibc0_conn_id = ibc1_conn_end.counterparty.connection_id
ibc0_conn_end = query_connection_end(c, ibc0, ibc0_conn_id)
if ibc0_conn_end.state == 'Open' and ibc1_conn_end.state == 'Open':
break
else:
assert (ibc0_conn_end.state == 'Open'), (ibc0_conn_end, "state is not Open")
assert (ibc1_conn_end.state == 'Open'), (ibc1_conn_end, "state is not Open")

elif strategy == 'packets':
sleep(5.0)
ibc1_conn_end = query_connection_end(c, ibc1, ibc1_conn_id)
assert (ibc1_conn_end.state == 'Init'), (ibc1_conn_end, "state is not Init")

def passive_connection_start_then_init(c: Config,
ibc1: ChainId, ibc0: ChainId,
ibc1_client_id: ClientId, ibc0_client_id: ClientId )-> ConnectionId:

# 1. start hermes
proc = relayer.start(c)
sleep(2.0)

# 2. create a connection in Init state
ibc1_conn_id_a = conn_init(c, dst=ibc1, src=ibc0, dst_client=ibc1_client_id, src_client=ibc0_client_id)

# 3. wait for connection handshake to finish and verify connection state on both chains
verify_state(c, ibc1, ibc0, ibc1_conn_id_a)

# 4. All good, stop the relayer
proc.kill()

return ibc1_conn_id_a

def passive_connection_init_then_start(c: Config,
ibc1: ChainId, ibc0: ChainId,
ibc1_client_id: ClientId, ibc0_client_id: ClientId ):

# 1. create a connection in Init state
ibc1_conn_id_a = conn_init(c, dst=ibc1, src=ibc0, dst_client=ibc1_client_id, src_client=ibc0_client_id)

# 2. start hermes
proc = relayer.start(c)
sleep(2.0)

# 3. wait for connection handshake to finish and verify connection state on both chains
verify_state(c, ibc1, ibc0, ibc1_conn_id_a)

# 4. All good, stop the relayer
proc.kill()


def passive_connection_try_then_start(c: Config,
ibc1: ChainId, ibc0: ChainId,
ibc1_client_id: ClientId, ibc0_client_id: ClientId ):

# 1. create a connection in Init state
ibc1_conn_id_a = conn_init(c, dst=ibc1, src=ibc0, dst_client=ibc1_client_id, src_client=ibc0_client_id)

# 2. create a connection in Try-Open state
ibc0_conn_id_b = conn_try(c, dst=ibc0, src=ibc1, dst_client=ibc0_client_id, src_client=ibc1_client_id, src_conn=ibc1_conn_id_a)

# 2. start hermes
proc = relayer.start(c)
sleep(2.0)

# 3. wait for connection handshake to finish and verify connection state on both chains
verify_state(c, ibc1, ibc0, ibc1_conn_id_a)

# 4. All good, stop the relayer
proc.kill()
10 changes: 10 additions & 0 deletions e2e/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def main():
passive_packets(config, ibc0, ibc1, port_id, ibc0_chan_id, ibc1_chan_id)
sleep(2.0)


connection.passive_connection_init_then_start(config, ibc1, ibc0, ibc1_client_id, ibc0_client_id)
sleep(2.0)

connection.passive_connection_start_then_init(config, ibc1, ibc0, ibc1_client_id, ibc0_client_id)
sleep(2.0)

connection.passive_connection_try_then_start(config, ibc1, ibc0, ibc1_client_id, ibc0_client_id)
sleep(2.0)

channel.passive_channel_start_then_init(config, ibc1, ibc0, ibc1_conn_id, port_id)
sleep(2.0)

Expand Down
11 changes: 9 additions & 2 deletions relayer-cli/src/commands/query/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use abscissa_core::{Options, Runnable};
use tokio::runtime::Runtime as TokioRuntime;

use ibc::ics24_host::identifier::ChainId;
use ibc::ics24_host::identifier::{ChainId, ConnectionId};
use ibc_proto::ibc::core::connection::v1::QueryConnectionsRequest;
use ibc_relayer::chain::{Chain, CosmosSdkChain};

Expand Down Expand Up @@ -44,7 +44,14 @@ impl Runnable for QueryConnectionsCmd {
let res = chain.query_connections(req);

match res {
Ok(ce) => Output::success(ce).exit(),
Ok(connections) => {
let ids: Vec<ConnectionId> = connections
.into_iter()
.map(|identified_connection| identified_connection.connection_id)
.collect();

Output::success(ids).exit()
}
Err(e) => Output::error(format!("{}", e)).exit(),
}
}
Expand Down
31 changes: 15 additions & 16 deletions relayer-cli/src/commands/tx/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,8 @@ impl Runnable for TxRawConnInitCmd {
|chains: ChainHandlePair| {
Connection {
delay_period: ZERO_DURATION,
a_side: ConnectionSide::new(
chains.src,
self.src_client_id.clone(),
ConnectionId::default(),
),
b_side: ConnectionSide::new(
chains.dst,
self.dst_client_id.clone(),
ConnectionId::default(),
),
a_side: ConnectionSide::new(chains.src, self.src_client_id.clone(), None),
b_side: ConnectionSide::new(chains.dst, self.dst_client_id.clone(), None),
}
}
);
Expand Down Expand Up @@ -95,6 +87,13 @@ pub struct TxRawConnTryCmd {
meta = "ID"
)]
src_conn_id: ConnectionId,

#[options(
help = "identifier of the destination connection (optional)",
short = "d",
meta = "ID"
)]
dst_conn_id: Option<ConnectionId>,
}

impl Runnable for TxRawConnTryCmd {
Expand All @@ -109,12 +108,12 @@ impl Runnable for TxRawConnTryCmd {
a_side: ConnectionSide::new(
chains.src,
self.src_client_id.clone(),
self.src_conn_id.clone(),
Some(self.src_conn_id.clone()),
),
b_side: ConnectionSide::new(
chains.dst,
self.dst_client_id.clone(),
ConnectionId::default(),
self.dst_conn_id.clone(),
),
}
}
Expand Down Expand Up @@ -165,12 +164,12 @@ impl Runnable for TxRawConnAckCmd {
a_side: ConnectionSide::new(
chains.src,
self.src_client_id.clone(),
self.src_conn_id.clone(),
Some(self.src_conn_id.clone()),
),
b_side: ConnectionSide::new(
chains.dst,
self.dst_client_id.clone(),
self.dst_conn_id.clone(),
Some(self.dst_conn_id.clone()),
),
}
}
Expand Down Expand Up @@ -221,12 +220,12 @@ impl Runnable for TxRawConnConfirmCmd {
a_side: ConnectionSide::new(
chains.src,
self.src_client_id.clone(),
self.src_conn_id.clone(),
Some(self.src_conn_id.clone()),
),
b_side: ConnectionSide::new(
chains.dst,
self.dst_client_id.clone(),
self.dst_conn_id.clone(),
Some(self.dst_conn_id.clone()),
),
}
}
Expand Down
4 changes: 2 additions & 2 deletions relayer/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ibc::ics02_client::client_consensus::{
};
use ibc::ics02_client::client_state::{AnyClientState, ClientState, IdentifiedAnyClientState};
use ibc::ics02_client::header::Header;
use ibc::ics03_connection::connection::{ConnectionEnd, State};
use ibc::ics03_connection::connection::{ConnectionEnd, IdentifiedConnectionEnd, State};
use ibc::ics03_connection::version::{get_compatible_versions, Version};
use ibc::ics04_channel::channel::{ChannelEnd, IdentifiedChannelEnd};
use ibc::ics04_channel::packet::{PacketMsgType, Sequence};
Expand Down Expand Up @@ -160,7 +160,7 @@ pub trait Chain: Sized {
fn query_connections(
&self,
request: QueryConnectionsRequest,
) -> Result<Vec<ConnectionId>, Error>;
) -> Result<Vec<IdentifiedConnectionEnd>, Error>;

/// Performs a query to retrieve the identifiers of all connections.
fn query_client_connections(
Expand Down
14 changes: 7 additions & 7 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
cmp::min,
convert::{TryFrom, TryInto},
future::Future,
str::FromStr,
Expand Down Expand Up @@ -32,7 +33,7 @@ use ibc::ics02_client::client_consensus::{
};
use ibc::ics02_client::client_state::{AnyClientState, IdentifiedAnyClientState};
use ibc::ics02_client::events as ClientEvents;
use ibc::ics03_connection::connection::ConnectionEnd;
use ibc::ics03_connection::connection::{ConnectionEnd, IdentifiedConnectionEnd};
use ibc::ics04_channel::channel::{ChannelEnd, IdentifiedChannelEnd, QueryPacketEventDataRequest};
use ibc::ics04_channel::events as ChannelEvents;
use ibc::ics04_channel::packet::{PacketMsgType, Sequence};
Expand Down Expand Up @@ -80,7 +81,6 @@ use crate::light_client::LightClient;
use crate::light_client::Verified;

use super::Chain;
use std::cmp::min;

const DEFAULT_MAX_GAS: u64 = 300_000;
const DEFAULT_GAS_PRICE_PRICE: f64 = 0.001;
Expand Down Expand Up @@ -986,7 +986,7 @@ impl Chain for CosmosSdkChain {
fn query_connections(
&self,
request: QueryConnectionsRequest,
) -> Result<Vec<ConnectionId>, Error> {
) -> Result<Vec<IdentifiedConnectionEnd>, Error> {
crate::time!("query_connections");

let mut client = self
Expand All @@ -1007,13 +1007,13 @@ impl Chain for CosmosSdkChain {
// TODO: add warnings for any identifiers that fail to parse (below).
// similar to the parsing in `query_connection_channels`.

let ids = response
let connections = response
.connections
.iter()
.filter_map(|ic| ConnectionId::from_str(ic.id.as_str()).ok())
.into_iter()
.filter_map(|co| IdentifiedConnectionEnd::try_from(co).ok())
.collect();

Ok(ids)
Ok(connections)
}

fn query_connection(
Expand Down
Loading

0 comments on commit c37c4c3

Please sign in to comment.