mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-21 19:20:37 +00:00
core: fix genesis setup in benchReadChain (#28856)
This commit is contained in:
parent
19d9977641
commit
819a4977e8
@ -243,7 +243,7 @@ func BenchmarkChainWrite_full_500k(b *testing.B) {
|
||||
|
||||
// makeChainForBench writes a given number of headers or empty blocks/receipts
|
||||
// into a database.
|
||||
func makeChainForBench(db ethdb.Database, full bool, count uint64) {
|
||||
func makeChainForBench(db ethdb.Database, genesis *Genesis, full bool, count uint64) {
|
||||
var hash common.Hash
|
||||
for n := uint64(0); n < count; n++ {
|
||||
header := &types.Header{
|
||||
@ -255,6 +255,9 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
|
||||
TxHash: types.EmptyTxsHash,
|
||||
ReceiptHash: types.EmptyReceiptsHash,
|
||||
}
|
||||
if n == 0 {
|
||||
header = genesis.ToBlock().Header()
|
||||
}
|
||||
hash = header.Hash()
|
||||
|
||||
rawdb.WriteHeader(db, header)
|
||||
@ -262,7 +265,7 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
|
||||
rawdb.WriteTd(db, hash, n, big.NewInt(int64(n+1)))
|
||||
|
||||
if n == 0 {
|
||||
rawdb.WriteChainConfig(db, hash, params.AllEthashProtocolChanges)
|
||||
rawdb.WriteChainConfig(db, hash, genesis.Config)
|
||||
}
|
||||
rawdb.WriteHeadHeaderHash(db, hash)
|
||||
|
||||
@ -276,13 +279,14 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
|
||||
}
|
||||
|
||||
func benchWriteChain(b *testing.B, full bool, count uint64) {
|
||||
genesis := &Genesis{Config: params.AllEthashProtocolChanges}
|
||||
for i := 0; i < b.N; i++ {
|
||||
dir := b.TempDir()
|
||||
db, err := rawdb.NewLevelDBDatabase(dir, 128, 1024, "", false)
|
||||
if err != nil {
|
||||
b.Fatalf("error opening database at %v: %v", dir, err)
|
||||
}
|
||||
makeChainForBench(db, full, count)
|
||||
makeChainForBench(db, genesis, full, count)
|
||||
db.Close()
|
||||
}
|
||||
}
|
||||
@ -294,7 +298,8 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
|
||||
if err != nil {
|
||||
b.Fatalf("error opening database at %v: %v", dir, err)
|
||||
}
|
||||
makeChainForBench(db, full, count)
|
||||
genesis := &Genesis{Config: params.AllEthashProtocolChanges}
|
||||
makeChainForBench(db, genesis, full, count)
|
||||
db.Close()
|
||||
cacheConfig := *defaultCacheConfig
|
||||
cacheConfig.TrieDirtyDisabled = true
|
||||
@ -307,7 +312,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
|
||||
if err != nil {
|
||||
b.Fatalf("error opening database at %v: %v", dir, err)
|
||||
}
|
||||
chain, err := NewBlockChain(db, &cacheConfig, nil, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
|
||||
chain, err := NewBlockChain(db, &cacheConfig, genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
|
||||
if err != nil {
|
||||
b.Fatalf("error creating chain: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user