Skip to content

Commit fc02a8f

Browse files
authored
feat(consensus): Added view_timeout to consensus config (#3383)
## What ❔ The duration of a view timeout was previously hard-coded in era-consensus (at 2 seconds). This caused excessive view changes in networks with low traffic. era-consensus v0.7 now has view timeout duration as a config parameter and downgraded view change logging from `error` to `warn`. This PR includes those changes in zksync-era.
1 parent 3cffdb2 commit fc02a8f

File tree

11 files changed

+426
-379
lines changed

11 files changed

+426
-379
lines changed

Cargo.lock

Lines changed: 21 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,16 @@ zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.7" }
246246
zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "457d8a7eea9093af9440662e33e598c13ba41633" }
247247

248248
# Consensus dependencies.
249-
zksync_concurrency = "=0.6.0"
250-
zksync_consensus_bft = "=0.6.0"
251-
zksync_consensus_crypto = "=0.6.0"
252-
zksync_consensus_executor = "=0.6.0"
253-
zksync_consensus_network = "=0.6.0"
254-
zksync_consensus_roles = "=0.6.0"
255-
zksync_consensus_storage = "=0.6.0"
256-
zksync_consensus_utils = "=0.6.0"
257-
zksync_protobuf = "=0.6.0"
258-
zksync_protobuf_build = "=0.6.0"
249+
zksync_concurrency = "=0.7.0"
250+
zksync_consensus_bft = "=0.7.0"
251+
zksync_consensus_crypto = "=0.7.0"
252+
zksync_consensus_executor = "=0.7.0"
253+
zksync_consensus_network = "=0.7.0"
254+
zksync_consensus_roles = "=0.7.0"
255+
zksync_consensus_storage = "=0.7.0"
256+
zksync_consensus_utils = "=0.7.0"
257+
zksync_protobuf = "=0.7.0"
258+
zksync_protobuf_build = "=0.7.0"
259259

260260
# "Local" dependencies
261261
zksync_multivm = { version = "0.1.0", path = "core/lib/multivm" }

core/lib/config/src/configs/consensus.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ pub struct ConsensusConfig {
126126
/// Maximal allowed size of the payload in bytes.
127127
pub max_payload_size: usize,
128128

129+
/// View timeout duration in milliseconds.
130+
pub view_timeout: Option<time::Duration>,
131+
129132
/// Maximal allowed size of the sync-batch payloads in bytes.
130133
///
131134
/// The batch consists of block payloads and a Merkle proof of inclusion on L1 (~1kB),
@@ -155,6 +158,10 @@ pub struct ConsensusConfig {
155158
}
156159

157160
impl ConsensusConfig {
161+
pub fn view_timeout(&self) -> time::Duration {
162+
self.view_timeout.unwrap_or(time::Duration::seconds(2))
163+
}
164+
158165
pub fn rpc(&self) -> RpcConfig {
159166
self.rpc.clone().unwrap_or_default()
160167
}

core/lib/config/src/testonly.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ impl Distribution<configs::consensus::ConsensusConfig> for EncodeDist {
809809
server_addr: self.sample(rng),
810810
public_addr: Host(self.sample(rng)),
811811
max_payload_size: self.sample(rng),
812+
view_timeout: self.sample(rng),
812813
max_batch_size: self.sample(rng),
813814
gossip_dynamic_inbound_limit: self.sample(rng),
814815
gossip_static_inbound: self

core/lib/protobuf_config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ links = "zksync_protobuf_config_proto"
1616
serde_json.workspace = true
1717
serde_yaml.workspace = true
1818
zksync_basic_types.workspace = true
19+
zksync_concurrency.workspace = true
1920
zksync_config.workspace = true
2021
zksync_protobuf.workspace = true
2122
zksync_types.workspace = true

core/lib/protobuf_config/src/consensus.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::Context as _;
22
use zksync_basic_types::L2ChainId;
3+
use zksync_concurrency::time;
34
use zksync_config::configs::consensus::{
45
AttesterPublicKey, ConsensusConfig, GenesisSpec, Host, NodePublicKey, ProtocolVersion,
56
RpcConfig, ValidatorPublicKey, WeightedAttester, WeightedValidator,
@@ -154,6 +155,11 @@ impl ProtoRepr for proto::Config {
154155
.context("server_addr")?,
155156
public_addr: Host(required(&self.public_addr).context("public_addr")?.clone()),
156157
max_payload_size,
158+
view_timeout: self
159+
.view_timeout
160+
.as_ref()
161+
.map(|x| time::Duration::read(x).context("view_timeout"))
162+
.transpose()?,
157163
max_batch_size,
158164
gossip_dynamic_inbound_limit: required(&self.gossip_dynamic_inbound_limit)
159165
.and_then(|x| Ok((*x).try_into()?))
@@ -187,6 +193,7 @@ impl ProtoRepr for proto::Config {
187193
server_addr: Some(this.server_addr.to_string()),
188194
public_addr: Some(this.public_addr.0.clone()),
189195
max_payload_size: Some(this.max_payload_size.try_into().unwrap()),
196+
view_timeout: this.view_timeout.as_ref().map(ProtoFmt::build),
190197
max_batch_size: Some(this.max_batch_size.try_into().unwrap()),
191198
gossip_dynamic_inbound_limit: Some(
192199
this.gossip_dynamic_inbound_limit.try_into().unwrap(),

core/lib/protobuf_config/src/proto/core/consensus.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ message Config {
8787
// Maximal allowed size of the sync batches.
8888
optional uint64 max_batch_size = 10; // required; bytes
8989

90+
// View timeout for the consensus protocol.
91+
optional std.Duration view_timeout = 13; // optional
92+
9093
// Inbound connections that should be unconditionally accepted on the gossip network.
9194
repeated string gossip_static_inbound = 5; // required; NodePublicKey
9295

core/node/consensus/src/config.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::{BTreeMap, HashMap};
33

44
use anyhow::Context as _;
55
use secrecy::{ExposeSecret as _, Secret};
6-
use zksync_concurrency::{limiter, net, time};
6+
use zksync_concurrency::net;
77
use zksync_config::{
88
configs,
99
configs::consensus::{ConsensusConfig, ConsensusSecrets, Host, NodePublicKey},
@@ -152,11 +152,6 @@ pub(super) fn executor(
152152

153153
let mut rpc = executor::RpcConfig::default();
154154
rpc.get_block_rate = cfg.rpc().get_block_rate();
155-
// Disable batch syncing, because it is not implemented.
156-
rpc.get_batch_rate = limiter::Rate {
157-
burst: 0,
158-
refresh: time::Duration::ZERO,
159-
};
160155

161156
let debug_page = cfg.debug_page_addr.map(|addr| network::debug_page::Config {
162157
addr,
@@ -169,6 +164,7 @@ pub(super) fn executor(
169164
server_addr: cfg.server_addr,
170165
public_addr: net::Host(cfg.public_addr.0.clone()),
171166
max_payload_size: cfg.max_payload_size,
167+
view_timeout: cfg.view_timeout(),
172168
node_key: node_key(secrets)
173169
.context("node_key")?
174170
.context("missing node_key")?,

core/node/consensus/src/testonly.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ fn make_config(
149149
public_addr: config::Host(cfg.public_addr.0.clone()),
150150
max_payload_size: usize::MAX,
151151
max_batch_size: usize::MAX,
152+
view_timeout: None,
152153
gossip_dynamic_inbound_limit: cfg.gossip.dynamic_inbound_limit,
153154
gossip_static_inbound: cfg
154155
.gossip

0 commit comments

Comments
 (0)