mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Move Benchutil to Testing/ Folder (#9583)
* benchutil to testing * gaz Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -9,7 +9,6 @@ go_library(
|
||||
"//endtoend/evaluators:__pkg__",
|
||||
"//fuzz:__pkg__",
|
||||
"//shared/attestationutil:__pkg__",
|
||||
"//shared/benchutil/benchmark_files:__subpackages__",
|
||||
"//shared/depositutil:__pkg__",
|
||||
"//shared/interop:__pkg__",
|
||||
"//shared/keystore:__pkg__",
|
||||
@@ -17,6 +16,7 @@ go_library(
|
||||
"//shared/testutil:__pkg__",
|
||||
"//shared/testutil/altair:__pkg__",
|
||||
"//slasher:__subpackages__",
|
||||
"//testing/benchmark/benchmark_files:__subpackages__",
|
||||
"//testing/spectest:__subpackages__",
|
||||
"//tools:__subpackages__",
|
||||
"//validator:__subpackages__",
|
||||
|
||||
@@ -21,7 +21,6 @@ go_library(
|
||||
"//endtoend/evaluators:__pkg__",
|
||||
"//fuzz:__pkg__",
|
||||
"//shared/attestationutil:__pkg__",
|
||||
"//shared/benchutil/benchmark_files:__subpackages__",
|
||||
"//shared/depositutil:__pkg__",
|
||||
"//shared/interop:__pkg__",
|
||||
"//shared/keystore:__pkg__",
|
||||
@@ -29,6 +28,7 @@ go_library(
|
||||
"//shared/testutil:__pkg__",
|
||||
"//shared/testutil/altair:__pkg__",
|
||||
"//slasher:__subpackages__",
|
||||
"//testing/benchmark/benchmark_files:__subpackages__",
|
||||
"//testing/spectest:__subpackages__",
|
||||
"//tools:__subpackages__",
|
||||
"//validator:__subpackages__",
|
||||
|
||||
@@ -70,7 +70,7 @@ go_test(
|
||||
"transition_test.go",
|
||||
],
|
||||
data = [
|
||||
"//shared/benchutil/benchmark_files:benchmark_data",
|
||||
"//testing/benchmark/benchmark_files:benchmark_data",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
shard_count = 3,
|
||||
@@ -85,7 +85,6 @@ go_test(
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v1alpha1/wrapper:go_default_library",
|
||||
"//shared/attestationutil:go_default_library",
|
||||
"//shared/benchutil:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
@@ -94,6 +93,7 @@ go_test(
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"//testing/benchmark:go_default_library",
|
||||
"@com_github_google_gofuzz//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
@@ -122,9 +122,9 @@ go_test(
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/state/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//shared/benchutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//testing/benchmark:go_default_library",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -11,20 +11,20 @@ import (
|
||||
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/shared/benchutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/testing/benchmark"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var runAmount = 25
|
||||
|
||||
func BenchmarkExecuteStateTransition_FullBlock(b *testing.B) {
|
||||
benchutil.SetBenchmarkConfig()
|
||||
beaconState, err := benchutil.PreGenState1Epoch()
|
||||
benchmark.SetBenchmarkConfig()
|
||||
beaconState, err := benchmark.PreGenState1Epoch()
|
||||
require.NoError(b, err)
|
||||
cleanStates := clonedStates(beaconState)
|
||||
block, err := benchutil.PreGenFullBlock()
|
||||
block, err := benchmark.PreGenFullBlock()
|
||||
require.NoError(b, err)
|
||||
|
||||
b.ResetTimer()
|
||||
@@ -35,12 +35,12 @@ func BenchmarkExecuteStateTransition_FullBlock(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkExecuteStateTransition_WithCache(b *testing.B) {
|
||||
benchutil.SetBenchmarkConfig()
|
||||
benchmark.SetBenchmarkConfig()
|
||||
|
||||
beaconState, err := benchutil.PreGenState1Epoch()
|
||||
beaconState, err := benchmark.PreGenState1Epoch()
|
||||
require.NoError(b, err)
|
||||
cleanStates := clonedStates(beaconState)
|
||||
block, err := benchutil.PreGenFullBlock()
|
||||
block, err := benchmark.PreGenFullBlock()
|
||||
require.NoError(b, err)
|
||||
|
||||
// We have to reset slot back to last epoch to hydrate cache. Since
|
||||
@@ -61,8 +61,8 @@ func BenchmarkExecuteStateTransition_WithCache(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkProcessEpoch_2FullEpochs(b *testing.B) {
|
||||
benchutil.SetBenchmarkConfig()
|
||||
beaconState, err := benchutil.PreGenstateFullEpochs()
|
||||
benchmark.SetBenchmarkConfig()
|
||||
beaconState, err := benchmark.PreGenstateFullEpochs()
|
||||
require.NoError(b, err)
|
||||
|
||||
// We have to reset slot back to last epoch to hydrate cache. Since
|
||||
@@ -82,7 +82,7 @@ func BenchmarkProcessEpoch_2FullEpochs(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkHashTreeRoot_FullState(b *testing.B) {
|
||||
beaconState, err := benchutil.PreGenstateFullEpochs()
|
||||
beaconState, err := benchmark.PreGenstateFullEpochs()
|
||||
require.NoError(b, err)
|
||||
|
||||
b.ResetTimer()
|
||||
@@ -93,7 +93,7 @@ func BenchmarkHashTreeRoot_FullState(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkHashTreeRootState_FullState(b *testing.B) {
|
||||
beaconState, err := benchutil.PreGenstateFullEpochs()
|
||||
beaconState, err := benchmark.PreGenstateFullEpochs()
|
||||
require.NoError(b, err)
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -110,7 +110,7 @@ func BenchmarkHashTreeRootState_FullState(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkMarshalState_FullState(b *testing.B) {
|
||||
beaconState, err := benchutil.PreGenstateFullEpochs()
|
||||
beaconState, err := benchmark.PreGenstateFullEpochs()
|
||||
require.NoError(b, err)
|
||||
natState, err := v1.ProtobufBeaconState(beaconState.InnerStateUnsafe())
|
||||
require.NoError(b, err)
|
||||
@@ -134,7 +134,7 @@ func BenchmarkMarshalState_FullState(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkUnmarshalState_FullState(b *testing.B) {
|
||||
beaconState, err := benchutil.PreGenstateFullEpochs()
|
||||
beaconState, err := benchmark.PreGenstateFullEpochs()
|
||||
require.NoError(b, err)
|
||||
natState, err := v1.ProtobufBeaconState(beaconState.InnerStateUnsafe())
|
||||
require.NoError(b, err)
|
||||
|
||||
@@ -12,10 +12,10 @@ go_library(
|
||||
"//fuzz:__pkg__",
|
||||
"//proto/testing:__subpackages__",
|
||||
"//shared/aggregation:__subpackages__",
|
||||
"//shared/benchutil:__pkg__",
|
||||
"//shared/depositutil:__subpackages__",
|
||||
"//shared/testutil:__pkg__",
|
||||
"//slasher/rpc:__subpackages__",
|
||||
"//testing/benchmark:__pkg__",
|
||||
"//testing/spectest:__subpackages__",
|
||||
"//tools/benchmark-files-gen:__pkg__",
|
||||
"//tools/exploredb:__pkg__",
|
||||
|
||||
@@ -33,11 +33,11 @@ go_library(
|
||||
"//fuzz:__pkg__",
|
||||
"//proto/testing:__subpackages__",
|
||||
"//shared/aggregation:__subpackages__",
|
||||
"//shared/benchutil:__pkg__",
|
||||
"//shared/depositutil:__subpackages__",
|
||||
"//shared/interop:__subpackages__",
|
||||
"//shared/testutil:__pkg__",
|
||||
"//slasher/rpc:__subpackages__",
|
||||
"//testing/benchmark:__pkg__",
|
||||
"//testing/spectest:__subpackages__",
|
||||
"//tools/benchmark-files-gen:__pkg__",
|
||||
"//tools/pcli:__pkg__",
|
||||
|
||||
@@ -3,8 +3,8 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["pregen.go"],
|
||||
data = ["//shared/benchutil/benchmark_files:benchmark_data"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/benchutil",
|
||||
data = ["//testing/benchmark/benchmark_files:benchmark_data"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/testing/benchmark",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//beacon-chain/state:go_default_library",
|
||||
@@ -1,5 +1,5 @@
|
||||
# Benchmarks for Prysm State Transition
|
||||
This package contains the functionality needed for benchmarking Prysms state transitions, this includes its block processing (with and without caching) and epoch processing functions. There is also a benchmark for HashTreeRoot on a large beacon state.
|
||||
This package contains the functionality needed for benchmarking Prysm state transitions, this includes its block processing (with and without caching) and epoch processing functions. There is also a benchmark for HashTreeRoot on a large beacon state.
|
||||
|
||||
## Benchmark Configuration
|
||||
The following configs are in `config.go`:
|
||||
@@ -11,7 +11,7 @@ Due to the sheer size of the benchmarking configurations (16384 validators), the
|
||||
|
||||
To generate new files to use for benchmarking, run the below command in the root of Prysm.
|
||||
```
|
||||
bazel run //tools/benchmark-files-gen -- --output-dir $PRYSMPATH/shared/benchutil/benchmark_files/ --overwrite
|
||||
bazel run //tools/benchmark-files-gen -- --output-dir $PRYSMPATH/testing/benchmark/benchmark_files/ --overwrite
|
||||
```
|
||||
|
||||
## Running the benchmarks
|
||||
@@ -5,6 +5,6 @@ filegroup(
|
||||
]),
|
||||
visibility = [
|
||||
"//beacon-chain/core/transition:__pkg__",
|
||||
"//shared/benchutil:__subpackages__",
|
||||
"//testing/benchmark:__subpackages__",
|
||||
],
|
||||
)
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package benchutil contains useful helpers
|
||||
// Package benchmark contains useful helpers
|
||||
// for pregenerating filled data structures such as blocks/states for benchmarks.
|
||||
package benchutil
|
||||
package benchmark
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -36,7 +36,7 @@ var BstateEpochFileName = fmt.Sprintf("bstateEpochs-%dAtts-%dVals.ssz", Attestat
|
||||
var FullBlockFileName = fmt.Sprintf("fullBlock-%dAtts-%dVals.ssz", AttestationsPerEpoch, ValidatorCount)
|
||||
|
||||
func filePath(path string) string {
|
||||
return fmt.Sprintf("shared/benchutil/benchmark_files/%s", path)
|
||||
return fmt.Sprintf("testing/benchmark/benchmark_files/%s", path)
|
||||
}
|
||||
|
||||
// PreGenState1Epoch unmarshals the pre-generated beacon state after 1 epoch of block processing and returns it.
|
||||
@@ -1,4 +1,4 @@
|
||||
package benchutil
|
||||
package benchmark
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -15,11 +15,11 @@ go_library(
|
||||
"//beacon-chain/state/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v1alpha1/wrapper:go_default_library",
|
||||
"//shared/benchutil:go_default_library",
|
||||
"//shared/fileutil:go_default_library",
|
||||
"//shared/interop:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//testing/benchmark:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
],
|
||||
|
||||
@@ -17,11 +17,11 @@ import (
|
||||
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
||||
"github.com/prysmaticlabs/prysm/shared/benchutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/interop"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/testing/benchmark"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -36,13 +36,13 @@ func main() {
|
||||
}
|
||||
|
||||
if !*overwrite {
|
||||
if _, err := os.Stat(path.Join(*outputDir, benchutil.BState1EpochFileName)); err == nil {
|
||||
if _, err := os.Stat(path.Join(*outputDir, benchmark.BState1EpochFileName)); err == nil {
|
||||
log.Fatal("The file exists. Use a different file name or the --overwrite flag")
|
||||
}
|
||||
if _, err := os.Stat(path.Join(*outputDir, benchutil.BstateEpochFileName)); err == nil {
|
||||
if _, err := os.Stat(path.Join(*outputDir, benchmark.BstateEpochFileName)); err == nil {
|
||||
log.Fatal("The file exists. Use a different file name or the --overwrite flag")
|
||||
}
|
||||
if _, err := os.Stat(path.Join(*outputDir, benchutil.FullBlockFileName)); err == nil {
|
||||
if _, err := os.Stat(path.Join(*outputDir, benchmark.FullBlockFileName)); err == nil {
|
||||
log.Fatal("The file exists. Use a different file name or the --overwrite flag")
|
||||
}
|
||||
}
|
||||
@@ -66,13 +66,13 @@ func main() {
|
||||
log.Fatalf("Could not generate 2 full epoch state: %v", err)
|
||||
}
|
||||
// Removing the genesis state SSZ since its 10MB large and no longer needed.
|
||||
if err := os.Remove(path.Join(*outputDir, benchutil.GenesisFileName)); err != nil {
|
||||
if err := os.Remove(path.Join(*outputDir, benchmark.GenesisFileName)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func generateGenesisBeaconState() error {
|
||||
genesisState, _, err := interop.GenerateGenesisState(context.Background(), 0, benchutil.ValidatorCount)
|
||||
genesisState, _, err := interop.GenerateGenesisState(context.Background(), 0, benchmark.ValidatorCount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -80,17 +80,17 @@ func generateGenesisBeaconState() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fileutil.WriteFile(path.Join(*outputDir, benchutil.GenesisFileName), beaconBytes)
|
||||
return fileutil.WriteFile(path.Join(*outputDir, benchmark.GenesisFileName), beaconBytes)
|
||||
}
|
||||
|
||||
func generateMarshalledFullStateAndBlock() error {
|
||||
benchutil.SetBenchmarkConfig()
|
||||
benchmark.SetBenchmarkConfig()
|
||||
beaconState, err := genesisBeaconState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
privs, _, err := interop.DeterministicallyGenerateKeys(0, benchutil.ValidatorCount)
|
||||
privs, _, err := interop.DeterministicallyGenerateKeys(0, benchmark.ValidatorCount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func generateMarshalledFullStateAndBlock() error {
|
||||
}
|
||||
|
||||
attConfig := &testutil.BlockGenConfig{
|
||||
NumAttestations: benchutil.AttestationsPerEpoch / uint64(slotsPerEpoch),
|
||||
NumAttestations: benchmark.AttestationsPerEpoch / uint64(slotsPerEpoch),
|
||||
}
|
||||
|
||||
var atts []*ethpb.Attestation
|
||||
@@ -153,7 +153,7 @@ func generateMarshalledFullStateAndBlock() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := fileutil.WriteFile(path.Join(*outputDir, benchutil.BState1EpochFileName), beaconBytes); err != nil {
|
||||
if err := fileutil.WriteFile(path.Join(*outputDir, benchmark.BState1EpochFileName), beaconBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -168,23 +168,23 @@ func generateMarshalledFullStateAndBlock() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return fileutil.WriteFile(path.Join(*outputDir, benchutil.FullBlockFileName), blockBytes)
|
||||
return fileutil.WriteFile(path.Join(*outputDir, benchmark.FullBlockFileName), blockBytes)
|
||||
}
|
||||
|
||||
func generate2FullEpochState() error {
|
||||
benchutil.SetBenchmarkConfig()
|
||||
benchmark.SetBenchmarkConfig()
|
||||
beaconState, err := genesisBeaconState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
privs, _, err := interop.DeterministicallyGenerateKeys(0, benchutil.ValidatorCount)
|
||||
privs, _, err := interop.DeterministicallyGenerateKeys(0, benchmark.ValidatorCount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
attConfig := &testutil.BlockGenConfig{
|
||||
NumAttestations: benchutil.AttestationsPerEpoch / uint64(params.BeaconConfig().SlotsPerEpoch),
|
||||
NumAttestations: benchmark.AttestationsPerEpoch / uint64(params.BeaconConfig().SlotsPerEpoch),
|
||||
}
|
||||
|
||||
for i := types.Slot(0); i < params.BeaconConfig().SlotsPerEpoch*2-1; i++ {
|
||||
@@ -203,11 +203,11 @@ func generate2FullEpochState() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return fileutil.WriteFile(path.Join(*outputDir, benchutil.BstateEpochFileName), beaconBytes)
|
||||
return fileutil.WriteFile(path.Join(*outputDir, benchmark.BstateEpochFileName), beaconBytes)
|
||||
}
|
||||
|
||||
func genesisBeaconState() (state.BeaconState, error) {
|
||||
beaconBytes, err := ioutil.ReadFile(path.Join(*outputDir, benchutil.GenesisFileName))
|
||||
beaconBytes, err := ioutil.ReadFile(path.Join(*outputDir, benchmark.GenesisFileName))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cannot read genesis state file")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user