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(axelar-gateway): emit event when upgrade is completed #85

Merged
merged 7 commits into from
Nov 22, 2024
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
20 changes: 11 additions & 9 deletions contracts/axelar-gateway/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ pub struct AxelarGateway;

#[contractimpl]
impl UpgradeableInterface for AxelarGateway {
fn version(env: Env) -> String {
String::from_str(&env, CONTRACT_VERSION)
fn version(env: &Env) -> String {
String::from_str(env, CONTRACT_VERSION)
}

fn upgrade(env: Env, new_wasm_hash: BytesN<32>) {
Self::owner(&env).require_auth();
fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
Self::owner(env).require_auth();

env.deployer().update_current_contract_wasm(new_wasm_hash);
Self::start_migration(&env);
Self::start_migration(env);
}
}

Expand Down Expand Up @@ -64,13 +64,15 @@ impl AxelarGateway {
}

/// Migrate the contract state after upgrading the contract code. the migration_data type can be adjusted as needed.
pub fn migrate(env: Env, migration_data: ()) -> Result<(), ContractError> {
pub fn migrate(env: &Env, migration_data: ()) -> Result<(), ContractError> {
// This function should not get modified.
// Custom migration logic that changes from version to version should be added in the run_migration function
Self::ensure_is_migrating(&env)?;
Self::ensure_is_migrating(env)?;

Self::run_migration(&env, migration_data);
Self::complete_migration(&env);
Self::run_migration(env, migration_data);
Self::complete_migration(env);

event::upgraded(env, &Self::version(env));

Ok(())
}
Expand Down
5 changes: 3 additions & 2 deletions contracts/axelar-gateway/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use soroban_sdk::contracterror;
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[repr(u32)]
pub enum ContractError {
// Auth
/// Auth
InvalidThreshold = 1,
InvalidProof = 2,
InvalidSigners = 3,
Expand All @@ -16,7 +16,8 @@ pub enum ContractError {
DuplicateSigners = 9,
InvalidSignersHash = 10,
InvalidEpoch = 11,
// Messages
/// Messages
EmptyMessages = 12,
/// Upgradeable
MigrationNotAllowed = 13,
}
5 changes: 5 additions & 0 deletions contracts/axelar-gateway/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ pub fn transfer_ownership(env: &Env, previous_owner: Address, new_owner: Address
);
env.events().publish(topics, ());
}

pub fn upgraded(env: &Env, version: &String) {
env.events()
.publish((Symbol::new(env, "upgraded"),), (version.to_val(),));
}
1 change: 1 addition & 0 deletions contracts/axelar-gateway/src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum DataKey {
Owner,
Operator,
MessageApproval(MessageApprovalKey),
/// Upgradeable
Migrating,
/// Auth Module
PreviousSignerRetention,
Expand Down
8 changes: 4 additions & 4 deletions contracts/upgrader/tests/utils/dummy_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ pub struct DummyContract;
/// Dummy contract logic before upgrade
#[contractimpl]
impl UpgradeableInterface for DummyContract {
fn version(env: Env) -> soroban_sdk::String {
soroban_sdk::String::from_str(&env, "0.1.0")
fn version(env: &Env) -> soroban_sdk::String {
soroban_sdk::String::from_str(env, "0.1.0")
}

fn upgrade(env: Env, new_wasm_hash: BytesN<32>) {
Self::owner(&env).require_auth();
fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
Self::owner(env).require_auth();

env.deployer().update_current_contract_wasm(new_wasm_hash);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/axelar-soroban-std/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use soroban_sdk::{contractclient, BytesN, Env, String};
#[contractclient(name = "UpgradeableClient")]
pub trait UpgradeableInterface {
/// Returns the current version of the contract.
fn version(env: Env) -> String;
fn version(env: &Env) -> String;

/// Upgrades the contract to a new WASM hash.
fn upgrade(env: Env, new_wasm_hash: BytesN<32>);
fn upgrade(env: &Env, new_wasm_hash: BytesN<32>);
}
Loading