Skip to content

Commit

Permalink
remove: ValidatorAttSlot from rewards table
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardo-gnosis committed Sep 24, 2024
1 parent 222bb21 commit 21d68fa
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 93 deletions.
68 changes: 33 additions & 35 deletions pkg/clientapi/duties.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion pkg/clientapi/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/migrations/000001_init_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions pkg/db/validator_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/migalabs/goteth/pkg/spec"
)

// f_att_slot,
var (
valRewardsTable = "t_validator_rewards_summary"
insertValidatorRewardsQuery = `
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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},
Expand Down
16 changes: 8 additions & 8 deletions pkg/spec/metrics/state_altair.go
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
16 changes: 8 additions & 8 deletions pkg/spec/metrics/state_phase0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
58 changes: 29 additions & 29 deletions pkg/spec/validator_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
// }

0 comments on commit 21d68fa

Please sign in to comment.