Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection worker #1019

Merged
merged 50 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
1edc4be
under construction
cezarad May 29, 2021
03519f8
under construction
cezarad May 29, 2021
52cf85a
identified connection end
cezarad May 30, 2021
54589e9
compiles up to supervisor
cezarad May 31, 2021
95e8ddf
Update supervisor.rs
cezarad May 31, 2021
c5a6e82
compiles
cezarad May 31, 2021
63f5ceb
Update counterparty.rs
cezarad May 31, 2021
9625858
without fmt and without clippy
cezarad May 31, 2021
a372d30
fmt and clippy
cezarad May 31, 2021
8b2e74f
option for counterparty in conn open try
cezarad Jun 1, 2021
c43fa63
Update connection.rs
cezarad Jun 1, 2021
fed963f
Update connection.rs
cezarad Jun 2, 2021
cdf10de
Merge branch 'master' into connection821
cezarad Jun 2, 2021
451825b
Update supervisor.rs
cezarad Jun 2, 2021
b454071
added some telemetry to connection
cezarad Jun 2, 2021
fd13690
update supervisor with connection
cezarad Jun 2, 2021
553e60c
Update supervisor.rs
cezarad Jun 2, 2021
67eeaa8
on going
cezarad Jun 9, 2021
192c9e7
conenction updates
cezarad Jun 9, 2021
af2ed55
Update supervisor.rs
cezarad Jun 9, 2021
b2dfa66
e2e
cezarad Jun 9, 2021
966a1bd
Update connection.py
cezarad Jun 10, 2021
00f9a34
Update connection.py
cezarad Jun 10, 2021
4b89134
Update connection.py
cezarad Jun 10, 2021
465c0cf
update e2e
cezarad Jun 10, 2021
afc971a
Merge branch 'master' into connection821
cezarad Jun 10, 2021
f5c8108
merge
cezarad Jun 10, 2021
385ed42
Review comments
ancazamfir Jun 14, 2021
807d3b1
Add user2 to CI
ancazamfir Jun 14, 2021
62f77ed
Merge branch 'master' into connection821
ancazamfir Jun 14, 2021
8d6c1d7
Added new files for gaia 4.2.0 to fix CI
andynog Jun 14, 2021
96139b6
Added config path info to e2e script (#1019)
andynog Jun 14, 2021
28e2e13
Merge branch 'master' into connection821
ancazamfir Jun 14, 2021
6b6864e
Merge branch 'connection821' of https://github.com/informalsystems/ib…
ancazamfir Jun 14, 2021
b4132ca
Merge branch 'master' into connection821
ancazamfir Jun 14, 2021
a109ed9
Merge branch 'master' into connection821
ancazamfir Jun 17, 2021
8863c50
Fix output of hermes query connections
ancazamfir Jun 17, 2021
0c48215
Merge branch 'master' into connection821
ancazamfir Jun 17, 2021
127b530
Move binding down to declaration site
romac Jun 18, 2021
ccbcd75
Merge branch 'master' into connection821
romac Jun 18, 2021
e6d4e2a
Update relayer/src/chain/counterparty.rs
adizere Jun 21, 2021
7fc859b
Added reporting for the underlying error in counterparty_state()
adizere Jun 21, 2021
97b4b7b
Better import of IdentifiedConnectionEnd in cosmos.rs
adizere Jun 21, 2021
4115774
Masked tonic::Code::NotFound result for query_client_connections.
adizere Jun 18, 2021
6ed3a65
Remove unwraps
ancazamfir Jun 21, 2021
fc6e38b
Nit: fix comment & log output
adizere Jun 21, 2021
27d27c6
Merge branch 'master' into connection821
adizere Jun 22, 2021
5c711ae
Cleanup
adizere Jun 22, 2021
bd99f0a
Update changelog
romac Jun 22, 2021
b84772e
Enable handshake completion on CI
romac Jun 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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.

90 changes: 90 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,89 @@ 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']
# verify connection state on both chains, should be 'Open' for 'all' strategy, 'Init' otherwise

if strategy == 'all':
romac marked this conversation as resolved.
Show resolved Hide resolved
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()
2 changes: 1 addition & 1 deletion e2e/e2e/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def query_unreceived_acks(
def packet_send(c: Config, src: ChainId, dst: ChainId,
src_port: PortId, src_channel: ChannelId,
amount: int, height_offset: int, number_msgs: Optional[int] = None,
key: Optional[str] = None) -> Packet:
key: Optional[str] = 'user2') -> Packet:

cmd = TxPacketSend(dst_chain_id=dst, src_chain_id=src,
src_port=src_port, src_channel=src_channel,
Expand Down
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: 11 additions & 0 deletions modules/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use serde_derive::{Deserialize, Serialize};
use crate::ics02_client::events as ClientEvents;
use crate::ics02_client::events::NewBlock;
use crate::ics03_connection::events as ConnectionEvents;
use crate::ics03_connection::events::Attributes as ConnectionAttributes;
use crate::ics04_channel::events as ChannelEvents;
use crate::ics04_channel::events::Attributes as ChannelAttributes;

use crate::Height;
use prost::alloc::fmt::Formatter;
use std::fmt;
Expand Down Expand Up @@ -197,6 +199,15 @@ impl IbcEvent {
_ => None,
}
}
pub fn connection_attributes(&self) -> Option<&ConnectionAttributes> {
match self {
IbcEvent::OpenInitConnection(ev) => Some(ev.attributes()),
IbcEvent::OpenTryConnection(ev) => Some(ev.attributes()),
IbcEvent::OpenAckConnection(ev) => Some(ev.attributes()),
IbcEvent::OpenConfirmConnection(ev) => Some(ev.attributes()),
_ => None,
}
}
}

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down
117 changes: 88 additions & 29 deletions modules/src/ics03_connection/connection.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,89 @@
use std::convert::{TryFrom, TryInto};
use std::str::FromStr;
use std::time::Duration;
use std::u64;

