feat: #363 compact identical price rows before median sort#397
Open
Fury03 wants to merge 1 commit into
Open
Conversation
|
@Fury03 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
feat: #363 compact identical price rows before median sort
Summary
Refactors the validator payload iterator (
calculate_median_from_buffer) to compact identical price values into(price, count)buckets in a single linear pass before sorting, so the median sort runs only over distinct values rather than every row.Motivation
Closes #363. During high-volatility telemetry sweeps, many nodes report identical price rows. The previous path copied every entry into a flat vector and sorted all of them. Compacting first means the sort operates on the distinct set, trimming work in the common case where duplicates are dense.
Approach (note on correctness)
The issue describes pruning duplicate rows. Dropping identical prices outright would corrupt the median — providers are already deduplicated per ledger (
has_provider_submitted), so identical prices are independent votes, and a median must count each one. Instead, this preserves each value's multiplicity viacountand computes the median using cumulative counts, so the result is identical to sorting the full expanded multiset. This is the "vector compacting" framing from the issue title, done without altering the consensus price.Changes
median.rs: addedcalculate_median_compacted((price, count)), which insertion-sorts only distinct values and locates the median via cumulative counts; plus avalue_athelper.lib.rs:calculate_median_from_buffernow folds identical prices into(price, count)buckets in one linear pass before calling the new function.Testing
The median compaction logic is covered by 9 unit tests (5 new for the compacted path, 4 existing), all passing on soroban-sdk 20.5.0. Verified in isolation because the crate's full test suite does not currently compile against the pinned
soroban-sdk = "20.0.0"— the committed tests intest.rs/delegate_tests.rsuse the 21+ API (env.register,set_timestamp,set_sequence_number). The added logic is self-contained arithmetic and does not touch those files.closes #363.