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

Add Channel worker #924

Merged
merged 65 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e7dbcc8
update
cezarad May 10, 2021
9f9e563
add behavior for chan not open
cezarad May 10, 2021
70c5d8b
allow dst channel id to be specified
ancazamfir May 10, 2021
4d0359a
Merge branch 'channel822' of https://github.com/informalsystems/ibc-r…
ancazamfir May 10, 2021
c5cffae
intermiate.
cezarad May 10, 2021
4674677
Update supervisor.rs
cezarad May 10, 2021
54e43ef
Temp fix for option channel IDs
ancazamfir May 10, 2021
91e12b4
Merge branch 'channel822' of https://github.com/informalsystems/ibc-r…
ancazamfir May 10, 2021
1f80a9d
Fix open try
ancazamfir May 10, 2021
727f3b1
cleanup
ancazamfir May 10, 2021
60c9124
event loop but no channelEnd to complete started handshakes
cezarad May 10, 2021
478041b
handshake channel
cezarad May 11, 2021
306f501
added query_connection_channels
cezarad May 11, 2021
c30ea38
Update supervisor.rs
cezarad May 11, 2021
9432ee0
Update supervisor.rs
cezarad May 11, 2021
e6f96a4
fmt + clippy
cezarad May 11, 2021
a5fc0b7
Update supervisor.rs
cezarad May 11, 2021
3bc6091
add check for uninitialized channel_connection_client
cezarad May 11, 2021
833f8fe
refactor event loop
cezarad May 11, 2021
c0f7ea9
refactor channel worker new_block branch
cezarad May 12, 2021
f8f45b9
Merge branch 'master' into channel822
cezarad May 12, 2021
3ac9f55
merged master
cezarad May 12, 2021
3755d85
fmt
cezarad May 12, 2021
b391956
fmt + clippy
cezarad May 12, 2021
a031f7e
refactor and add retry
cezarad May 13, 2021
446bc5d
Merge master and small reorg
ancazamfir May 16, 2021
9103414
Reorg and fixes
ancazamfir May 17, 2021
8352828
Don't spawn channel worker if it cannot advance state
ancazamfir May 17, 2021
2f125bb
Small reorg
ancazamfir May 18, 2021
685761c
Default strategy 'packets', handshake if 'all'
ancazamfir May 18, 2021
faf73c6
Cleanup
ancazamfir May 18, 2021
c273e46
Add channel worker test to CI
ancazamfir May 18, 2021
4bb561e
Change the CI config file to relay all
ancazamfir May 18, 2021
ac07abc
Update changelog
ancazamfir May 18, 2021
bf20399
Read strategy and chain ids from config file
ancazamfir May 19, 2021
b3ff416
Merge branch 'master' into channel822
ancazamfir May 19, 2021
1f7f6a2
Install toml in CI
ancazamfir May 19, 2021
68cd510
Fix stray exit(1) in e2e
ancazamfir May 20, 2021
f4a8d3d
Merge branch 'master' into channel822
ancazamfir May 20, 2021
8c47d96
Change back query to return Uninitialized, fix only the caller/CLI
ancazamfir May 21, 2021
9eb721f
Cleanup
ancazamfir May 21, 2021
6a7aa03
Merge branch 'master' into channel822
ancazamfir May 21, 2021
c0028e4
Remove unwraps
ancazamfir May 21, 2021
ebc1581
Update changelog
ancazamfir May 21, 2021
6c4b44a
Cleanup more unwraps
ancazamfir May 21, 2021
d9fcdd0
add more tests to e2e
ancazamfir May 21, 2021
1627991
Format
ancazamfir May 21, 2021
6ee1110
error fmt
ancazamfir May 21, 2021
3a99fc6
Small reorder
ancazamfir May 24, 2021
bb6e6f4
Merge branch 'master' into channel822
ancazamfir May 25, 2021
11a27de
cargo fmt
ancazamfir May 25, 2021
aca62f8
Merge branch 'master' into channel822
ancazamfir May 25, 2021
800ee2a
Merge branch 'master' into channel822
romac May 25, 2021
29bcb5a
Small refactor
adizere May 25, 2021
9053cb1
Minor supervisor refactoring to reuse source/destination terminology.
adizere May 25, 2021
135f915
Merge branch 'master' into channel822
romac May 26, 2021
d92fc8b
Fix post-merge compile error
romac May 26, 2021
8cad2c3
Return Option<&ChannelId> instead of &Option<ChannelId>
romac May 26, 2021
f375b35
Review comments
ancazamfir May 26, 2021
c0b507f
Remove todos
ancazamfir May 26, 2021
d901b50
Update docs/architecture/adr-002-ibc-relayer.md
romac May 26, 2021
3ffc739
Remove unecessary &mut self
romac May 26, 2021
86ab51f
Set packet relaying strategy in CI, tweek sleeps to speed up CI
ancazamfir May 26, 2021
fb80fa2
Merge branch 'channel822' of https://github.com/informalsystems/ibc-r…
ancazamfir May 26, 2021
1c76c26
Small doc fix
ancazamfir May 26, 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### FEATURES