use anomaly::fail;
use serde::{Deserialize, Serialize};
use tendermint_proto::Protobuf;

use ibc_proto::ibc::core::connection::v1::{
ConnectionEnd as RawConnectionEnd, Counterparty as RawCounterparty,
IdentifiedConnection as RawIdentifiedConnection,
};

use crate::ics03_connection::error::Kind;
use crate::ics03_connection::error::{self, Error, Kind};
use crate::ics03_connection::version::Version;
use crate::ics23_commitment::commitment::CommitmentPrefix;
use crate::ics24_host::error::ValidationError;
use crate::ics24_host::identifier::{ClientId, ConnectionId};
use crate::timestamp::ZERO_DURATION;

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct IdentifiedConnectionEnd {
pub connection_id: ConnectionId,
pub connection_end: ConnectionEnd,
}

impl IdentifiedConnectionEnd {
pub fn new(connection_id: ConnectionId, connection_end: ConnectionEnd) -> Self {
IdentifiedConnectionEnd {
connection_id,
connection_end,
}
}

pub fn id(&self) -> &ConnectionId {
&self.connection_id
}

pub fn end(&self) -> &ConnectionEnd {
&self.connection_end
}
}

impl Protobuf<RawIdentifiedConnection> for IdentifiedConnectionEnd {}

impl TryFrom<RawIdentifiedConnection> for IdentifiedConnectionEnd {
type Error = anomaly::Error<Kind>;

fn try_from(value: RawIdentifiedConnection) -> Result<Self, Self::Error> {
let raw_connection_end = RawConnectionEnd {
client_id: value.client_id.to_string(),
versions: value.versions,
state: value.state,
counterparty: value.counterparty,
delay_period: value.delay_period,
};

Ok(IdentifiedConnectionEnd {
connection_id: value.id.parse().map_err(|_| Kind::IdentifierError)?,
connection_end: raw_connection_end.try_into()?,
})
}
}

