-
Notifications
You must be signed in to change notification settings - Fork 1
PLT-465: wire key/size/op distributions into StorageRW #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bdchatham
merged 6 commits into
main
from
brandon2/plt-465-m33-wire-key-distslot-and-size-distcalldata-into-storagerw
Aug 20, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
247833d
feat(generator): wire key/size/op distributions into StorageRW (PLT-465)
bdchatham ca2b957
fix(config): validate SizeBuckets + inline op-stream field (cohort re…
bdchatham a541fba
docs(generator): comment-discipline sweep (PLT-465)
bdchatham 67551c5
merge: main into PLT-465, adapting distributions to the per-call RNG
bdchatham 705b089
docs(config): state the reproducibility contract that actually holds
bdchatham d0d0f4f
fix(generator): size the gas limit to the EIP-7623 floor, not the 202…
bdchatham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestScenarioValidateSizeBuckets: a negative pad length (makeslice panic on the | ||
| // hot path) and an over-cap pad length (OOM risk) are both rejected; a valid | ||
| // histogram, the cap boundary, and an empty/nil bucket list pass. | ||
| func TestScenarioValidateSizeBuckets(t *testing.T) { | ||
| t.Parallel() | ||
| t.Run("negative rejected", func(t *testing.T) { | ||
| s := Scenario{Name: "s", SizeDistribution: &Distribution{}, SizeBuckets: []int{0, -1}} | ||
| require.ErrorContains(t, s.Validate(), "negative") | ||
| }) | ||
| t.Run("over cap rejected", func(t *testing.T) { | ||
| s := Scenario{Name: "s", SizeDistribution: &Distribution{}, SizeBuckets: []int{maxCalldataPadBytes + 1}} | ||
| require.ErrorContains(t, s.Validate(), "cap") | ||
| }) | ||
| t.Run("valid accepted", func(t *testing.T) { | ||
| s := Scenario{Name: "s", SizeDistribution: &Distribution{}, SizeBuckets: []int{0, 64, maxCalldataPadBytes}} | ||
| require.NoError(t, s.Validate()) | ||
| }) | ||
| t.Run("empty accepted", func(t *testing.T) { | ||
| require.NoError(t, (&Scenario{Name: "s"}).Validate()) | ||
| }) | ||
| } | ||
|
|
||
| // TestScenarioValidateRecordCountCap: the keyspace is capped because the zipfian | ||
| // sampler precomputes zeta in O(n) under a mutex on the generator's only | ||
| // goroutine, so a stray extra digit stalls the run rather than failing it. | ||
| func TestScenarioValidateRecordCountCap(t *testing.T) { | ||
| t.Parallel() | ||
| at := Scenario{Name: "s", KeyDistribution: &Distribution{}, RecordCount: maxRecordCount} | ||
| require.NoError(t, at.Validate()) | ||
| over := Scenario{Name: "s", KeyDistribution: &Distribution{}, RecordCount: maxRecordCount + 1} | ||
| require.ErrorContains(t, over.Validate(), "cap") | ||
| } | ||
|
|
||
| // TestScenarioValidateAxisPairing: an axis needs a sampler and a space to sample. | ||
| // Configured with only one half it silently runs the baseline instead of the | ||
| // experiment, so each direction is rejected. | ||
| func TestScenarioValidateAxisPairing(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cases := map[string]struct { | ||
| scenario Scenario | ||
| wantErr string | ||
| }{ | ||
| "key distribution without a keyspace": { | ||
| Scenario{Name: "s", KeyDistribution: &Distribution{}}, | ||
| "recordCount is 0", | ||
| }, | ||
| "keyspace without a key distribution": { | ||
| Scenario{Name: "s", RecordCount: 1000}, | ||
| "no keyDistribution", | ||
| }, | ||
| "size distribution without buckets": { | ||
| Scenario{Name: "s", SizeDistribution: &Distribution{}}, | ||
| "sizeBuckets is empty", | ||
| }, | ||
| "buckets without a size distribution": { | ||
| Scenario{Name: "s", SizeBuckets: []int{0, 32}}, | ||
| "no sizeDistribution", | ||
| }, | ||
| } | ||
| for name, tc := range cases { | ||
| t.Run(name, func(t *testing.T) { | ||
| require.ErrorContains(t, tc.scenario.Validate(), tc.wantErr) | ||
| }) | ||
| } | ||
|
|
||
| both := Scenario{ | ||
| Name: "s", | ||
| KeyDistribution: &Distribution{}, | ||
| RecordCount: 1000, | ||
| SizeDistribution: &Distribution{}, | ||
| SizeBuckets: []int{0, 32}, | ||
| } | ||
| require.NoError(t, both.Validate()) | ||
| } | ||
|
|
||
| // TestScenarioValidateOperationsPresentButEmpty: an explicit all-zero mix is a | ||
| // misconfiguration, not the default. Omitting the field is the default, and | ||
| // Select's zero-total guard stays a safety net for that case rather than a | ||
| // swallower of this one. | ||
| func TestScenarioValidateOperationsPresentButEmpty(t *testing.T) { | ||
| t.Parallel() | ||
| empty := Scenario{Name: "s", Operations: &OperationMix{}} | ||
| require.ErrorContains(t, empty.Validate(), "every weight is 0") | ||
|
|
||
| require.NoError(t, (&Scenario{Name: "s"}).Validate()) | ||
| require.NoError(t, (&Scenario{Name: "s", Operations: &OperationMix{Rmw: 1}}).Validate()) | ||
| } | ||
|
|
||
| // TestValidateScenariosReportsOffendingScenario: validation runs across every | ||
| // scenario and names the one that failed, so an operator can find it in a | ||
| // multi-scenario profile. | ||
| func TestValidateScenariosReportsOffendingScenario(t *testing.T) { | ||
| t.Parallel() | ||
| cfg := LoadConfig{Scenarios: []Scenario{ | ||
| {Name: "good"}, | ||
| {Name: "bad", Operations: &OperationMix{}}, | ||
| }} | ||
| require.ErrorContains(t, cfg.ValidateScenarios(), `scenario "bad"`) | ||
|
|
||
| cfg.Scenarios[1].Operations = &OperationMix{Read: 1} | ||
| require.NoError(t, cfg.ValidateScenarios()) | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "fmt" | ||
| mrand "math/rand/v2" | ||
| ) | ||
|
|
||
| // Operation identifies one StorageRW contract method. | ||
| type Operation uint8 | ||
|
|
||
| const ( | ||
| // OpRmw is the read-modify-write operation. It is the zero value so a | ||
| // zero-weight or absent OperationMix selects rmw, matching the default. | ||
| OpRmw Operation = iota | ||
| OpRead | ||
| OpWrite | ||
| ) | ||
|
|
||
| // OperationMix is the relative weighting of the StorageRW read/write/rmw | ||
| // operations. The weights need not sum to anything in particular: a per-tx draw | ||
| // selects an operation in proportion to its weight over the total. An all-zero | ||
| // mix falls back to rmw, the default. | ||
| type OperationMix struct { | ||
| Read uint64 `json:"read,omitempty"` | ||
| Write uint64 `json:"write,omitempty"` | ||
| Rmw uint64 `json:"rmw,omitempty"` | ||
| } | ||
|
|
||
| // validate rejects a mix that is present but cannot select anything, so an | ||
| // operator who writes "operations": {} — or misspells every weight key — gets an | ||
| // error instead of a silent all-rmw run. Select's own zero-total guard then | ||
| // covers only the absent-mix case it was written for. A nil mix is the | ||
| // documented default and passes. | ||
| func (m *OperationMix) validate(scenario string) error { | ||
| if m == nil { | ||
| return nil | ||
| } | ||
| if m.Read == 0 && m.Write == 0 && m.Rmw == 0 { | ||
| return fmt.Errorf("scenario %q: operations is set but every weight is 0; omit it for the all-rmw default", scenario) | ||
| } | ||
| if m.Read+m.Write+m.Rmw < m.Read { | ||
| return fmt.Errorf("scenario %q: operations weights sum past uint64", scenario) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Select draws one operation in proportion to the configured weights. A zero | ||
| // total falls back to OpRmw, so an absent mix is the default rather than a | ||
| // division by zero, and it draws no randomness. | ||
| // | ||
| // The comparison order (rmw, then read, then write) fixes which weight owns | ||
| // which sub-range of the draw. It is arbitrary but must stay stable, because | ||
| // changing it changes which operation a given draw selects. | ||
| func (m *OperationMix) Select(rng *mrand.Rand) Operation { | ||
| total := m.Read + m.Write + m.Rmw | ||
| if total == 0 { | ||
| return OpRmw | ||
| } | ||
| switch u := rng.Uint64N(total); { | ||
| case u < m.Rmw: | ||
| return OpRmw | ||
| case u < m.Rmw+m.Read: | ||
| return OpRead | ||
| default: | ||
| return OpWrite | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.