Skip to content

Commit

Permalink
feat: consensus support for pruning (BFT-473) (#2334)
Browse files Browse the repository at this point in the history
Added a task which is monitoring the persisted block range and notifies
consensus if it shrinks.
  • Loading branch information
pompon0 authored Jun 28, 2024
1 parent f508ac1 commit abc4256
Show file tree
Hide file tree
Showing 21 changed files with 715 additions and 319 deletions.
241 changes: 193 additions & 48 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ zk_evm_1_3_3 = { package = "zk_evm", git = "https://github.com/matter-labs/era-z
zk_evm_1_4_0 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.0" }
zk_evm_1_4_1 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.4.1" }
zk_evm_1_5_0 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", branch = "v1.5.0" }
zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_consensus_bft = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_consensus_network = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_consensus_utils = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "3e6f101ee4124308c4c974caaa259d524549b0c6" }
zksync_concurrency = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }
zksync_consensus_bft = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }
zksync_consensus_crypto = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }
zksync_consensus_executor = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }
zksync_consensus_network = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }
zksync_consensus_roles = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }
zksync_consensus_storage = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }
zksync_consensus_utils = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }
zksync_protobuf = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }
zksync_protobuf_build = { version = "0.1.0", git = "https://github.com/matter-labs/era-consensus.git", rev = "ba7b171456e7362eada685234a91c20907b6a097" }

# "Local" dependencies
zksync_multivm = { path = "core/lib/multivm" }
Expand Down
1 change: 1 addition & 0 deletions core/lib/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ categories.workspace = true
zksync_basic_types.workspace = true
zksync_crypto_primitives.workspace = true
zksync_consensus_utils.workspace = true
zksync_concurrency.workspace = true

anyhow.workspace = true
rand.workspace = true
Expand Down
26 changes: 26 additions & 0 deletions core/lib/config/src/configs/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::{BTreeMap, BTreeSet};

use secrecy::{ExposeSecret as _, Secret};
use zksync_basic_types::L2ChainId;
use zksync_concurrency::{limiter, time};

/// `zksync_consensus_crypto::TextFmt` representation of `zksync_consensus_roles::validator::PublicKey`.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down Expand Up @@ -65,6 +66,22 @@ pub struct GenesisSpec {
pub leader: ValidatorPublicKey,
}

#[derive(Clone, Debug, PartialEq, Default)]
pub struct RpcConfig {
/// Max number of blocks that can be send from/to each peer.
/// Defaults to 10 blocks/s/connection.
pub get_block_rate: Option<limiter::Rate>,
}

impl RpcConfig {
pub fn get_block_rate(&self) -> limiter::Rate {
self.get_block_rate.unwrap_or(limiter::Rate {
burst: 10,
refresh: time::Duration::milliseconds(100),
})
}
}

/// Config (shared between main node and external node).
#[derive(Clone, Debug, PartialEq)]
pub struct ConsensusConfig {
Expand All @@ -91,6 +108,15 @@ pub struct ConsensusConfig {
/// Used to (re)initialize genesis if needed.
/// External nodes fetch the genesis from the main node.
pub genesis_spec: Option<GenesisSpec>,

/// Rate limiting configuration for the p2p RPCs.
pub rpc: Option<RpcConfig>,
}

impl ConsensusConfig {
pub fn rpc(&self) -> RpcConfig {
self.rpc.clone().unwrap_or_default()
}
}

/// Secrets need for consensus.
Expand Down
9 changes: 9 additions & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,15 @@ impl Distribution<configs::consensus::ConsensusConfig> for EncodeDist {
.map(|_| (NodePublicKey(self.sample(rng)), Host(self.sample(rng))))
.collect(),
genesis_spec: self.sample(rng),
rpc: self.sample(rng),
}
}
}

impl Distribution<configs::consensus::RpcConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::consensus::RpcConfig {
configs::consensus::RpcConfig {
get_block_rate: self.sample(rng),
}
}
}
Expand Down

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

This file was deleted.

Loading

0 comments on commit abc4256

Please sign in to comment.