massa_grpc/config.rs
1// Copyright (c) 2023 MASSA LABS <info@massa.net>
2
3use massa_models::amount::Amount;
4use massa_signature::KeyPair;
5use massa_time::MassaTime;
6use serde::Deserialize;
7use std::{net::SocketAddr, path::PathBuf, time::Duration};
8
9/// gRPC configuration.
10/// the gRPC configuration
11#[derive(Debug, Deserialize, Clone)]
12pub struct GrpcConfig {
13 /// whether to enable gRPC
14 pub name: ServiceName,
15 /// whether to enable gRPC
16 pub enabled: bool,
17 /// whether to accept HTTP/1.1 requests
18 pub accept_http1: bool,
19 /// whether to enable CORS. Works only if `accept_http1` is true
20 pub enable_cors: bool,
21 /// whether to enable gRPC health service
22 pub enable_health: bool,
23 /// whether to enable gRPC reflection
24 pub enable_reflection: bool,
25 /// whether to enable TLS
26 pub enable_tls: bool,
27 /// whether to enable mTLS (requires `enable_tls` to be true)
28 pub enable_mtls: bool,
29 /// whether to generate a self-signed certificate if none is provided(ignored if `enable_tls` is false)
30 pub generate_self_signed_certificates: bool,
31 /// Subject Alternative Names is an extension in X.509 certificates that allows a certificate to specify additional subject identifiers. It is used to support alternative names for a subject, other than its primary Common Name (CN), which is typically used to represent the primary domain name.
32 pub subject_alt_names: Vec<String>,
33 /// bind for the Massa gRPC API
34 pub bind: SocketAddr,
35 /// which compression encodings does the server accept for requests
36 pub accept_compressed: Option<String>,
37 /// which compression encodings might the server use for responses
38 pub send_compressed: Option<String>,
39 /// limits the maximum size of a decoded message. Defaults to 4MB
40 pub max_decoding_message_size: usize,
41 /// limits the maximum size of an encoded message. Defaults to 4MB
42 pub max_encoding_message_size: usize,
43 /// set the concurrency limit applied to on requests inbound per connection. Defaults to 32
44 pub concurrency_limit_per_connection: usize,
45 /// set a timeout on for all request handlers
46 pub timeout: Duration,
47 /// sets the SETTINGS_INITIAL_WINDOW_SIZE spec option for HTTP2 stream-level flow control. Default is 65,535
48 pub initial_stream_window_size: Option<u32>,
49 /// sets the max connection-level flow control for HTTP2. Default is 65,535
50 pub initial_connection_window_size: Option<u32>,
51 /// sets the SETTINGS_MAX_CONCURRENT_STREAMS spec option for HTTP2 connections. Default is no limit (`None`)
52 pub max_concurrent_streams: Option<u32>,
53 /// max number of arguments per gRPC request
54 pub max_arguments: u64,
55 /// set whether TCP keepalive messages are enabled on accepted connections
56 pub tcp_keepalive: Option<Duration>,
57 /// set the value of `TCP_NODELAY` option for accepted connections. Enabled by default
58 pub tcp_nodelay: bool,
59 /// set whether HTTP2 Ping frames are enabled on accepted connections. Default is no HTTP2 keepalive (`None`)
60 pub http2_keepalive_interval: Option<Duration>,
61 /// sets a timeout for receiving an acknowledgement of the keepalive ping. Default is 20 seconds
62 pub http2_keepalive_timeout: Option<Duration>,
63 /// sets whether to use an adaptive flow control. Defaults to false
64 pub http2_adaptive_window: Option<bool>,
65 /// sets the maximum frame size to use for HTTP2. If not set, will default from underlying transport
66 pub max_frame_size: Option<u32>,
67 /// thread count
68 pub thread_count: u8,
69 /// max operations per block
70 pub max_operations_per_block: u32,
71 /// endorsement count
72 pub endorsement_count: u32,
73 /// max endorsements per message
74 pub max_endorsements_per_message: u32,
75 /// max size of a smart contract bytecode in an `ExecuteSC` operation
76 pub max_bytecode_size: u64,
77 /// max op datastore entry
78 pub max_op_datastore_entry_count: u64,
79 /// max op datastore entries per request
80 pub max_datastore_entries_per_request: u64,
81 /// max datastore key length
82 pub max_op_datastore_key_length: u8,
83 /// max datastore value length
84 pub max_op_datastore_value_length: u64,
85 /// max function name length
86 pub max_function_name_length: u16,
87 /// max parameter size
88 pub max_parameter_size: u32,
89 /// max operations per message in the network to avoid sending to big data packet
90 pub max_operations_per_message: u32,
91 /// max gas per block
92 pub max_gas_per_block: u64,
93 /// maximum serialized size of a single operation: an operation bigger than
94 /// the whole operations payload of a block can never be propagated by the
95 /// protocol nor included in a block (`MAX_BLOCK_SIZE`)
96 pub max_serialized_operation_size: usize,
97 /// gas cost of a basic operation
98 pub base_operation_gas_cost: u64,
99 /// gas cost of the smart contract compilation
100 pub sp_compilation_cost: u64,
101 /// `genesis_timestamp`
102 pub genesis_timestamp: MassaTime,
103 /// t0
104 pub t0: MassaTime,
105 /// periods per cycle
106 pub periods_per_cycle: u64,
107 /// keypair file
108 pub keypair: KeyPair,
109 /// limits the maximum size of streaming channel
110 pub max_channel_size: usize,
111 /// when looking for next draw we want to look at max `draw_lookahead_period_count`
112 pub draw_lookahead_period_count: u64,
113 /// last_start_period of the network, used to deserialize blocks
114 pub last_start_period: u64,
115 /// max denunciations in block header
116 pub max_denunciations_per_block_header: u32,
117 /// max number of addresses that can be included in a single request
118 pub max_addresses_per_request: u32,
119 /// max number of slot ranges that can be included in a single request
120 pub max_slot_ranges_per_request: u32,
121 /// max number of block ids that can be included in a single request
122 pub max_block_ids_per_request: u32,
123 /// max number of endorsement ids that can be included in a single request
124 pub max_endorsement_ids_per_request: u32,
125 /// max number of operation ids that can be included in a single request
126 pub max_operation_ids_per_request: u32,
127 /// max number of filters that can be included in a single request
128 pub max_filters_per_request: u32,
129 /// max number of query items that can be included in a single request
130 pub max_query_items_per_request: u32,
131 /// max events returned per query_state batch
132 pub max_event_per_query: u32,
133 /// wall-clock deadline for a query_state batch, in ms (`None` = no deadline)
134 pub query_state_deadline_ms: Option<u64>,
135 /// certificate authority root path
136 pub certificate_authority_root_path: PathBuf,
137 /// server certificate path
138 pub server_certificate_path: PathBuf,
139 /// server private key path
140 pub server_private_key_path: PathBuf,
141 /// client certificate authority root path
142 pub client_certificate_authority_root_path: PathBuf,
143 /// client certificate path
144 pub client_certificate_path: PathBuf,
145 /// client private key path
146 pub client_private_key_path: PathBuf,
147 /// chain id
148 pub chain_id: u64,
149 /// minimal fees
150 pub minimal_fees: Amount,
151 /// max datastore keys queries
152 pub max_datastore_keys_queries: Option<u32>,
153 /// max datastore key length
154 pub max_datastore_key_length: u8,
155 /// interval check for stream connection
156 pub unidirectional_stream_interval_check: u64,
157}
158
159/// gRPC API configuration.
160#[derive(Debug, Deserialize, Clone)]
161pub struct GrpcApiConfig {
162 /// Public server gRPC configuration.
163 pub public: GrpcConfig,
164 /// Private server gRPC configuration.
165 pub private: GrpcConfig,
166}
167
168/// gRPC service name
169#[derive(Debug, Deserialize, Clone)]
170pub enum ServiceName {
171 /// Public service name
172 Public,
173 /// Private service name
174 Private,
175}