From 21d68fa66545d31048b09ea7d8c6d650bbf1b66f Mon Sep 17 00:00:00 2001 From: riccardo <106812074+riccardo-gnosis@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:19:17 +0200 Subject: [PATCH] remove: ValidatorAttSlot from rewards table --- pkg/clientapi/duties.go | 68 ++++++++++----------- pkg/clientapi/state.go | 5 +- pkg/db/migrations/000001_init_schema.up.sql | 2 +- pkg/db/validator_rewards.go | 22 +++---- pkg/spec/metrics/state_altair.go | 16 ++--- pkg/spec/metrics/state_phase0.go | 16 ++--- pkg/spec/validator_rewards.go | 58 +++++++++--------- 7 files changed, 94 insertions(+), 93 deletions(-) diff --git a/pkg/clientapi/duties.go b/pkg/clientapi/duties.go index cf2b3301..5313194e 100644 --- a/pkg/clientapi/duties.go +++ b/pkg/clientapi/duties.go @@ -1,8 +1,6 @@ package clientapi import ( - "fmt" - "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/migalabs/goteth/pkg/spec" @@ -12,39 +10,39 @@ func (s *APIClient) NewEpochData(slot phase0.Slot) spec.EpochDuties { epochDuties := spec.EpochDuties{} - epochCommittees, err := s.Api.BeaconCommittees(s.ctx, &api.BeaconCommitteesOpts{ - State: fmt.Sprintf("%d", slot), - }) - - if err != nil { - log.Errorf("could not fetch epoch committees and validator at slot %d: %s", slot, err) - } else { - if epochCommittees != nil && epochCommittees.Data != nil { - epochDuties.BeaconCommittees = epochCommittees.Data - - validatorsAttSlot := make(map[phase0.ValidatorIndex]phase0.Slot) // each validator, when it had to attest - validatorsPerSlot := make(map[phase0.Slot][]phase0.ValidatorIndex) - - for _, committee := range epochCommittees.Data { - for _, valID := range committee.Validators { - validatorsAttSlot[valID] = committee.Slot - - if val, ok := validatorsPerSlot[committee.Slot]; ok { - // the slot exists in the map - validatorsPerSlot[committee.Slot] = append(val, valID) - } else { - // the slot does not exist, create - validatorsPerSlot[committee.Slot] = []phase0.ValidatorIndex{valID} - } - } - } - - epochDuties.ValidatorAttSlot = validatorsAttSlot - } else { - log.Warningf("no epoch committees and validator at slot %d: %s", slot, err) - } - - } + // epochCommittees, err := s.Api.BeaconCommittees(s.ctx, &api.BeaconCommitteesOpts{ + // State: fmt.Sprintf("%d", slot), + // }) + + // if err != nil { + // log.Errorf("could not fetch epoch committees and validator at slot %d: %s", slot, err) + // } else { + // if epochCommittees != nil && epochCommittees.Data != nil { + // epochDuties.BeaconCommittees = epochCommittees.Data + + // validatorsAttSlot := make(map[phase0.ValidatorIndex]phase0.Slot) // each validator, when it had to attest + // // validatorsPerSlot := make(map[phase0.Slot][]phase0.ValidatorIndex) + + // for _, committee := range epochCommittees.Data { + // for _, valID := range committee.Validators { + // validatorsAttSlot[valID] = committee.Slot + + // // if val, ok := validatorsPerSlot[committee.Slot]; ok { + // // // the slot exists in the map + // // validatorsPerSlot[committee.Slot] = append(val, valID) + // // } else { + // // // the slot does not exist, create + // // validatorsPerSlot[committee.Slot] = []phase0.ValidatorIndex{valID} + // // } + // } + // } + + // epochDuties.ValidatorAttSlot = validatorsAttSlot + // } else { + // log.Warningf("no epoch committees and validator at slot %d: %s", slot, err) + // } + + // } proposerDuties, err := s.Api.ProposerDuties(s.ctx, &api.ProposerDutiesOpts{ Epoch: phase0.Epoch(slot / spec.SlotsPerEpoch), diff --git a/pkg/clientapi/state.go b/pkg/clientapi/state.go index bd2913bc..8822b254 100644 --- a/pkg/clientapi/state.go +++ b/pkg/clientapi/state.go @@ -55,7 +55,10 @@ func (s *APIClient) RequestBeaconState(slot phase0.Slot) (*local_spec.AgnosticSt } log.Infof("state at slot %d downloaded in %f seconds", slot, time.Since(startTime).Seconds()) - resultState, err := local_spec.GetCustomState(*newState.Data, s.NewEpochData(slot)) + + epochData := s.NewEpochData(slot) + + resultState, err := local_spec.GetCustomState(*newState.Data, epochData) if err != nil { // close the channel (to tell other routines to stop processing and end) return nil, fmt.Errorf("unable to open beacon state, closing requester routine. %s", err.Error()) diff --git a/pkg/db/migrations/000001_init_schema.up.sql b/pkg/db/migrations/000001_init_schema.up.sql index f4bcbfca..790d4486 100644 --- a/pkg/db/migrations/000001_init_schema.up.sql +++ b/pkg/db/migrations/000001_init_schema.up.sql @@ -153,7 +153,7 @@ CREATE TABLE IF NOT EXISTS t_validator_rewards_summary( f_max_reward UInt64, f_max_att_reward UInt64, f_max_sync_reward UInt64, - f_att_slot UInt64, + -- f_att_slot UInt64, f_base_reward UInt64, f_in_sync_committee BOOL, f_missing_source BOOL, diff --git a/pkg/db/validator_rewards.go b/pkg/db/validator_rewards.go index 05245e97..41120aca 100644 --- a/pkg/db/validator_rewards.go +++ b/pkg/db/validator_rewards.go @@ -7,6 +7,7 @@ import ( "github.com/migalabs/goteth/pkg/spec" ) +// f_att_slot, var ( valRewardsTable = "t_validator_rewards_summary" insertValidatorRewardsQuery = ` @@ -18,7 +19,6 @@ var ( f_max_reward, f_max_att_reward, f_max_sync_reward, - f_att_slot, f_base_reward, f_in_sync_committee, f_missing_source, @@ -43,14 +43,14 @@ var ( func rewardsInput(vals []spec.ValidatorRewards) proto.Input { // one object per column var ( - f_val_idx proto.ColUInt64 - f_epoch proto.ColUInt64 - f_balance_eth proto.ColFloat32 - f_reward proto.ColInt64 - f_max_reward proto.ColUInt64 - f_max_att_reward proto.ColUInt64 - f_max_sync_reward proto.ColUInt64 - f_att_slot proto.ColUInt64 + f_val_idx proto.ColUInt64 + f_epoch proto.ColUInt64 + f_balance_eth proto.ColFloat32 + f_reward proto.ColInt64 + f_max_reward proto.ColUInt64 + f_max_att_reward proto.ColUInt64 + f_max_sync_reward proto.ColUInt64 + // f_att_slot proto.ColUInt64 f_base_reward proto.ColUInt64 f_in_sync_committee proto.ColBool f_missing_source proto.ColBool @@ -70,7 +70,7 @@ func rewardsInput(vals []spec.ValidatorRewards) proto.Input { f_max_reward.Append(uint64(val.MaxReward)) f_max_att_reward.Append(uint64(val.AttestationReward)) f_max_sync_reward.Append(uint64(val.SyncCommitteeReward)) - f_att_slot.Append(uint64(val.AttSlot)) + // f_att_slot.Append(uint64(val.AttSlot)) f_base_reward.Append(uint64(val.BaseReward)) f_in_sync_committee.Append(val.InSyncCommittee) f_missing_source.Append(val.MissingSource) @@ -90,7 +90,7 @@ func rewardsInput(vals []spec.ValidatorRewards) proto.Input { {Name: "f_max_reward", Data: f_max_reward}, {Name: "f_max_att_reward", Data: f_max_att_reward}, {Name: "f_max_sync_reward", Data: f_max_sync_reward}, - {Name: "f_att_slot", Data: f_att_slot}, + // {Name: "f_att_slot", Data: f_att_slot}, {Name: "f_base_reward", Data: f_base_reward}, {Name: "f_in_sync_committee", Data: f_in_sync_committee}, {Name: "f_missing_source", Data: f_missing_source}, diff --git a/pkg/spec/metrics/state_altair.go b/pkg/spec/metrics/state_altair.go index dadb7b99..f6579c78 100644 --- a/pkg/spec/metrics/state_altair.go +++ b/pkg/spec/metrics/state_altair.go @@ -314,14 +314,14 @@ func (p AltairMetrics) GetMaxReward(valIdx phase0.ValidatorIndex) (spec.Validato baseReward := p.GetBaseReward(valIdx, p.baseMetrics.NextState.Validators[valIdx].EffectiveBalance, p.baseMetrics.NextState.TotalActiveBalance) result := spec.ValidatorRewards{ - ValidatorIndex: valIdx, - Epoch: p.baseMetrics.NextState.Epoch, - ValidatorBalance: p.baseMetrics.NextState.Balances[valIdx], - Reward: p.baseMetrics.EpochReward(valIdx), - MaxReward: maxReward, - AttestationReward: flagIndexMaxReward, - SyncCommitteeReward: syncComMaxReward, - AttSlot: p.baseMetrics.PrevState.EpochStructs.ValidatorAttSlot[valIdx], + ValidatorIndex: valIdx, + Epoch: p.baseMetrics.NextState.Epoch, + ValidatorBalance: p.baseMetrics.NextState.Balances[valIdx], + Reward: p.baseMetrics.EpochReward(valIdx), + MaxReward: maxReward, + AttestationReward: flagIndexMaxReward, + SyncCommitteeReward: syncComMaxReward, + // AttSlot: p.baseMetrics.PrevState.EpochStructs.ValidatorAttSlot[valIdx], MissingSource: flags[spec.AttSourceFlagIndex], MissingTarget: flags[spec.AttTargetFlagIndex], MissingHead: flags[spec.AttHeadFlagIndex], diff --git a/pkg/spec/metrics/state_phase0.go b/pkg/spec/metrics/state_phase0.go index eb00c095..7f128e4f 100644 --- a/pkg/spec/metrics/state_phase0.go +++ b/pkg/spec/metrics/state_phase0.go @@ -159,14 +159,14 @@ func (p Phase0Metrics) GetMaxReward(valIdx phase0.ValidatorIndex) (spec.Validato maxReward += proposerReward result := spec.ValidatorRewards{ - ValidatorIndex: valIdx, - Epoch: p.baseMetrics.NextState.Epoch, - ValidatorBalance: p.baseMetrics.CurrentState.Balances[valIdx], - Reward: p.baseMetrics.EpochReward(valIdx), - MaxReward: maxReward, - AttestationReward: p.baseMetrics.MaxAttesterRewards[valIdx], - SyncCommitteeReward: 0, - AttSlot: p.baseMetrics.PrevState.EpochStructs.ValidatorAttSlot[valIdx], + ValidatorIndex: valIdx, + Epoch: p.baseMetrics.NextState.Epoch, + ValidatorBalance: p.baseMetrics.CurrentState.Balances[valIdx], + Reward: p.baseMetrics.EpochReward(valIdx), + MaxReward: maxReward, + AttestationReward: p.baseMetrics.MaxAttesterRewards[valIdx], + SyncCommitteeReward: 0, + // AttSlot: p.baseMetrics.PrevState.EpochStructs.ValidatorAttSlot[valIdx], MissingSource: !p.baseMetrics.CurrentState.PrevEpochCorrectFlags[spec.AttSourceFlagIndex][valIdx], MissingTarget: !p.baseMetrics.CurrentState.PrevEpochCorrectFlags[spec.AttTargetFlagIndex][valIdx], MissingHead: !p.baseMetrics.CurrentState.PrevEpochCorrectFlags[spec.AttHeadFlagIndex][valIdx], diff --git a/pkg/spec/validator_rewards.go b/pkg/spec/validator_rewards.go index 0c63defb..7ecbd180 100644 --- a/pkg/spec/validator_rewards.go +++ b/pkg/spec/validator_rewards.go @@ -5,15 +5,15 @@ import ( ) type ValidatorRewards struct { - ValidatorIndex phase0.ValidatorIndex - Epoch phase0.Epoch - ValidatorBalance phase0.Gwei - Reward int64 // it can be negative - MaxReward phase0.Gwei - AttestationReward phase0.Gwei - SyncCommitteeReward phase0.Gwei - BaseReward phase0.Gwei - AttSlot phase0.Slot + ValidatorIndex phase0.ValidatorIndex + Epoch phase0.Epoch + ValidatorBalance phase0.Gwei + Reward int64 // it can be negative + MaxReward phase0.Gwei + AttestationReward phase0.Gwei + SyncCommitteeReward phase0.Gwei + BaseReward phase0.Gwei + // AttSlot phase0.Slot InSyncCommittee bool ProposerSlot phase0.Slot ProposerApiReward phase0.Gwei @@ -33,23 +33,23 @@ func (f ValidatorRewards) BalanceToEth() float32 { return float32(f.ValidatorBalance) / EffectiveBalanceInc } -func (f ValidatorRewards) ToArray() []interface{} { - rows := []interface{}{ - f.ValidatorIndex, - f.Epoch, - f.BalanceToEth(), - f.Reward, - f.MaxReward, - f.AttestationReward, - f.SyncCommitteeReward, - f.BaseReward, - f.AttSlot, - f.InSyncCommittee, - f.MissingSource, - f.MissingTarget, - f.MissingHead, - f.Status, - f.InclusionDelay, - } - return rows -} +// func (f ValidatorRewards) ToArray() []interface{} { +// rows := []interface{}{ +// f.ValidatorIndex, +// f.Epoch, +// f.BalanceToEth(), +// f.Reward, +// f.MaxReward, +// f.AttestationReward, +// f.SyncCommitteeReward, +// f.BaseReward, +// f.AttSlot, +// f.InSyncCommittee, +// f.MissingSource, +// f.MissingTarget, +// f.MissingHead, +// f.Status, +// f.InclusionDelay, +// } +// return rows +// }