Skip to content
Draft
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
36 changes: 18 additions & 18 deletions benchmark/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ func prefixEnvVars(name string) []string {
}

const (
ConfigFlagName = "config"
RootDirFlagName = "root-dir"
OutputDirFlagName = "output-dir"
TxFuzzBinFlagName = "tx-fuzz-bin"
ProxyPortFlagName = "proxy-port"
BenchmarkRunIDFlagName = "benchmark-run-id"
MachineTypeFlagName = "machine-type"
MachineProviderFlagName = "machine-provider"
MachineRegionFlagName = "machine-region"
FileSystemFlagName = "file-system"
ConfigFlagName = "config"
RootDirFlagName = "root-dir"
OutputDirFlagName = "output-dir"
TxFuzzBinFlagName = "tx-fuzz-bin"
ProxyPortFlagName = "proxy-port"
BenchmarkRunIDFlagName = "benchmark-run-id"
MachineTypeFlagName = "machine-type"
MachineProviderFlagName = "machine-provider"
MachineRegionFlagName = "machine-region"
FileSystemFlagName = "file-system"
ParallelTxBatchesFlagName = "parallel-tx-batches"
)

Expand All @@ -42,17 +42,17 @@ var (
}

RootDirFlag = &cli.StringFlag{
Name: RootDirFlagName,
Usage: "Root Directory",
EnvVars: prefixEnvVars("ROOT_DIR"),
Required: true,
Name: RootDirFlagName,
Usage: "Root Directory",
EnvVars: prefixEnvVars("ROOT_DIR"),
Value: "./data-dir",
}

OutputDirFlag = &cli.StringFlag{
Name: OutputDirFlagName,
Usage: "Output Directory",
EnvVars: prefixEnvVars("OUTPUT_DIR"),
Required: true,
Name: OutputDirFlagName,
Usage: "Output Directory",
Value: "./output",
EnvVars: prefixEnvVars("OUTPUT_DIR"),
}

TxFuzzBinFlag = &cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build: build-abi build-bin build-abi-go

