Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(consensus): Added view_timeout to consensus config #3383

Merged
merged 12 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,16 @@ zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.7" }
zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "457d8a7eea9093af9440662e33e598c13ba41633" }

# Consensus dependencies.
zksync_concurrency = "=0.6.0"
zksync_consensus_bft = "=0.6.0"
zksync_consensus_crypto = "=0.6.0"
zksync_consensus_executor = "=0.6.0"
zksync_consensus_network = "=0.6.0"
zksync_consensus_roles = "=0.6.0"
zksync_consensus_storage = "=0.6.0"
zksync_consensus_utils = "=0.6.0"
zksync_protobuf = "=0.6.0"
zksync_protobuf_build = "=0.6.0"
zksync_concurrency = "=0.7.0"
zksync_consensus_bft = "=0.7.0"
zksync_consensus_crypto = "=0.7.0"
zksync_consensus_executor = "=0.7.0"
zksync_consensus_network = "=0.7.0"
zksync_consensus_roles = "=0.7.0"
zksync_consensus_storage = "=0.7.0"
zksync_consensus_utils = "=0.7.0"
zksync_protobuf = "=0.7.0"
zksync_protobuf_build = "=0.7.0"

# "Local" dependencies
zksync_multivm = { version = "0.1.0", path = "core/lib/multivm" }
Expand Down
7 changes: 7 additions & 0 deletions core/lib/config/src/configs/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ pub struct ConsensusConfig {
/// Maximal allowed size of the payload in bytes.
pub max_payload_size: usize,

/// View timeout duration in milliseconds.
pub view_timeout: Option<time::Duration>,

/// Maximal allowed size of the sync-batch payloads in bytes.
///
/// The batch consists of block payloads and a Merkle proof of inclusion on L1 (~1kB),
Expand Down Expand Up @@ -155,6 +158,10 @@ pub struct ConsensusConfig {
}

impl ConsensusConfig {
pub fn view_timeout(&self) -> time::Duration {
self.view_timeout.unwrap_or(time::Duration::seconds(2))
}

pub fn rpc(&self) -> RpcConfig {
self.rpc.clone().unwrap_or_default()
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ impl Distribution<configs::consensus::ConsensusConfig> for EncodeDist {
server_addr: self.sample(rng),
public_addr: Host(self.sample(rng)),
max_payload_size: self.sample(rng),
view_timeout: self.sample(rng),
max_batch_size: self.sample(rng),
gossip_dynamic_inbound_limit: self.sample(rng),
gossip_static_inbound: self
Expand Down
1 change: 1 addition & 0 deletions core/lib/protobuf_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ links = "zksync_protobuf_config_proto"
serde_json.workspace = true
serde_yaml.workspace = true
zksync_basic_types.workspace = true
zksync_concurrency.workspace = true
zksync_config.workspace = true
zksync_protobuf.workspace = true
zksync_types.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions core/lib/protobuf_config/src/consensus.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Context as _;
use zksync_basic_types::L2ChainId;
use zksync_concurrency::time;
use zksync_config::configs::consensus::{
AttesterPublicKey, ConsensusConfig, GenesisSpec, Host, NodePublicKey, ProtocolVersion,
RpcConfig, ValidatorPublicKey, WeightedAttester, WeightedValidator,
Expand Down Expand Up @@ -154,6 +155,11 @@ impl ProtoRepr for proto::Config {
.context("server_addr")?,
public_addr: Host(required(&self.public_addr).context("public_addr")?.clone()),
max_payload_size,
view_timeout: self
.view_timeout
.as_ref()
.map(|x| time::Duration::read(x).context("view_timeout"))
.transpose()?,
max_batch_size,
gossip_dynamic_inbound_limit: required(&self.gossip_dynamic_inbound_limit)
.and_then(|x| Ok((*x).try_into()?))
Expand Down Expand Up @@ -187,6 +193,7 @@ impl ProtoRepr for proto::Config {
server_addr: Some(this.server_addr.to_string()),
public_addr: Some(this.public_addr.0.clone()),
max_payload_size: Some(this.max_payload_size.try_into().unwrap()),
view_timeout: this.view_timeout.as_ref().map(ProtoFmt::build),
max_batch_size: Some(this.max_batch_size.try_into().unwrap()),
gossip_dynamic_inbound_limit: Some(
this.gossip_dynamic_inbound_limit.try_into().unwrap(),
Expand Down
3 changes: 3 additions & 0 deletions core/lib/protobuf_config/src/proto/core/consensus.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ message Config {
// Maximal allowed size of the sync batches.
optional uint64 max_batch_size = 10; // required; bytes

// View timeout for the consensus protocol.
optional std.Duration view_timeout = 13; // optional

// Inbound connections that should be unconditionally accepted on the gossip network.
repeated string gossip_static_inbound = 5; // required; NodePublicKey

Expand Down
8 changes: 2 additions & 6 deletions core/node/consensus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::{BTreeMap, HashMap};

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

let mut rpc = executor::RpcConfig::default();
rpc.get_block_rate = cfg.rpc().get_block_rate();
// Disable batch syncing, because it is not implemented.
rpc.get_batch_rate = limiter::Rate {
burst: 0,
refresh: time::Duration::ZERO,
};

let debug_page = cfg.debug_page_addr.map(|addr| network::debug_page::Config {
addr,
Expand All @@ -169,6 +164,7 @@ pub(super) fn executor(
server_addr: cfg.server_addr,
public_addr: net::Host(cfg.public_addr.0.clone()),
max_payload_size: cfg.max_payload_size,
view_timeout: cfg.view_timeout(),
node_key: node_key(secrets)
.context("node_key")?
.context("missing node_key")?,
Expand Down
1 change: 1 addition & 0 deletions core/node/consensus/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fn make_config(
public_addr: config::Host(cfg.public_addr.0.clone()),
max_payload_size: usize::MAX,
max_batch_size: usize::MAX,
view_timeout: None,
gossip_dynamic_inbound_limit: cfg.gossip.dynamic_inbound_limit,
gossip_static_inbound: cfg
.gossip
Expand Down
Loading
Loading