Skip to content

Commit

Permalink
Better logging and strip null characters from channel_id from governa…
Browse files Browse the repository at this point in the history
…nce VAA
  • Loading branch information
nik-suri committed Apr 24, 2023
1 parent 5836f66 commit 306f17f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs
Expand Up @@ -111,14 +111,15 @@ fn handle_vaa(deps: DepsMut<WormholeQuery>, vaa: Binary) -> anyhow::Result<Event

let channel_id_str = String::from_utf8(channel_id.to_vec())
.context("failed to parse channel-id as utf-8")?;
let channel_id_trimmed = channel_id_str.trim_start_matches(char::from(0));

// update storage with the mapping
CHANNEL_CHAIN
.save(deps.storage, channel_id_str.clone(), &chain_id.into())
.save(deps.storage, channel_id_trimmed.to_string(), &chain_id.into())
.context("failed to save channel chain")?;
Ok(Event::new("UpdateChannelChain")
.add_attribute("chain_id", chain_id.to_string())
.add_attribute("channel_id", channel_id_str))
.add_attribute("channel_id", channel_id_trimmed))
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions cosmwasm/contracts/wormhole-ibc/src/contract.rs
Expand Up @@ -92,7 +92,11 @@ fn handle_vaa(deps: DepsMut, env: Env, vaa: Binary) -> anyhow::Result<Event> {
.context("failed to load contract config")?;
ensure!(
govpacket.chain == Chain::from(state.chain_id),
format!("this governance VAA is for chain {}, which does not match this chain ({})", u16::from(govpacket.chain), state.chain_id)
format!(
"this governance VAA is for chain {}, which does not match this chain ({})",
u16::from(govpacket.chain),
state.chain_id
)
);

// governance VAA replay protection
Expand All @@ -118,10 +122,11 @@ fn handle_vaa(deps: DepsMut, env: Env, vaa: Binary) -> anyhow::Result<Event> {

let channel_id_str = String::from_utf8(channel_id.to_vec())
.context("failed to parse channel-id as utf-8")?;
let channel_id_trimmed = channel_id_str.trim_start_matches(char::from(0));

// update the whitelisted wormchain channel id
WORMCHAIN_CHANNEL_ID
.save(deps.storage, &channel_id_str)
.save(deps.storage, &channel_id_trimmed.to_string())
.context("failed to save channel chain")?;
Ok(Event::new("UpdateChannelChain")
.add_attribute("chain_id", chain_id.to_string())
Expand Down

0 comments on commit 306f17f

Please sign in to comment.