Repository navigation
Conversation
The year reports need the rate of each day since 1 January 2025. The history keeps the 00:00 UTC rate of each day in stable memory. A timer fills the missing days at start and every 6 hours.
📊 Build Bundle StatsThe latest build generated the following assets: 🚦 Startup JS budget✅ The startup JS is 478,602 bytes gzip. The budget is 480,000. 27 startup files
|
|
✅ No security or compliance issues detected. Reviewed everything up to 2bc5fa1. Security OverviewDetected Code Changes
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
An older XRC rate is stored under the requested date and never refreshed, making report values depend on when the first fetch occurred.
1 open issue
What changed in this PR
Adds persistent daily exchange-rate history for the Reports page’s fiat columns and yearly summaries, covering dates from 1 January 2025.
Changes:
- Stores daily ICP/USD and supported USD/fiat rates in stable memory.
- Fills missing rates newest first at startup and every six hours, preventing overlapping runs.
- Exposes a date-range query with optional fiat selection and adds coverage for queries, retries, and fill guarding.
| File | Description |
|---|---|
src/governance-app-backend/src/stable_memory.rs |
Allocates stable-memory IDs for daily histories. |
src/governance-app-backend/src/lib.rs |
Exposes the daily exchange-rate query. |
src/governance-app-backend/src/exchange_rate/tests.rs |
Tests missing rates, range queries, retries, and validation. |
src/governance-app-backend/src/exchange_rate/daily_history.rs |
Implements stable storage, range reads, and missing-rate detection. |
src/governance-app-backend/src/exchange_rate.rs |
Adds scheduled gap filling, overlap protection, and query handling. |
src/governance-app-backend/backend.did |
Defines the public daily-rate query and its types. |
Review effort: Balanced
The XRC updates a day's forex rates for up to 2 days, and it gives an earlier day's rate while a day has none. The fill keeps the first rate that it gets, so it now waits 3 days before it fetches a fiat rate.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
The Reports page needs the ICP/USD rate and the fiat rate of each day since 1 January 2025, for the fiat columns and the Year summary. The backend keeps only 30 days of ICP/USD and the current fiat rates. The first fill costs about 690 ICP/USD calls at 500M cycles each (about 0.35T cycles), one time. Fiat pairs make no exchange calls, so they cost less.
Changes
fill_daily_history_gaps, which fetches the missing days, newest first, at start and every 6 hours. A run does nothing while another run is in progress.list_daily_exchange_ratesquery. It takes a time range and an optional fiat symbol, and returns one entry for each day with a rate.