Skip to content

Commit

Permalink
Remove migration of old(pre 0.19) adapters on manager (#433)
Browse files Browse the repository at this point in the history
* remove old adapter migration

* update changelog
  • Loading branch information
Buckram123 authored Aug 20, 2024
1 parent e01d6ac commit dca0301
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 230 deletions.
111 changes: 18 additions & 93 deletions framework/contracts/account/manager/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use abstract_std::{
},
manager::{
state::{
AccountInfo, SuspensionStatus, ACCOUNT_MODULES, CONFIG, DEPENDENTS, INFO,
REMOVE_ADAPTER_AUTHORIZED_CONTEXT, SUB_ACCOUNTS, SUSPENSION_STATUS,
AccountInfo, SuspensionStatus, ACCOUNT_MODULES, CONFIG, DEPENDENTS, INFO, SUB_ACCOUNTS,
SUSPENSION_STATUS,
},
CallbackMsg, ExecuteMsg, InternalConfigAction, ModuleInstallConfig, UpdateSubAccountAction,
},
Expand Down Expand Up @@ -43,7 +43,6 @@ use crate::{
};

pub const REGISTER_MODULES_DEPENDENCIES: u64 = 1;
pub const HANDLE_ADAPTER_AUTHORIZED_REMOVE: u64 = 2;

#[abstract_response(MANAGER)]
pub struct ManagerResponse;
Expand Down Expand Up @@ -540,12 +539,6 @@ pub(crate) fn remove_account_from_contracts(deps: DepsMut) -> ManagerResult<Vec<
Ok(msgs)
}

// How many adapters removed, list of submessages
pub(crate) struct RemoveAdapterAuthorized {
sent_count: u64,
sub_msgs: Vec<SubMsg>,
}

/// Migrate modules through address updates or contract migrations
/// The dependency store is updated during migration
/// A reply message is called after performing all the migrations which ensures version compatibility of the new state.
Expand All @@ -561,11 +554,6 @@ pub fn upgrade_modules(

let mut upgrade_msgs = vec![];

let mut remove_adapter_authorized = RemoveAdapterAuthorized {
sent_count: 0,
sub_msgs: vec![],
};

let mut manager_migrate_info = None;

let mut upgraded_module_ids = Vec::new();
Expand All @@ -589,7 +577,6 @@ pub fn upgrade_modules(
module_info,
migrate_msg,
&mut upgrade_msgs,
&mut remove_adapter_authorized,
)?;
}
}
Expand All @@ -610,19 +597,10 @@ pub fn upgrade_modules(
vec![],
)?;

// Save context
// TODO: remove after next patch
let RemoveAdapterAuthorized {
sent_count,
sub_msgs,
} = remove_adapter_authorized;
REMOVE_ADAPTER_AUTHORIZED_CONTEXT.save(deps.storage, &sent_count)?;

