Skip to content

Commit ac031cb

Browse files
authored
ci(bench): patch genesis gas limit when snapshot differs (#3987)
## Summary - Extend local e2e genesis patching to handle `gasLimit` alongside hardfork activation times. - Skip regenesis when the snapshot already matches the requested hardfork and gas limit, mirroring the existing hardfork-only behavior. - Keep the cached hardfork-mode genesis files in sync with the requested gas limit. ## Testing - Verified Nushell helpers for gas-limit normalization and genesis synthesis. - Checked the regenesis skip path against a temp marker and confirmed `gasLimit` is written back as an Ethereum quantity. - `git diff --check` passed.
1 parent e216ece commit ac031cb

2 files changed

Lines changed: 120 additions & 26 deletions

File tree

bench-e2e.nu

Lines changed: 115 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -223,45 +223,137 @@ def e2e-snapshot-state-hardfork [datadir: string] {
223223
normalize-hardfork $state_hardfork
224224
}
225225

226-
def e2e-update-snapshot-hardfork-marker [datadir: string, hardfork: string] {
227-
let fork = (normalize-hardfork $hardfork)
226+
def normalize-gas-limit [gas_limit: string] {
227+
if $gas_limit == "" {
228+
return ""
229+
}
230+
$gas_limit | into int | into string
231+
}
232+
233+
def gas-limit-quantity [gas_limit: string] {
234+
let normalized = (normalize-gas-limit $gas_limit)
235+
if $normalized == "" {
236+
return ""
237+
}
238+
$normalized | into int | format number | get lowerhex
239+
}
240+
241+
def e2e-snapshot-state-gas-limit [datadir: string] {
242+
let marker = (read-bench-marker $datadir)
243+
if $marker != null {
244+
let marker_gas_limit = ($marker | get -o gas_limit | default "")
245+
if $marker_gas_limit != "" {
246+
return (normalize-gas-limit $marker_gas_limit)
247+
}
248+
}
249+
250+
let genesis_path = $"($datadir)/($BENCH_META_SUBDIR)/genesis.json"
251+
if ($genesis_path | path exists) {
252+
let genesis_gas_limit = (open $genesis_path | get -o gasLimit | default "")
253+
if $genesis_gas_limit != "" {
254+
return (normalize-gas-limit $genesis_gas_limit)
255+
}
256+
}
257+
258+
""
259+
}
260+
261+
def e2e-update-snapshot-genesis-marker [
262+
datadir: string,
263+
hardfork: string,
264+
gas_limit: string,
265+
] {
228266
let marker_path = $"($datadir)/($BENCH_META_SUBDIR)/marker.json"
229-
let marker = (open $marker_path)
230-
$marker | upsert state_hardfork $fork | to json | save -f $marker_path
267+
mut marker = (open $marker_path)
268+
if $hardfork != "" {
269+
let fork = (normalize-hardfork $hardfork)
270+
$marker = ($marker | upsert state_hardfork $fork)
271+
}
272+
if $gas_limit != "" {
273+
$marker = ($marker | upsert gas_limit (normalize-gas-limit $gas_limit))
274+
}
275+
$marker | to json | save -f $marker_path
231276
}
232277

233-
def e2e-synthesize-hardfork-genesis [source_genesis: string, target_genesis: string, hardfork: string] {
234-
let fork = (normalize-hardfork $hardfork)
278+
def e2e-synthesize-genesis [
279+
source_genesis: string,
280+
target_genesis: string,
281+
hardfork: string,
282+
gas_limit: string,
283+
] {
235284
let source = (open $source_genesis)
236285
mut config = ($source | get config)
237-
for field in (hardfork-genesis-config-fields $fork) {
238-
$config = ($config | upsert $field.name $field.value)
286+
mut patch_labels = []
287+
if $hardfork != "" {
288+
let fork = (normalize-hardfork $hardfork)
289+
for field in (hardfork-genesis-config-fields $fork) {
290+
$config = ($config | upsert $field.name $field.value)
291+
}
292+
$patch_labels = ($patch_labels | append $"hardfork=($fork)")
293+
}
294+
mut genesis = ($source | upsert config $config)
295+
if $gas_limit != "" {
296+
let normalized_gas_limit = (normalize-gas-limit $gas_limit)
297+
$genesis = ($genesis | upsert gasLimit (gas-limit-quantity $normalized_gas_limit))
298+
$patch_labels = ($patch_labels | append $"gas_limit=($normalized_gas_limit)")
239299
}
240-
let genesis = ($source | upsert config $config)
241300
let target_dir = ($target_genesis | path dirname)
242301
mkdir $target_dir
243302
$genesis | to json | save -f $target_genesis
244-
print $"Synthesized ($fork) genesis at ($target_genesis)"
303+
let patch_label = if ($patch_labels | length) > 0 {
304+
$patch_labels | str join ", "
305+
} else {
306+
"unchanged"
307+
}
308+
print $"Synthesized genesis \(($patch_label)\) at ($target_genesis)"
245309
}
246310

247-
def e2e-regenesis [tempo_bin: string, genesis: string, datadir: string, hardfork: string] {
248-
let fork = (normalize-hardfork $hardfork)
311+
def e2e-regenesis [
312+
tempo_bin: string,
313+
genesis: string,
314+
datadir: string,
315+
hardfork: string,
316+
gas_limit: string,
317+
] {
318+
let target_hardfork = if $hardfork != "" { normalize-hardfork $hardfork } else { "" }
319+
let target_gas_limit = if $gas_limit != "" { normalize-gas-limit $gas_limit } else { "" }
249320
let current_hardfork = (e2e-snapshot-state-hardfork $datadir)
250-
if $current_hardfork == $fork {
251-
print $"Skipping tempo regenesis for ($datadir); marker state_hardfork already matches ($fork)"
321+
let current_gas_limit = (e2e-snapshot-state-gas-limit $datadir)
322+
let hardfork_matches = $target_hardfork == "" or $current_hardfork == $target_hardfork
323+
let gas_limit_matches = $target_gas_limit == "" or $current_gas_limit == $target_gas_limit
324+
if $hardfork_matches and $gas_limit_matches {
325+
mut matches = []
326+
if $target_hardfork != "" {
327+
$matches = ($matches | append $"state_hardfork=($target_hardfork)")
328+
}
329+
if $target_gas_limit != "" {
330+
$matches = ($matches | append $"gas_limit=($target_gas_limit)")
331+
}
332+
print $"Skipping tempo regenesis for ($datadir); marker already matches (($matches | str join ', '))"
252333
return
253334
}
254335

255-
print $"Running tempo regenesis for ($datadir): state_hardfork=($current_hardfork) -> ($fork) with ($genesis)..."
256-
let result = (run-external $tempo_bin "regenesis" "--chain" $genesis "--datadir" $datadir | complete)
336+
let target_genesis = $"($datadir)/($BENCH_META_SUBDIR)/regenesis-target.json"
337+
e2e-synthesize-genesis $genesis $target_genesis $target_hardfork $target_gas_limit
338+
339+
mut changes = []
340+
if not $hardfork_matches {
341+
$changes = ($changes | append $"state_hardfork=($current_hardfork) -> ($target_hardfork)")
342+
}
343+
if not $gas_limit_matches {
344+
$changes = ($changes | append $"gas_limit=($current_gas_limit) -> ($target_gas_limit)")
345+
}
346+
print $"Running tempo regenesis for ($datadir): ($changes | str join ', ') with ($target_genesis)..."
347+
let result = (run-external $tempo_bin "regenesis" "--chain" $target_genesis "--datadir" $datadir | complete)
257348
if $result.stdout != "" { print $result.stdout }
258349
if $result.stderr != "" { print $result.stderr }
259350
if $result.exit_code != 0 {
260351
print $"Error: tempo regenesis failed for ($datadir) with exit code ($result.exit_code)"
261352
exit $result.exit_code
262353
}
263-
e2e-synthesize-hardfork-genesis $"($datadir)/($BENCH_META_SUBDIR)/genesis.json" $"($datadir)/($BENCH_META_SUBDIR)/genesis.json" $fork
264-
e2e-update-snapshot-hardfork-marker $datadir $fork
354+
e2e-synthesize-genesis $"($datadir)/($BENCH_META_SUBDIR)/genesis.json" $"($datadir)/($BENCH_META_SUBDIR)/genesis.json" $target_hardfork $target_gas_limit
355+
e2e-update-snapshot-genesis-marker $datadir $target_hardfork $target_gas_limit
356+
rm $target_genesis
265357
}
266358

267359
def derive-tracing-otlp [tracing_otlp: string] {
@@ -643,9 +735,9 @@ def run-local-e2e-phase [run: record, ctx: record] {
643735
exit 1
644736
}
645737
}
646-
if $hardfork != "" {
647-
e2e-regenesis $run.tempo $genesis $ctx.a.datadir $hardfork
648-
e2e-regenesis $run.tempo $genesis $ctx.b.datadir $hardfork
738+
if $hardfork != "" or $ctx.gas_limit != "" {
739+
e2e-regenesis $run.tempo $genesis $ctx.a.datadir $hardfork $ctx.gas_limit
740+
e2e-regenesis $run.tempo $genesis $ctx.b.datadir $hardfork $ctx.gas_limit
649741
}
650742
for role_info in [
651743
{ role: "a", node_dir: $ctx.a.node_dir }
@@ -997,8 +1089,8 @@ def "main e2e" [
9971089
if $hardfork_mode {
9981090
if ($hardfork_genesis_dir | path exists) { rm -rf $hardfork_genesis_dir }
9991091
mkdir $hardfork_genesis_dir
1000-
e2e-synthesize-hardfork-genesis $genesis_path $baseline_genesis_path $baseline_hardfork_name
1001-
e2e-synthesize-hardfork-genesis $genesis_path $feature_genesis_path $feature_hardfork_name
1092+
e2e-synthesize-genesis $genesis_path $baseline_genesis_path $baseline_hardfork_name $gas_limit
1093+
e2e-synthesize-genesis $genesis_path $feature_genesis_path $feature_hardfork_name $gas_limit
10021094
}
10031095
let trusted_peers = if ($a_trusted_peers_path | path exists) {
10041096
open $a_trusted_peers_path | str trim

bin/tempo/src/regenesis.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ where
113113

114114
let static_file_provider = provider_rw.static_file_provider();
115115
static_file_provider.delete_segment(StaticFileSegment::Headers)?;
116-
let mut writer =
117-
static_file_provider.get_writer(genesis_block_number, StaticFileSegment::Headers)?;
118-
writer.append_header(genesis_header, &new_genesis_hash)?;
116+
{
117+
let mut writer = static_file_provider
118+
.get_writer(genesis_block_number, StaticFileSegment::Headers)?;
119+
writer.append_header(genesis_header, &new_genesis_hash)?;
120+
}
119121

120122
tx.delete::<tables::HeaderNumbers>(stored_genesis_hash, None)?;
121123
tx.put::<tables::HeaderNumbers>(new_genesis_hash, 0)?;

0 commit comments

Comments
 (0)