Skip to content

Commit 77d043f

Browse files
fix(consensus): Debug page server port reuse (#4273)
## What ❔ Introduces a new consensus version that contains a fix that solves the debug page server being stopped because another debug page server is already using the same port. Also adds new config parameters: one that determines how often a node reads from the ConsensusRegistry contract for validator set updates, another for the maximum size of transactions propagated in the p2p network. ## Is this a breaking change? - [ ] Yes - [x] No ## Operational changes The new parameters can be left at their default values. ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`. --------- Co-authored-by: perekopskiy <[email protected]>
1 parent 7433b51 commit 77d043f

File tree

13 files changed

+131
-78
lines changed

13 files changed

+131
-78
lines changed

core/Cargo.lock

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

core/Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,16 @@ bellman = { package = "zksync_bellman", version = "=0.32.1" }
268268
zksync_vm2 = "=0.4.0"
269269

270270
# Consensus dependencies.
271-
zksync_concurrency = "=0.11.4"
272-
zksync_consensus_bft = "=0.11.4"
273-
zksync_consensus_crypto = "=0.11.4"
274-
zksync_consensus_engine = "=0.11.4"
275-
zksync_consensus_executor = "=0.11.4"
276-
zksync_consensus_network = "=0.11.4"
277-
zksync_consensus_roles = "=0.11.4"
278-
zksync_consensus_utils = "=0.11.4"
279-
zksync_protobuf = "=0.11.4"
280-
zksync_protobuf_build = "=0.11.4"
271+
zksync_concurrency = "=0.13"
272+
zksync_consensus_bft = "=0.13"
273+
zksync_consensus_crypto = "=0.13"
274+
zksync_consensus_engine = "=0.13"
275+
zksync_consensus_executor = "=0.13"
276+
zksync_consensus_network = "=0.13"
277+
zksync_consensus_roles = "=0.13"
278+
zksync_consensus_utils = "=0.13"
279+
zksync_protobuf = "=0.13"
280+
zksync_protobuf_build = "=0.13"
281281

282282
# "Local" dependencies
283283
zksync_multivm = { version = "28.7.0-non-semver-compat", path = "lib/multivm" }

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,14 @@ pub struct ConsensusConfig {
146146
/// that will be advertised to peers, so that they can connect to this
147147
/// node.
148148
pub public_addr: Host,
149+
/// Local socket address to expose the node debug page.
150+
pub debug_page_addr: Option<std::net::SocketAddr>,
149151
/// Maximal allowed size of the payload in bytes.
150152
#[config(default_t = ByteSize(2_500_000), with = Fallback(SizeUnit::Bytes))]
151153
pub max_payload_size: ByteSize,
154+
/// Maximal allowed size of transactions propagated through the p2p network, in bytes.
155+
#[config(default_t = ByteSize(1_000_000), with = Fallback(SizeUnit::Bytes))]
156+
pub max_transaction_size: ByteSize,
152157
/// View timeout duration.
153158
#[config(default_t = Duration::from_secs(2), with = Fallback(CustomDurationFormat))]
154159
pub view_timeout: Duration,
@@ -170,19 +175,20 @@ pub struct ConsensusConfig {
170175
/// establish and maintain.
171176
#[config(default, with = Entries::WELL_KNOWN.named("key", "addr"))]
172177
pub gossip_static_outbound: BTreeMap<NodePublicKey, Host>,
178+
/// Rate limiting configuration for the p2p RPCs.
179+
#[config(nest)]
180+
pub rpc: RpcConfig,
181+
182+
/// Rate at which the node tries to read from the ConsensusRegistry contract, in milliseconds.
183+
/// It should be set to a value that is much less than what we expect a validator epoch to be.
184+
#[config(default_t = Duration::from_secs(30), with = Fallback(CustomDurationFormat))]
185+
pub consensus_registry_read_rate: Duration,
173186

174187
/// MAIN NODE ONLY: consensus genesis specification.
175188
/// Used to (re)initialize genesis if needed.
176189
/// External nodes fetch the genesis from the main node.
177190
#[config(nest)]
178191
pub genesis_spec: Option<GenesisSpec>,
179-
180-
/// Rate limiting configuration for the p2p RPCs.
181-
#[config(nest)]
182-
pub rpc: RpcConfig,
183-
184-
/// Local socket address to expose the node debug page.
185-
pub debug_page_addr: Option<std::net::SocketAddr>,
186192
}
187193

188194
impl ConsensusConfig {
@@ -200,6 +206,7 @@ impl ConsensusConfig {
200206
server_addr: "127.0.0.1:0".parse().unwrap(),
201207
public_addr: Host("127.0.0.1:0".into()),
202208
max_payload_size: ByteSize(2000000),
209+
max_transaction_size: ByteSize(1000000),
203210
view_timeout: Duration::from_secs(3),
204211
max_batch_size: ByteSize(125001024),
205212
gossip_dynamic_inbound_limit: 10,
@@ -224,7 +231,8 @@ impl ConsensusConfig {
224231
rpc: RpcConfig {
225232
get_block_rps: NonZeroUsize::new(5).unwrap(),
226233
},
227-
debug_page_addr: Some("127.0.0.1:0".parse().unwrap()),
234+
debug_page_addr: Some("127.0.0.1:5000".parse().unwrap()),
235+
consensus_registry_read_rate: Duration::from_secs(30),
228236
}
229237
}
230238
}
@@ -255,6 +263,7 @@ mod tests {
255263
server_addr: "127.0.0.1:2954".parse().unwrap(),
256264
public_addr: Host("127.0.0.1:2954".into()),
257265
max_payload_size: ByteSize(2000000),
266+
max_transaction_size: ByteSize(1000000),
258267
view_timeout: Duration::from_secs(3),
259268
max_batch_size: ByteSize(125001024),
260269
gossip_dynamic_inbound_limit: 10,
@@ -280,6 +289,7 @@ mod tests {
280289
get_block_rps: NonZeroUsize::new(5).unwrap(),
281290
},
282291
debug_page_addr: Some("127.0.0.1:3000".parse().unwrap()),
292+
consensus_registry_read_rate: Duration::from_secs(30),
283293
}
284294
}
285295

@@ -290,6 +300,7 @@ mod tests {
290300
public_addr: 127.0.0.1:2954
291301
debug_page_addr: 127.0.0.1:3000
292302
max_payload_size: 2000000
303+
max_transaction_size: 1000000
293304
view_timeout:
294305
seconds: 3
295306
nanos: 0
@@ -314,6 +325,9 @@ mod tests {
314325
port: 2954
315326
rpc:
316327
get_block_rps: 5
328+
consensus_registry_read_rate:
329+
seconds: 30
330+
nanos: 0
317331
"#;
318332
let yaml = Yaml::new("test.yml", serde_yaml::from_str(yaml).unwrap()).unwrap();
319333
let config: ConsensusConfig = test_complete(yaml).unwrap();
@@ -327,6 +341,7 @@ mod tests {
327341
public_addr: 127.0.0.1:2954
328342
debug_page_addr: 127.0.0.1:3000
329343
max_payload_size: 2000000 bytes
344+
max_transaction_size: 1000000 bytes
330345
view_timeout: 3s
331346
gossip_dynamic_inbound_limit: 10
332347
gossip_static_inbound:
@@ -346,6 +361,9 @@ mod tests {
346361
port: 2954
347362
rpc:
348363
get_block_rps: 5
364+
consensus_registry_read_rate:
365+
seconds: 30
366+
nanos: 0
349367
"#;
350368
let yaml = Yaml::new("test.yml", serde_yaml::from_str(yaml).unwrap()).unwrap();
351369
let config: ConsensusConfig = test_complete(yaml).unwrap();

core/node/consensus/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ pub(super) fn executor(
148148
server_addr: cfg.server_addr,
149149
public_addr: net::Host(cfg.public_addr.0.clone()),
150150
max_payload_size: cfg.max_payload_size.0 as usize,
151+
max_tx_size: cfg.max_transaction_size.0 as usize,
151152
view_timeout: cfg.view_timeout.try_into().context("view_timeout")?,
152153
node_key: node_key(secrets)
153154
.context("node_key")?

core/node/consensus/src/en.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,18 @@ impl EN {
107107
.wrap("Store::new()")?;
108108
s.spawn_bg(async { Ok(runner.run(ctx).await.context("Store::runner()")?) });
109109

110-
let (engine_manager, engine_runner) = EngineManager::new(ctx, Box::new(store.clone()))
111-
.await
112-
.wrap("BlockStore::new()")?;
110+
let (engine_manager, engine_runner) = EngineManager::new(
111+
ctx,
112+
Box::new(store.clone()),
113+
time::Duration::seconds(
114+
cfg.consensus_registry_read_rate
115+
.as_secs()
116+
.try_into()
117+
.unwrap(),
118+
),
119+
)
120+
.await
121+
.wrap("BlockStore::new()")?;
113122
s.spawn_bg(async { Ok(engine_runner.run(ctx).await.context("BlockStore::run()")?) });
114123

115124
let executor = executor::Executor {

core/node/consensus/src/mn.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use anyhow::Context as _;
4-
use zksync_concurrency::{ctx, error::Wrap as _, scope};
4+
use zksync_concurrency::{ctx, error::Wrap as _, scope, time};
55
use zksync_config::configs::consensus::{ConsensusConfig, ConsensusSecrets};
66
use zksync_consensus_engine::EngineManager;
77
use zksync_consensus_executor::{self as executor};
@@ -55,9 +55,18 @@ pub async fn run_main_node(
5555
.wrap("Store::new()")?;
5656
s.spawn_bg(async { Ok(runner.run(ctx).await.context("Store::runner()")?) });
5757

58-
let (engine_manager, engine_runner) = EngineManager::new(ctx, Box::new(store.clone()))
59-
.await
60-
.wrap("BlockStore::new()")?;
58+
let (engine_manager, engine_runner) = EngineManager::new(
59+
ctx,
60+
Box::new(store.clone()),
61+
time::Duration::seconds(
62+
cfg.consensus_registry_read_rate
63+
.as_secs()
64+
.try_into()
65+
.unwrap(),
66+
),
67+
)
68+
.await
69+
.wrap("BlockStore::new()")?;
6170
s.spawn_bg(async { Ok(engine_runner.run(ctx).await.context("BlockStore::run()")?) });
6271

6372
let executor = executor::Executor {

core/node/consensus/src/storage/store.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ impl EngineInterface for Store {
327327
.await
328328
.wrap("set_replica_state()")
329329
}
330+
331+
async fn push_tx(&self, _ctx: &ctx::Ctx, _tx: engine::Transaction) -> ctx::Result<bool> {
332+
unimplemented!()
333+
}
330334
}
331335

332336
/// Background task of the `Store`.

core/node/consensus/src/testonly.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn make_config(
135135
server_addr: *cfg.server_addr,
136136
public_addr: config::Host(cfg.public_addr.0.clone()),
137137
max_payload_size: u64::MAX.into(),
138+
max_transaction_size: u64::MAX.into(),
138139
max_batch_size: u64::MAX.into(),
139140
view_timeout: Duration::from_secs(2),
140141
gossip_dynamic_inbound_limit: cfg.gossip.dynamic_inbound_limit,
@@ -158,6 +159,7 @@ fn make_config(
158159
genesis_spec,
159160
rpc: RpcConfig::default(),
160161
debug_page_addr: None,
162+
consensus_registry_read_rate: Duration::from_secs(1),
161163
}
162164
}
163165

core/node/consensus/src/tests/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ use anyhow::Context as _;
44
use rand::Rng as _;
55
use test_casing::{test_casing, Product};
66
use tracing::Instrument as _;
7-
use zksync_concurrency::{ctx, error::Wrap as _, scope, time};
7+
use zksync_concurrency::{
8+
ctx,
9+
error::Wrap as _,
10+
scope,
11+
time::{self, Duration},
12+
};
813
use zksync_config::configs::consensus as config;
914
use zksync_consensus_crypto::TextFmt as _;
1015
use zksync_consensus_engine::{EngineInterface as _, EngineManager};
@@ -170,9 +175,10 @@ async fn test_validator_block_store(version: ProtocolVersionId) {
170175
.await
171176
.unwrap();
172177
s.spawn_bg(runner.run(ctx));
173-
let (engine_manager, runner) = EngineManager::new(ctx, Box::new(store.clone()))
174-
.await
175-
.unwrap();
178+
let (engine_manager, runner) =
179+
EngineManager::new(ctx, Box::new(store.clone()), Duration::seconds(1))
180+
.await
181+
.unwrap();
176182
s.spawn_bg(runner.run(ctx));
177183
engine_manager
178184
.queue_block(ctx, block.clone())

core/node/state_keeper/src/executor/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ async fn complex_rollback_test() {
468468
block_hasher.push_tx_hash(txs2[1].hash());
469469
let block_hash2 = block_hasher.finalize(ProtocolVersionId::latest());
470470

471-
let blocks = vec![
471+
let blocks = [
472472
(
473473
L2BlockEnv {
474474
number: 2,

0 commit comments

Comments
 (0)