mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
RPC: GetValidatorPerformance for Bellatrix (#10482)
This commit is contained in:
parent
defa602e50
commit
9b64c33bd1
@ -693,7 +693,7 @@ func (bs *Server) GetValidatorPerformance(
|
||||
return nil, err
|
||||
}
|
||||
validatorSummary = vp
|
||||
case version.Altair:
|
||||
case version.Altair, version.Bellatrix:
|
||||
vp, bp, err := altair.InitializePrecomputeValidators(ctx, headState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -871,7 +871,7 @@ func (bs *Server) GetIndividualVotes(
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not pre compute attestations: %v", err)
|
||||
}
|
||||
case version.Altair:
|
||||
case version.Altair, version.Bellatrix:
|
||||
v, bal, err = altair.InitializePrecomputeValidators(ctx, st)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not set up altair pre compute instance: %v", err)
|
||||
|
@ -2100,6 +2100,76 @@ func TestGetValidatorPerformanceAltair_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetValidatorPerformanceBellatrix_OK(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
||||
|
||||
ctx := context.Background()
|
||||
epoch := types.Epoch(1)
|
||||
headState, _ := util.DeterministicGenesisStateBellatrix(t, 32)
|
||||
require.NoError(t, headState.SetSlot(params.BeaconConfig().SlotsPerEpoch.Mul(uint64(epoch+1))))
|
||||
|
||||
defaultBal := params.BeaconConfig().MaxEffectiveBalance
|
||||
extraBal := params.BeaconConfig().MaxEffectiveBalance + params.BeaconConfig().GweiPerEth
|
||||
balances := []uint64{defaultBal, extraBal, extraBal + params.BeaconConfig().GweiPerEth}
|
||||
require.NoError(t, headState.SetBalances(balances))
|
||||
publicKey1 := bytesutil.ToBytes48([]byte{1})
|
||||
publicKey2 := bytesutil.ToBytes48([]byte{2})
|
||||
publicKey3 := bytesutil.ToBytes48([]byte{3})
|
||||
validators := []*ethpb.Validator{
|
||||
{
|
||||
PublicKey: publicKey1[:],
|
||||
ActivationEpoch: 5,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{
|
||||
PublicKey: publicKey2[:],
|
||||
EffectiveBalance: defaultBal,
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
{
|
||||
PublicKey: publicKey3[:],
|
||||
EffectiveBalance: defaultBal,
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
}
|
||||
require.NoError(t, headState.SetValidators(validators))
|
||||
require.NoError(t, headState.SetInactivityScores([]uint64{0, 0, 0}))
|
||||
require.NoError(t, headState.SetBalances([]uint64{100, 101, 102}))
|
||||
offset := int64(headState.Slot().Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
bs := &Server{
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
},
|
||||
GenesisTimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*offset) * time.Second)},
|
||||
SyncChecker: &mockSync.Sync{IsSyncing: false},
|
||||
}
|
||||
want := ðpb.ValidatorPerformanceResponse{
|
||||
PublicKeys: [][]byte{publicKey2[:], publicKey3[:]},
|
||||
CurrentEffectiveBalances: []uint64{params.BeaconConfig().MaxEffectiveBalance, params.BeaconConfig().MaxEffectiveBalance},
|
||||
InclusionSlots: nil,
|
||||
InclusionDistances: nil,
|
||||
CorrectlyVotedSource: []bool{false, false},
|
||||
CorrectlyVotedTarget: []bool{false, false},
|
||||
CorrectlyVotedHead: []bool{false, false},
|
||||
BalancesBeforeEpochTransition: []uint64{101, 102},
|
||||
BalancesAfterEpochTransition: []uint64{0, 0},
|
||||
MissingValidators: [][]byte{publicKey1[:]},
|
||||
InactivityScores: []uint64{0, 0},
|
||||
}
|
||||
|
||||
res, err := bs.GetValidatorPerformance(ctx, ðpb.ValidatorPerformanceRequest{
|
||||
PublicKeys: [][]byte{publicKey1[:], publicKey3[:], publicKey2[:]},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
if !proto.Equal(want, res) {
|
||||
t.Errorf("Wanted %v\nReceived %v", want, res)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkListValidatorBalances(b *testing.B) {
|
||||
b.StopTimer()
|
||||
beaconDB := dbTest.SetupDB(b)
|
||||
@ -2475,6 +2545,98 @@ func TestServer_GetIndividualVotes_AltairEndOfEpoch(t *testing.T) {
|
||||
assert.DeepEqual(t, wanted, res, "Unexpected response")
|
||||
}
|
||||
|
||||
func TestServer_GetIndividualVotes_BellatrixEndOfEpoch(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
beaconDB := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
validators := uint64(32)
|
||||
beaconState, _ := util.DeterministicGenesisStateBellatrix(t, validators)
|
||||
startSlot, err := slots.EpochStart(1)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, beaconState.SetSlot(startSlot))
|
||||
|
||||
b := util.NewBeaconBlock()
|
||||
b.Block.Slot = startSlot
|
||||
wsb, err := wrapper.WrappedSignedBeaconBlock(b)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, beaconDB.SaveBlock(ctx, wsb))
|
||||
gRoot, err := b.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
gen := stategen.New(beaconDB)
|
||||
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
|
||||
require.NoError(t, beaconDB.SaveState(ctx, beaconState, gRoot))
|
||||
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, gRoot))
|
||||
// Save State at the end of the epoch:
|
||||
endSlot, err := slots.EpochEnd(1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
beaconState, _ = util.DeterministicGenesisStateBellatrix(t, validators)
|
||||
require.NoError(t, beaconState.SetSlot(endSlot))
|
||||
|
||||
pb, err := beaconState.CurrentEpochParticipation()
|
||||
require.NoError(t, err)
|
||||
for i := range pb {
|
||||
pb[i] = 0xff
|
||||
}
|
||||
require.NoError(t, beaconState.SetCurrentParticipationBits(pb))
|
||||
require.NoError(t, beaconState.SetPreviousParticipationBits(pb))
|
||||
|
||||
b.Block.Slot = endSlot
|
||||
wsb, err = wrapper.WrappedSignedBeaconBlock(b)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, beaconDB.SaveBlock(ctx, wsb))
|
||||
gRoot, err = b.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
|
||||
require.NoError(t, beaconDB.SaveState(ctx, beaconState, gRoot))
|
||||
bs := &Server{
|
||||
StateGen: gen,
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
}
|
||||
addDefaultReplayerBuilder(bs, beaconDB)
|
||||
|
||||
res, err := bs.GetIndividualVotes(ctx, ðpb.IndividualVotesRequest{
|
||||
Indices: []types.ValidatorIndex{0, 1},
|
||||
Epoch: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
wanted := ðpb.IndividualVotesRespond{
|
||||
IndividualVotes: []*ethpb.IndividualVotesRespond_IndividualVote{
|
||||
{
|
||||
ValidatorIndex: 0,
|
||||
PublicKey: beaconState.Validators()[0].PublicKey,
|
||||
IsActiveInCurrentEpoch: true,
|
||||
IsActiveInPreviousEpoch: true,
|
||||
IsCurrentEpochTargetAttester: true,
|
||||
IsCurrentEpochAttester: true,
|
||||
IsPreviousEpochAttester: true,
|
||||
IsPreviousEpochHeadAttester: true,
|
||||
IsPreviousEpochTargetAttester: true,
|
||||
CurrentEpochEffectiveBalanceGwei: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Epoch: 1,
|
||||
},
|
||||
{
|
||||
ValidatorIndex: 1,
|
||||
PublicKey: beaconState.Validators()[1].PublicKey,
|
||||
IsActiveInCurrentEpoch: true,
|
||||
IsActiveInPreviousEpoch: true,
|
||||
IsCurrentEpochTargetAttester: true,
|
||||
IsCurrentEpochAttester: true,
|
||||
IsPreviousEpochAttester: true,
|
||||
IsPreviousEpochHeadAttester: true,
|
||||
IsPreviousEpochTargetAttester: true,
|
||||
CurrentEpochEffectiveBalanceGwei: params.BeaconConfig().MaxEffectiveBalance,
|
||||
Epoch: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.DeepEqual(t, wanted, res, "Unexpected response")
|
||||
}
|
||||
|
||||
func Test_validatorStatus(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
Loading…
Reference in New Issue
Block a user