- [ibc-relayer]
- Add support for event based channel relaying ([#822])
- Graceful handling of packet events in the presence of multiple relayers ([#983])

### IMPROVEMENTS
Expand All @@ -22,10 +23,11 @@
- [ibc-relayer-cli]
- Promote `start-multi` command to `start` ([#911])

[#983]: https://github.com/informalsystems/ibc-rs/issues/983
[#822]: https://github.com/informalsystems/ibc-rs/issues/822
[#871]: https://github.com/informalsystems/ibc-rs/issues/871
[#911]: https://github.com/informalsystems/ibc-rs/issues/911
[#972]: https://github.com/informalsystems/ibc-rs/issues/972
[#983]: https://github.com/informalsystems/ibc-rs/issues/983

## v0.3.2
*May 21st, 2021*
Expand Down
2 changes: 1 addition & 1 deletion ci/relayer.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LABEL maintainer="hello@informal.systems"
ARG RELEASE

# Add Python 3
RUN apt-get update -y && apt-get install python3 -y
RUN apt-get update -y && apt-get install python3 -y && apt-get install python3-toml -y

# Copy relayer executable
COPY ./hermes /usr/bin/hermes
Expand Down
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 = 'naive'
strategy = 'packets'
log_level = 'info'

[[chains]]
Expand Down
7 changes: 5 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[global]
strategy = 'naive'
log_level = 'error'
# Valid strategies:
# 'packets': restricts relaying to packets only, or
# 'all': relay from all types of events
strategy = 'packets'
log_level = 'info'

[[chains]]
id = 'ibc-0'
Expand Down
58 changes: 0 additions & 58 deletions config_example.toml

This file was deleted.

30 changes: 3 additions & 27 deletions docs/architecture/adr-002-ibc-relayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Below is an example of a configuration file.

```toml
[global]
strategy = "naive"
strategy = "packets"
log_level = "error"

[[chains]]
Expand Down Expand Up @@ -152,31 +152,6 @@ log_level = "error"
gas_price = "0.025stake"
trusting_period = "336h"

[[connections]]

[connections.src]
client_id = "clB1"
connection_id = "connAtoB"

[connections.dest]
client_id = "clA1"
connection_id = "connBtoA"

[[connections.paths]]
src_port = "portA1"
dest_port = "portB1"
direction = "unidirectional"

[[connections.paths]]
src_port = "portA2"
dest_port = "portB2"
direction = "bidirectional"

[[connections.paths]]
src_port = "portA3"
dest_port = "portB3"
src_channel = "chan3-on-A"
dest_channel = "chan3-on-B"
```
The main sections of the configuration file are:
- `global`:
Expand All @@ -200,7 +175,8 @@ pub struct Config {
}

pub enum Strategy {
Naive,
Packets,
romac marked this conversation as resolved.
Show resolved Hide resolved
HandshakeAndPackets,
}

pub struct GlobalConfig {
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/adr-006-hermes-v0.2-usecases.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ of the config file will look as follows:

```toml
[global]
strategy = 'naive'
strategy = 'packets'
log_level = 'error'
log_json = 'false'
```
Expand Down
102 changes: 97 additions & 5 deletions e2e/e2e/channel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Optional, Tuple
import toml

from .cmd import *
from .common import *

import e2e.relayer as relayer

@dataclass
class TxChanOpenInitRes:
Expand Down Expand Up @@ -418,18 +420,19 @@ def handshake(
c: Config,
side_a: ChainId, side_b: ChainId,
conn_a: ConnectionId, conn_b: ConnectionId,
port_id: PortId
) -> Tuple[ChannelId, ChannelId]:
a_chan_id = chan_open_init(c, dst=side_a, src=side_b, dst_conn=conn_a)

split()

b_chan_id = chan_open_try(
c, dst=side_b, src=side_a, dst_conn=conn_b, dst_port=PortId('transfer'), src_port=PortId('transfer'),
c, dst=side_b, src=side_a, dst_conn=conn_b, dst_port=port_id, src_port=port_id,
src_chan=a_chan_id)

split()

ack_res = chan_open_ack(c, dst=side_a, src=side_b, dst_port=PortId('transfer'), src_port=PortId('transfer'),
ack_res = chan_open_ack(c, dst=side_a, src=side_b, dst_port=port_id, src_port=port_id,
dst_conn=conn_a, dst_chan=a_chan_id, src_chan=b_chan_id)

if ack_res != a_chan_id:
Expand All @@ -438,7 +441,7 @@ def handshake(
exit(1)

confirm_res = chan_open_confirm(
c, dst=side_b, src=side_a, dst_port=PortId('transfer'), src_port=PortId('transfer'),
c, dst=side_b, src=side_a, dst_port=port_id, src_port=port_id,
dst_conn=conn_b, dst_chan=b_chan_id, src_chan=a_chan_id)

if confirm_res != b_chan_id:
Expand All @@ -448,13 +451,13 @@ def handshake(

split()

a_chan_end = query_channel_end(c, side_a, PortId('transfer'), a_chan_id)
a_chan_end = query_channel_end(c, side_a, port_id, a_chan_id)
if a_chan_end.state != 'Open':
l.error(
f'Channel end with id {a_chan_id} on chain {side_a} is not in Open state, got: {a_chan_end.state}')
exit(1)

b_chan_end = query_channel_end(c, side_b, PortId('transfer'), b_chan_id)
b_chan_end = query_channel_end(c, side_b, port_id, b_chan_id)
if b_chan_end.state != 'Open':
l.error(
f'Channel end with id {b_chan_id} on chain {side_b} is not in Open state, got: {b_chan_end.state}')
Expand All @@ -475,3 +478,92 @@ def query_channel_end(c: Config, chain_id: ChainId, port: PortId, chan_id: Chann
l.debug(f'Status of channel end {chan_id}: {res}')

return res


# =============================================================================
# Passive CHANNEL relayer tests
# =============================================================================

def verify_state(c: Config,
ibc1: ChainId, ibc0: ChainId,
ibc1_chan_id: ChannelId, port_id: PortId):

strategy = toml.load(c.config_file)['global']['strategy']
# verify channel 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_chan_end = query_channel_end(c, ibc1, port_id, ibc1_chan_id)
ibc0_chan_id = ibc1_chan_end.remote.channel_id
ibc0_chan_end = query_channel_end(c, ibc0, port_id, ibc0_chan_id)
if ibc0_chan_end.state == 'Open' and ibc1_chan_end.state == 'Open':
break
else:
assert (ibc0_chan_end.state == 'Open'), (ibc0_chan_end, "state is not Open")
assert (ibc1_chan_end.state == 'Open'), (ibc1_chan_end, "state is not Open")

elif strategy == 'packets':
sleep(5.0)
ibc1_chan_end = query_channel_end(c, ibc1, port_id, ibc1_chan_id)
assert (ibc1_chan_end.state == 'Init'), (ibc1_chan_end, "state is not Init")


def passive_channel_start_then_init(c: Config,
ibc1: ChainId, ibc0: ChainId,
ibc1_conn_id: ConnectionId, port_id: PortId):

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

# 2. create a channel in Init state
ibc1_chan_id = chan_open_init(c, dst=ibc1, src=ibc0, dst_conn=ibc1_conn_id)

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

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


def passive_channel_init_then_start(c: Config,
ibc1: ChainId, ibc0: ChainId,
ibc1_conn_id: ConnectionId, port_id: PortId):

# 1. create a channel in Init state
ibc1_chan_id = chan_open_init(c, dst=ibc1, src=ibc0, dst_conn=ibc1_conn_id)
sleep(2.0)

# 2. start relaying
proc = relayer.start(c)

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

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


def passive_channel_try_then_start(c: Config,
ibc1: ChainId,
ibc0: ChainId,
ibc1_conn_id: ConnectionId,
ibc0_conn_id: ConnectionId,
port_id: PortId):

# 1. create a channel in Try state
ibc1_chan_id = chan_open_init(c, dst=ibc1, src=ibc0, dst_conn=ibc1_conn_id)
sleep(2.0)
ibc0_chan_id = chan_open_try(c, dst=ibc0, src=ibc1, dst_conn=ibc0_conn_id, src_port=port_id, dst_port=port_id, src_chan=ibc1_chan_id)
sleep(2.0)

# 2. start relaying
proc = relayer.start(c)

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

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