Skip to content

Commit cac437f

Browse files
authored
Revert snapshot changes (#131)
1 parent b13cad4 commit cac437f

File tree

8 files changed

+193
-603
lines changed

8 files changed

+193
-603
lines changed

configs/examples/snapshot.yml

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
name: Two-Tier Snapshot Functionality Test
1+
name: Snapshot Functionality Test
22
description: |
3-
IMPORTANT: This feature is currently in development, and the results are not yet reliable.
3+
Snapshot Functionality Test - Tests client snapshot creation and loading capabilities to validate state snapshot performance for fast sync operations.
44
5-
Two-Tier Snapshot Functionality Test - Demonstrates the new optimized snapshot system with initial snapshots and per-test copying.
5+
This benchmark suite tests snapshot functionality with both Sepolia Alpha and development network data, including snapshot creation, loading, and validation processes. Features skip-if-nonempty optimization for development efficiency and tests multiple gas limit configurations.
66
7-
This benchmark suite uses a two-tier snapshot approach:
8-
1. Initial snapshots are downloaded once at benchmark startup and stored persistently
9-
2. Per-test snapshots are copied from initial snapshots for each test run using rsync
10-
3. Test-specific copies are cleaned up after each test while preserving initial snapshots
11-
12-
Use Case: Optimized snapshot performance for fast test execution, reduced network overhead, and efficient storage management across multiple node types.
7+
Use Case: Validate state snapshot performance for fast sync operations, test snapshot creation and loading capabilities across different environments, and ensure snapshot performance remains consistent in development workflows.
138
149
payloads:
1510
- name: Transfer-only
1611
id: transfer-only
1712
type: transfer-only
1813

1914
benchmarks:
20-
- initial_snapshots:
21-
- node_type: reth
22-
# Download an initial reth snapshot that can be copied for each test
23-
command: ./scripts/setup-base-snapshot.sh --network=sepolia --node-type=reth --destination=/data/snapshots/reth/initial
24-
destination: /data/snapshots/reth/initial
25-
superchain_chain_id: 84532
26-
- node_type: geth
27-
# Download an initial geth snapshot that can be copied for each test
28-
command: ./scripts/setup-base-snapshot.sh --network=sepolia --node-type=geth --destination=/data/snapshots/geth/initial
29-
destination: /data/snapshots/geth/initial
30-
superchain_chain_id: 84532
15+
- snapshot:
16+
# skip non-empty for testing so we don't copy every time we run this
17+
# just delete the snapshot directory to force a full copy
18+
command: ./scripts/copy-local-snapshot.sh --skip-if-nonempty
19+
genesis_file: ../../sepolia-alpha/sepolia-alpha-genesis.json
20+
# force_clean is true by default to ensure consistency, but we can skip it for testing
21+
force_clean: false
3122
variables:
3223
- type: payload
3324
value: transfer-only
3425
- type: node_type
3526
values:
3627
- reth
37-
- geth
28+
- type: num_blocks
29+
value: 10
30+
- type: gas_limit
31+
values:
32+
- 15000000
33+
- 30000000
34+
- 60000000
35+
- 90000000
36+
- variables:
37+
- type: payload
38+
value: transfer-only
39+
- type: node_type
40+
values:
41+
- reth
3842
- type: num_blocks
3943
value: 10
4044
- type: gas_limit

runner/benchmark/definition.go

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package benchmark
22

33
import (
44
"errors"
5+
"fmt"
6+
"os"
7+
"os/exec"
8+
"path"
9+
"strings"
510

611
"github.com/base/base-bench/runner/payload"
712
)
@@ -31,6 +36,54 @@ type ProofProgramOptions struct {
3136
Type string `yaml:"type"`
3237
}
3338

39+
// SnapshotDefinition is the user-facing YAML configuration for specifying
40+
// a snapshot to be restored before running a benchmark.
41+
type SnapshotDefinition struct {
42+
Command string `yaml:"command"`
43+
GenesisFile *string `yaml:"genesis_file"`
44+
SuperchainChainID *uint64 `yaml:"superchain_chain_id"`
45+
ForceClean *bool `yaml:"force_clean"`
46+
}
47+
48+
// CreateSnapshot copies the snapshot to the output directory for the given
49+
// node type.
50+
func (s SnapshotDefinition) CreateSnapshot(nodeType string, outputDir string) error {
51+
// default to true if not set
52+
forceClean := s.ForceClean == nil || *s.ForceClean
53+
if _, err := os.Stat(outputDir); err == nil && forceClean {
54+
// TODO: we could reuse it here potentially
55+
if err := os.RemoveAll(outputDir); err != nil {
56+
return fmt.Errorf("failed to remove existing snapshot: %w", err)
57+
}
58+
}
59+
60+
// get absolute path of outputDir
61+
currentDir, err := os.Getwd()
62+
if err != nil {
63+
return fmt.Errorf("failed to get absolute path of outputDir: %w", err)
64+
}
65+
66+
outputDir = path.Join(currentDir, outputDir)
67+
68+
var cmdBin string
69+
var args []string
70+
// split out default args from command
71+
parts := strings.SplitN(s.Command, " ", 2)
72+
if len(parts) < 2 {
73+
cmdBin = parts[0]
74+
} else {
75+
cmdBin = parts[0]
76+
args = strings.Split(parts[1], " ")
77+
}
78+
79+
args = append(args, nodeType, outputDir)
80+
81+
cmd := exec.Command(cmdBin, args...)
82+
cmd.Stdout = os.Stdout
83+
cmd.Stderr = os.Stderr
84+
return cmd.Run()
85+
}
86+
3487
type BenchmarkConfig struct {
3588
Name string `yaml:"name"`
3689
Description *string `yaml:"description"`
@@ -41,11 +94,11 @@ type BenchmarkConfig struct {
4194
// TestDefinition is the user-facing YAML configuration for specifying a
4295
// matrix of benchmark runs.
4396
type TestDefinition struct {
44-
InitialSnapshots []SnapshotDefinition `yaml:"initial_snapshots"`
45-
Metrics *ThresholdConfig `yaml:"metrics"`
46-
Tags *map[string]string `yaml:"tags"`
47-
Variables []Param `yaml:"variables"`
48-
ProofProgram *ProofProgramOptions `yaml:"proof_program"`
97+
Snapshot *SnapshotDefinition `yaml:"snapshot"`
98+
Metrics *ThresholdConfig `yaml:"metrics"`
99+
Tags *map[string]string `yaml:"tags"`
100+
Variables []Param `yaml:"variables"`
101+
ProofProgram *ProofProgramOptions `yaml:"proof_program"`
49102
}
50103

51104
func (bc *TestDefinition) Check() error {

runner/benchmark/matrix.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ type ThresholdConfig struct {
1212

1313
// TestPlan represents a list of test runs to be executed.
1414
type TestPlan struct {
15-
Runs []TestRun
16-
InitialSnapshots []SnapshotDefinition
17-
ProofProgram *ProofProgramOptions
18-
Thresholds *ThresholdConfig
15+
Runs []TestRun
16+
Snapshot *SnapshotDefinition
17+
ProofProgram *ProofProgramOptions
18+
Thresholds *ThresholdConfig
1919
}
2020

2121
func NewTestPlanFromConfig(c TestDefinition, testFileName string, config *BenchmarkConfig) (*TestPlan, error) {
@@ -36,24 +36,13 @@ func NewTestPlanFromConfig(c TestDefinition, testFileName string, config *Benchm
3636
}
3737

3838
return &TestPlan{
39-
Runs: testRuns,
40-
InitialSnapshots: c.InitialSnapshots,
41-
ProofProgram: proofProgram,
42-
Thresholds: c.Metrics,
39+
Runs: testRuns,
40+
Snapshot: c.Snapshot,
41+
ProofProgram: proofProgram,
42+
Thresholds: c.Metrics,
4343
}, nil
4444
}
4545

46-
// GetInitialSnapshotForNodeType returns the initial snapshot definition for the given node type.
47-
// Returns nil if no initial snapshot is found for the node type.
48-
func (tp *TestPlan) GetInitialSnapshotForNodeType(nodeType string) *SnapshotDefinition {
49-
for _, snapshot := range tp.InitialSnapshots {
50-
if snapshot.NodeType == nodeType {
51-
return &snapshot
52-
}
53-
}
54-
return nil
55-
}
56-
5746
// ResolveTestRunsFromMatrix constructs a new ParamsMatrix from a config.
5847
func ResolveTestRunsFromMatrix(c TestDefinition, testFileName string, config *BenchmarkConfig) ([]TestRun, error) {
5948
seenParams := make(map[string]bool)
@@ -128,7 +117,7 @@ func ResolveTestRunsFromMatrix(c TestDefinition, testFileName string, config *Be
128117
testParams[i] = TestRun{
129118
ID: id,
130119
Params: *params,
131-
OutputDir: fmt.Sprintf("%s/%s-%d", id, id, i),
120+
OutputDir: fmt.Sprintf("%s-%d", id, i),
132121
Name: params.Name,
133122
Description: params.Description,
134123
TestFile: testFileName,

0 commit comments

Comments
 (0)