@@ -365,6 +365,29 @@ func (m *ApiService) handleMemoryStatistics(w http.ResponseWriter, req *http.Req
365365 avgBlockRewardWei = big .NewInt (0 ).Div (totalRewardsSentWei , big .NewInt (0 ).SetUint64 (totalOkPoolProposalBlocks ))
366366 }
367367
368+ // Total and average effective balance
369+ totalEffectiveBalance := uint64 (0 )
370+ effectiveBalances := m .Onchain .Validators ()
371+
372+ for _ , validator := range m .oracle .State ().Validators {
373+ if validator .ValidatorStatus == oracle .Active ||
374+ validator .ValidatorStatus == oracle .YellowCard ||
375+ validator .ValidatorStatus == oracle .RedCard {
376+
377+ beaconState , found := effectiveBalances [phase0 .ValidatorIndex (validator .ValidatorIndex )]
378+ if ! found {
379+ log .Warn ("could not find validator in beacon state: " , validator .ValidatorIndex )
380+ continue
381+ }
382+ totalEffectiveBalance += uint64 (beaconState .Validator .EffectiveBalance )
383+ }
384+ }
385+
386+ avgEffectiveBalance := uint64 (0 )
387+ if totalSubscribed > 0 {
388+ avgEffectiveBalance = totalEffectiveBalance / totalSubscribed
389+ }
390+
368391 m .respondOK (w , httpOkMemoryStatistics {
369392 TotalSubscribed : totalSubscribed ,
370393 TotalActive : totalActive ,
@@ -384,6 +407,8 @@ func (m *ApiService) handleMemoryStatistics(w http.ResponseWriter, req *http.Req
384407 TotalProposedBlocks : totalProposedBlocks ,
385408 TotalMissedBlocks : uint64 (len (m .oracle .State ().MissedBlocks )),
386409 TotalWrongFeeBlocks : uint64 (len (m .oracle .State ().WrongFeeBlocks )),
410+ TotalEffectiveBalanceGwei : fmt .Sprintf ("%d" , totalEffectiveBalance ),
411+ AvgEffectiveBalanceGwei : fmt .Sprintf ("%d" , avgEffectiveBalance ),
387412 })
388413}
389414
@@ -515,15 +540,17 @@ func (m *ApiService) handleMemoryValidators(w http.ResponseWriter, req *http.Req
515540 continue
516541 }
517542 validatorsResp = append (validatorsResp , httpOkValidatorInfo {
518- ValidatorStatus : v .ValidatorStatus .String (),
519- BeaconValidatorStatus : beaconState .Status .String (),
520- AccumulatedRewardsWei : v .AccumulatedRewardsWei .String (),
521- PendingRewardsWei : v .PendingRewardsWei .String (),
522- CollateralWei : v .CollateralWei .String (),
523- WithdrawalAddress : v .WithdrawalAddress ,
524- ValidatorIndex : v .ValidatorIndex ,
525- ValidatorKey : v .ValidatorKey ,
526- SubscriptionType : v .SubscriptionType .String (),
543+ ValidatorStatus : v .ValidatorStatus .String (),
544+ BeaconValidatorBalanceGwei : fmt .Sprintf ("%d" , beaconState .Balance ),
545+ BeaconValidatorEffectiveBalanceGwei : fmt .Sprintf ("%d" , beaconState .Validator .EffectiveBalance ),
546+ BeaconValidatorStatus : beaconState .Status .String (),
547+ AccumulatedRewardsWei : v .AccumulatedRewardsWei .String (),
548+ PendingRewardsWei : v .PendingRewardsWei .String (),
549+ CollateralWei : v .CollateralWei .String (),
550+ WithdrawalAddress : v .WithdrawalAddress ,
551+ ValidatorIndex : v .ValidatorIndex ,
552+ ValidatorKey : v .ValidatorKey ,
553+ SubscriptionType : v .SubscriptionType .String (),
527554 })
528555 }
529556
@@ -601,15 +628,17 @@ func (m *ApiService) handleMemoryValidatorsByIndex(w http.ResponseWriter, req *h
601628 continue
602629 }
603630 foundValidator := httpOkValidatorInfo {
604- ValidatorStatus : validator .ValidatorStatus .String (),
605- BeaconValidatorStatus : beaconState .Status .String (),
606- AccumulatedRewardsWei : validator .AccumulatedRewardsWei .String (),
607- PendingRewardsWei : validator .PendingRewardsWei .String (),
608- CollateralWei : validator .CollateralWei .String (),
609- WithdrawalAddress : validator .WithdrawalAddress ,
610- ValidatorIndex : validator .ValidatorIndex ,
611- ValidatorKey : validator .ValidatorKey ,
612- SubscriptionType : validator .SubscriptionType .String (),
631+ ValidatorStatus : validator .ValidatorStatus .String (),
632+ BeaconValidatorBalanceGwei : fmt .Sprintf ("%d" , beaconState .Balance ),
633+ BeaconValidatorEffectiveBalanceGwei : fmt .Sprintf ("%d" , beaconState .Validator .EffectiveBalance ),
634+ BeaconValidatorStatus : beaconState .Status .String (),
635+ AccumulatedRewardsWei : validator .AccumulatedRewardsWei .String (),
636+ PendingRewardsWei : validator .PendingRewardsWei .String (),
637+ CollateralWei : validator .CollateralWei .String (),
638+ WithdrawalAddress : validator .WithdrawalAddress ,
639+ ValidatorIndex : validator .ValidatorIndex ,
640+ ValidatorKey : validator .ValidatorKey ,
641+ SubscriptionType : validator .SubscriptionType .String (),
613642 }
614643 foundValidators = append (foundValidators , foundValidator )
615644 } else {
@@ -754,15 +783,17 @@ func (m *ApiService) handleMemoryValidatorsByWithdrawal(w http.ResponseWriter, r
754783 continue
755784 }
756785 validatorsResp = append (validatorsResp , httpOkValidatorInfo {
757- ValidatorStatus : v .ValidatorStatus .String (),
758- BeaconValidatorStatus : beaconState .Status .String (),
759- AccumulatedRewardsWei : v .AccumulatedRewardsWei .String (),
760- PendingRewardsWei : v .PendingRewardsWei .String (),
761- CollateralWei : v .CollateralWei .String (),
762- WithdrawalAddress : v .WithdrawalAddress ,
763- ValidatorIndex : v .ValidatorIndex ,
764- ValidatorKey : v .ValidatorKey ,
765- SubscriptionType : v .SubscriptionType .String (),
786+ ValidatorStatus : v .ValidatorStatus .String (),
787+ BeaconValidatorBalanceGwei : fmt .Sprintf ("%d" , beaconState .Balance ),
788+ BeaconValidatorEffectiveBalanceGwei : fmt .Sprintf ("%d" , beaconState .Validator .EffectiveBalance ),
789+ BeaconValidatorStatus : beaconState .Status .String (),
790+ AccumulatedRewardsWei : v .AccumulatedRewardsWei .String (),
791+ PendingRewardsWei : v .PendingRewardsWei .String (),
792+ CollateralWei : v .CollateralWei .String (),
793+ WithdrawalAddress : v .WithdrawalAddress ,
794+ ValidatorIndex : v .ValidatorIndex ,
795+ ValidatorKey : v .ValidatorKey ,
796+ SubscriptionType : v .SubscriptionType .String (),
766797 })
767798 }
768799 m .respondOK (w , validatorsResp )
0 commit comments