mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 20:20:05 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package stateutil_test
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"strconv"
|
|
"testing"
|
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/runtime/interop"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func TestState_FieldCount(t *testing.T) {
|
|
count := params.BeaconConfig().BeaconStateFieldCount
|
|
typ := reflect.TypeOf(ethpb.BeaconState{})
|
|
numFields := 0
|
|
for i := 0; i < typ.NumField(); i++ {
|
|
if typ.Field(i).Name == "state" ||
|
|
typ.Field(i).Name == "sizeCache" ||
|
|
typ.Field(i).Name == "unknownFields" {
|
|
continue
|
|
}
|
|
numFields++
|
|
}
|
|
assert.Equal(t, count, numFields)
|
|
}
|
|
|
|
func BenchmarkHashTreeRoot_Generic_512(b *testing.B) {
|
|
b.StopTimer()
|
|
genesisState := setupGenesisState(b, 512)
|
|
b.StartTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := genesisState.HashTreeRoot()
|
|
require.NoError(b, err)
|
|
}
|
|
}
|
|
|
|
func BenchmarkHashTreeRoot_Generic_16384(b *testing.B) {
|
|
b.StopTimer()
|
|
genesisState := setupGenesisState(b, 16384)
|
|
b.StartTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := genesisState.HashTreeRoot()
|
|
require.NoError(b, err)
|
|
}
|
|
}
|
|
|
|
func BenchmarkHashTreeRoot_Generic_300000(b *testing.B) {
|
|
b.StopTimer()
|
|
genesisState := setupGenesisState(b, 300000)
|
|
b.StartTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := genesisState.HashTreeRoot()
|
|
require.NoError(b, err)
|
|
}
|
|
}
|
|
|
|
func setupGenesisState(tb testing.TB, count uint64) *ethpb.BeaconState {
|
|
genesisState, _, err := interop.GenerateGenesisState(context.Background(), 0, 1)
|
|
require.NoError(tb, err, "Could not generate genesis beacon state")
|
|
for i := uint64(1); i < count; i++ {
|
|
someRoot := [32]byte{}
|
|
someKey := [fieldparams.BLSPubkeyLength]byte{}
|
|
copy(someRoot[:], strconv.Itoa(int(i)))
|
|
copy(someKey[:], strconv.Itoa(int(i)))
|
|
genesisState.Validators = append(genesisState.Validators, ðpb.Validator{
|
|
PublicKey: someKey[:],
|
|
WithdrawalCredentials: someRoot[:],
|
|
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
|
Slashed: false,
|
|
ActivationEligibilityEpoch: 1,
|
|
ActivationEpoch: 1,
|
|
ExitEpoch: 1,
|
|
WithdrawableEpoch: 1,
|
|
})
|
|
genesisState.Balances = append(genesisState.Balances, params.BeaconConfig().MaxEffectiveBalance)
|
|
}
|
|
return genesisState
|
|
}
|