Skip to content

Commit

Permalink
Merge branch 'main' into pen-364-minting-per-canister
Browse files Browse the repository at this point in the history
  • Loading branch information
jedna authored Nov 18, 2024
2 parents a303ba8 + bc5e939 commit 0f44ed6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ let obtain_cycles_config = ObtainCyclesOptions {
)),
from_subaccount: Subaccount::from(DEFAULT_SUBACCOUNT),
}),
top_up_self: true,
};

funding_options.with_obtain_cycles_options(Some(obtain_cycles_config));
Expand Down Expand Up @@ -223,7 +222,11 @@ fn initialize() {
),
);

// Funding canister is automatically registered
// Note: the funding canister is NOT automatically registered
fund_manager.register(
id(),
RegisterOpts::new(),
);

fund_manager.start();
}
Expand Down
19 changes: 5 additions & 14 deletions canfund-rs/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,10 @@ impl Default for FundManager {
impl FundManager {
/// Creates a new fund manager with the specified options.
pub fn new() -> Self {
let mut manager = FundManager {
FundManager {
inner: FundManagerCore::new(),
tracker: None,
};

manager.register(id(), RegisterOpts::new());

manager
}
}

/// Configures the fund manager with the specified options.
Expand Down Expand Up @@ -195,6 +191,7 @@ impl FundManager {
}

/// Executes the scheduled monitoring of the canisters and fund them if needed.
#[allow(clippy::too_many_lines)]
async fn execute_scheduled_monitoring(manager: Rc<RefCell<FundManagerCore>>) {
// Lock the process execution to prevent concurrent executions, it is dropped automatically
// when it goes out of scope.
Expand Down Expand Up @@ -236,7 +233,7 @@ impl FundManager {
// Get the current balance.
let funding_canister_balance = ic_cdk::api::canister_balance128();

// Get the record of the funding canister, if it exists, to access the previsous cycles balance to calculate estimated runtime left.
// Get the record of the funding canister, if it exists, to access the previous cycles balance to calculate estimated runtime left.
let maybe_funding_canister_record =
manager.borrow().canisters.get(&id()).cloned();

Expand All @@ -248,8 +245,7 @@ impl FundManager {
),
maybe_funding_canister_record
.as_ref()
.map(|record| record.get_average_consumption() as u128)
.unwrap_or(0),
.map_or(0, |record| record.get_average_consumption() as u128),
&maybe_funding_canister_record
.as_ref()
.and_then(|record| record.get_strategy().clone())
Expand All @@ -271,11 +267,6 @@ impl FundManager {
.or_else(|| manager.borrow().options.obtain_cycles_options().clone());

if let Some(obtain_cycles_options) = maybe_obtain_cycles {
if canister_id == id() && !obtain_cycles_options.top_up_self {
// Obtaining cycles solely for topping up the funding canister is disabled.
continue;
}

ic_cdk::println!(
"Topping up {} with {} cycles",
canister_id,
Expand Down
2 changes: 0 additions & 2 deletions canfund-rs/src/manager/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ impl Default for FundStrategy {
pub struct ObtainCyclesOptions {
/// How to obtain cycles when the funding canister balance gets low.
pub obtain_cycles: Arc<dyn ObtainCycles>,
/// If canfund should use obtain_cycles to top up the canister balance canfund is running on.
pub top_up_self: bool,
}

#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced_funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ path = "src/lib.rs"

[dependencies]
candid = { workspace = true }
canfund = { path = "../../canfund-rs", version = "0.2.0" }
canfund = { path = "../../canfund-rs" }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-ledger-types = { workspace = true }
Expand Down
5 changes: 1 addition & 4 deletions examples/advanced_funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ pub fn start_canister_cycles_monitoring(config: FundingConfig) {
);
}

// The funding canister itself is also registered for monitoring by default. We can override
// the strategy by re-registering it.
fund_manager.unregister(id());
// The funding canister itself can also be monitored.
fund_manager.register(
id(),
RegisterOpts::new()
Expand All @@ -109,7 +107,6 @@ pub fn get_obtain_cycles_config() -> Option<ObtainCyclesOptions> {
)),
from_subaccount: DEFAULT_SUBACCOUNT,
}),
top_up_self: true,
})
}

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ path = "src/lib.rs"

[dependencies]
candid = { workspace = true }
canfund = { path = "../../canfund-rs", version = "0.2.0" }
canfund = { path = "../../canfund-rs" }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-ledger-types = { workspace = true }
Expand Down

0 comments on commit 0f44ed6

Please sign in to comment.