build-abi: src/**
mkdir -p abi
forge inspect src/Simulator.sol:Simulator abi --json > abi/Simulator.json
forge inspect contracts/src/Simulator.sol:Simulator abi --json > abi/Simulator.json

build-bin: src/**
forge build --extra-output-files bin --force
Expand Down
31 changes: 19 additions & 12 deletions contracts/src/Simulator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -319,26 +319,33 @@ contract Simulator {

function run_blake2f(uint256 num_iterations) private {
bytes32[2] memory h;
h[0] = 0x48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5;
h[1] = 0xd182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b;
h[0] = 0xa1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8;
h[1] = 0xa1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8;

bytes32[4] memory m;
m[0] = 0x6162630000000000000000000000000000000000000000000000000000000000;
m[1] = 0x0000000000000000000000000000000000000000000000000000000000000000;
m[2] = 0x0000000000000000000000000000000000000000000000000000000000000000;
m[3] = 0x0000000000000000000000000000000000000000000000000000000000000000;
m[0] = 0xc3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2;
m[1] = 0xc3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2;
m[2] = 0xc3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2;
m[3] = 0xc3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2;

bytes8[2] memory t;
t[0] = 0x0300000000000000;
t[1] = 0x0000000000000000;
t[0] = 0x0000000000000000;
t[1] = 0x0000000000ff00ff;

bool f = true;

for (uint256 i = 0; i < num_iterations; i++) {
uint32 rounds = uint32(i);
(bool ok,) =
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
require(ok, "Blake2f failed");
uint32 rounds = 0xc00;
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
}
}

Expand Down
7 changes: 3 additions & 4 deletions runner/benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"strings"
"sync/atomic"
"time"

"github.com/base/base-bench/runner/network/types"
"github.com/ethereum/go-ethereum/core"
Expand All @@ -29,9 +28,9 @@ const (
)

var DefaultParams = &types.RunParams{
NodeType: "geth",
GasLimit: 50e9,
BlockTime: 1 * time.Second,
NodeType: "geth",
GasLimit: 50e9,
// BlockTime is set from the top-level block_time config in ResolveTestRunsFromMatrix.
}

// NewParamsFromValues constructs a new benchmark params given a config and a set of transaction payloads to run.
Expand Down
28 changes: 28 additions & 0 deletions runner/benchmark/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path"
"path/filepath"
"strings"
"time"

"github.com/base/base-bench/runner/payload"
)
Expand Down Expand Up @@ -87,13 +88,40 @@ func (s SnapshotDefinition) CreateSnapshot(nodeType string, outputDir string) er
return cmd.Run()
}

// FlashblocksConfig holds top-level flashblocks configuration.
type FlashblocksConfig struct {
BlockTime string `yaml:"block_time"`
}

const DefaultFlashblocksBlockTime = "250ms"
const DefaultBlockTime = "1s"

type BenchmarkConfig struct {
Name string `yaml:"name"`
Description *string `yaml:"description"`
BlockTime *string `yaml:"block_time"`
Flashblocks *FlashblocksConfig `yaml:"flashblocks"`
Benchmarks []TestDefinition `yaml:"benchmarks"`
TransactionPayloads []payload.Definition `yaml:"payloads"`
}

// GetBlockTime returns the configured block time as a duration, or the default (1s).
func (bc *BenchmarkConfig) GetBlockTime() (time.Duration, error) {
raw := DefaultBlockTime
if bc.BlockTime != nil && *bc.BlockTime != "" {
raw = *bc.BlockTime
}
return time.ParseDuration(raw)
}

// FlashblocksBlockTime returns the configured flashblocks block time, or the default.
func (bc *BenchmarkConfig) FlashblocksBlockTime() string {
if bc.Flashblocks != nil && bc.Flashblocks.BlockTime != "" {
return bc.Flashblocks.BlockTime
}
return DefaultFlashblocksBlockTime
}

type DatadirConfig struct {
Sequencer *string `yaml:"sequencer"`
Validator *string `yaml:"validator"`
Expand Down
6 changes: 6 additions & 0 deletions runner/benchmark/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func NewTestPlanFromConfig(c TestDefinition, testFileName string, config *Benchm

// ResolveTestRunsFromMatrix constructs a new ParamsMatrix from a config.
func ResolveTestRunsFromMatrix(c TestDefinition, testFileName string, config *BenchmarkConfig) ([]TestRun, error) {
blockTime, err := config.GetBlockTime()
if err != nil {
return nil, fmt.Errorf("invalid block_time: %w", err)
}

seenParams := make(map[string]bool)

// Multiple payloads can run in a single benchmark.
Expand Down Expand Up @@ -107,6 +112,7 @@ func ResolveTestRunsFromMatrix(c TestDefinition, testFileName string, config *Be
return nil, err
}

params.BlockTime = blockTime
params.Name = config.Name
if config.Description != nil {
params.Description = *config.Description
Expand Down
11 changes: 6 additions & 5 deletions runner/benchmark/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package benchmark_test

import (
"testing"
"time"

"github.com/base/base-bench/runner/benchmark"
"github.com/base/base-bench/runner/network/types"
Expand Down Expand Up @@ -31,7 +32,7 @@ func TestResolveTestRunsFromMatrix(t *testing.T) {
NodeType: "geth",
PayloadID: "simple",
GasLimit: benchmark.DefaultParams.GasLimit,
BlockTime: benchmark.DefaultParams.BlockTime,
BlockTime: 1 * time.Second,
},
},
},
Expand All @@ -57,31 +58,31 @@ func TestResolveTestRunsFromMatrix(t *testing.T) {
NodeType: "geth",
GasLimit: benchmark.DefaultParams.GasLimit,
PayloadID: "simple",
BlockTime: benchmark.DefaultParams.BlockTime,
BlockTime: 1 * time.Second,
},
},
{
Params: types.RunParams{
NodeType: "erigon",
GasLimit: benchmark.DefaultParams.GasLimit,
PayloadID: "simple",
BlockTime: benchmark.DefaultParams.BlockTime,
BlockTime: 1 * time.Second,
},
},
{
Params: types.RunParams{
NodeType: "geth",
GasLimit: benchmark.DefaultParams.GasLimit,
PayloadID: "complex",
BlockTime: benchmark.DefaultParams.BlockTime,
BlockTime: 1 * time.Second,
},
},
{
Params: types.RunParams{
NodeType: "erigon",
GasLimit: benchmark.DefaultParams.GasLimit,
PayloadID: "complex",
BlockTime: benchmark.DefaultParams.BlockTime,
BlockTime: 1 * time.Second,
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions runner/clients/builder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func (r *BuilderClient) Run(ctx context.Context, cfg *types.RuntimeConfig) error
cfg2 := *cfg
cfg2.Args = append(cfg2.Args, "--flashblocks.port", fmt.Sprintf("%d", r.websocketPort))
cfg2.Args = append(cfg2.Args, "--flashblocks.fixed")
if cfg.FlashblocksBlockTime != "" {
cfg2.Args = append(cfg2.Args, "--flashblocks.block-time", cfg.FlashblocksBlockTime)
}
if cfg.BlockTimeMs > 0 {
cfg2.Args = append(cfg2.Args, "--rollup.chain-block-time", fmt.Sprintf("%d", cfg.BlockTimeMs))
}
err := r.elClient.Run(ctx, &cfg2)
if err != nil {
return err
Expand Down
10 changes: 6 additions & 4 deletions runner/clients/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
)

type RuntimeConfig struct {
Stdout io.WriteCloser
Stderr io.WriteCloser
Args []string
FlashblocksURL *string // Optional URL for flashblocks websocket server (only used by clients that support it)
Stdout io.WriteCloser
Stderr io.WriteCloser
Args []string
FlashblocksURL *string // Optional URL for flashblocks websocket server (only used by clients that support it)
FlashblocksBlockTime string // Block time for flashblocks (e.g. "250ms")
BlockTimeMs uint64 // L2 block time in milliseconds
}

// ExecutionClient is an abstraction over the different clients that can be used to run the chain like
Expand Down
6 changes: 3 additions & 3 deletions runner/network/configutil/rollup_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/ethereum/go-ethereum/params"
)

// GetRollupConfig creates a rollup configuration for the given genesis and chain
func GetRollupConfig(genesis *core.Genesis, chain fakel1.L1Chain, batcherAddr common.Address) *rollup.Config {
// GetRollupConfig creates a rollup configuration for the given genesis, chain, and block time (in seconds).
func GetRollupConfig(genesis *core.Genesis, chain fakel1.L1Chain, batcherAddr common.Address, blockTimeSec uint64) *rollup.Config {
var eipParams eth.Bytes8
copy(eipParams[:], eip1559.EncodeHolocene1559Params(50, 1))

Expand Down Expand Up @@ -50,7 +50,7 @@ func GetRollupConfig(genesis *core.Genesis, chain fakel1.L1Chain, batcherAddr co
}),
},
},
BlockTime: 1,
BlockTime: blockTimeSec,
MaxSequencerDrift: 20,
SeqWindowSize: 24,
L1ChainID: big.NewInt(1),
Expand Down
1 change: 1 addition & 0 deletions runner/network/consensus/sequencer_consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func (f *SequencerConsensusClient) Propose(ctx context.Context, blockMetrics *me
blockMetrics.AddExecutionMetric(networktypes.UpdateForkChoiceLatencyMetric, duration)

f.currentPayloadID = payloadID
f.log.Info("Waiting for block time", "block_time", f.options.BlockTime)
// wait block time
time.Sleep(f.options.BlockTime)

Expand Down
4 changes: 2 additions & 2 deletions runner/network/fault_proof_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type opProgramBenchmark struct {
rollupCfg *rollup.Config
}

func NewOPProgramBenchmark(genesis *core.Genesis, log log.Logger, opProgramBin string, l2RPCURL string, l1Chain fakel1.L1Chain, batcherKey *ecdsa.PrivateKey) ProofProgramBenchmark {
rollupCfg := configutil.GetRollupConfig(genesis, l1Chain, crypto.PubkeyToAddress(batcherKey.PublicKey))
func NewOPProgramBenchmark(genesis *core.Genesis, log log.Logger, opProgramBin string, l2RPCURL string, l1Chain fakel1.L1Chain, batcherKey *ecdsa.PrivateKey, blockTimeSec uint64) ProofProgramBenchmark {
rollupCfg := configutil.GetRollupConfig(genesis, l1Chain, crypto.PubkeyToAddress(batcherKey.PublicKey), blockTimeSec)
batcher := proofprogram.NewBatcher(rollupCfg, batcherKey, l1Chain)

return &opProgramBenchmark{
Expand Down
38 changes: 21 additions & 17 deletions runner/network/network_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ type NetworkBenchmark struct {
testConfig *benchtypes.TestConfig
proofConfig *benchmark.ProofProgramOptions

transactionPayload payload.Definition
ports portmanager.PortManager
transactionPayload payload.Definition
ports portmanager.PortManager
flashblocksBlockTime string
}

// NewNetworkBenchmark creates a new network benchmark and initializes the payload worker and consensus client
func NewNetworkBenchmark(config *benchtypes.TestConfig, log log.Logger, sequencerOptions *config.InternalClientOptions, validatorOptions *config.InternalClientOptions, proofConfig *benchmark.ProofProgramOptions, transactionPayload payload.Definition, ports portmanager.PortManager) (*NetworkBenchmark, error) {
func NewNetworkBenchmark(config *benchtypes.TestConfig, log log.Logger, sequencerOptions *config.InternalClientOptions, validatorOptions *config.InternalClientOptions, proofConfig *benchmark.ProofProgramOptions, transactionPayload payload.Definition, ports portmanager.PortManager, flashblocksBlockTime string) (*NetworkBenchmark, error) {
return &NetworkBenchmark{
log: log,
sequencerOptions: sequencerOptions,
validatorOptions: validatorOptions,
testConfig: config,
proofConfig: proofConfig,
transactionPayload: transactionPayload,
ports: ports,
log: log,
sequencerOptions: sequencerOptions,
validatorOptions: validatorOptions,
testConfig: config,
proofConfig: proofConfig,
transactionPayload: transactionPayload,
ports: ports,
flashblocksBlockTime: flashblocksBlockTime,
}, nil
}

Expand Down Expand Up @@ -88,7 +90,7 @@ func (nb *NetworkBenchmark) Run(ctx context.Context) error {
}

func (nb *NetworkBenchmark) benchmarkSequencer(ctx context.Context, l1Chain *l1Chain) (*benchtypes.PayloadResult, uint64, types.ExecutionClient, error) {
sequencerClient, err := setupNode(ctx, nb.log, nb.testConfig.Params.NodeType, nb.testConfig.Params, nb.sequencerOptions, nb.ports, "")
sequencerClient, err := setupNode(ctx, nb.log, nb.testConfig.Params.NodeType, nb.testConfig.Params, nb.sequencerOptions, nb.ports, "", nb.flashblocksBlockTime)
if err != nil {
return nil, 0, nil, fmt.Errorf("failed to setup sequencer node: %w", err)
}
Expand Down Expand Up @@ -158,7 +160,7 @@ func (nb *NetworkBenchmark) benchmarkValidator(ctx context.Context, payloadResul
validatorNodeType = nb.testConfig.Params.NodeType
}

validatorClient, err := setupNode(ctx, nb.log, validatorNodeType, nb.testConfig.Params, nb.validatorOptions, nb.ports, flashblockServerURL)
validatorClient, err := setupNode(ctx, nb.log, validatorNodeType, nb.testConfig.Params, nb.validatorOptions, nb.ports, flashblockServerURL, nb.flashblocksBlockTime)
if err != nil {
sequencerClient.Stop()
return fmt.Errorf("failed to setup validator node: %w", err)
Expand Down Expand Up @@ -253,7 +255,7 @@ func (nb *NetworkBenchmark) GetResult() (*benchmark.RunResult, error) {
}, nil
}

func setupNode(ctx context.Context, l log.Logger, nodeTypeStr string, params benchtypes.RunParams, options *config.InternalClientOptions, portManager portmanager.PortManager, flashblockServerURL string) (types.ExecutionClient, error) {
func setupNode(ctx context.Context, l log.Logger, nodeTypeStr string, params benchtypes.RunParams, options *config.InternalClientOptions, portManager portmanager.PortManager, flashblockServerURL string, flashblocksBlockTime string) (types.ExecutionClient, error) {
if options == nil {
return nil, errors.New("client options cannot be nil")
}
Expand Down Expand Up @@ -293,10 +295,12 @@ func setupNode(ctx context.Context, l log.Logger, nodeTypeStr string, params ben
}

runtimeConfig := &types.RuntimeConfig{
Stdout: stdoutLogger,
Stderr: stderrLogger,
Args: args,
FlashblocksURL: flashblocksURLPtr,
Stdout: stdoutLogger,
Stderr: stderrLogger,
Args: args,
FlashblocksURL: flashblocksURLPtr,
FlashblocksBlockTime: flashblocksBlockTime,
BlockTimeMs: uint64(params.BlockTime.Milliseconds()),
}

if err := client.Run(ctx, runtimeConfig); err != nil {
Expand Down
Loading
Loading