@@ -20,19 +20,21 @@ use account_utils::{
20
20
} ;
21
21
pub use api_secret:: ApiSecret ;
22
22
use beacon_node_fallback:: CandidateInfo ;
23
+ use core:: convert:: Infallible ;
23
24
use create_validator:: {
24
25
create_validators_mnemonic, create_validators_web3signer, get_voting_password_storage,
25
26
} ;
26
27
use eth2:: lighthouse_vc:: {
27
28
std_types:: { AuthResponse , GetFeeRecipientResponse , GetGasLimitResponse } ,
28
29
types:: {
29
30
self as api_types, GenericResponse , GetGraffitiResponse , Graffiti , PublicKey ,
30
- PublicKeyBytes , SetGraffitiRequest ,
31
+ PublicKeyBytes , SetGraffitiRequest , UpdateCandidatesRequest , UpdateCandidatesResponse ,
31
32
} ,
32
33
} ;
33
34
use lighthouse_version:: version_with_platform;
34
35
use logging:: SSELoggingComponents ;
35
36
use parking_lot:: RwLock ;
37
+ use sensitive_url:: SensitiveUrl ;
36
38
use serde:: { Deserialize , Serialize } ;
37
39
use slog:: { crit, info, warn, Logger } ;
38
40
use slot_clock:: SlotClock ;
@@ -49,7 +51,8 @@ use tokio_stream::{wrappers::BroadcastStream, StreamExt};
49
51
use types:: { ChainSpec , ConfigAndPreset , EthSpec } ;
50
52
use validator_dir:: Builder as ValidatorDirBuilder ;
51
53
use validator_services:: block_service:: BlockService ;
52
- use warp:: { sse:: Event , Filter } ;
54
+ use warp:: { reply:: Response , sse:: Event , Filter } ;
55
+ use warp_utils:: reject:: convert_rejection;
53
56
use warp_utils:: task:: blocking_json_task;
54
57
55
58
#[ derive( Debug ) ]
@@ -99,6 +102,7 @@ pub struct Config {
99
102
pub allow_origin : Option < String > ,
100
103
pub allow_keystore_export : bool ,
101
104
pub store_passwords_in_secrets_dir : bool ,
105
+ pub bn_long_timeouts : bool ,
102
106
}
103
107
104
108
impl Default for Config {
@@ -110,6 +114,7 @@ impl Default for Config {
110
114
allow_origin : None ,
111
115
allow_keystore_export : false ,
112
116
store_passwords_in_secrets_dir : false ,
117
+ bn_long_timeouts : false ,
113
118
}
114
119
}
115
120
}
@@ -136,6 +141,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
136
141
let config = & ctx. config ;
137
142
let allow_keystore_export = config. allow_keystore_export ;
138
143
let store_passwords_in_secrets_dir = config. store_passwords_in_secrets_dir ;
144
+ let use_long_timeouts = config. bn_long_timeouts ;
139
145
let log = ctx. log . clone ( ) ;
140
146
141
147
// Configure CORS.
@@ -835,6 +841,57 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
835
841
} )
836
842
} ) ;
837
843
844
+ // POST /lighthouse/update_beacon_nodes
845
+ let post_lighthouse_update_beacon_nodes = warp:: path ( "lighthouse" )
846
+ . and ( warp:: path ( "update_beacon_nodes" ) )
847
+ . and ( warp:: path:: end ( ) )
848
+ . and ( warp:: body:: json ( ) )
849
+ . and ( block_service_filter. clone ( ) )
850
+ . then (
851
+ move |request : UpdateCandidatesRequest , block_service : BlockService < T , E > | async move {
852
+ async fn parse_urls ( urls : & [ String ] ) -> Result < Vec < SensitiveUrl > , Response > {
853
+ match urls
854
+ . iter ( )
855
+ . map ( |url| SensitiveUrl :: parse ( url) . map_err ( |e| e. to_string ( ) ) )
856
+ . collect ( )
857
+ {
858
+ Ok ( sensitive_urls) => Ok ( sensitive_urls) ,
859
+ Err ( _) => Err ( convert_rejection :: < Infallible > ( Err (
860
+ warp_utils:: reject:: custom_bad_request (
861
+ "one or more urls could not be parsed" . to_string ( ) ,
862
+ ) ,
863
+ ) )
864
+ . await ) ,
865
+ }
866
+ }
867
+
868
+ let beacons: Vec < SensitiveUrl > = match parse_urls ( & request. beacon_nodes ) . await {
869
+ Ok ( new_beacons) => {
870
+ match block_service
871
+ . beacon_nodes
872
+ . update_candidates_list ( new_beacons, use_long_timeouts)
873
+ . await
874
+ {
875
+ Ok ( beacons) => beacons,
876
+ Err ( e) => {
877
+ return convert_rejection :: < Infallible > ( Err (
878
+ warp_utils:: reject:: custom_bad_request ( e. to_string ( ) ) ,
879
+ ) )
880
+ . await
881
+ }
882
+ }
883
+ }
884
+ Err ( e) => return e,
885
+ } ;
886
+
887
+ let response: UpdateCandidatesResponse = UpdateCandidatesResponse {
888
+ new_beacon_nodes_list : beacons. iter ( ) . map ( |surl| surl. to_string ( ) ) . collect ( ) ,
889
+ } ;
890
+
891
+ blocking_json_task ( move || Ok ( api_types:: GenericResponse :: from ( response) ) ) . await
892
+ } ,
893
+ ) ;
894
+
838
895
// Standard key-manager endpoints.
839
896
let eth_v1 = warp:: path ( "eth" ) . and ( warp:: path ( "v1" ) ) ;
840
897
let std_keystores = eth_v1. and ( warp:: path ( "keystores" ) ) . and ( warp:: path:: end ( ) ) ;
@@ -1322,6 +1379,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
1322
1379
. or ( post_std_keystores)
1323
1380
. or ( post_std_remotekeys)
1324
1381
. or ( post_graffiti)
1382
+ . or ( post_lighthouse_update_beacon_nodes)
1325
1383
. recover ( warp_utils:: reject:: handle_rejection) ,
1326
1384
) )
1327
1385
. or ( warp:: patch ( )
0 commit comments