Skip to content

feat: charge cycles for log memory resize in update_settings#9118

Closed
maksymar wants to merge 66 commits intomasterfrom
maksym/logging-costs
Closed

feat: charge cycles for log memory resize in update_settings#9118
maksymar wants to merge 66 commits intomasterfrom
maksym/logging-costs

Conversation

@maksymar
Copy link
Copy Markdown
Contributor

@maksymar maksymar commented Mar 2, 2026

closed in favour of #9883

@maksymar maksymar changed the title tests: add canister logging benchmarks test: add canister logging benchmarks Mar 2, 2026
@github-actions github-actions Bot added the test label Mar 2, 2026
maksymar added 21 commits March 10, 2026 12:56
Pass canister_log_memory_usage as a parameter so the resize cycle cost
check compiles. Use a placeholder cost_per_byte=1 until benchmarks
determine the real value. Also fix a missed fetch_canister_logs rename
in the test helper.
Add two tests that verify cycle charging for log memory store resize:
- test_canister_log_resize_deducts_cycles: fills a 256 KiB log buffer
  and asserts the cycle balance decreases proportionally after resize
- test_canister_log_resize_rejected_insufficient_cycles: verifies that
  resize is rejected when the canister cannot afford the cost

Both tests currently fail as expected — cycle deduction is not yet
implemented. They will pass once the proper charging flow is added.
- Use div_ceil() instead of manual ceiling division in benchmark
- Remove unused debug variables and dead update_settings_duration_sum fn
The removal caused new canisters to not get a default log memory store
allocated when LOG_MEMORY_STORE_FEATURE_ENABLED=true, breaking tests
that depend on the default log memory usage (empty_canister_memory_usage,
backtraces, etc). Removing this default is a separate concern from
resize charging and should not be part of this PR.
Add proper cycle charging when update_settings resizes the log memory
store. The implementation follows a two-step pattern:

1. validate_canister_settings: pre-check that the canister can afford
   the resize cost (bytes_used * 32 instr/byte) without freezing, using
   management_canister_cost for proper instruction-to-cycles conversion.

2. update_settings: after do_update_settings applies the resize, deduct
   cycles via consume_cycles_for_management_canister_instructions and
   account instructions in round_limits.

Charging only triggers when the user explicitly sets log_memory_limit,
not when the default fallback is applied during canister creation.

Add LogResizeNotEnoughCycles error variant with proper user-facing
error message. Fix the insufficient-cycles rejection test to use a
high freezing threshold to lock up the canister's balance.
- Remove all commented-out debug println! statements and variables
- Revert unnecessary canister_logs.rs rename (old_logs/new_logs -> s)
- Revert semicolon change in log_memory_store resize method
- Replace LogResizeNotEnoughCycles(CanisterOutOfCyclesError) with a
  struct variant that doesn't require a canister_id, since
  validate_canister_settings doesn't have access to it
Group the default fallback, max-limit check, and resize cost check
into a single coherent block with a clear top-level comment explaining
the two code paths (user-set vs default). Extract user_set_log_memory_limit
flag to avoid calling settings.log_memory_limit() multiple times.
@maksymar maksymar changed the title test: add canister logging benchmarks feat: charge cycles for log memory resize in update_settings Apr 14, 2026
@github-actions github-actions Bot added feat and removed test labels Apr 14, 2026
Sync benchmark with maksym/log-resize-bench: use 0-byte messages for
worst case, compute repeat count from buffer size, fill in single call.
Sync with maksym/log-store-cleanup: const fn for record size estimation,
narrow visibility to pub(super), improve doc comments.
Sync canister_manager.rs, types.rs and canister_logging.rs with
maksym/log-resize-charging: remove LogResizeNotEnoughCycles in favor
of InsufficientCyclesInMemoryAllocation, restore debug_assert,
simplify tests to use 100-byte messages and single-call fill.
Use records_to_fill() helper instead of hardcoded repeat counts.
@maksymar maksymar closed this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant