@@ -26,6 +26,7 @@ pub mod test_utils;
26
26
mod ui;
27
27
mod validator;
28
28
mod validator_inclusion;
29
+ mod validators;
29
30
mod version;
30
31
31
32
use crate :: produce_block:: { produce_blinded_block_v2, produce_block_v2, produce_block_v3} ;
@@ -41,7 +42,8 @@ use bytes::Bytes;
41
42
use directory:: DEFAULT_ROOT_DIR ;
42
43
use eth2:: types:: {
43
44
self as api_types, BroadcastValidation , EndpointVersion , ForkChoice , ForkChoiceNode ,
44
- PublishBlockRequest , ValidatorId , ValidatorStatus ,
45
+ PublishBlockRequest , ValidatorBalancesRequestBody , ValidatorId , ValidatorStatus ,
46
+ ValidatorsRequestBody ,
45
47
} ;
46
48
use lighthouse_network:: { types:: SyncState , EnrExt , NetworkGlobals , PeerId , PubsubMessage } ;
47
49
use lighthouse_version:: version_with_platform;
@@ -663,47 +665,32 @@ pub fn serve<T: BeaconChainTypes>(
663
665
query_res : Result < api_types:: ValidatorBalancesQuery , warp:: Rejection > | {
664
666
task_spawner. blocking_json_task ( Priority :: P1 , move || {
665
667
let query = query_res?;
666
- let ( data, execution_optimistic, finalized) = state_id
667
- . map_state_and_execution_optimistic_and_finalized (
668
- & chain,
669
- |state, execution_optimistic, finalized| {
670
- Ok ( (
671
- state
672
- . validators ( )
673
- . iter ( )
674
- . zip ( state. balances ( ) . iter ( ) )
675
- . enumerate ( )
676
- // filter by validator id(s) if provided
677
- . filter ( |( index, ( validator, _) ) | {
678
- query. id . as_ref ( ) . map_or ( true , |ids| {
679
- ids. iter ( ) . any ( |id| match id {
680
- ValidatorId :: PublicKey ( pubkey) => {
681
- & validator. pubkey == pubkey
682
- }
683
- ValidatorId :: Index ( param_index) => {
684
- * param_index == * index as u64
685
- }
686
- } )
687
- } )
688
- } )
689
- . map ( |( index, ( _, balance) ) | {
690
- Some ( api_types:: ValidatorBalanceData {
691
- index : index as u64 ,
692
- balance : * balance,
693
- } )
694
- } )
695
- . collect :: < Vec < _ > > ( ) ,
696
- execution_optimistic,
697
- finalized,
698
- ) )
699
- } ,
700
- ) ?;
668
+ crate :: validators:: get_beacon_state_validator_balances (
669
+ state_id,
670
+ chain,
671
+ query. id . as_deref ( ) ,
672
+ )
673
+ } )
674
+ } ,
675
+ ) ;
701
676
702
- Ok ( api_types:: ExecutionOptimisticFinalizedResponse {
703
- data,
704
- execution_optimistic : Some ( execution_optimistic) ,
705
- finalized : Some ( finalized) ,
706
- } )
677
+ // POST beacon/states/{state_id}/validator_balances
678
+ let post_beacon_state_validator_balances = beacon_states_path
679
+ . clone ( )
680
+ . and ( warp:: path ( "validator_balances" ) )
681
+ . and ( warp:: path:: end ( ) )
682
+ . and ( warp:: body:: json ( ) )
683
+ . then (
684
+ |state_id : StateId ,
685
+ task_spawner : TaskSpawner < T :: EthSpec > ,
686
+ chain : Arc < BeaconChain < T > > ,
687
+ query : ValidatorBalancesRequestBody | {
688
+ task_spawner. blocking_json_task ( Priority :: P1 , move || {
689
+ crate :: validators:: get_beacon_state_validator_balances (
690
+ state_id,
691
+ chain,
692
+ Some ( & query. ids ) ,
693
+ )
707
694
} )
708
695
} ,
709
696
) ;
@@ -721,69 +708,34 @@ pub fn serve<T: BeaconChainTypes>(
721
708
query_res : Result < api_types:: ValidatorsQuery , warp:: Rejection > | {
722
709
task_spawner. blocking_json_task ( Priority :: P1 , move || {
723
710
let query = query_res?;
724
- let ( data, execution_optimistic, finalized) = state_id
725
- . map_state_and_execution_optimistic_and_finalized (
726
- & chain,
727
- |state, execution_optimistic, finalized| {
728
- let epoch = state. current_epoch ( ) ;
729
- let far_future_epoch = chain. spec . far_future_epoch ;
730
-
731
- Ok ( (
732
- state
733
- . validators ( )
734
- . iter ( )
735
- . zip ( state. balances ( ) . iter ( ) )
736
- . enumerate ( )
737
- // filter by validator id(s) if provided
738
- . filter ( |( index, ( validator, _) ) | {
739
- query. id . as_ref ( ) . map_or ( true , |ids| {
740
- ids. iter ( ) . any ( |id| match id {
741
- ValidatorId :: PublicKey ( pubkey) => {
742
- & validator. pubkey == pubkey
743
- }
744
- ValidatorId :: Index ( param_index) => {
745
- * param_index == * index as u64
746
- }
747
- } )
748
- } )
749
- } )
750
- // filter by status(es) if provided and map the result
751
- . filter_map ( |( index, ( validator, balance) ) | {
752
- let status = api_types:: ValidatorStatus :: from_validator (
753
- validator,
754
- epoch,
755
- far_future_epoch,
756
- ) ;
757
-
758
- let status_matches =
759
- query. status . as_ref ( ) . map_or ( true , |statuses| {
760
- statuses. contains ( & status)
761
- || statuses. contains ( & status. superstatus ( ) )
762
- } ) ;
763
-
764
- if status_matches {
765
- Some ( api_types:: ValidatorData {
766
- index : index as u64 ,
767
- balance : * balance,
768
- status,
769
- validator : validator. clone ( ) ,
770
- } )
771
- } else {
772
- None
773
- }
774
- } )
775
- . collect :: < Vec < _ > > ( ) ,
776
- execution_optimistic,
777
- finalized,
778
- ) )
779
- } ,
780
- ) ?;
711
+ crate :: validators:: get_beacon_state_validators (
712
+ state_id,
713
+ chain,
714
+ & query. id ,
715
+ & query. status ,
716
+ )
717
+ } )
718
+ } ,
719
+ ) ;
781
720
782
- Ok ( api_types:: ExecutionOptimisticFinalizedResponse {
783
- data,
784
- execution_optimistic : Some ( execution_optimistic) ,
785
- finalized : Some ( finalized) ,
786
- } )
721
+ // POST beacon/states/{state_id}/validators
722
+ let post_beacon_state_validators = beacon_states_path
723
+ . clone ( )
724
+ . and ( warp:: path ( "validators" ) )
725
+ . and ( warp:: path:: end ( ) )
726
+ . and ( warp:: body:: json ( ) )
727
+ . then (
728
+ |state_id : StateId ,
729
+ task_spawner : TaskSpawner < T :: EthSpec > ,
730
+ chain : Arc < BeaconChain < T > > ,
731
+ query : ValidatorsRequestBody | {
732
+ task_spawner. blocking_json_task ( Priority :: P1 , move || {
733
+ crate :: validators:: get_beacon_state_validators (
734
+ state_id,
735
+ chain,
736
+ & query. ids ,
737
+ & query. statuses ,
738
+ )
787
739
} )
788
740
} ,
789
741
) ;
@@ -4709,6 +4661,8 @@ pub fn serve<T: BeaconChainTypes>(
4709
4661
. uor ( post_beacon_pool_voluntary_exits)
4710
4662
. uor ( post_beacon_pool_sync_committees)
4711
4663
. uor ( post_beacon_pool_bls_to_execution_changes)
4664
+ . uor ( post_beacon_state_validators)
4665
+ . uor ( post_beacon_state_validator_balances)
4712
4666
. uor ( post_beacon_rewards_attestations)
4713
4667
. uor ( post_beacon_rewards_sync_committee)
4714
4668
. uor ( post_validator_duties_attester)
0 commit comments