Skip to content

Commit

Permalink
Check value balance during IBC packet timeout (#3903)
Browse files Browse the repository at this point in the history
Once the mock test framework is further along, it would be good to add
some tests around this logic.

Closes #3773
  • Loading branch information
zbuc authored Feb 29, 2024
1 parent 455d0e6 commit a9694cf
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/core/component/shielded-pool/src/component/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ async fn recv_transfer_packet_inner<S: StateWrite>(
//
// https://github.com/cosmos/ibc/tree/main/spec/app/ics-020-fungible-token-transfer (onRecvPacket)
//
// NOTE: spec says proto but thsi is actualy JSON according to the ibc-go implementation
// NOTE: spec says proto but this is actually JSON according to the ibc-go implementation
let packet_data: FungibleTokenPacketData = serde_json::from_slice(msg.packet.data.as_slice())
.with_context(|| "failed to decode FTPD packet")?;
let denom: asset::Metadata = packet_data
Expand Down Expand Up @@ -355,7 +355,6 @@ async fn recv_transfer_packet_inner<S: StateWrite>(
// prefixedDenomination = prefix + data.denom
//
// then mint that denom to packet_data.receiver in packet_data.amount
// no value balance to update here since this is an exogenous denom
let prefixed_denomination = format!(
"{}/{}/{}",
msg.packet.port_on_b, msg.packet.chan_on_b, packet_data.denom
Expand Down Expand Up @@ -478,6 +477,14 @@ async fn timeout_packet_inner<S: StateWrite>(mut state: S, msg: &MsgTimeout) ->
new_value_balance,
);
} else {
let value_balance: Amount = state
.get(&state_key::ics20_value_balance(
&msg.packet.chan_on_a,
&denom.id(),
))
.await?
.unwrap_or_else(Amount::zero);

state
.mint_note(
value,
Expand All @@ -491,6 +498,12 @@ async fn timeout_packet_inner<S: StateWrite>(mut state: S, msg: &MsgTimeout) ->
)
.await
.context("failed to mint return voucher in ics20 transfer timeout")?;

let new_value_balance = value_balance.saturating_add(&value.amount);
state.put(
state_key::ics20_value_balance(&msg.packet.chan_on_a, &denom.id()),
new_value_balance,
);
}

Ok(())
Expand Down

0 comments on commit a9694cf

Please sign in to comment.