fix(pm): compute avg_resolution_time running mean in uint128 - #137
Merged
On1x merged 1 commit intoAug 6, 2026
Merged
Conversation
avg_resolution_time (uint32) * (n-1) + rt can reach the uint64 boundary once n approaches the uint32 max (product of two uint32 values is within a hair of 2^64, and adding rt can tip it over). Accumulate the running mean in fc::uint128_t to keep the counter exact. Mathematically equivalent to the previous integer formula; verified with a quick script across normal and boundary cases (matches on all).
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.
Summary
Small follow-up to P5 (oracle-metrics) on
pm(#124): the running-mean formula forpm_oracle_object::avg_resolution_timeaccumulates inuint64, butavg_resolution_time (uint32) * (n-1) + rtcan reach theuint64boundary oncenapproaches theuint32max — the product of twouint32values sits within a hair of2^64, and addingrtcan tip it over.Change
libraries/chain/pm_evaluator.cpp, inpm_resolve_market_evaluator::do_apply:fc::uint128_tis already used elsewhere in the same file (time-penalty math), so no new includes.Verification
avg=0..UINT32_MAX,n=1..4e9,rt=0..UINT32_MAX) — matches on all cases, and confirms the originaluint64path lands within 1 bit of overflow on the extreme (bit_length()==64).git diff --checkclean; single file, 6 insertions / 2 deletions.