Skip to content

Commit 33c6ff9

Browse files
committed
fix: Use separate snapshots for sequencer and validator workloads
1 parent 519274b commit 33c6ff9

File tree

1 file changed

+83
-41
lines changed

1 file changed

+83
-41
lines changed

runner/service.go

Lines changed: 83 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func readBenchmarkConfig(path string) (*benchmark.BenchmarkConfig, error) {
8080
return config, err
8181
}
8282

83-
func (s *service) setupInternalDirectories(testDir string, params types.RunParams, genesis *core.Genesis, snapshot *benchmark.SnapshotDefinition, role string) (*config.InternalClientOptions, error) {
83+
func (s *service) setupInternalDirectories(testDir string, params types.RunParams, genesis *core.Genesis, snapshot *benchmark.SnapshotDefinition, role string, dataDirOverride string) (*config.InternalClientOptions, error) {
8484
err := os.MkdirAll(testDir, 0755)
8585
if err != nil {
8686
return nil, errors.Wrap(err, "failed to create test directory")
@@ -105,52 +105,61 @@ func (s *service) setupInternalDirectories(testDir string, params types.RunParam
105105
}
106106

107107
var dataDirPath string
108-
isSnapshot := snapshot != nil && snapshot.Command != ""
109-
if isSnapshot {
110-
dataDirPath = path.Join(testDir, "data")
108+
var isSnapshot bool
111109

112-
initialSnapshotPath := s.dataDirState.GetInitialSnapshotPath(params.NodeType)
113-
114-
if initialSnapshotPath != "" && s.fileExists(initialSnapshotPath) {
115-
snapshotMethod := snapshot.GetSnapshotMethod()
116-
117-
switch snapshotMethod {
118-
case benchmark.SnapshotMethodReuseExisting:
119-
dataDirPath = initialSnapshotPath
120-
s.log.Info("Reusing existing snapshot", "snapshotPath", initialSnapshotPath, "method", snapshotMethod)
121-
case benchmark.SnapshotMethodHeadRollback:
122-
// For head_rollback, copy the snapshot but mark it for rollback later
123-
err := s.dataDirState.CopyFromInitialSnapshot(initialSnapshotPath, dataDirPath)
124-
if err != nil {
125-
return nil, errors.Wrap(err, "failed to copy from initial snapshot for head rollback")
110+
// If dataDirOverride is provided, use it (already set up by caller)
111+
if dataDirOverride != "" {
112+
dataDirPath = dataDirOverride
113+
isSnapshot = true // dataDirOverride is only set when using snapshots
114+
s.log.Info("Using pre-configured datadir", "path", dataDirPath, "role", role)
115+
} else {
116+
isSnapshot = snapshot != nil && snapshot.Command != ""
117+
if isSnapshot {
118+
dataDirPath = path.Join(testDir, "data")
119+
120+
initialSnapshotPath := s.dataDirState.GetInitialSnapshotPath(params.NodeType)
121+
122+
if initialSnapshotPath != "" && s.fileExists(initialSnapshotPath) {
123+
snapshotMethod := snapshot.GetSnapshotMethod()
124+
125+
switch snapshotMethod {
126+
case benchmark.SnapshotMethodReuseExisting:
127+
dataDirPath = initialSnapshotPath
128+
s.log.Info("Reusing existing snapshot", "snapshotPath", initialSnapshotPath, "method", snapshotMethod)
129+
case benchmark.SnapshotMethodHeadRollback:
130+
// For head_rollback, copy the snapshot but mark it for rollback later
131+
err := s.dataDirState.CopyFromInitialSnapshot(initialSnapshotPath, dataDirPath)
132+
if err != nil {
133+
return nil, errors.Wrap(err, "failed to copy from initial snapshot for head rollback")
134+
}
135+
s.log.Info("Copied from initial snapshot for head rollback", "initialSnapshotPath", initialSnapshotPath, "dataDirPath", dataDirPath, "method", snapshotMethod)
136+
default:
137+
// Default chain_copy behavior
138+
err := s.dataDirState.CopyFromInitialSnapshot(initialSnapshotPath, dataDirPath)
139+
if err != nil {
140+
return nil, errors.Wrap(err, "failed to copy from initial snapshot")
141+
}
142+
s.log.Info("Copied from initial snapshot", "initialSnapshotPath", initialSnapshotPath, "dataDirPath", dataDirPath)
126143
}
127-
s.log.Info("Copied from initial snapshot for head rollback", "initialSnapshotPath", initialSnapshotPath, "dataDirPath", dataDirPath, "method", snapshotMethod)
128-
default:
129-
// Default chain_copy behavior
130-
err := s.dataDirState.CopyFromInitialSnapshot(initialSnapshotPath, dataDirPath)
144+
} else {
145+
// Fallback to direct snapshot creation
146+
if initialSnapshotPath != "" {
147+
s.log.Warn("Initial snapshot path registered but doesn't exist, falling back to direct snapshot creation",
148+
"path", initialSnapshotPath, "nodeType", params.NodeType)
149+
}
150+
snapshotDir, err := s.dataDirState.EnsureSnapshot(*snapshot, params.NodeType, role)
131151
if err != nil {
132-
return nil, errors.Wrap(err, "failed to copy from initial snapshot")
152+
return nil, errors.Wrap(err, "failed to ensure snapshot")
133153
}
134-
s.log.Info("Copied from initial snapshot", "initialSnapshotPath", initialSnapshotPath, "dataDirPath", dataDirPath)
154+
dataDirPath = snapshotDir
135155
}
136156
} else {
137-
// Fallback to direct snapshot creation
138-
if initialSnapshotPath != "" {
139-
s.log.Warn("Initial snapshot path registered but doesn't exist, falling back to direct snapshot creation",
140-
"path", initialSnapshotPath, "nodeType", params.NodeType)
141-
}
142-
snapshotDir, err := s.dataDirState.EnsureSnapshot(*snapshot, params.NodeType, role)
157+
// if no snapshot, just create a new datadir
158+
dataDirPath = path.Join(testDir, "data")
159+
err = os.Mkdir(dataDirPath, 0755)
143160
if err != nil {
144-
return nil, errors.Wrap(err, "failed to ensure snapshot")
161+
return nil, errors.Wrap(err, "failed to create data directory")
145162
}
146-
dataDirPath = snapshotDir
147-
}
148-
} else {
149-
// if no snapshot, just create a new datadir
150-
dataDirPath = path.Join(testDir, "data")
151-
err = os.Mkdir(dataDirPath, 0755)
152-
if err != nil {
153-
return nil, errors.Wrap(err, "failed to create data directory")
154163
}
155164
}
156165

@@ -326,12 +335,45 @@ func (s *service) setupDataDirs(workingDir string, params types.RunParams, genes
326335
sequencerTestDir := path.Join(workingDir, fmt.Sprintf("%s-sequencer", testName))
327336
validatorTestDir := path.Join(workingDir, fmt.Sprintf("%s-validator", testName))
328337

329-
sequencerOptions, err := s.setupInternalDirectories(sequencerTestDir, params, genesis, snapshot, "sequencer")
338+
// Special handling for SnapshotMethodReuseExisting to avoid both nodes using the same datadir
339+
var sequencerDataDirOverride, validatorDataDirOverride string
340+
if snapshot != nil && snapshot.GetSnapshotMethod() == benchmark.SnapshotMethodReuseExisting {
341+
initialSnapshotPath := s.dataDirState.GetInitialSnapshotPath(params.NodeType)
342+
if initialSnapshotPath != "" && s.fileExists(initialSnapshotPath) {
343+
validatorDataDirOverride = path.Join(validatorTestDir, "data")
344+
sequencerDataDirOverride = path.Join(sequencerTestDir, "data")
345+
346+
s.log.Info("Setting up reuse_existing snapshot: copying to validator, moving to sequencer",
347+
"initialSnapshot", initialSnapshotPath,
348+
"sequencerDataDir", sequencerDataDirOverride,
349+
"validatorDataDir", validatorDataDirOverride)
350+
351+
// First: copy from initial snapshot to validator directory
352+
err := s.dataDirState.CopyFromInitialSnapshot(initialSnapshotPath, validatorDataDirOverride)
353+
if err != nil {
354+
return nil, nil, errors.Wrap(err, "failed to copy initial snapshot to validator directory")
355+
}
356+
s.log.Info("Copied initial snapshot to validator directory", "path", validatorDataDirOverride)
357+
358+
err = os.MkdirAll(sequencerTestDir, 0755)
359+
if err != nil {
360+
return nil, nil, errors.Wrap(err, "failed to create sequencer test directory")
361+
}
362+
363+
err = os.Rename(initialSnapshotPath, sequencerDataDirOverride)
364+
if err != nil {
365+
return nil, nil, errors.Wrap(err, "failed to move initial snapshot to sequencer directory")
366+
}
367+
s.log.Info("Moved initial snapshot to sequencer directory", "from", initialSnapshotPath, "to", sequencerDataDirOverride)
368+
}
369+
}
370+
371+
sequencerOptions, err := s.setupInternalDirectories(sequencerTestDir, params, genesis, snapshot, "sequencer", sequencerDataDirOverride)
330372
if err != nil {
331373
return nil, nil, errors.Wrap(err, "failed to setup internal directories")
332374
}
333375

334-
validatorOptions, err := s.setupInternalDirectories(validatorTestDir, params, genesis, snapshot, "validator")
376+
validatorOptions, err := s.setupInternalDirectories(validatorTestDir, params, genesis, snapshot, "validator", validatorDataDirOverride)
335377
if err != nil {
336378
return nil, nil, errors.Wrap(err, "failed to setup internal directories")
337379
}

0 commit comments

Comments
 (0)