Ok(ManagerResponse::new(
"upgrade_modules",
vec![("upgraded_modules", upgraded_module_ids.join(","))],
)
.add_submessages(sub_msgs)
.add_messages(upgrade_msgs)
.add_message(callback_msg))
}
Expand All @@ -632,7 +610,6 @@ pub(crate) fn set_migrate_msgs_and_context(
module_info: ModuleInfo,
migrate_msg: Option<Binary>,
msgs: &mut Vec<CosmosMsg>,
remove_adapter_authorized: &mut RemoveAdapterAuthorized,
) -> Result<(), ManagerError> {
let config = CONFIG.load(deps.storage)?;
let version_control = VersionControlContract::new(config.version_control_address);
Expand All @@ -644,21 +621,12 @@ pub(crate) fn set_migrate_msgs_and_context(

let migrate_msgs = match requested_module.module.reference {
// upgrading an adapter is done by moving the authorized addresses to the new contract address and updating the permissions on the proxy.
ModuleReference::Adapter(new_adapter_addr) => {
let (remove_authorized_submsg, msgs) = handle_adapter_migration(
deps,
requested_module.module.info,
old_module_addr,
new_adapter_addr,
)?;
remove_adapter_authorized
.sub_msgs
.extend(remove_authorized_submsg);
// we send 2 messages, one will succeed and other fail -
// so we count down to make sure we get expected amount of failed "updates"
remove_adapter_authorized.sent_count += 1;
msgs
}
ModuleReference::Adapter(new_adapter_addr) => handle_adapter_migration(
deps,
requested_module.module.info,
old_module_addr,
new_adapter_addr,
)?,
ModuleReference::App(code_id) => handle_app_migration(
deps,
migrate_msg,
Expand Down Expand Up @@ -686,7 +654,7 @@ fn handle_adapter_migration(
module_info: ModuleInfo,
old_adapter_addr: Addr,
new_adapter_addr: Addr,
) -> ManagerResult<([SubMsg; 2], Vec<CosmosMsg>)> {
) -> ManagerResult<Vec<CosmosMsg>> {
let module_id = module_info.id();
versioning::assert_migrate_requirements(
deps.as_ref(),
Expand Down Expand Up @@ -764,7 +732,7 @@ pub fn replace_adapter(
deps: DepsMut,
new_adapter_addr: Addr,
old_adapter_addr: Addr,
) -> Result<([SubMsg; 2], Vec<CosmosMsg>), ManagerError> {
) -> Result<Vec<CosmosMsg>, ManagerError> {
let mut msgs = vec![];
// Makes sure we already have the adapter installed
let proxy_addr = ACCOUNT_MODULES.load(deps.storage, PROXY)?;
Expand All @@ -781,31 +749,13 @@ pub fn replace_adapter(
.map(|addr| addr.into_string())
.collect();
// Remove authorized addresses
// If removing of authorized addresses on adapter failed - maybe it's old adapter
// and we need to retry it with old base message
let remove_authorized_submsg: SubMsg = SubMsg::reply_on_error(
configure_adapter(
&old_adapter_addr,
AdapterBaseMsg::UpdateAuthorizedAddresses {
to_add: vec![],
to_remove: authorized_to_migrate.clone(),
},
)?,
HANDLE_ADAPTER_AUTHORIZED_REMOVE,
);
// If removing of authorized addresses on adapter failed - maybe it's old adapter
// and we need to retry it with old base message
let remove_old_authorized_submsg: SubMsg = SubMsg::reply_on_error(
configure_old_adapter(
&old_adapter_addr,
AdapterBaseMsg::UpdateAuthorizedAddresses {
to_add: vec![],
to_remove: authorized_to_migrate.clone(),
},
)?,
HANDLE_ADAPTER_AUTHORIZED_REMOVE,
);

msgs.push(configure_adapter(
&old_adapter_addr,
AdapterBaseMsg::UpdateAuthorizedAddresses {
to_add: vec![],
to_remove: authorized_to_migrate.clone(),
},
)?);
// Add authorized addresses to new
msgs.push(configure_adapter(
&new_adapter_addr,
Expand All @@ -825,10 +775,7 @@ pub fn replace_adapter(
vec![new_adapter_addr.into_string()],
)?);

Ok((
[remove_authorized_submsg, remove_old_authorized_submsg],
msgs,
))
Ok(msgs)
}

/// Update the Account information
Expand Down Expand Up @@ -974,18 +921,6 @@ fn configure_adapter(
Ok(wasm_execute(adapter_address, &adapter_msg, vec![])?.into())
}

// TODO: remove after patch
#[inline(always)]
fn configure_old_adapter(
adapter_address: impl Into<String>,
message: AdapterBaseMsg,
) -> StdResult<CosmosMsg> {
type OldAdapterBaseExecuteMsg = abstract_std::base::ExecuteMsg<AdapterBaseMsg, Empty, Empty>;

let adapter_msg = OldAdapterBaseExecuteMsg::Base(message);
Ok(wasm_execute(adapter_address, &adapter_msg, vec![])?.into())
}

pub fn update_account_status(
deps: DepsMut,
info: MessageInfo,
Expand Down Expand Up @@ -1022,16 +957,6 @@ pub fn update_internal_config(deps: DepsMut, info: MessageInfo, config: Binary)
update_module_addresses(deps, add, remove)
}

pub(crate) fn adapter_authorized_remove(deps: DepsMut, result: SubMsgResult) -> ManagerResult {
REMOVE_ADAPTER_AUTHORIZED_CONTEXT.update(deps.storage, |count| {
count
.checked_sub(1)
// If we got more errors than expected - return errors from now on
.ok_or(StdError::generic_err(result.unwrap_err()))
})?;
Ok(Response::new())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
3 changes: 0 additions & 3 deletions framework/contracts/account/manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,6 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> ManagerResult {
commands::REGISTER_MODULES_DEPENDENCIES => {
commands::register_dependencies(deps, msg.result)
}
commands::HANDLE_ADAPTER_AUTHORIZED_REMOVE => {
commands::adapter_authorized_remove(deps, msg.result)
}
_ => Err(ManagerError::UnexpectedReply {}),
}
}
Expand Down
32 changes: 0 additions & 32 deletions framework/contracts/account/manager/tests/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,35 +633,3 @@ fn subaccount_adapter_ownership() -> AResult {
);
Ok(())
}

mod old_mock {
use super::*;

use abstract_adapter::gen_adapter_old_mock;
use mock_modules::adapter_1::MOCK_ADAPTER_ID;

gen_adapter_old_mock!(OldMockAdapter1V1, MOCK_ADAPTER_ID, "1.0.0", &[]);

#[test]
fn old_adapters_migratable() -> AResult {
let chain = MockBech32::new("mock");
let sender = chain.sender_addr();
let deployment = Abstract::deploy_on(chain.clone(), sender.to_string())?;
let account = create_default_account(&deployment.account_factory)?;

deployment
.version_control
.claim_namespace(TEST_ACCOUNT_ID, "tester".to_owned())?;

let old = OldMockAdapter1V1::new_test(chain.clone());
old.deploy(V1.parse().unwrap(), MockInitMsg {}, DeployStrategy::Try)?;

account.install_adapter(&old, None)?;

let new = MockAdapterI1V2::new_test(chain.clone());
new.deploy(V2.parse().unwrap(), MockInitMsg {}, DeployStrategy::Try)?;

account.manager.upgrade_module(MOCK_ADAPTER_ID, &Empty {})?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion framework/docs/src/releases/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

- Value calculation logic from proxy contract.
- `cw-semver` dependency removed

- Manager no longer able to migrate pre `0.19` abstract adapters

### Fixed

Expand Down
99 changes: 0 additions & 99 deletions framework/packages/abstract-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,103 +269,4 @@ pub mod mock {
}
};
}

/// Generate a BOOT instance for a 0.19 abstract mock adapter
/// - $name: name of the contract (&str)
/// - $id: id of the contract (&str)
/// - $version: version of the contract (&str)
/// - $deps: dependencies of the contract (&[StaticDependency])
#[macro_export]
macro_rules! gen_adapter_old_mock {
($name:ident, $id:expr, $version:expr, $deps:expr) => {
use $crate::std::adapter::*;
use $crate::sdk::base::Handler;
use ::cosmwasm_std::Empty;
use ::abstract_adapter::mock::{MockExecMsg, MockQueryMsg, MockReceiveMsg, MockInitMsg, MockAdapterContract, MockError};
use ::cw_orch::environment::CwEnv;

const MOCK_ADAPTER: ::abstract_adapter::mock::MockAdapterContract = ::abstract_adapter::mock::MockAdapterContract::new($id, $version, None)
.with_dependencies($deps);

fn instantiate(
deps: ::cosmwasm_std::DepsMut,
env: ::cosmwasm_std::Env,
info: ::cosmwasm_std::MessageInfo,
msg: <::abstract_adapter::mock::MockAdapterContract as ::abstract_sdk::base::InstantiateEndpoint>::InstantiateMsg,
) -> Result<::cosmwasm_std::Response, <::abstract_adapter::mock::MockAdapterContract as ::abstract_sdk::base::Handler>::Error> {
use ::abstract_sdk::base::InstantiateEndpoint;
MOCK_ADAPTER.instantiate(deps, env, info, msg)
}

/// Execute entrypoint
fn execute(
deps: ::cosmwasm_std::DepsMut,
env: ::cosmwasm_std::Env,
info: ::cosmwasm_std::MessageInfo,
msg: $crate::std::base::ExecuteMsg<$crate::std::adapter::AdapterBaseMsg, MockExecMsg, MockReceiveMsg>,
) -> Result<::cosmwasm_std::Response, <::abstract_adapter::mock::MockAdapterContract as ::abstract_sdk::base::Handler>::Error> {
use ::abstract_sdk::base::ExecuteEndpoint;
Ok(::cosmwasm_std::Response::new().set_data("mock_exec".as_bytes()))
}

/// Query entrypoint
fn query(
deps: ::cosmwasm_std::Deps,
env: ::cosmwasm_std::Env,
msg: <::abstract_adapter::mock::MockAdapterContract as ::abstract_sdk::base::QueryEndpoint>::QueryMsg,
) -> Result<::cosmwasm_std::Binary, <::abstract_adapter::mock::MockAdapterContract as ::abstract_sdk::base::Handler>::Error> {
use ::abstract_sdk::base::QueryEndpoint;
MOCK_ADAPTER.query(deps, env, msg)
}

type Exec = $crate::std::base::ExecuteMsg<$crate::std::adapter::AdapterBaseMsg, MockExecMsg, MockReceiveMsg>;
type Query = $crate::std::adapter::QueryMsg<MockQueryMsg>;
type Init = $crate::std::adapter::InstantiateMsg<MockInitMsg>;
#[cw_orch::interface(Init, Exec, Query, Empty)]
pub struct $name ;

impl ::abstract_interface::AdapterDeployer<::cw_orch::prelude::MockBech32, MockInitMsg> for $name <::cw_orch::prelude::MockBech32> {}

impl ::abstract_interface::RegisteredModule for $name<::cw_orch::prelude::MockBech32> {
type InitMsg = MockInitMsg;

fn module_id<'a>() -> &'a str {
$crate::traits::ModuleIdentification::module_id(&MOCK_ADAPTER)
}

fn module_version<'a>() -> &'a str {
MOCK_ADAPTER.version()
}

fn dependencies<'a>() -> &'a [$crate::objects::dependency::StaticDependency] {
MOCK_ADAPTER.dependencies()
}
}

impl Uploadable for $name<::cw_orch::prelude::MockBech32> {
fn wrapper() -> <MockBech32 as ::cw_orch::environment::TxHandler>::ContractSource {
Box::new(ContractWrapper::<
Exec,
_,
_,
_,
_,
_,
>::new_with_empty(
self::execute,
self::instantiate,
self::query,
))
}
}

impl<Chain: ::cw_orch::environment::CwEnv> $name <Chain> {
pub fn new_test(chain: Chain) -> Self {
Self(
::cw_orch::contract::Contract::new($id, chain),
)
}
}
};
}
}
2 changes: 0 additions & 2 deletions framework/packages/abstract-std/src/core/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ pub mod state {
pub const DEPENDENTS: Map<ModuleId, HashSet<String>> = Map::new("dependents");
/// List of sub-accounts
pub const SUB_ACCOUNTS: Map<u32, cosmwasm_std::Empty> = Map::new("sub_accs");
/// Context for old adapters that are currently removing authorized addresses
pub const REMOVE_ADAPTER_AUTHORIZED_CONTEXT: Item<u64> = Item::new("rm_a_auth");
// Additional states, not listed here: cw_gov_ownable::GovOwnership
}

Expand Down

0 comments on commit dca0301

Please sign in to comment.