Skip to content

Commit

Permalink
move Ics20Withdrawal and Ics20Transfer to shielded-pool crate
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Oct 31, 2023
1 parent 3991c00 commit 82be92a
Show file tree
Hide file tree
Showing 28 changed files with 1,368 additions and 642 deletions.
5 changes: 4 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/bin/pcli/src/command/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use penumbra_asset::{asset, asset::DenomMetadata, Value, STAKING_TOKEN_ASSET_ID}
use penumbra_dex::{lp::position, swap_claim::SwapClaimPlan};
use penumbra_fee::Fee;
use penumbra_governance::{proposal::ProposalToml, Vote};
use penumbra_ibc::Ics20Withdrawal;
use penumbra_keys::keys::AddressIndex;
use penumbra_num::Amount;
use penumbra_proto::{
Expand All @@ -42,6 +41,7 @@ use penumbra_proto::{
},
view::v1alpha1::GasPricesRequest,
};
use penumbra_shielded_pool::Ics20Withdrawal;
use penumbra_stake::rate::RateData;
use penumbra_stake::{DelegationToken, IdentityKey, Penalty, UnbondingToken, UndelegateClaimPlan};
use penumbra_transaction::{gas::swap_claim_gas_cost, memo::MemoPlaintext};
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/src/action_handler/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use penumbra_chain::TransactionContext;
use penumbra_ibc::component::transfer::Ics20Transfer;
use penumbra_ibc::component::StateReadExt as _;
use penumbra_shielded_pool::component::Ics20Transfer;
use penumbra_storage::{StateRead, StateWrite};
use penumbra_transaction::Action;

