mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 11:11:20 +00:00
73443208a1
* Remove native state flag and use native state in spectests * remove feature from tests * use e2e config in slasher simulator * use params.BeaconConfig in testutil * use correct function * use minimal config in go_test * fix TestListValidators * parameterize sync committee bits and aggregation bits * Fix TestServer_ListIndexedAttestations_GenesisEpoch (cherry picked from commit 254ab623dde08ae8886b152facdbbd8889ed79db) * fix more tests * fix even more * moreeee * aaaand more * one more fix * one more * simplify TestGetAltairDuties_UnknownPubkey * comment out problematic test * one more fix * one more * aaaand one more * another * use fieldparams in HydrateBlindedBeaconBlockBodyBellatrix * create new package for mainnet tests * TestServer_GetBellatrixBeaconBlock * change slashed validator index * clear cache in reward_test.go * deprecate flag * create bazel mainnet target * move attester mainnet test to mainnet target * "fix" proposer tests * use minimal config in TestServer_circuitBreakBuilder * fix TestProposer_ProposeBlock_OK * more fixes in validator package * more fixes * more fixes * test code * move TestProposer_GetBeaconBlock_BellatrixEpoch to minimal * finally * remove proposer_bellatrix_mainnet_test.go * fix TestServer_GetBellatrixBeaconBlock_HappyCase * fix TestServer_GetBellatrixBeaconBlock_BuilderCase * Preston needs to fix this! * Revert "Preston needs to fix this!" This reverts commit b03d97a16e3080e254c7b19d7f193d3c600ca869. * remove proto state tests * fix migration tests * static analysis fix * review * remove proto state * swap state in tests * fix BUILD file in /proto/testing * remove metrics test with nil state
183 lines
5.7 KiB
Go
183 lines
5.7 KiB
Go
package transition_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time"
|
|
coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
|
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/benchmark"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
var runAmount = 25
|
|
|
|
func BenchmarkExecuteStateTransition_FullBlock(b *testing.B) {
|
|
undo, err := benchmark.SetBenchmarkConfig()
|
|
require.NoError(b, err)
|
|
defer undo()
|
|
beaconState, err := benchmark.PreGenState1Epoch()
|
|
require.NoError(b, err)
|
|
cleanStates := clonedStates(beaconState)
|
|
block, err := benchmark.PreGenFullBlock()
|
|
require.NoError(b, err)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
wsb, err := blocks.NewSignedBeaconBlock(block)
|
|
require.NoError(b, err)
|
|
_, err = coreState.ExecuteStateTransition(context.Background(), cleanStates[i], wsb)
|
|
require.NoError(b, err)
|
|
}
|
|
}
|
|
|
|
func BenchmarkExecuteStateTransition_WithCache(b *testing.B) {
|
|
undo, err := benchmark.SetBenchmarkConfig()
|
|
require.NoError(b, err)
|
|
defer undo()
|
|
|
|
beaconState, err := benchmark.PreGenState1Epoch()
|
|
require.NoError(b, err)
|
|
cleanStates := clonedStates(beaconState)
|
|
block, err := benchmark.PreGenFullBlock()
|
|
require.NoError(b, err)
|
|
|
|
// We have to reset slot back to last epoch to hydrate cache. Since
|
|
// some attestations in block are from previous epoch
|
|
currentSlot := beaconState.Slot()
|
|
require.NoError(b, beaconState.SetSlot(beaconState.Slot()-params.BeaconConfig().SlotsPerEpoch))
|
|
require.NoError(b, helpers.UpdateCommitteeCache(context.Background(), beaconState, time.CurrentEpoch(beaconState)))
|
|
require.NoError(b, beaconState.SetSlot(currentSlot))
|
|
// Run the state transition once to populate the cache.
|
|
wsb, err := blocks.NewSignedBeaconBlock(block)
|
|
require.NoError(b, err)
|
|
_, err = coreState.ExecuteStateTransition(context.Background(), beaconState, wsb)
|
|
require.NoError(b, err, "Failed to process block, benchmarks will fail")
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
wsb, err := blocks.NewSignedBeaconBlock(block)
|
|
require.NoError(b, err)
|
|
_, err = coreState.ExecuteStateTransition(context.Background(), cleanStates[i], wsb)
|
|
require.NoError(b, err, "Failed to process block, benchmarks will fail")
|
|
}
|
|
}
|
|
|
|
func BenchmarkProcessEpoch_2FullEpochs(b *testing.B) {
|
|
undo, err := benchmark.SetBenchmarkConfig()
|
|
require.NoError(b, err)
|
|
defer undo()
|
|
beaconState, err := benchmark.PreGenstateFullEpochs()
|
|
require.NoError(b, err)
|
|
|
|
// We have to reset slot back to last epoch to hydrate cache. Since
|
|
// some attestations in block are from previous epoch
|
|
currentSlot := beaconState.Slot()
|
|
require.NoError(b, beaconState.SetSlot(beaconState.Slot()-params.BeaconConfig().SlotsPerEpoch))
|
|
require.NoError(b, helpers.UpdateCommitteeCache(context.Background(), beaconState, time.CurrentEpoch(beaconState)))
|
|
require.NoError(b, beaconState.SetSlot(currentSlot))
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
// ProcessEpochPrecompute is the optimized version of process epoch. It's enabled by default
|
|
// at run time.
|
|
_, err := coreState.ProcessEpochPrecompute(context.Background(), beaconState.Copy())
|
|
require.NoError(b, err)
|
|
}
|
|
}
|
|
|
|
func BenchmarkHashTreeRoot_FullState(b *testing.B) {
|
|
beaconState, err := benchmark.PreGenstateFullEpochs()
|
|
require.NoError(b, err)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := beaconState.HashTreeRoot(context.Background())
|
|
require.NoError(b, err)
|
|
}
|
|
}
|
|
|
|
func BenchmarkHashTreeRootState_FullState(b *testing.B) {
|
|
beaconState, err := benchmark.PreGenstateFullEpochs()
|
|
require.NoError(b, err)
|
|
|
|
ctx := context.Background()
|
|
|
|
// Hydrate the HashTreeRootState cache.
|
|
_, err = beaconState.HashTreeRoot(ctx)
|
|
require.NoError(b, err)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := beaconState.HashTreeRoot(ctx)
|
|
require.NoError(b, err)
|
|
}
|
|
}
|
|
|
|
func BenchmarkMarshalState_FullState(b *testing.B) {
|
|
beaconState, err := benchmark.PreGenstateFullEpochs()
|
|
require.NoError(b, err)
|
|
natState, err := state_native.ProtobufBeaconStatePhase0(beaconState.InnerStateUnsafe())
|
|
require.NoError(b, err)
|
|
b.Run("Proto_Marshal", func(b *testing.B) {
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := proto.Marshal(natState)
|
|
require.NoError(b, err)
|
|
}
|
|
})
|
|
|
|
b.Run("Fast_SSZ_Marshal", func(b *testing.B) {
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := natState.MarshalSSZ()
|
|
require.NoError(b, err)
|
|
}
|
|
})
|
|
}
|
|
|
|
func BenchmarkUnmarshalState_FullState(b *testing.B) {
|
|
beaconState, err := benchmark.PreGenstateFullEpochs()
|
|
require.NoError(b, err)
|
|
natState, err := state_native.ProtobufBeaconStatePhase0(beaconState.InnerStateUnsafe())
|
|
require.NoError(b, err)
|
|
protoObject, err := proto.Marshal(natState)
|
|
require.NoError(b, err)
|
|
sszObject, err := natState.MarshalSSZ()
|
|
require.NoError(b, err)
|
|
|
|
b.Run("Proto_Unmarshal", func(b *testing.B) {
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
require.NoError(b, proto.Unmarshal(protoObject, ðpb.BeaconState{}))
|
|
}
|
|
})
|
|
|
|
b.Run("Fast_SSZ_Unmarshal", func(b *testing.B) {
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
sszState := ðpb.BeaconState{}
|
|
require.NoError(b, sszState.UnmarshalSSZ(sszObject))
|
|
}
|
|
})
|
|
}
|
|
|
|
func clonedStates(beaconState state.BeaconState) []state.BeaconState {
|
|
clonedStates := make([]state.BeaconState, runAmount)
|
|
for i := 0; i < runAmount; i++ {
|
|
clonedStates[i] = beaconState.Copy()
|
|
}
|
|
return clonedStates
|
|
}
|