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

Top up canisters which have fewer than MIN_CYCLES_BALANCE cycles #6819

Merged
merged 4 commits into from
Nov 14, 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
4 changes: 4 additions & 0 deletions backend/canisters/local_group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Top up canisters which have fewer than `MIN_CYCLES_BALANCE` cycles ([#6819](https://github.com/open-chat-labs/open-chat/pull/6819))

## [[2.0.1449](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1449-local_group_index)] - 2024-11-13

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ fn next(state: &mut RuntimeState) -> GetNextResult {
async fn run_async(canister_id: CanisterId) {
match ic_cdk::api::management_canister::main::canister_status(CanisterIdRecord { canister_id }).await {
Ok((status,)) => {
if status.cycles < Nat::from(60u32) * status.idle_cycles_burned_per_day {
if status.cycles < utils::cycles::MIN_CYCLES_BALANCE
|| status.cycles < Nat::from(60u32) * status.idle_cycles_burned_per_day
{
top_up_canister(Some(canister_id)).await;
}
}
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/local_user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Top up canisters which have fewer than `MIN_CYCLES_BALANCE` cycles ([#6819](https://github.com/open-chat-labs/open-chat/pull/6819))

## [[2.0.1447](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1447-local_user_index)] - 2024-11-13

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ async fn run_async(user_id: UserId) {
.await
{
Ok((status,)) => {
if status.cycles < Nat::from(60u32) * status.idle_cycles_burned_per_day {
if status.cycles < utils::cycles::MIN_CYCLES_BALANCE
|| status.cycles < Nat::from(60u32) * status.idle_cycles_burned_per_day
{
top_up_user(Some(user_id)).await;
}
}
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/local_user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ struct Data {
pub ic_root_key: Vec<u8>,
pub events_for_remote_users: Vec<(UserId, UserEvent)>,
pub canisters_pending_events_migration_to_stable_memory: Vec<CanisterId>,
#[serde(skip_deserializing)]
pub cycles_balance_check_queue: VecDeque<UserId>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing::error;
use types::{CanisterId, Cycles};

const FREEZE_THRESHOLD_SECONDS: u32 = 30 * 24 * 60 * 60; // 30 days
const MIN_CYCLES_BALANCE: Cycles = CYCLES_REQUIRED_FOR_UPGRADE + 50_000_000_000;
pub const MIN_CYCLES_BALANCE: Cycles = CYCLES_REQUIRED_FOR_UPGRADE + 50_000_000_000;
const GB_STORAGE_PER_SECOND_FEE: Cycles = 127_000;

pub fn check_cycles_balance(top_up_canister_id: CanisterId) {
Expand Down
2 changes: 1 addition & 1 deletion backend/libraries/utils/src/cycles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod cycles_dispenser_client;
pub use self::cycles_dispenser_client::init_cycles_dispenser_client;
pub use accept_cycles::accept_cycles;
pub use can_spend_cycles::can_spend_cycles;
pub use check_cycles_balance::{check_cycles_balance, send_low_balance_notification};
pub use check_cycles_balance::{check_cycles_balance, send_low_balance_notification, MIN_CYCLES_BALANCE};

pub fn is_out_of_cycles_error(code: RejectionCode, message: &str) -> bool {
code == RejectionCode::SysTransient && message.starts_with("IC0207:")
Expand Down
Loading