Skip to content
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

feat(minor-interchain-token-service): all chains with optional filter query message #754

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

maancham
Copy link
Contributor

@maancham maancham commented Feb 5, 2025

Description

AXE-7369

Todos

  • Unit tests
  • Manual tests
  • Documentation
  • Connect epics/issues

Convention Checklist

  • Each contract should have a client mod for others to interact with it.
  • Derive macros
  • The state mod and msg mod should use separate data structures so that internal state changes do not break the contract interface. Check out the interchain-token-service for reference.
    • msg.rs should never use any type from the state.rs
    • Shared types must be defined in a separate exported mod. If those types have already been defined somewhere else, then they should get re-exported in the exported mod

Steps to Test

Expected Behaviour

Notes

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.66%. Comparing base (541aad9) to head (ed452c9).

Files with missing lines Patch % Lines
...cts/interchain-token-service/src/contract/query.rs 94.73% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #754   +/-   ##
=======================================
  Coverage   93.65%   93.66%           
=======================================
  Files         222      222           
  Lines       36332    36373   +41     
=======================================
+ Hits        34028    34068   +40     
- Misses       2304     2305    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -85,6 +96,10 @@ pub enum QueryMsg {
#[returns(HashMap<ChainNameRaw, Address>)]
AllItsContracts,

/// Query all chain configs with optional frozen filter
#[returns(Vec<ChainConfigResponse>)]
ItsChains { filter: Option<ChainConfigFilter> },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to paginate this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgorenflo Do we have an estimate on the rate of chain registration OR the current number of registered chains on ITS?

contracts/interchain-token-service/src/msg.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/msg.rs Outdated Show resolved Hide resolved
contracts/interchain-token-service/src/contract/query.rs Outdated Show resolved Hide resolved
@maancham maancham marked this pull request as ready for review February 6, 2025 16:00
@maancham maancham requested a review from a team as a code owner February 6, 2025 16:00
Comment on lines +55 to +56
Some(msg::ChainStatusFilter::Frozen) => config.frozen,
Some(msg::ChainStatusFilter::Active) => !config.frozen,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to implement a matches function directly on the ChainStatusFilter

@@ -137,6 +139,9 @@ pub fn query(deps: Deps, _: Env, msg: QueryMsg) -> Result<Binary, ContractError>
QueryMsg::AllItsContracts => {
query::all_its_contracts(deps).change_context(Error::QueryAllItsContracts)
}
QueryMsg::ItsChains { filter } => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also needs pagination to avoid gas overflow

@@ -34,6 +34,30 @@ pub fn all_its_contracts(deps: Deps) -> Result<Binary, Error> {
to_json_binary(&contract_addresses).change_context(Error::JsonSerialization)
}

pub fn its_chains(deps: Deps, filter: Option<msg::ChainFilter>) -> Result<Binary, Error> {
let state_configs = state::load_chain_configs(deps.storage).change_context(Error::State)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the load_chain_configs should make use of pagination as well. Loading all configs from storage could lead to gas overflow later on

Comment on lines +40 to +45
let chain_configs = match filter {
Some(filter) if filter.frozen_status.is_some() => state_configs
.into_iter()
.filter(|config| matches_filter(config, filter.frozen_status.as_ref()))
.collect(),
_ => state_configs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let chain_configs = match filter {
Some(filter) if filter.frozen_status.is_some() => state_configs
.into_iter()
.filter(|config| matches_filter(config, filter.frozen_status.as_ref()))
.collect(),
_ => state_configs,
let chain_configs = match filter {
Some(msg::ChainFilter {
frozen_status: Some(frozen_status),
}) => state_configs
.into_iter()
.filter(|config| frozen_status.matches(config))
.collect(),
_ => state_configs,

@@ -170,6 +170,27 @@ pub fn load_chain_config(
.ok_or_else(|| report!(Error::ChainNotFound(chain.to_owned())))
}

pub fn load_chain_configs(storage: &dyn Storage) -> Result<Vec<msg::ChainConfigResponse>, Error> {
let configs = CHAIN_CONFIGS
.range(storage, None, None, Order::Ascending)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned before, this shouldn't be an unbounded range query

Comment on lines +176 to +190
.map(|res| {
res.change_context(Error::Storage)
.map(|(chain, config)| msg::ChainConfigResponse {
chain,
its_edge_contract: config.its_address,
truncation: msg::TruncationConfig {
max_uint: config.truncation.max_uint,
max_decimals_when_truncating: config
.truncation
.max_decimals_when_truncating,
},
frozen: config.frozen,
})
})
.collect::<Result<Vec<_>, _>>()?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use map_ok(...).try_collect() instead

Comment on lines +178 to +187
.map(|(chain, config)| msg::ChainConfigResponse {
chain,
its_edge_contract: config.its_address,
truncation: msg::TruncationConfig {
max_uint: config.truncation.max_uint,
max_decimals_when_truncating: config
.truncation
.max_decimals_when_truncating,
},
frozen: config.frozen,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to extract the mapping into it's own function, it's a separate concern to convert it into a msg type from loading it from storage. In fact, I think it's cleaner to return the actual chain configs here, and convert it in a separate step, at the call site

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants