From a9694cfc997a893bf3a9a66a6822e2b078b861b4 Mon Sep 17 00:00:00 2001 From: Chris Czub Date: Wed, 28 Feb 2024 20:34:08 -0500 Subject: [PATCH] Check value balance during IBC packet timeout (#3903) Once the mock test framework is further along, it would be good to add some tests around this logic. Closes #3773 --- .../shielded-pool/src/component/transfer.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/core/component/shielded-pool/src/component/transfer.rs b/crates/core/component/shielded-pool/src/component/transfer.rs index d5f6431756..2b95298ecc 100644 --- a/crates/core/component/shielded-pool/src/component/transfer.rs +++ b/crates/core/component/shielded-pool/src/component/transfer.rs @@ -261,7 +261,7 @@ async fn recv_transfer_packet_inner( // // 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 @@ -355,7 +355,6 @@ async fn recv_transfer_packet_inner( // 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 @@ -478,6 +477,14 @@ async fn timeout_packet_inner(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, @@ -491,6 +498,12 @@ async fn timeout_packet_inner(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(())