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(gateway): add instance ttl extension #51

Merged
merged 5 commits into from
Nov 3, 2024
Merged
Changes from 2 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
17 changes: 17 additions & 0 deletions contracts/axelar-gateway/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ use crate::{auth, event};

const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

/// Parameters for extending the contract instance and its instance storage.
///
/// If the instance's time to live falls below 7 days, it will be extended by 60 days.
///
AttissNgo marked this conversation as resolved.
Show resolved Hide resolved
/// If at least one message is approved per week, the instance should never be archived.
const LEDGERS_PER_DAY: u32 = (24 * 3600) / 5;
const INSTANCE_TTL_THRESHOLD: u32 = 7 * LEDGERS_PER_DAY;
AttissNgo marked this conversation as resolved.
Show resolved Hide resolved
const INSTANCE_TTL_EXTEND_TO: u32 = 60 * LEDGERS_PER_DAY;

#[contract]
pub struct AxelarGateway;

Expand Down Expand Up @@ -188,6 +197,8 @@ impl AxelarGateway {
event::approve_message(&env, message);
}

Self::extend_instance_ttl(&env);

Ok(())
}

Expand Down Expand Up @@ -307,4 +318,10 @@ impl AxelarGateway {
fn message_approval_hash(env: &Env, message: Message) -> MessageApprovalValue {
MessageApprovalValue::Approved(env.crypto().keccak256(&message.to_xdr(env)).into())
}

pub fn extend_instance_ttl(env: &Env) {
AttissNgo marked this conversation as resolved.
Show resolved Hide resolved
env.storage()
.instance()
.extend_ttl(INSTANCE_TTL_THRESHOLD, INSTANCE_TTL_EXTEND_TO);
}
}
Loading