Skip to content

Commit

Permalink
improve canfund init
Browse files Browse the repository at this point in the history
  • Loading branch information
jedna committed Nov 11, 2024
1 parent a8603ac commit 19b1304
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions core/station/impl/src/services/cycle_manager.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::services::{SystemService, SYSTEM_SERVICE};
use canfund::manager::options::{FundManagerOptions, FundStrategy};
use canfund::manager::RegisterOpts;
use canfund::FundManager;
Expand All @@ -8,27 +9,35 @@ use std::cell::RefCell;
use std::sync::Arc;

thread_local! {
static FUND_MANAGER: RefCell<FundManager> = RefCell::new({
let mut manager = FundManager::new();
// Strategy can be default as we always override per canister
manager.with_options(FundManagerOptions::new().with_interval_secs(60*60*6));
// The station canister is already being monitored, we need to override the default registration
// This instance of canfund also won't mint cycles and rely on station to do so
manager.unregister(id());

manager
});
static FUND_MANAGER: RefCell<FundManager> = RefCell::new(FundManager::new());
}

lazy_static! {
pub static ref CYCLE_MANAGER: Arc<CycleManager> = Arc::new(CycleManager::new());
pub static ref CYCLE_MANAGER: Arc<CycleManager> =
Arc::new(CycleManager::new(Arc::clone(&SYSTEM_SERVICE),));
}

#[derive(Debug, Default)]
pub struct CycleManager {}

impl CycleManager {
fn new() -> Self {
fn new(system_service: Arc<SystemService>) -> Self {
let system_info = system_service.get_system_info();

FUND_MANAGER.with(|manager| {
let mut manager = manager.borrow_mut();
// Strategy can be default as we always override per canister
// Obtain cycles config is inherited from the system service
let options = FundManagerOptions::new()
.with_interval_secs(60 * 60 * 6)
.with_obtain_cycles_options(
system_service.get_obtain_cycle_config(system_info.get_cycle_obtain_strategy()),
);
manager.with_options(options);
// The station canister is already being monitored, we need to override the default registration
manager.unregister(id());
});

Self {}
}

Expand Down

0 comments on commit 19b1304

Please sign in to comment.