@@ -6,7 +6,7 @@ use apollo_config::converters::deserialize_milliseconds_to_duration;
66use apollo_config:: dumping:: { prepend_sub_config_name, ser_param, SerializeConfig } ;
77use apollo_config:: { ParamPath , ParamPrivacyInput , SerializedParam } ;
88use serde:: { Deserialize , Serialize } ;
9- use validator:: Validate ;
9+ use validator:: { Validate , ValidationError } ;
1010
1111const HTTP_SERVER_PORT : u16 = 8080 ;
1212pub const DEFAULT_MAX_SIERRA_PROGRAM_SIZE : usize = 4 * 1024 * 1024 ; // 4MB
@@ -17,6 +17,7 @@ const DEFAULT_DYNAMIC_CONFIG_POLL_INTERVAL_MS: u64 = 1_000; // 1 second.
1717
1818/// The http server connection related configuration.
1919#[ derive( Clone , Debug , Default , Serialize , Deserialize , Validate , PartialEq ) ]
20+ #[ validate( schema( function = "max_size_validations" ) ) ]
2021pub struct HttpServerConfig {
2122 pub dynamic_config : HttpServerDynamicConfig ,
2223 pub static_config : HttpServerStaticConfig ,
@@ -51,8 +52,6 @@ impl HttpServerConfig {
5152pub struct HttpServerStaticConfig {
5253 pub ip : IpAddr ,
5354 pub port : u16 ,
54- // TODO(Arni): add a validation that this size is bigger than
55- // http_server_config.dynamic_config.max_sierra_program_size.
5655 pub max_request_body_size : usize ,
5756 #[ serde( deserialize_with = "deserialize_milliseconds_to_duration" ) ]
5857 pub dynamic_config_poll_interval : Duration ,
@@ -122,3 +121,20 @@ impl Default for HttpServerDynamicConfig {
122121 Self { accept_new_txs : true , max_sierra_program_size : DEFAULT_MAX_SIERRA_PROGRAM_SIZE }
123122 }
124123}
124+
125+ fn max_size_validations ( http_server_config : & HttpServerConfig ) -> Result < ( ) , ValidationError > {
126+ let max_request_body_size = http_server_config. static_config . max_request_body_size ;
127+ validate_dynamic_config_bounds ( & http_server_config. dynamic_config , max_request_body_size)
128+ }
129+
130+ pub fn validate_dynamic_config_bounds (
131+ dynamic_config : & HttpServerDynamicConfig ,
132+ max_request_body_size : usize ,
133+ ) -> Result < ( ) , ValidationError > {
134+ if max_request_body_size < dynamic_config. max_sierra_program_size {
135+ return Err ( ValidationError :: new (
136+ "max_request_body_size must be greater than max_sierra_program_size" ,
137+ ) ) ;
138+ }
139+ Ok ( ( ) )
140+ }
0 commit comments