-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(minor-interchain-token-service): skip invariant checks for p2p #687
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
use axelar_core_std::nexus; | ||
use axelar_wasm_std::{killswitch, nonempty, FnExt, IntoContractError}; | ||
use cosmwasm_std::{DepsMut, HexBinary, QuerierWrapper, Response, Storage}; | ||
use error_stack::{bail, ensure, report, Result, ResultExt}; | ||
|
@@ -72,6 +73,8 @@ | |
token_id: TokenId, | ||
chain: ChainNameRaw, | ||
}, | ||
#[error("error querying nexus module for chain registration for chain {0}")] | ||
Nexus(ChainNameRaw), | ||
} | ||
|
||
/// Executes an incoming ITS message. | ||
|
@@ -111,6 +114,7 @@ | |
|
||
let message = apply_to_hub( | ||
deps.storage, | ||
deps.querier, | ||
cc_id.source_chain.clone(), | ||
destination_chain.clone(), | ||
message, | ||
|
@@ -141,6 +145,7 @@ | |
|
||
fn apply_to_hub( | ||
storage: &mut dyn Storage, | ||
querier: QuerierWrapper, | ||
source_chain: ChainNameRaw, | ||
destination_chain: ChainNameRaw, | ||
message: Message, | ||
|
@@ -150,7 +155,7 @@ | |
|
||
match message { | ||
Message::InterchainTransfer(transfer) => { | ||
apply_to_transfer(storage, source_chain, destination_chain, transfer) | ||
apply_to_transfer(storage, querier, source_chain, destination_chain, transfer) | ||
.map(Message::InterchainTransfer)? | ||
} | ||
Message::DeployInterchainToken(deploy_token) => { | ||
|
@@ -163,18 +168,39 @@ | |
|
||
fn apply_to_transfer( | ||
storage: &mut dyn Storage, | ||
querier: QuerierWrapper, | ||
source_chain: ChainNameRaw, | ||
destination_chain: ChainNameRaw, | ||
transfer: InterchainTransfer, | ||
) -> Result<InterchainTransfer, Error> { | ||
interceptors::subtract_supply_amount(storage, &source_chain, &transfer)?; | ||
let transfer = interceptors::apply_scaling_factor_to_amount( | ||
storage, | ||
&source_chain, | ||
&destination_chain, | ||
transfer, | ||
)?; | ||
interceptors::add_supply_amount(storage, &destination_chain, &transfer)?; | ||
// we only do balance tracking for amplifier chains | ||
let client: nexus::Client = client::CosmosClient::new(querier).into(); | ||
let source_is_amplifier_chain = !client | ||
.is_chain_registered(&source_chain.normalize()) | ||
.change_context(Error::Nexus(source_chain.clone()))?; | ||
let destination_is_amplifier_chain = !client | ||
.is_chain_registered(&destination_chain.normalize()) | ||
.change_context(Error::Nexus(destination_chain.clone()))?; | ||
|
||
if source_is_amplifier_chain { | ||
interceptors::subtract_supply_amount(storage, &source_chain, &transfer)?; | ||
} | ||
|
||
// we only possibly scale if both source chain and destination chain are amplifier chains | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still need to scale for consensus chains. E.g. Ethereum <-> Sui Instead of skipping the interceptors completely for consensus chains, we need to apply the interceptors, but if the token instance can't be loaded and the chain is consensus, then we will need to use the "default" instance instead of failing. Perhaps the default instance can be the Untracked supply and the decimals from the token instance for the origin chain. This is more convoluted though. We could consider exposing a setter for the token instance for consensus chain and just migrate a few popular tokens but the others would fail |
||
let transfer = if source_is_amplifier_chain && destination_is_amplifier_chain { | ||
interceptors::apply_scaling_factor_to_amount( | ||
storage, | ||
&source_chain, | ||
&destination_chain, | ||
transfer, | ||
)? | ||
} else { | ||
transfer | ||
}; | ||
|
||
if destination_is_amplifier_chain { | ||
interceptors::add_supply_amount(storage, &destination_chain, &transfer)?; | ||
} | ||
|
||
Ok(transfer) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very procedural and is exactly what the interceptors PR wanted to avoid. I'd much prefer this function to just look like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should pass the querier in, because then we are going to need to repeatedly query whether a chain is registered with core. I can just query first and pass that data in though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the
ChainSpecifier
, it looks even worse now. We are repeatedly loading/querying/saving a lot of stuff. If gas cost is the top priority, we wouldn't be loading source token instance, subtracting, saving, loading destination token instance, adding, saving, loading both token instances again, applying scaling factor.