Expand Down
4 changes: 2 additions & 2 deletions crates/core/component/ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ component = [
"penumbra-storage",
"penumbra-proto/penumbra-storage",
"penumbra-chain/component",
"penumbra-shielded-pool/component",
#"penumbra-shielded-pool/component",
]
default = ["component", "std"]
std = ["ibc-types/std"]
Expand All @@ -24,7 +24,7 @@ penumbra-proto = { path = "../../../proto", default-features = false }
penumbra-storage = { path = "../../../storage", optional = true }
penumbra-component = { path = "../component", optional = true }
penumbra-chain = { path = "../chain", default-features = false }
penumbra-shielded-pool = { path = "../shielded-pool", default-features = false }
# penumbra-shielded-pool = { path = "../shielded-pool", default-features = false }
penumbra-asset = { path = "../../../core/asset", default-features = false }
penumbra-num = { path = "../../../core/num", default-features = false }
penumbra-keys = { path = "../../../core/keys", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions crates/core/component/ibc/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ pub mod rpc;
mod ibc_component;
mod metrics;
mod msg_handler;
mod packet;
pub mod packet;
mod proof_verification;
mod state_key;
pub mod state_key;
// TODO: move this to the shielded pool crate
pub mod transfer;
// pub mod transfer;
mod view;

use msg_handler::MsgHandler;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/ibc/src/component/action_handler.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod ibc_action;
mod ics20_withdrawal;
//mod ics20_withdrawal;
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
use std::sync::Arc;
// use std::sync::Arc;

use anyhow::Result;
use async_trait::async_trait;
use penumbra_component::ActionHandler;
use penumbra_storage::{StateRead, StateWrite};
// use anyhow::Result;
// use async_trait::async_trait;
// use penumbra_component::ActionHandler;
// use penumbra_storage::{StateRead, StateWrite};

use crate::{
component::transfer::{Ics20TransferReadExt as _, Ics20TransferWriteExt as _},
Ics20Withdrawal,
};
// use crate::{
// component::transfer::{Ics20TransferReadExt as _, Ics20TransferWriteExt as _},
// Ics20Withdrawal,
// };

#[async_trait]
impl ActionHandler for Ics20Withdrawal {
type CheckStatelessContext = ();
async fn check_stateless(&self, _context: ()) -> Result<()> {
self.validate()
}
// #[async_trait]
// impl ActionHandler for Ics20Withdrawal {
// type CheckStatelessContext = ();
// async fn check_stateless(&self, _context: ()) -> Result<()> {
// self.validate()
// }

async fn check_stateful<S: StateRead + 'static>(&self, state: Arc<S>) -> Result<()> {
state.withdrawal_check(self).await
}
// async fn check_stateful<S: StateRead + 'static>(&self, state: Arc<S>) -> Result<()> {
// state.withdrawal_check(self).await
// }

async fn execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
state.withdrawal_execute(self).await;
// async fn execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
// state.withdrawal_execute(self).await;

Ok(())
}
}
// Ok(())
// }
// }
85 changes: 81 additions & 4 deletions crates/core/component/ibc/src/component/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,84 @@ mod tests {
use crate::ibc_action::IbcActionWithHandler;
use crate::IbcAction;

use crate::component::transfer::Ics20Transfer;
use crate::component::app_handler::{AppHandler, AppHandlerCheck, AppHandlerExecute};
use ibc_types::core::channel::msgs::{
MsgAcknowledgement, MsgChannelCloseConfirm, MsgChannelCloseInit, MsgChannelOpenAck,
MsgChannelOpenConfirm, MsgChannelOpenInit, MsgChannelOpenTry, MsgRecvPacket, MsgTimeout,
};

struct MockAppHandler {}

#[async_trait]
impl AppHandlerCheck for MockAppHandler {
async fn chan_open_init_check<S: StateRead>(
state: S,
msg: &MsgChannelOpenInit,
) -> Result<()> {
Ok(())
}
async fn chan_open_try_check<S: StateRead>(
state: S,
msg: &MsgChannelOpenTry,
) -> Result<()> {
Ok(())
}
async fn chan_open_ack_check<S: StateRead>(
state: S,
msg: &MsgChannelOpenAck,
) -> Result<()> {
Ok(())
}
async fn chan_open_confirm_check<S: StateRead>(
state: S,
msg: &MsgChannelOpenConfirm,
) -> Result<()> {
Ok(())
}
async fn chan_close_confirm_check<S: StateRead>(
state: S,
msg: &MsgChannelCloseConfirm,
) -> Result<()> {
Ok(())
}
async fn chan_close_init_check<S: StateRead>(
state: S,
msg: &MsgChannelCloseInit,
) -> Result<()> {
Ok(())
}

async fn recv_packet_check<S: StateRead>(state: S, msg: &MsgRecvPacket) -> Result<()> {
Ok(())
}
async fn timeout_packet_check<S: StateRead>(state: S, msg: &MsgTimeout) -> Result<()> {
Ok(())
}
async fn acknowledge_packet_check<S: StateRead>(
state: S,
msg: &MsgAcknowledgement,
) -> Result<()> {
Ok(())
}
}

#[async_trait]
impl AppHandlerExecute for MockAppHandler {
async fn chan_open_init_execute<S: StateWrite>(state: S, msg: &MsgChannelOpenInit) {}
async fn chan_open_try_execute<S: StateWrite>(state: S, msg: &MsgChannelOpenTry) {}
async fn chan_open_ack_execute<S: StateWrite>(state: S, msg: &MsgChannelOpenAck) {}
async fn chan_open_confirm_execute<S: StateWrite>(state: S, msg: &MsgChannelOpenConfirm) {}
async fn chan_close_confirm_execute<S: StateWrite>(state: S, msg: &MsgChannelCloseConfirm) {
}
async fn chan_close_init_execute<S: StateWrite>(state: S, msg: &MsgChannelCloseInit) {}

async fn recv_packet_execute<S: StateWrite>(state: S, msg: &MsgRecvPacket) {}
async fn timeout_packet_execute<S: StateWrite>(state: S, msg: &MsgTimeout) {}
async fn acknowledge_packet_execute<S: StateWrite>(state: S, msg: &MsgAcknowledgement) {}
}

#[async_trait]
impl AppHandler for MockAppHandler {}

// test that we can create and update a light client.
#[tokio::test]
Expand Down Expand Up @@ -436,10 +513,10 @@ mod tests {

msg_update_stargaze_client.client_id = ClientId::from_str("07-tendermint-0").unwrap();

let create_client_action = IbcActionWithHandler::<Ics20Transfer>::new(
let create_client_action = IbcActionWithHandler::<MockAppHandler>::new(
IbcAction::CreateClient(msg_create_stargaze_client),
);
let update_client_action = IbcActionWithHandler::<Ics20Transfer>::new(
let update_client_action = IbcActionWithHandler::<MockAppHandler>::new(
IbcAction::UpdateClient(msg_update_stargaze_client),
);

Expand Down Expand Up @@ -467,7 +544,7 @@ mod tests {
let mut second_update = MsgUpdateClient::decode(msg_update_second.as_slice()).unwrap();
second_update.client_id = ClientId::from_str("07-tendermint-0").unwrap();
let second_update_client_action =
IbcActionWithHandler::<Ics20Transfer>::new(IbcAction::UpdateClient(second_update));
IbcActionWithHandler::<MockAppHandler>::new(IbcAction::UpdateClient(second_update));

second_update_client_action.check_stateless(()).await?;
second_update_client_action
Expand Down
54 changes: 34 additions & 20 deletions crates/core/component/ibc/src/component/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ use ibc_types::core::{
};
use penumbra_storage::{StateRead, StateWrite};

use crate::{
component::{
channel::{StateReadExt as _, StateWriteExt as _},
client::StateReadExt as _,
connection::StateReadExt as _,
},
Ics20Withdrawal,
use crate::component::{
channel::{StateReadExt as _, StateWriteExt as _},
client::StateReadExt as _,
connection::StateReadExt as _,
};

pub trait CheckStatus: private::Sealed {}
Expand Down Expand Up @@ -44,6 +41,23 @@ pub struct IBCPacket<S: CheckStatus> {
}

impl IBCPacket<Unchecked> {
pub fn new(
source_port: PortId,
source_channel: ChannelId,
timeout_height: Height,
timeout_timestamp: u64,
data: Vec<u8>,
) -> Self {
Self {
source_port,
source_channel,
timeout_height,
timeout_timestamp,
data,
m: std::marker::PhantomData,
}
}

pub fn assume_checked(self) -> IBCPacket<Checked> {
IBCPacket {
source_port: self.source_port,
Expand All @@ -56,19 +70,19 @@ impl IBCPacket<Unchecked> {
}
}

impl From<Ics20Withdrawal> for IBCPacket<Unchecked> {
fn from(withdrawal: Ics20Withdrawal) -> Self {
Self {
source_port: PortId::transfer(),
source_channel: withdrawal.source_channel.clone(),
timeout_height: withdrawal.timeout_height,
timeout_timestamp: withdrawal.timeout_time,
data: withdrawal.packet_data(),

m: std::marker::PhantomData,
}
}
}
// impl From<Ics20Withdrawal> for IBCPacket<Unchecked> {
// fn from(withdrawal: Ics20Withdrawal) -> Self {
// Self {
// source_port: PortId::transfer(),
// source_channel: withdrawal.source_channel.clone(),
// timeout_height: withdrawal.timeout_height,
// timeout_timestamp: withdrawal.timeout_time,
// data: withdrawal.packet_data(),

// m: std::marker::PhantomData,
// }
// }
// }

#[async_trait]
pub trait SendPacketRead: StateRead {
Expand Down
Loading

0 comments on commit 82be92a

Please sign in to comment.