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

ibc: use ibc-types typed events, add SendPacket event #2829

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 2 additions & 43 deletions crates/core/component/ibc/src/component/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{Context, Result};
use async_trait::async_trait;

use ibc_types::core::client::msgs::MsgUpdateClient;
use ibc_types::core::client::ClientId;
use ibc_types::core::client::ClientType;
use ibc_types::core::client::Height;
Expand All @@ -15,10 +14,7 @@ use penumbra_chain::component::StateReadExt as _;
use penumbra_proto::{StateReadProto, StateWriteProto};
use penumbra_storage::{StateRead, StateWrite};

use crate::{
component::client_counter::{ics02_validation, ClientCounter, VerifiedHeights},
event,
};
use crate::component::client_counter::{ClientCounter, VerifiedHeights};

use super::state_key;

Expand All @@ -32,44 +28,6 @@ use super::state_key;

#[async_trait]
pub(crate) trait Ics2ClientExt: StateWrite {
// execute a UpdateClient IBC action. this assumes that the UpdateClient has already been
// validated, including header verification.
async fn execute_update_client(&mut self, msg_update_client: &MsgUpdateClient) -> Result<()> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is dead code; we inlined it into the msg handler for update client a while ago

// TODO(erwan): deferred client state deserialization means `execute_update_client` is faillible
// see ibc-rs ADR004: https://github.com/cosmos/ibc-rs/blob/main/docs/architecture/adr-004-light-client-crates-extraction.md#light-client-specific-code
let tm_header = ics02_validation::get_tendermint_header(msg_update_client.header.clone())?;

// get the latest client state
let client_state = self
.get_client_state(&msg_update_client.client_id)
.await
.unwrap();

let (next_tm_client_state, next_tm_consensus_state) = self
.next_tendermint_state(
msg_update_client.client_id.clone(),
client_state.clone(),
tm_header.clone(),
)
.await;

// store the updated client and consensus states
self.put_client(&msg_update_client.client_id, next_tm_client_state);
self.put_verified_consensus_state(
tm_header.height(),
msg_update_client.client_id.clone(),
next_tm_consensus_state,
)
.await
.unwrap();

self.record(event::update_client(
msg_update_client.client_id.clone(),
tm_header,
));
Ok(())
}