impl From<IdentifiedConnectionEnd> for RawIdentifiedConnection {
fn from(value: IdentifiedConnectionEnd) -> Self {
RawIdentifiedConnection {
id: value.connection_id.to_string(),
client_id: value.connection_end.client_id.to_string(),
versions: value
.connection_end
.versions
.iter()
.map(|v| From::from(v.clone()))
.collect(),
state: value.connection_end.state as i32,
delay_period: value.connection_end.delay_period.as_nanos() as u64,
counterparty: Some(value.connection_end.counterparty().clone().into()),
}
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ConnectionEnd {
state: State,
pub state: State,
client_id: ClientId,
counterparty: Counterparty,
versions: Vec<Version>,
Expand Down Expand Up @@ -138,6 +203,10 @@ impl ConnectionEnd {
self.state_matches(&State::Open)
}

pub fn is_uninitialized(&self) -> bool {
self.state_matches(&State::Uninitialized)
}

/// Helper function to compare the state of this end with another state.
pub fn state_matches(&self, other: &State) -> bool {
self.state.eq(other)
Expand All @@ -154,8 +223,8 @@ impl ConnectionEnd {
}

/// Getter for the counterparty. Returns a `clone()`.
pub fn counterparty(&self) -> Counterparty {
self.counterparty.clone()
pub fn counterparty(&self) -> &Counterparty {
&self.counterparty
}

/// Getter for the delay_period field. This represents the duration, at minimum,
Expand All @@ -170,33 +239,10 @@ impl ConnectionEnd {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct IdentifiedConnectionEnd {
connection_id: ConnectionId,
connection_end: ConnectionEnd,
}

impl IdentifiedConnectionEnd {
pub fn new(connection_id: ConnectionId, connection_end: ConnectionEnd) -> Self {
IdentifiedConnectionEnd {
connection_id,
connection_end,
}
}

pub fn id(&self) -> &ConnectionId {
&self.connection_id
}

pub fn end(&self) -> &ConnectionEnd {
&self.connection_end
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Counterparty {
client_id: ClientId,
connection_id: Option<ConnectionId>,
pub connection_id: Option<ConnectionId>,
prefix: CommitmentPrefix,
}

Expand Down Expand Up @@ -282,7 +328,7 @@ impl Counterparty {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum State {
Uninitialized = 0,
Init = 1,
Expand All @@ -300,6 +346,19 @@ impl State {
Self::Open => "OPEN",
}
}
// Parses the State out from a i32.
pub fn from_i32(s: i32) -> Result<Self, Error> {
match s {
0 => Ok(Self::Uninitialized),
1 => Ok(Self::Init),
2 => Ok(Self::TryOpen),
3 => Ok(Self::Open),
_ => fail!(error::Kind::InvalidState(s), s),
}
}
pub fn is_open(self) -> bool {
self == State::Open
}
}

impl TryFrom<i32> for State {
Expand Down
12 changes: 12 additions & 0 deletions modules/src/ics03_connection/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ impl Default for Attributes {
pub struct OpenInit(Attributes);

impl OpenInit {
pub fn attributes(&self) -> &Attributes {
&self.0
}
pub fn connection_id(&self) -> &Option<ConnectionId> {
&self.0.connection_id
}
Expand Down Expand Up @@ -128,6 +131,9 @@ impl From<OpenInit> for IbcEvent {
pub struct OpenTry(Attributes);

impl OpenTry {
pub fn attributes(&self) -> &Attributes {
&self.0
}
pub fn connection_id(&self) -> &Option<ConnectionId> {
&self.0.connection_id
}
Expand Down Expand Up @@ -171,6 +177,9 @@ impl From<OpenTry> for IbcEvent {
pub struct OpenAck(Attributes);

impl OpenAck {
pub fn attributes(&self) -> &Attributes {
&self.0
}
pub fn connection_id(&self) -> &Option<ConnectionId> {
&self.0.connection_id
}
Expand Down Expand Up @@ -214,6 +223,9 @@ impl From<OpenAck> for IbcEvent {
pub struct OpenConfirm(Attributes);

impl OpenConfirm {
pub fn attributes(&self) -> &Attributes {
&self.0
}
pub fn connection_id(&self) -> &Option<ConnectionId> {
&self.0.connection_id
}
Expand Down
Loading