fix(credit-score): expose config_version in get_credit_score to detect stale scores#590
Conversation
…t stale scores Closes astera-hq#573 When set_scoring_config() bumped the scoring parameters the score stored on CreditScoreData was still computed under the old config, but get_credit_score() returned only score_version (the config version active at last computation) with no way to compare it against the current config version in a single call. Consumers — the pool contract, frontend, and third-party integrations — had no means to tell whether a returned score of 720 was current or stale without an additional get_scoring_config() round-trip and manual comparison. Fix: add CreditScoreResponse, a new return type for get_credit_score() that includes all existing CreditScoreData fields plus: - config_version: the config version currently active on the contract - is_stale: true when score_version != config_version Scoring storage (CreditScoreData) is unchanged — no on-chain migration is needed. Existing consumers that only read score/total_invoices/paid_on_time/etc. continue to work unchanged; the two new fields are purely additive. Five new tests cover: - config_version returned on fresh SME - not stale immediately after a payment under the current config - stale flag set after set_scoring_config() bumps the version - stale flag cleared once a new payment is recorded under the new config - new SMEs always start current even when config has already been bumped
|
The approach is right and the staleness lifecycle tests are exactly what we need here. One blocker and one thing to verify before I can merge: BlockerThis is a breaking contract interface change. The PR description says existing consumers continue to work, but that is only true for dynamically-typed callers, not our typed bindings. Before merge I need either:
Please verify before merge
The function is not visible in this diff. Please confirm this is how it behaves and add a brief comment on the test explaining the dependency. Notes (no action needed)
The test structure and the decision to keep |
Closes #573
Problem
When
set_scoring_config()updates point values thescore_versionfield on existingCreditScoreDatarecords is not updated. Consumers could not distinguish a score computed under the old config from one under the new config — a score of 720 before a config change is semantically different from 720 after, but both looked identical. Detecting staleness required callingget_scoring_config()separately and manually comparingscore_versionfields.Solution
Add
CreditScoreResponse— a new return type forget_credit_score()— that includes all existingCreditScoreDatafields plus two additive fields:config_versionis_staletruewhenscore_version != config_versionConsumers can now detect staleness in a single call:
What changed
contracts/credit_score/src/lib.rsCreditScoreResponsestruct (#[contracttype]) with all existing fields +config_version+is_staleget_credit_score()return type fromCreditScoreData→CreditScoreResponseNo migration needed
CreditScoreData(on-chain persistent storage) is unchanged. Existing consumers that only readscore,total_invoices,paid_on_time, etc. continue to work — the two new response fields are purely additive.Test results