Skip to content

Commit c00924c

Browse files
committed
make num blocks to write a config
1 parent 3c26315 commit c00924c

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

config/settings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Settings struct {
2626
ReportPath string `json:"reportPath,omitempty"`
2727
TxsDir string `json:"txsDir,omitempty"`
2828
TargetGas uint64 `json:"targetGas,omitempty"`
29+
NumBlocksToWrite int `json:"numBlocksToWrite,omitempty"`
2930
}
3031

3132
// DefaultSettings returns the default configuration values
@@ -45,6 +46,7 @@ func DefaultSettings() Settings {
4546
ReportPath: "",
4647
TxsDir: "",
4748
TargetGas: 10_000_000,
49+
NumBlocksToWrite: 100,
4850
}
4951
}
5052

@@ -66,6 +68,7 @@ func InitializeViper(cmd *cobra.Command) error {
6668
"reportPath": "report-path",
6769
"txsDir": "txs-dir",
6870
"targetGas": "target-gas",
71+
"numBlocksToWrite": "num-blocks-to-write",
6972
}
7073

7174
for viperKey, flagName := range flagBindings {
@@ -90,6 +93,7 @@ func InitializeViper(cmd *cobra.Command) error {
9093
viper.SetDefault("reportPath", defaults.ReportPath)
9194
viper.SetDefault("txsDir", defaults.TxsDir)
9295
viper.SetDefault("targetGas", defaults.TargetGas)
96+
viper.SetDefault("numBlocksToWrite", defaults.NumBlocksToWrite)
9397
return nil
9498
}
9599

@@ -130,5 +134,6 @@ func ResolveSettings() Settings {
130134
ReportPath: viper.GetString("reportPath"),
131135
TxsDir: viper.GetString("txsDir"),
132136
TargetGas: viper.GetUint64("targetGas"),
137+
NumBlocksToWrite: viper.GetInt("numBlocksToWrite"),
133138
}
134139
}

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func init() {
6868
rootCmd.Flags().String("report-path", "", "Path to save the report")
6969
rootCmd.Flags().String("txs-dir", "", "Path to save the transactions")
7070
rootCmd.Flags().Uint64("target-gas", 10_000_000, "Target gas per block")
71+
rootCmd.Flags().Int("num-blocks-to-write", 100, "Number of blocks to write")
7172

7273
// Initialize Viper with proper error handling
7374
if err := config.InitializeViper(rootCmd); err != nil {
@@ -239,9 +240,10 @@ func runLoadTest(ctx context.Context, cmd *cobra.Command, args []string) error {
239240
if err != nil {
240241
return fmt.Errorf("failed to get latest height: %w", err)
241242
}
243+
numBlocksToWrite := settings.NumBlocksToWrite
242244
writerHeight := latestHeight + 10 // some buffer
243245
log.Printf("🔍 Latest height: %d, writer start height: %d", latestHeight, writerHeight)
244-
writer := sender.NewTxsWriter(settings.TargetGas, settings.TxsDir, writerHeight, 100)
246+
writer := sender.NewTxsWriter(settings.TargetGas, settings.TxsDir, writerHeight, uint64(numBlocksToWrite))
245247
dispatcher = sender.NewDispatcher(gen, writer)
246248
} else {
247249
dispatcher = sender.NewDispatcher(gen, snd)

sender/writer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func TestTxsWriter_Flush(t *testing.T) {
1515
// two evm transfer txs
16-
writer := NewTxsWriter(42000, "/tmp", 1)
16+
writer := NewTxsWriter(42000, "/tmp", 1, 1)
1717

1818
loadConfig := &config.LoadConfig{
1919
ChainID: 7777,

0 commit comments

Comments
 (0)