Skip to content

feat: #363 compact identical price rows before median sort#397

Open
Fury03 wants to merge 1 commit into
StellarFlow-Network:mainfrom
Fury03:issue-363-gas-throttling-compaction
Open

feat: #363 compact identical price rows before median sort#397
Fury03 wants to merge 1 commit into
StellarFlow-Network:mainfrom
Fury03:issue-363-gas-throttling-compaction

Conversation

@Fury03
Copy link
Copy Markdown

@Fury03 Fury03 commented Jun 2, 2026

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 via count and 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: added calculate_median_compacted((price, count)), which insertion-sorts only distinct values and locates the median via cumulative counts; plus a value_at helper.
  • lib.rs: calculate_median_from_buffer now 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 in test.rs/delegate_tests.rs use 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.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 2, 2026

@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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

⛽ Gas-Throttling | Vector Compacting loops for Consensus Checkpoints

1 participant