flashbots / flashbots/contender

use ratios instead of percentages in campaign mix

Open
#509 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
141
Forks
57
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

Regarding [campaign definitions](https://github.com/flashbots/contender/tree/main/campaigns), `mix_pct` (percentage) forces the user to manually sum up each mix's percentage to get the right ratio, which can be error-prone and tedious in campaigns with lots of mixes.

**Describe the solution you'd like**

Use ratios instead.
- in `CampaignMixEntry` and `ResolvedMixEntry`, change `share_pct` to `ratio`
- use unsigned ints instead of signed

Example:

`mix_ratio_A` = 2
`mix_ratio_B` = 1
`total_tps` = 100

Mix A would then produce 67 tps, and Mix B would produce 33, because A ≈ 2B.

Example:

`mix_ratio_A` = 1
`mix_ratio_B` = 1
`mix_ratio_C` = 1
`mix_ratio_D` = 1
`total_tps` = 100

Each mix would produce 25 tps.

Here's how I'd work out the final rate of each mix_ratio $\large m_i$ given total spam rate (tps/tpb) $\large t$:
$$\Large spamRate(m_i) = \frac{t * m_i}{\sum_{k=1}^n m_k}$$

or in code:

```rs
fn mix_spam_rate(ratio: u64, ratios: &[u64], total_rate: u64) -> u64 {
(total_rate * ratio) / ratios.iter().sum::()
}
```

Using unsigned ints in this formula sometimes creates conditions where the sum of the individual rates doesn't meet the total desired rate (e.g. you get 99 tps instead of 100 because of a round-down), but it gets close enough.

Using floating point integers at the intake (`CampaignMixEntry`) could solve this (allowing us to round more intelligently before casting to unsigned) but not sure it's worth the effort. Users can always just increase the total_rate a little bit to compensate if they need to *exactly* hit the target spam rate.

Contributor guide

Open the contributing guide

Research direction

Start in the campaign definitions linked from the issue and search for CampaignMixEntry, ResolvedMixEntry, and share_pct to find every affected entry point. Trace how mix rates are calculated, then verify that ratio-based inputs distribute total rates as described and use unsigned integers throughout; the issue notes that rounding may leave a small remainder.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.