Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beacon API: Added attestation rewards endpoint. #9091

Merged
merged 21 commits into from
Dec 28, 2023
2 changes: 2 additions & 0 deletions cl/abstract/beacon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ type BeaconStateMinimal interface {
Eth1Data() *cltypes.Eth1Data
Eth1DataVotes() *solid.ListSSZ[*cltypes.Eth1Data]
Eth1DepositIndex() uint64
ValidatorSet() *solid.ValidatorSet
PreviousEpochParticipation() *solid.BitList

ForEachValidator(fn func(v solid.Validator, idx int, total int) bool)
ValidatorForValidatorIndex(index int) (solid.Validator, error)
Expand Down
24 changes: 23 additions & 1 deletion cl/antiquary/state_antiquary.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ func (s *Antiquary) IncrementBeaconState(ctx context.Context, to uint64) error {
defer eth1DataVotes.Close()
stateEvents := etl.NewCollector(kv.StateEvents, s.dirs.Tmp, etl.NewSortableBuffer(etl.BufferOptimalSize), s.logger)
defer stateEvents.Close()
activeValidatorIndicies := etl.NewCollector(kv.ActiveValidatorIndicies, s.dirs.Tmp, etl.NewSortableBuffer(etl.BufferOptimalSize), s.logger)
defer activeValidatorIndicies.Close()

progress, err := state_accessors.GetStateProcessingProgress(tx)
if err != nil {
Expand Down Expand Up @@ -311,6 +313,23 @@ func (s *Antiquary) IncrementBeaconState(ctx context.Context, to uint64) error {
if err := randaoMixes.Collect(base_encoding.Encode64ToBytes4(prevEpoch*s.cfg.SlotsPerEpoch), mix[:]); err != nil {
return err
}
// Write active validator indicies
actives := s.currentState.GetActiveValidatorsIndices(prevEpoch)
commonBuffer.Reset()
if err := base_encoding.WriteRabbits(actives, commonBuffer); err != nil {
return err
}
if err := activeValidatorIndicies.Collect(base_encoding.Encode64ToBytes4(prevEpoch), libcommon.Copy(commonBuffer.Bytes())); err != nil {
return err
}
actives = s.currentState.GetActiveValidatorsIndices(epoch)
commonBuffer.Reset()
if err := base_encoding.WriteRabbits(actives, commonBuffer); err != nil {
return err
}
if err := activeValidatorIndicies.Collect(base_encoding.Encode64ToBytes4(epoch), libcommon.Copy(commonBuffer.Bytes())); err != nil {
return err
}
// truncate the file
return proposers.Collect(base_encoding.Encode64ToBytes4(epoch), getProposerDutiesValue(s.currentState))
},
Expand Down Expand Up @@ -504,6 +523,9 @@ func (s *Antiquary) IncrementBeaconState(ctx context.Context, to uint64) error {
if err := stateRoots.Load(rwTx, kv.StateRoot, loadfunc, etl.TransformArgs{Quit: ctx.Done()}); err != nil {
return err
}
if err := activeValidatorIndicies.Load(rwTx, kv.ActiveValidatorIndicies, loadfunc, etl.TransformArgs{Quit: ctx.Done()}); err != nil {
return err
}

if err := minimalBeaconStates.Load(rwTx, kv.MinimalBeaconState, loadfunc, etl.TransformArgs{Quit: ctx.Done()}); err != nil {
return err
Expand Down Expand Up @@ -758,7 +780,7 @@ func (s *Antiquary) collectGenesisState(ctx context.Context, compressor *zstd.En

func (s *Antiquary) storeMinimalState(buffer *bytes.Buffer, st *state.CachingBeaconState, collector *etl.Collector) error {
buffer.Reset()
minimalBeaconState := state_accessors.MinimalBeaconStateFromBeaconState(st.BeaconState)
minimalBeaconState := state_accessors.MinimalBeaconStateFromBeaconState(st)

if err := minimalBeaconState.WriteTo(buffer); err != nil {
return err
Expand Down
Loading
Loading