Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions report/src/components/ConfigCard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it } from "vitest";

import { formatTransactions } from "./ConfigCard";

describe("formatTransactions", () => {
it("formats a weighted transaction mix", () => {
expect(
formatTransactions({
transactions: [
{ type: "uniswap_v3", weight: 50 },
{ type: "aerodrome_cl", weight: 50 },
],
}),
).toBe("uniswap_v3 (50%) · aerodrome_cl (50%)");
});

it("labels full fresh-recipient transfers as account-create", () => {
expect(
formatTransactions({
fresh_recipient_ratio: 1,
transactions: [{ type: "transfer", weight: 100 }],
}),
).toBe("account-create (100%)");
});

it("keeps partial fresh-recipient transfer ratios visible", () => {
expect(
formatTransactions({
fresh_recipient_ratio: 0.25,
transactions: [{ type: "transfer", weight: 100 }],
}),
).toBe("transfer (100%, 25% account-create)");
});
});
21 changes: 18 additions & 3 deletions report/src/components/ConfigCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,27 @@ interface Row {
value: string;
}

const formatTransactions = (txs: LoadTestConfig["transactions"]): string => {
const percent = (value: number): string => `${Math.round(value * 100)}%`;

export const formatTransactions = (
config: Pick<LoadTestConfig, "transactions" | "fresh_recipient_ratio">,
): string => {
const txs = config.transactions;
if (!txs || txs.length === 0) return "—";
const total = txs.reduce((acc, t) => acc + t.weight, 0);
if (total === 0) return txs.map((t) => t.type).join(" · ");

const freshRecipientRatio = config.fresh_recipient_ratio ?? 0;
return txs
.map((t) => `${t.type} (${Math.round((t.weight / total) * 100)}%)`)
.map((t) => {
if (t.type === "transfer" && freshRecipientRatio >= 1) {
return `account-create (${percent(t.weight / total)})`;
}
if (t.type === "transfer" && freshRecipientRatio > 0) {
return `${t.type} (${percent(t.weight / total)}, ${percent(freshRecipientRatio)} account-create)`;
}
return `${t.type} (${percent(t.weight / total)})`;
})
.join(" · ");
};

Expand Down Expand Up @@ -94,7 +109,7 @@ const RowGroup = ({ rows }: { rows: Row[] }) => (

const ConfigCard = ({ config }: ConfigCardProps) => {
const groups = buildRows(config);
const txLine = formatTransactions(config.transactions);
const txLine = formatTransactions(config);

return (
<StatCard title="Run config">
Expand Down
1 change: 1 addition & 0 deletions report/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export interface LoadTestConfig {
seed: number;
chain_id: number | null;
transactions: Array<{ type: string; weight: number }>;
fresh_recipient_ratio?: number;
looper_contract: string | null;
swap_token_amount: string;
// Producer omits unless real-token setup is enabled; loosely typed.
Expand Down
203 changes: 127 additions & 76 deletions runner/benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,90 +37,141 @@ func NewParamsFromValues(assignments map[string]interface{}) (*types.RunParams,
params := *DefaultParams

for k, v := range assignments {
switch k {
case "payload":
if vPtrStr, ok := v.(*string); ok {
params.PayloadID = string(*vPtrStr)
} else if vStr, ok := v.(string); ok {
params.PayloadID = string(vStr)
} else {
return nil, fmt.Errorf("invalid payload %s", v)
}
case "node_type":
if vStr, ok := v.(string); ok {
params.NodeType = vStr
} else {
return nil, fmt.Errorf("invalid node type %s", v)
}
case "client_bin":
if vStr, ok := v.(string); ok {
params.ClientBinPath = vStr
} else {
return nil, fmt.Errorf("invalid client bin %s", v)
}
case "validator_node_type":
if vStr, ok := v.(string); ok {
params.ValidatorNodeType = vStr
} else {
return nil, fmt.Errorf("invalid validator node type %s", v)
}
case "gas_limit":
if vInt, ok := v.(int); ok {
params.GasLimit = uint64(vInt)
} else {
return nil, fmt.Errorf("invalid gas limit %s", v)
}
case "consensus_timing":
if vStr, ok := v.(string); ok {
if vStr != "" && vStr != types.ConsensusTimingModePreventLateFCU && vStr != types.ConsensusTimingModeBaseConsensus {
return nil, fmt.Errorf("invalid consensus timing %s", v)
}
params.ConsensusTimingMode = vStr
} else {
return nil, fmt.Errorf("invalid consensus timing %s", v)
if err := applyParam(&params, k, v); err != nil {
return nil, err
}
}

return &params, nil
}

func applyParam(params *types.RunParams, k string, v interface{}) error {
if k == "params" {
return applyParamGroup(params, v)
}

switch k {
case "payload":
if vPtrStr, ok := v.(*string); ok {
params.PayloadID = string(*vPtrStr)
} else if vStr, ok := v.(string); ok {
params.PayloadID = string(vStr)
} else {
return fmt.Errorf("invalid payload %s", v)
}
case "node_type":
if vStr, ok := v.(string); ok {
params.NodeType = vStr
} else {
return fmt.Errorf("invalid node type %s", v)
}
case "client_bin":
if vStr, ok := v.(string); ok {
params.ClientBinPath = vStr
} else {
return fmt.Errorf("invalid client bin %s", v)
}
case "validator_node_type":
if vStr, ok := v.(string); ok {
params.ValidatorNodeType = vStr
} else {
return fmt.Errorf("invalid validator node type %s", v)
}
case "gas_limit":
if vInt, ok := v.(int); ok {
params.GasLimit = uint64(vInt)
} else {
return fmt.Errorf("invalid gas limit %s", v)
}
case "load_test_config":
overrides, err := normalizeStringKeyMap(v)
if err != nil {
return fmt.Errorf("invalid load test config %v", v)
}
params.LoadTestConfigOverrides = overrides
case "consensus_timing":
if vStr, ok := v.(string); ok {
if vStr != "" && vStr != types.ConsensusTimingModePreventLateFCU && vStr != types.ConsensusTimingModeBaseConsensus {
return fmt.Errorf("invalid consensus timing %s", v)
}
case "env":
if vStr, ok := v.(string); ok {
entries := strings.Split(vStr, ";")
params.Env = make(map[string]string)
for _, entry := range entries {
kv := strings.Split(entry, "=")
if len(kv) != 2 {
return nil, fmt.Errorf("invalid env entry %s", entry)
}
params.Env[kv[0]] = kv[1]
params.ConsensusTimingMode = vStr
} else {
return fmt.Errorf("invalid consensus timing %s", v)
}
case "env":
if vStr, ok := v.(string); ok {
entries := strings.Split(vStr, ";")
params.Env = make(map[string]string)
for _, entry := range entries {
kv := strings.Split(entry, "=")
if len(kv) != 2 {
return fmt.Errorf("invalid env entry %s", entry)
}
} else {
return nil, fmt.Errorf("invalid env %s", v)
params.Env[kv[0]] = kv[1]
}
case "num_blocks":
if vInt, ok := v.(int); ok {
params.NumBlocks = vInt
} else {
return nil, fmt.Errorf("invalid num blocks %s", v)
}
case "node_args":
// either a list of strings or a string (separated by spaces)
if vStr, ok := v.(string); ok {
params.NodeArgs = strings.Split(vStr, " ")
} else if vArr, ok := v.([]interface{}); ok {
// convert []interface{} to []string
nodeArgs := make([]string, len(vArr))
for i, arg := range vArr {
arg, ok := arg.(string)
if !ok {
return nil, fmt.Errorf("invalid non-string node arg %v", arg)
}
nodeArgs[i] = arg
} else {
return fmt.Errorf("invalid env %s", v)
}
case "num_blocks":
if vInt, ok := v.(int); ok {
params.NumBlocks = vInt
} else {
return fmt.Errorf("invalid num blocks %s", v)
}
case "node_args":
// either a list of strings or a string (separated by spaces)
if vStr, ok := v.(string); ok {
params.NodeArgs = strings.Split(vStr, " ")
} else if vArr, ok := v.([]interface{}); ok {
// convert []interface{} to []string
nodeArgs := make([]string, len(vArr))
for i, arg := range vArr {
arg, ok := arg.(string)
if !ok {
return fmt.Errorf("invalid non-string node arg %v", arg)
}
params.NodeArgs = nodeArgs
} else {
return nil, fmt.Errorf("invalid node args %v", v)
nodeArgs[i] = arg
}
params.NodeArgs = nodeArgs
} else {
return fmt.Errorf("invalid node args %v", v)
}
}
return nil
}

return &params, nil
func applyParamGroup(params *types.RunParams, value interface{}) error {
// A params value groups multiple assignments into one matrix dimension,
// preserving relationships between values that should vary together.
expanded, err := normalizeStringKeyMap(value)
if err != nil {
return fmt.Errorf("invalid params %v", value)
}
for param, value := range expanded {
if err := applyParam(params, param, value); err != nil {
return fmt.Errorf("invalid params.%s: %w", param, err)
}
}
return nil
}

func normalizeStringKeyMap(value interface{}) (map[string]interface{}, error) {
switch typed := value.(type) {
case map[string]interface{}:
return typed, nil
case map[interface{}]interface{}:
out := make(map[string]interface{}, len(typed))
for key, value := range typed {
keyString, ok := key.(string)
if !ok {
return nil, fmt.Errorf("non-string key %v", key)
}
out[keyString] = value
}
return out, nil
default:
return nil, fmt.Errorf("expected mapping")
}
}

const MAX_GAS_LIMIT = math.MaxUint64
Expand Down
Loading
Loading