// given an already verified tendermint header, and a trusted tendermint client state, compute
// the next client and consensus states.
async fn next_tendermint_state(
Expand Down Expand Up @@ -395,6 +353,7 @@ mod tests {
use std::sync::Arc;

use super::*;
use ibc_types::core::client::msgs::MsgUpdateClient;
use ibc_types::{core::client::msgs::MsgCreateClient, DomainType};
use penumbra_chain::component::StateWriteExt;
use penumbra_component::ActionHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use anyhow::Result;
use async_trait::async_trait;
use ibc_types::core::{
channel::channel::Order as ChannelOrder, channel::channel::State as ChannelState,
channel::msgs::MsgAcknowledgement, channel::PortId, connection::State as ConnectionState,
channel::events, channel::msgs::MsgAcknowledgement, channel::PortId,
connection::State as ConnectionState,
};
use penumbra_storage::StateWrite;

Expand All @@ -15,8 +16,6 @@ use crate::component::{
MsgHandler,
};

use crate::event;

#[async_trait]
impl MsgHandler for MsgAcknowledgement {
async fn check_stateless(&self) -> Result<()> {
Expand Down Expand Up @@ -96,7 +95,20 @@ impl MsgHandler for MsgAcknowledgement {
self.packet.sequence.into(),
);

state.record(event::acknowledge_packet(&self.packet, &channel));
state.record(
events::packet::AcknowledgePacket {
timeout_height: self.packet.timeout_height_on_b,
timeout_timestamp: self.packet.timeout_timestamp_on_b,
sequence: self.packet.sequence,
src_port_id: self.packet.port_on_a.clone(),
src_channel_id: self.packet.chan_on_a.clone(),
dst_port_id: self.packet.port_on_b.clone(),
dst_channel_id: self.packet.chan_on_b.clone(),
channel_ordering: channel.ordering,
src_connection_id: channel.connection_hops[0].clone(),
}
.into(),
);

let transfer = PortId::transfer();
if self.packet.port_on_b == transfer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ use anyhow::Result;
use async_trait::async_trait;
use ibc_types::core::{
channel::{
channel::State as ChannelState, msgs::MsgChannelCloseConfirm, ChannelEnd, Counterparty,
PortId,
channel::State as ChannelState, events, msgs::MsgChannelCloseConfirm, ChannelEnd,
Counterparty, PortId,
},
connection::State as ConnectionState,
};
use penumbra_storage::StateWrite;

use crate::{
component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
proof_verification::ChannelProofVerifier,
transfer::Ics20Transfer,
MsgHandler,
},
event,
use crate::component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
proof_verification::ChannelProofVerifier,
transfer::Ics20Transfer,
MsgHandler,
};

#[async_trait]
Expand Down Expand Up @@ -93,11 +90,20 @@ impl MsgHandler for MsgChannelCloseConfirm {
channel.set_state(ChannelState::Closed);
state.put_channel(&self.chan_id_on_b, &self.port_id_on_b, channel.clone());

state.record(event::channel_close_confirm(
&self.port_id_on_b,
&self.chan_id_on_b,
&channel,
));
state.record(
events::channel::CloseConfirm {
port_id: self.port_id_on_b.clone(),
channel_id: self.chan_id_on_b.clone(),
counterparty_port_id: channel.counterparty().port_id.clone(),
counterparty_channel_id: channel
.counterparty()
.channel_id
.clone()
.unwrap_or_default(),
connection_id: channel.connection_hops[0].clone(),
}
.into(),
);

let transfer = PortId::transfer();
if self.port_id_on_b == transfer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
use anyhow::Result;
use async_trait::async_trait;
use ibc_types::core::{
channel::channel::State as ChannelState, channel::msgs::MsgChannelCloseInit, channel::PortId,
connection::State as ConnectionState,
channel::channel::State as ChannelState, channel::events, channel::msgs::MsgChannelCloseInit,
channel::PortId, connection::State as ConnectionState,
};
use penumbra_storage::StateWrite;

use crate::{
component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
transfer::Ics20Transfer,
MsgHandler,
},
event,
use crate::component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
transfer::Ics20Transfer,
MsgHandler,
};

#[async_trait]
Expand Down Expand Up @@ -57,11 +54,20 @@ impl MsgHandler for MsgChannelCloseInit {
channel.set_state(ChannelState::Closed);
state.put_channel(&self.chan_id_on_a, &self.port_id_on_a, channel.clone());

state.record(event::channel_close_init(
&self.port_id_on_a,
&self.chan_id_on_a,
&channel,
));
state.record(
events::channel::CloseInit {
port_id: self.port_id_on_a.clone(),
channel_id: self.chan_id_on_a.clone(),
counterparty_port_id: channel.counterparty().port_id.clone(),
counterparty_channel_id: channel
.counterparty()
.channel_id
.clone()
.unwrap_or_default(),
connection_id: channel.connection_hops[0].clone(),
}
.into(),
);

let transfer = PortId::transfer();
if self.port_id_on_a == transfer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
use anyhow::Result;
use async_trait::async_trait;
use ibc_types::core::{
channel::channel::State as ChannelState, channel::msgs::MsgChannelOpenAck, channel::ChannelEnd,
channel::Counterparty, channel::PortId, connection::ConnectionEnd,
channel::channel::State as ChannelState, channel::events, channel::msgs::MsgChannelOpenAck,
channel::ChannelEnd, channel::Counterparty, channel::PortId, connection::ConnectionEnd,
connection::State as ConnectionState,
};
use penumbra_storage::{StateRead, StateWrite};

use crate::{
component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
proof_verification::ChannelProofVerifier,
transfer::Ics20Transfer,
MsgHandler,
},
event,
use crate::component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
proof_verification::ChannelProofVerifier,
transfer::Ics20Transfer,
MsgHandler,
};

#[async_trait]
Expand Down Expand Up @@ -80,11 +77,20 @@ impl MsgHandler for MsgChannelOpenAck {
channel.set_counterparty_channel_id(self.chan_id_on_b.clone());
state.put_channel(&self.chan_id_on_a, &self.port_id_on_a, channel.clone());

state.record(event::channel_open_ack(
&self.port_id_on_a,
&self.chan_id_on_a,
&channel,
));
state.record(
events::channel::OpenAck {
port_id: self.port_id_on_a.clone(),
channel_id: self.chan_id_on_a.clone(),
counterparty_channel_id: channel
.counterparty()
.channel_id
.clone()
.unwrap_or_default(),
counterparty_port_id: channel.counterparty().port_id.clone(),
connection_id: channel.connection_hops[0].clone(),
}
.into(),
);

let transfer = PortId::transfer();
if self.port_id_on_a == transfer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
use anyhow::Result;
use async_trait::async_trait;
use ibc_types::core::{
channel::channel::State as ChannelState, channel::msgs::MsgChannelOpenConfirm,
channel::channel::State as ChannelState, channel::events, channel::msgs::MsgChannelOpenConfirm,
channel::ChannelEnd, channel::Counterparty, channel::PortId,
connection::State as ConnectionState,
};
use penumbra_storage::StateWrite;

use crate::{
component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
proof_verification::ChannelProofVerifier,
transfer::Ics20Transfer,
MsgHandler,
},
event,
use crate::component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
proof_verification::ChannelProofVerifier,
transfer::Ics20Transfer,
MsgHandler,
};

#[async_trait]
Expand Down Expand Up @@ -89,11 +86,20 @@ impl MsgHandler for MsgChannelOpenConfirm {
channel.set_state(ChannelState::Open);
state.put_channel(&self.chan_id_on_b, &self.port_id_on_b, channel.clone());

state.record(event::channel_open_confirm(
&self.port_id_on_b,
&self.chan_id_on_b,
&channel,
));
state.record(
events::channel::OpenConfirm {
port_id: self.port_id_on_b.clone(),
channel_id: self.chan_id_on_b.clone(),
counterparty_port_id: channel.counterparty().port_id.clone(),
counterparty_channel_id: channel
.counterparty()
.channel_id
.clone()
.unwrap_or_default(),
connection_id: channel.connection_hops[0].clone(),
}
.into(),
);

let transfer = PortId::transfer();
if self.port_id_on_b == transfer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use anyhow::Result;
use async_trait::async_trait;
use ibc_types::core::channel::msgs::MsgChannelOpenInit;
use ibc_types::core::channel::{channel::State, ChannelEnd, ChannelId, Counterparty, PortId};
use ibc_types::core::channel::{
channel::State, events, ChannelEnd, ChannelId, Counterparty, PortId,
};
use penumbra_storage::{StateRead, StateWrite};

use crate::{
component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
transfer::Ics20Transfer,
MsgHandler,
},
event,
use crate::component::{
app_handler::{AppHandlerCheck, AppHandlerExecute},
channel::{StateReadExt as _, StateWriteExt as _},
connection::StateReadExt as _,
transfer::Ics20Transfer,
MsgHandler,
};

#[async_trait]
Expand Down Expand Up @@ -55,11 +54,16 @@ impl MsgHandler for MsgChannelOpenInit {
state.put_recv_sequence(&channel_id, &self.port_id_on_a, 1);
state.put_ack_sequence(&channel_id, &self.port_id_on_a, 1);

state.record(event::channel_open_init(
&self.port_id_on_a,
&channel_id,
&new_channel,
));
state.record(
events::channel::OpenInit {
port_id: self.port_id_on_a.clone(),
channel_id: channel_id.clone(),
counterparty_port_id: new_channel.counterparty().port_id().clone(),
connection_id: new_channel.connection_hops[0].clone(),
version: new_channel.version.clone(),
}
.into(),
);

let transfer = PortId::transfer();
if self.port_id_on_a == transfer {
Expand Down
Loading
Loading