-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ulan/run-1001' into 'master'
fix: RUN-1001 Properly handle updating of reserved cycles limit This fixes a bug in update settings validation for setting the reserved cycles limit below the existing reserved cycles. Now an attempt to set the limit below reserved cycles returns an error explaining that it is not allowed. Closes RUN-1001 See merge request dfinity-lab/public/ic!20022
- Loading branch information
Showing
9 changed files
with
166 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -519,43 +519,47 @@ pub(crate) fn validate_canister_settings( | |
} | ||
} | ||
|
||
let reservation_cycles = if new_memory_bytes <= old_memory_bytes { | ||
Cycles::zero() | ||
let allocated_bytes = if new_memory_bytes > old_memory_bytes { | ||
new_memory_bytes - old_memory_bytes | ||
} else { | ||
let allocated_bytes = new_memory_bytes - old_memory_bytes; | ||
let reservation_cycles = cycles_account_manager.storage_reservation_cycles( | ||
allocated_bytes, | ||
subnet_memory_saturation, | ||
subnet_size, | ||
); | ||
let reserved_balance_limit = settings | ||
.reserved_cycles_limit() | ||
.or(canister_reserved_balance_limit); | ||
if let Some(limit) = reserved_balance_limit { | ||
if canister_reserved_balance + reservation_cycles > limit { | ||
return Err( | ||
CanisterManagerError::ReservedCyclesLimitExceededInMemoryAllocation { | ||
memory_allocation: new_memory_allocation, | ||
requested: canister_reserved_balance + reservation_cycles, | ||
limit, | ||
}, | ||
); | ||
} | ||
} | ||
// Note that this check does not include the freezing threshold to be | ||
// consistent with the `reserve_cycles()` function, which moves | ||
// cycles between the main and reserved balances without checking | ||
// the freezing threshold. | ||
if canister_cycles_balance < reservation_cycles { | ||
return Err(CanisterManagerError::InsufficientCyclesInMemoryAllocation { | ||
memory_allocation: new_memory_allocation, | ||
available: canister_cycles_balance, | ||
threshold: reservation_cycles, | ||
}); | ||
} | ||
reservation_cycles | ||
NumBytes::new(0) | ||
}; | ||
|
||
let reservation_cycles = cycles_account_manager.storage_reservation_cycles( | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
AleDema
|
||
allocated_bytes, | ||
subnet_memory_saturation, | ||
subnet_size, | ||
); | ||
let reserved_balance_limit = settings | ||
.reserved_cycles_limit() | ||
.or(canister_reserved_balance_limit); | ||
|
||
if let Some(limit) = reserved_balance_limit { | ||
// TODO(RUN-1001): return `ReservedCyclesLimitIsTooLow` once | ||
// the replica with that error type rolls out successfully. | ||
if canister_reserved_balance + reservation_cycles > limit { | ||
return Err( | ||
CanisterManagerError::ReservedCyclesLimitExceededInMemoryAllocation { | ||
memory_allocation: new_memory_allocation, | ||
requested: canister_reserved_balance + reservation_cycles, | ||
limit, | ||
}, | ||
); | ||
} | ||
} | ||
|
||
// Note that this check does not include the freezing threshold to be | ||
// consistent with the `reserve_cycles()` function, which moves | ||
// cycles between the main and reserved balances without checking | ||
// the freezing threshold. | ||
if canister_cycles_balance < reservation_cycles { | ||
return Err(CanisterManagerError::InsufficientCyclesInMemoryAllocation { | ||
memory_allocation: new_memory_allocation, | ||
available: canister_cycles_balance, | ||
threshold: reservation_cycles, | ||
}); | ||
} | ||
|
||
Ok(ValidatedCanisterSettings { | ||
controller: settings.controller(), | ||
controllers: settings.controllers(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello @ulan,
I'm struggling to understand why this is not equivalent to the previous version. It seems that by the definition of
storage_reservation_cycles
, in caseallocated_bytes
isNumBytes::new(0)
,reservation_cycles
will still beCycles::zero()
(as in the previous version).Am i missing something?
Thanks a lot :)