refactor(nns): drop inner Options on MaturityModulation#10269
refactor(nns): drop inner Options on MaturityModulation#10269jasonz-dfinity wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
This pull request changes code owned by the Governance team. Therefore, make sure that
you have considered the following (for Governance-owned code):
-
Update
unreleased_changelog.md(if there are behavior changes, even if they are
non-breaking). -
Are there BREAKING changes?
-
Is a data migration needed?
-
Security review?
How to Satisfy This Automatic Review
-
Go to the bottom of the pull request page.
-
Look for where it says this bot is requesting changes.
-
Click the three dots to the right.
-
Select "Dismiss review".
-
In the text entry box, respond to each of the numbered items in the previous
section, declare one of the following:
-
Done.
-
$REASON_WHY_NO_NEED. E.g. for
unreleased_changelog.md, "No
canister behavior changes.", or for item 2, "Existing APIs
behave as before.".
Brief Guide to "Externally Visible" Changes
"Externally visible behavior change" is very often due to some NEW canister API.
Changes to EXISTING APIs are more likely to be "breaking".
If these changes are breaking, make sure that clients know how to migrate, how to
maintain their continuity of operations.
If your changes are behind a feature flag, then, do NOT add entrie(s) to
unreleased_changelog.md in this PR! But rather, add entrie(s) later, in the PR
that enables these changes in production.
Reference(s)
For a more comprehensive checklist, see here.
GOVERNANCE_CHECKLIST_REMINDER_DEDUP
There was a problem hiding this comment.
Pull request overview
This PR removes redundant inner Option wrappers from the protobuf MaturityModulation message by dropping optional on its scalar fields, switching the prost bindings to plain i32/u64. The implementation is updated to use updated_at_days_since_epoch == 0 as the “never measured” sentinel, while preserving the public API behavior by mapping that sentinel back to None in pb→api conversion.
Changes:
- Update
MaturityModulationprotobuf schema to use non-optional scalar fields and regenerate Rust prost bindings. - Update maturity modulation computation logic to use
updated_at_days_since_epoch == 0as the “no baseline yet” indicator. - Adjust call sites and tests to the new non-
Optionfields and preserve API semantics in conversion code.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rs/nns/governance/tests/governance.rs | Update test helper to construct MaturityModulation with scalar fields. |
| rs/nns/governance/src/timer_tasks/update_icp_xdr_rate_related_data.rs | Switch update logic and logging to scalar fields; use 0 sentinel for “never measured”. |
| rs/nns/governance/src/timer_tasks/update_icp_xdr_rate_related_data_tests.rs | Update task tests to the scalar-field representation and sentinel behavior. |
| rs/nns/governance/src/pb/conversions/mod.rs | Map updated_at_days_since_epoch == 0 to None for the public API; wrap scalar permyriad into Some. |
| rs/nns/governance/src/heap_governance_data.rs | Seed maturity_modulation with { current_value_permyriad: 0, updated_at_days_since_epoch: 0 } at init. |
| rs/nns/governance/src/governance/tla/mod.rs | Adjust extraction of permyriad from MaturityModulation now that it’s scalar. |
| rs/nns/governance/src/governance/tests/get_maturity_modulation.rs | Update API-facing tests to expect sentinel-driven updated_at mapping. |
| rs/nns/governance/src/governance/disburse_maturity.rs | Adjust modulation value read path to scalar field. |
| rs/nns/governance/src/governance/disburse_maturity_tests.rs | Update test construction to scalar current_value_permyriad. |
| rs/nns/governance/src/governance.rs | Adjust modulation value read path to scalar field. |
| rs/nns/governance/src/gen/ic_nns_governance.pb.v1.rs | Regenerated prost bindings reflecting non-optional fields and sentinel documentation. |
| rs/nns/governance/proto/ic_nns_governance/pb/v1/governance.proto | Remove optional from MaturityModulation scalar fields and document 0 sentinel. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Why
MaturityModulation's two scalar fields wereoptional, generatingOption<i32>/Option<u64>in prost. Both inner Options wereredundant:
current_value_permyriadhad no meaningful absent state(only ever set, never read as
Nonewith distinct semantics), andupdated_at_days_since_epochalready had0available as a "nevermeasured" sentinel —
current_dayis always >> 0 in practice, so areal measurement can never collide.
What
optionalfromMaturityModulationingovernance.proto;regenerate the prost bindings so the fields are bare
i32/u64.initialize_governancecontinues to pre-seedSome(MaturityModulation { current_value_permyriad: 0, updated_at_days_since_epoch: 0 })so spawning and disbursement keep their pre-PR behavior at init.
update_maturity_modulationkeys the "first calculation, nospeed-limit baseline" branch on
updated_at_days_since_epoch == 0.updated_at_days_since_epoch == 0back toNoneso the public API contract is preserved.Testing
The wire-format safety of dropping
optionalis demonstrated by areview-time scaffold commit on a side branch:
7b92bde
— it defines parallel prost messages with/without
optionalandround-trips encoded bytes through the other shape, asserting
Some(v) ↔ vand the default-elision asymmetry (None ↔ 0,Some(0) → 0) in both directions. Not merged here because theOldMaturityModulationshape no longer exists in the tree.