1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Network component configs.
use std::collections::{HashMap, HashSet};
use zksync_concurrency::{limiter, net, time};
use zksync_consensus_roles::{node, validator};
/// How often we should retry to establish a connection to a validator.
/// TODO(gprusak): once it becomes relevant, choose a more appropriate retry strategy.
pub(crate) const CONNECT_RETRY: time::Duration = time::Duration::seconds(20);
/// Rate limiting config for RPCs.
#[derive(Debug, Clone)]
pub struct RpcConfig {
/// Max rate of sending/receiving push_validator_addrs messages.
pub push_validator_addrs_rate: limiter::Rate,
/// Max rate of sending/receiving push_block_store_state messages.
pub push_block_store_state_rate: limiter::Rate,
/// Max rate of sending/receiving push_tx messages.
pub push_tx_rate: limiter::Rate,
/// Max rate of sending/receiving `get_block` RPCs.
pub get_block_rate: limiter::Rate,
/// Timeout for the `get_block` RPC.
pub get_block_timeout: Option<time::Duration>,
/// Max rate of sending/receiving consensus messages.
pub consensus_rate: limiter::Rate,
}
impl Default for RpcConfig {
fn default() -> Self {
Self {
push_validator_addrs_rate: limiter::Rate {
burst: 1,
refresh: time::Duration::seconds(5),
},
push_block_store_state_rate: limiter::Rate {
burst: 2,
refresh: time::Duration::milliseconds(200),
},
push_tx_rate: limiter::Rate {
burst: 10,
refresh: time::Duration::milliseconds(10),
},
get_block_rate: limiter::Rate {
burst: 10,
refresh: time::Duration::milliseconds(100),
},
get_block_timeout: Some(time::Duration::seconds(10)),
consensus_rate: limiter::Rate {
burst: 10,
refresh: time::Duration::ZERO,
},
}
}
}
/// Gossip network configuration.
#[derive(Debug, Clone)]
pub struct GossipConfig {
/// Private key of the node, every node should have one.
pub key: node::SecretKey,
/// Limit on the number of inbound connections outside
/// of the `static_inbound` set.
pub dynamic_inbound_limit: usize,
/// Inbound connections that should be unconditionally accepted.
pub static_inbound: HashSet<node::PublicKey>,
/// Outbound connections that the node should actively try to
/// establish and maintain.
pub static_outbound: HashMap<node::PublicKey, net::Host>,
}
/// Network component config.
#[derive(Debug, Clone)]
pub struct Config {
/// Label identifying the build version of the binary that this node is running.
/// There is no specific semantics assigned to it.
pub build_version: Option<semver::Version>,
/// TCP socket address to listen for inbound connections at.
pub server_addr: net::tcp::ListenerAddr,
/// Public TCP address that other nodes are expected to connect to.
/// It is announced over gossip network.
/// In case public_addr is a domain instead of ip, DNS resolution is
/// performed and a loopback connection is established before announcing
/// the IP address over the gossip network.
pub public_addr: net::Host,
/// Gossip network config.
pub gossip: GossipConfig,
/// Private key of the validator.
/// None if the node is NOT a validator.
pub validator_key: Option<validator::SecretKey>,
/// Maximal size of the proto-encoded `validator::FinalBlock` in bytes.
pub max_block_size: usize,
/// Maximal size of the proto-encoded `Transaction` in bytes.
pub max_tx_size: usize,
/// If a peer doesn't respond to a ping message within `ping_timeout`,
/// the connection is dropped.
/// `None` disables sending ping messages (useful for tests).
pub ping_timeout: Option<time::Duration>,
/// Max rate at which inbound TCP connections should be accepted.
pub tcp_accept_rate: limiter::Rate,
/// Rate limiting config for RPCs.
pub rpc: RpcConfig,
/// Maximum number of not-yet-persisted blocks fetched from the network.
/// If reached, network component will wait for more blocks to get persisted
/// before fetching the next ones. It is useful for limiting memory consumption
/// when the block persisting rate is low.
pub max_block_queue_size: usize,
}