-
Notifications
You must be signed in to change notification settings - Fork 27
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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. |
@@ -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> }, |
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.
do we want to paginate this now?
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.
@cgorenflo Do we have an estimate on the rate of chain registration OR the current number of registered chains on ITS?
Some(msg::ChainStatusFilter::Frozen) => config.frozen, | ||
Some(msg::ChainStatusFilter::Active) => !config.frozen, |
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 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 } => { |
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 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)?; |
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.
the load_chain_configs should make use of pagination as well. Loading all configs from storage could lead to gas overflow later on
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, |
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.
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) |
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.
as mentioned before, this shouldn't be an unbounded range query
.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<_>, _>>()?; |
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.
use map_ok(...).try_collect()
instead
.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, |
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 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
Description
AXE-7369
Todos
Convention Checklist
exported
mod. If those types have already been defined somewhere else, then they should get re-exported in theexported
modSteps to Test
Expected Behaviour
Notes