Skip to content

Commit

Permalink
Rework channel events (informalsystems#1859)
Browse files Browse the repository at this point in the history
* refactor events

* fmt

* chore: cleanup

* clippy fixes

* Formatting

* update channel event attributes conversion

* cargo clippy

* minor fix

* add changelog

Co-authored-by: Romain Ruetschi <romain.ruetschi@gmail.com>
  • Loading branch information
Wizdave97 and romac authored Mar 7, 2022
1 parent 52f5b12 commit a2eeb3c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Refactored ics04_channel events
([#718](https://github.com/informalsystems/ibc-rs/issues/718))
5 changes: 3 additions & 2 deletions relayer/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Channel<ChainA, ChainB> {
channel_open_event: IbcEvent,
) -> Result<Channel<ChainA, ChainB>, ChannelError> {
let channel_event_attributes = channel_open_event
.clone()
.channel_attributes()
.ok_or_else(|| ChannelError::invalid_event(channel_open_event.clone()))?;
.ok_or_else(|| ChannelError::invalid_event(channel_open_event))?;

let port_id = channel_event_attributes.port_id.clone();
let channel_id = channel_event_attributes.channel_id.clone();
Expand Down Expand Up @@ -232,7 +233,7 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Channel<ChainA, ChainB> {
connection.counterparty().client_id().clone(),
counterparty_connection_id.clone(),
channel_event_attributes.counterparty_port_id.clone(),
channel_event_attributes.counterparty_channel_id.clone(),
channel_event_attributes.counterparty_channel_id,
None,
),
connection_delay: connection.delay_period(),
Expand Down
20 changes: 11 additions & 9 deletions relayer/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,34 +418,36 @@ pub fn collect_events(
}
IbcEvent::OpenInitChannel(..) | IbcEvent::OpenTryChannel(..) => {
collect_event(&mut collected, event, mode.channels.enabled, || {
event.channel_attributes().and_then(|attr| {
Object::channel_from_chan_open_events(attr, src_chain).ok()
event.clone().channel_attributes().and_then(|attr| {
Object::channel_from_chan_open_events(&attr, src_chain).ok()
})
});
}
IbcEvent::OpenAckChannel(ref open_ack) => {
IbcEvent::OpenAckChannel(open_ack) => {
// Create client and packet workers here as channel end must be opened
let attributes = open_ack.clone().into();
collect_event(&mut collected, event, mode.clients.enabled, || {
Object::client_from_chan_open_events(open_ack.attributes(), src_chain).ok()
Object::client_from_chan_open_events(&attributes, src_chain).ok()
});

collect_event(&mut collected, event, mode.packets.enabled, || {
Object::packet_from_chan_open_events(open_ack.attributes(), src_chain).ok()
Object::packet_from_chan_open_events(&attributes, src_chain).ok()
});

// If handshake message relaying is enabled create worker to send the MsgChannelOpenConfirm message
collect_event(&mut collected, event, mode.channels.enabled, || {
Object::channel_from_chan_open_events(open_ack.attributes(), src_chain).ok()
Object::channel_from_chan_open_events(&attributes, src_chain).ok()
});
}
IbcEvent::OpenConfirmChannel(ref open_confirm) => {
IbcEvent::OpenConfirmChannel(open_confirm) => {
let attributes = open_confirm.clone().into();
// Create client worker here as channel end must be opened
collect_event(&mut collected, event, mode.clients.enabled, || {
Object::client_from_chan_open_events(open_confirm.attributes(), src_chain).ok()
Object::client_from_chan_open_events(&attributes, src_chain).ok()
});

collect_event(&mut collected, event, mode.packets.enabled, || {
Object::packet_from_chan_open_events(open_confirm.attributes(), src_chain).ok()
Object::packet_from_chan_open_events(&attributes, src_chain).ok()
});
}
IbcEvent::SendPacket(ref packet) => {
Expand Down

0 comments on commit a2eeb3c

Please sign in to comment.