Skip to content

feat: inject opcode txs #23

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 36 additions & 2 deletions packages/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
"github.com/urfave/cli/v2"
)

const (
StrategyTypeStress = "stress"
StrategyTypeReplay = "replay"
)

type ReplayorConfig struct {
EngineApiSecret common.Hash
SourceNodeUrl string
Expand All @@ -21,6 +26,7 @@ type ReplayorConfig struct {
EngineApiUrl string
ExecutionUrl string
Strategy string
StressConfig *StressConfig
BlockCount int
GasTarget uint64
GasLimit uint64
Expand All @@ -31,7 +37,12 @@ type ReplayorConfig struct {
Bucket string
StorageType string
DiskPath string
InjectERC20 bool
}

type StressConfig struct {
Type string
OpCodeType string
OpCodeExecNum uint64
}

func (r ReplayorConfig) TestDescription() string {
Expand Down Expand Up @@ -80,6 +91,13 @@ func LoadReplayorConfig(cliCtx *cli.Context, l log.Logger) (ReplayorConfig, erro
if gasTarget > gasLimit {
return ReplayorConfig{}, fmt.Errorf("cannot set gasTarget greater than gasLimit")
}
strategy := cliCtx.String(Strategy.Name)
var stressConfig *StressConfig
if strategy == StrategyTypeStress {
if stressConfig, err = LoadStressConfig(cliCtx); err != nil {
return ReplayorConfig{}, err
}
}

return ReplayorConfig{
EngineApiSecret: secretHash,
Expand All @@ -89,6 +107,7 @@ func LoadReplayorConfig(cliCtx *cli.Context, l log.Logger) (ReplayorConfig, erro
EngineApiUrl: cliCtx.String(EngineApiUrl.Name),
ExecutionUrl: cliCtx.String(ExecutionUrl.Name),
Strategy: cliCtx.String(Strategy.Name),
StressConfig: stressConfig,
BlockCount: cliCtx.Int(BlockCount.Name),
GasTarget: gasTarget,
GasLimit: gasLimit,
Expand All @@ -99,6 +118,21 @@ func LoadReplayorConfig(cliCtx *cli.Context, l log.Logger) (ReplayorConfig, erro
Bucket: cliCtx.String(S3Bucket.Name),
StorageType: cliCtx.String(StorageType.Name),
DiskPath: cliCtx.String(DiskPath.Name),
InjectERC20: cliCtx.Bool(InjectErc20.Name),
}, nil
}

func LoadStressConfig(cliCtx *cli.Context) (*StressConfig, error) {
stressConfig := &StressConfig{
Type: cliCtx.String(StressType.Name),
OpCodeType: cliCtx.String(StressOpcode.Name),
OpCodeExecNum: cliCtx.Uint64(StressOpcodeExecNum.Name),
}
if stressConfig.Type == "opcode" {
if stressConfig.OpCodeExecNum < 50 {
return nil, fmt.Errorf("op code execution number too low")
} else if stressConfig.OpCodeExecNum > 5000 {
return nil, fmt.Errorf("op code execution number too high")
}
}
return stressConfig, nil
}
53 changes: 45 additions & 8 deletions packages/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,31 @@ var (
}
Strategy = &cli.StringFlag{
Name: "strategy",
Usage: "The strategy to use for replaying transactions",
Usage: "The strategy to use for replaying transactions, support: replay, stress",
Required: true,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "STRATEGY"),
}
StressType = &cli.StringFlag{
Name: "stress-type",
Usage: "The type of stress strategy to use for replaying transactions, support: transfer, erc20, opcode",
Required: false,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "STRESS_TYPE"),
DefaultText: "transfer",
}
StressOpcode = &cli.StringFlag{
Name: "stress-opcode",
Usage: "The opcode that stress strategy to use for replaying transactions",
Required: false,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "STRESS_OPCODE"),
DefaultText: "SSTORE",
}
StressOpcodeExecNum = &cli.IntFlag{
Name: "stress-opcode-exec-num",
Usage: "The execution number of opCode to call for replaying transactions,minimum 50, maximum 5000",
Required: false,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "STRESS_OPCODE_EXEC_NUM"),
DefaultText: "500",
}
BlockCount = &cli.IntFlag{
Name: "block-count",
Usage: "How many blocks to replay",
Expand Down Expand Up @@ -106,17 +127,33 @@ var (
Required: false,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "DISK_PATH"),
}
InjectErc20 = &cli.BoolFlag{
Name: "inject-erc20-txs",
Usage: "whether to inject erc20 txs",
Required: false,
EnvVars: opservice.PrefixEnvVar(EnvVarPrefix, "INJECT_ERC20_TXS"),
}
)

func init() {
Flags = append(Flags, oplog.CLIFlags(EnvVarPrefix)...)
Flags = append(Flags, EngineApiSecret, SourceNodeUrl, ChainId, EngineApiUrl, ExecutionUrl, Strategy, BlockCount, GasTarget, GasLimit, S3Bucket, StorageType, DiskPath, BenchmarkStartBlock, BenchmarkOpcodes, ComputeStorageDiffs, TestName, RollupConfigPath, InjectErc20)
replayorFlags := []cli.Flag{
EngineApiSecret,
SourceNodeUrl,
ChainId,
RollupConfigPath,
EngineApiUrl,
ExecutionUrl,
Strategy,
StressType,
StressOpcode,
StressOpcodeExecNum,
BlockCount,
GasTarget,
GasLimit,
BenchmarkStartBlock,
BenchmarkOpcodes,
ComputeStorageDiffs,
TestName,
S3Bucket,
StorageType,
DiskPath,
}
Flags = append(Flags, replayorFlags...)
}

// Flags contains the list of configuration options available to the binary.
Expand Down
Loading
Loading