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(controller): ability to update timeout for IBC channels #29

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ibc-controller"
version = "0.2.0"
version = "0.3.0"
authors = ["Astroport"]
license = "Apache-2.0"
description = "IBC controller contract intended to be hosted on the main chain."
Expand Down
39 changes: 35 additions & 4 deletions contracts/controller/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use astroport_ibc::TIMEOUT_LIMITS;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, IbcMsg, IbcTimeout, MessageInfo,
Response, StdError,
to_binary, Binary, CosmosMsg, Deps, DepsMut, Env, IbcMsg, IbcTimeout, MessageInfo, Response,
StdError,
};
use cw2::{get_contract_version, set_contract_version};
use ibc_controller_package::astroport_governance::assembly::ProposalStatus;

use ibc_controller_package::astroport_governance::astroport::common::{
claim_ownership, drop_ownership_proposal, propose_new_owner,
};
use ibc_controller_package::QueryMsg;
use ibc_controller_package::{ExecuteMsg, IbcProposal, InstantiateMsg};
use ibc_controller_package::{MigrateMsg, QueryMsg};

use crate::error::ContractError;
use crate::migration::migrate_config;
Expand Down Expand Up @@ -82,6 +82,23 @@ pub fn execute(
.add_attribute("action", "ibc_execute")
.add_attribute("channel", channel_id))
}
ExecuteMsg::UpdateTimeout { new_timeout } => {
if config.owner != info.sender {
return Err(ContractError::Unauthorized {});
}
if !TIMEOUT_LIMITS.contains(&new_timeout) {
return Err(ContractError::TimeoutLimitsError {});
}

CONFIG.update::<_, StdError>(deps.storage, |mut config| {
config.timeout = new_timeout;
Ok(config)
})?;

Ok(Response::new()
.add_attribute("action", "update_timeout")
.add_attribute("timeout", new_timeout.to_string()))
}
ExecuteMsg::ProposeNewOwner { owner, expires_in } => propose_new_owner(
deps,
info,
Expand Down Expand Up @@ -122,12 +139,26 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(mut deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
pub fn migrate(mut deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
let contract_version = get_contract_version(deps.storage)?;

match contract_version.contract.as_ref() {
"ibc-controller" => match contract_version.version.as_ref() {
"0.1.0" => migrate_config(&mut deps)?,
"0.2.0" => {
let new_timeout = msg
.new_timeout
.ok_or_else(|| StdError::generic_err("Missing new_timeout field"))?;

if !TIMEOUT_LIMITS.contains(&new_timeout) {
return Err(ContractError::TimeoutLimitsError {});
}

CONFIG.update::<_, StdError>(deps.storage, |mut config| {
config.timeout = new_timeout;
Ok(config)
})?;
}
_ => return Err(ContractError::MigrationError {}),
},
_ => return Err(ContractError::MigrationError {}),
Expand Down
7 changes: 6 additions & 1 deletion contracts/satellite/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cosmwasm_std::{
StdResult,
};

use astroport_ibc::TIMEOUT_LIMITS;
use cw_multi_test::{App, Contract, ContractWrapper, Executor};

fn mock_app(owner: &Addr, coins: Vec<Coin>) -> App {
Expand Down Expand Up @@ -65,7 +66,11 @@ fn test_check_messages() {
)
.unwrap_err();
assert_eq!(
"Timeout must be within limits (60 <= timeout <= 600)",
format!(
"Timeout must be within limits ({} <= timeout <= {})",
TIMEOUT_LIMITS.start(),
TIMEOUT_LIMITS.end()
),
err.root_cause().to_string()
);

Expand Down
2 changes: 1 addition & 1 deletion packages/astroport-ibc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use std::ops::RangeInclusive;

pub const TIMEOUT_LIMITS: RangeInclusive<u64> = 60..=600;
pub const TIMEOUT_LIMITS: RangeInclusive<u64> = 60..=43200;
8 changes: 8 additions & 0 deletions packages/controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ pub struct IbcProposal {

#[cw_serde]
pub enum ExecuteMsg {
/// Executes the IBC proposal that came from Assembly contract
IbcExecuteProposal {
channel_id: String,
proposal_id: u64,
messages: Vec<CosmosMsg>,
},
/// Updates the timeout for the IBC channel
UpdateTimeout { new_timeout: u64 },
/// Creates a request to change contract ownership
/// ## Executor
/// Only the current owner can execute this.
Expand All @@ -39,6 +42,11 @@ pub enum ExecuteMsg {
ClaimOwnership {},
}

#[cw_serde]
pub struct MigrateMsg {
pub new_timeout: Option<u64>,
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
Expand Down