Skip to content

Commit

Permalink
review fixes - handle error in open_ack
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 18, 2023
1 parent 61fa9bb commit 21ac5ca
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
16 changes: 3 additions & 13 deletions integration-tests/testcases/claimer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ describe('Test claim artifact', () => {
airdrop_address: airdropAddress, // incorrect address, migrated below
channel_id_to_hub: transferChannel.channel_id, // neutron to cosmoshub transfer channel id
ibc_neutron_denom: ibcDenom,
transfer_timeout_height: {
revision_number: 1,
revision_height: 5000,
},
ica_timeout_seconds: 5000,
}, 'credits', 'auto', {
admin: deployer // want to be able to migrate contract for testing purposes (set low timeout values)
Expand Down Expand Up @@ -205,21 +201,15 @@ describe('Test claim artifact', () => {
// pause hermes to test creating ica account two times almost simultaneously
await context.park.relayers.find(r => r.type() === 'hermes').pause();

console.log('create first ica account')
const first = await client.execute(deployer, claimerAddress, {
await client.execute(deployer, claimerAddress, {
create_hub_i_c_a: {},
}, 'auto', '', [])
console.log('first executed: ' + JSON.stringify(first.logs), null, '\t')

// second transaction should fail right away
console.log('create second ica account')
const second = await client.execute(deployer, claimerAddress, {
await client.execute(deployer, claimerAddress, {
create_hub_i_c_a: {},
}, 'auto', '', [])
console.log('second executed: ' + JSON.stringify(second.logs), null, '\t')

console.log('unpaused relayer')
// await context.park.relayers.find(r => r.type() === 'hermes').unpause();
await context.park.relayers.find(r => r.type() === 'hermes').unpause();

await waitFor(async () => {
const ica = await client.queryContractSmart(claimerAddress, { interchain_account: {} })
Expand Down
44 changes: 30 additions & 14 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use neutron_sdk::bindings::query::NeutronQuery;
use neutron_sdk::bindings::types::ProtobufAny;
use neutron_sdk::sudo::msg::{RequestPacket, RequestPacketTimeoutHeight, SudoMsg};
use neutron_sdk::{NeutronError, NeutronResult};
use serde_json_wasm::de::Error;

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
Expand Down Expand Up @@ -360,28 +361,43 @@ fn sudo_timeout(deps: DepsMut, env: Env, request: RequestPacket) -> StdResult<Re

fn sudo_open_ack(
deps: DepsMut,
_env: Env,
env: Env,
port_id: String,
channel_id: String,
counterparty_channel_id: String,
counterparty_version: String,
) -> StdResult<Response> {
let parsed_version: Result<OpenAckVersion, _> =
let parsed_version: Result<OpenAckVersion, Error> =
serde_json_wasm::from_str(counterparty_version.as_str());
if let Ok(parsed_version) = parsed_version {
INTERCHAIN_ACCOUNT.save(
deps.storage,
&Some(InterchainAccount {
address: parsed_version.address,
port_id,
channel_id,
counterparty_channel_id,
}),
)?;
return Ok(Response::default());

match parsed_version {
Ok(version) => {
INTERCHAIN_ACCOUNT.save(
deps.storage,
&Some(InterchainAccount {
address: version.address,
port_id,
channel_id,
counterparty_channel_id,
}),
)?;
}
Err(e) => {
save_ibc_callback_state(
deps.storage,
IbcCallbackState::OpenAckError(
e.to_string(),
env.block.height,
port_id,
channel_id,
counterparty_channel_id,
counterparty_version,
),
)?;
}
}

Err(StdError::generic_err("Can't parse counterparty_version"))
Ok(Response::default())
}

fn ibc_fee_from_funds(info: &MessageInfo) -> NeutronResult<(Coin, IbcFee)> {
Expand Down
1 change: 1 addition & 0 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum ExecuteMsg {

/// Step 2. Requires ICA to be created. Send funds to ICA account.
SendClaimedTokensToICA {
/// timeout_height is block height on the destination chain when timeout happens for IbcTransfer
timeout_height: RequestPacketTimeoutHeight,
},

Expand Down
2 changes: 2 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ pub enum IbcCallbackState {
Response(RequestPacket, u64), // request_packet, block_height
Timeout(RequestPacket, u64), // request_packet, block_height
Error(RequestPacket, String, u64), // error with request_packet, details, block_height

OpenAckError(String, u64, String, String, String, String), // parse_error, block_height, port_id, channel_id, counterparty_channel_id, counterparty_version
}

0 comments on commit 21ac5ca

Please sign in to comment.