fix: clamp f64 GFLOP estimate before casting to i32 in node telemetry#2096
Open
amathxbt wants to merge 1 commit into
Open
fix: clamp f64 GFLOP estimate before casting to i32 in node telemetry#2096amathxbt wants to merge 1 commit into
amathxbt wants to merge 1 commit into
Conversation
estimate_peak_gflops returns an f64. Casting a large f64 directly to i32 with "as i32" saturates at i32::MIN on values below i32::MIN and at i32::MAX on values above i32::MAX (Rust 1.45+), but on earlier toolchains the cast is undefined behaviour. More practically, high-core-count machines (32+ cores) produce GFLOP estimates well above 2 billion, wrapping to large negative values and corrupting the NodeTelemetry flops_per_sec field. Use f64::clamp(i32::MIN as f64, i32::MAX as f64) before the cast so the conversion is always well-defined and the submitted value is the nearest representable integer.
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.
Problem
OrchestratorClient::submit_proofincludes a node telemetry payload:where
flopsis thef64returned byestimate_peak_gflops. For machines with many cores (roughly 16+ depending on the GFLOP model), the estimate exceedsi32::MAX(≈2.1 billion). In Rust 1.45+ theas i32cast saturates toi32::MAX, but for values that overflow further it can saturate toi32::MIN(a large negative number), corrupting the telemetry field and making the node appear to have near-zero or negative compute capacity.Fix
Clamp the value to
[i32::MIN, i32::MAX]before the cast:This is a one-character change that makes the conversion well-defined and correct for all inputs.