Skip to content

Commit 819a497

Browse files
author
Darioush Jalali
authored
core: fix genesis setup in benchReadChain (#28856)
1 parent 19d9977 commit 819a497

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

core/bench_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func BenchmarkChainWrite_full_500k(b *testing.B) {
243243

244244
// makeChainForBench writes a given number of headers or empty blocks/receipts
245245
// into a database.
246-
func makeChainForBench(db ethdb.Database, full bool, count uint64) {
246+
func makeChainForBench(db ethdb.Database, genesis *Genesis, full bool, count uint64) {
247247
var hash common.Hash
248248
for n := uint64(0); n < count; n++ {
249249
header := &types.Header{
@@ -255,14 +255,17 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
255255
TxHash: types.EmptyTxsHash,
256256
ReceiptHash: types.EmptyReceiptsHash,
257257
}
258+
if n == 0 {
259+
header = genesis.ToBlock().Header()
260+
}
258261
hash = header.Hash()
259262

260263
rawdb.WriteHeader(db, header)
261264
rawdb.WriteCanonicalHash(db, hash, n)
262265
rawdb.WriteTd(db, hash, n, big.NewInt(int64(n+1)))
263266

264267
if n == 0 {
265-
rawdb.WriteChainConfig(db, hash, params.AllEthashProtocolChanges)
268+
rawdb.WriteChainConfig(db, hash, genesis.Config)
266269
}
267270
rawdb.WriteHeadHeaderHash(db, hash)
268271

@@ -276,13 +279,14 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
276279
}
277280

278281
func benchWriteChain(b *testing.B, full bool, count uint64) {
282+
genesis := &Genesis{Config: params.AllEthashProtocolChanges}
279283
for i := 0; i < b.N; i++ {
280284
dir := b.TempDir()
281285
db, err := rawdb.NewLevelDBDatabase(dir, 128, 1024, "", false)
282286
if err != nil {
283287
b.Fatalf("error opening database at %v: %v", dir, err)
284288
}
285-
makeChainForBench(db, full, count)
289+
makeChainForBench(db, genesis, full, count)
286290
db.Close()
287291
}
288292
}
@@ -294,7 +298,8 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
294298
if err != nil {
295299
b.Fatalf("error opening database at %v: %v", dir, err)
296300
}
297-
makeChainForBench(db, full, count)
301+
genesis := &Genesis{Config: params.AllEthashProtocolChanges}
302+
makeChainForBench(db, genesis, full, count)
298303
db.Close()
299304
cacheConfig := *defaultCacheConfig
300305
cacheConfig.TrieDirtyDisabled = true
@@ -307,7 +312,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
307312
if err != nil {
308313
b.Fatalf("error opening database at %v: %v", dir, err)
309314
}
310-
chain, err := NewBlockChain(db, &cacheConfig, nil, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
315+
chain, err := NewBlockChain(db, &cacheConfig, genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
311316
if err != nil {
312317
b.Fatalf("error creating chain: %v", err)
313318
}

0 commit comments

Comments
 (0)