-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
387 additions
and
241 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
use anyhow::Context as _; | ||
use zksync_core::{consensus, temp_config_store::decode_yaml}; | ||
use zksync_config::configs::consensus::{ConsensusConfig, ConsensusSecrets}; | ||
use zksync_core::temp_config_store::decode_yaml_repr; | ||
use zksync_protobuf_config::proto; | ||
|
||
pub(crate) fn read_consensus_secrets() -> anyhow::Result<Option<consensus::Secrets>> { | ||
pub(crate) fn read_consensus_secrets() -> anyhow::Result<Option<ConsensusSecrets>> { | ||
// Read public config. | ||
let Ok(path) = std::env::var("CONSENSUS_SECRETS_PATH") else { | ||
return Ok(None); | ||
}; | ||
let secrets = std::fs::read_to_string(&path).context(path)?; | ||
Ok(Some(decode_yaml(&secrets).context("failed decoding YAML")?)) | ||
Ok(Some( | ||
decode_yaml_repr::<proto::consensus::Secrets>(&secrets).context("failed decoding YAML")?, | ||
)) | ||
} | ||
|
||
pub(crate) fn read_consensus_config() -> anyhow::Result<Option<consensus::Config>> { | ||
pub(crate) fn read_consensus_config() -> anyhow::Result<Option<ConsensusConfig>> { | ||
// Read public config. | ||
let Ok(path) = std::env::var("CONSENSUS_CONFIG_PATH") else { | ||
return Ok(None); | ||
}; | ||
let cfg = std::fs::read_to_string(&path).context(path)?; | ||
Ok(Some(decode_yaml(&cfg).context("failed decoding YAML")?)) | ||
Ok(Some( | ||
decode_yaml_repr::<proto::consensus::Config>(&cfg).context("failed decoding YAML")?, | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::{ | ||
collections::{BTreeMap, BTreeSet}, | ||
fmt, | ||
}; | ||
|
||
/// Public key of the validator (consensus participant) of the form "validator:public:<signature scheme>:<hex encoded key material>" | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct ValidatorPublicKey(pub String); | ||
|
||
// Secret key of the validator (consensus participant) of the form "validator:secret:<signature scheme>:<hex encoded key material>" | ||
#[derive(PartialEq)] | ||
pub struct ValidatorSecretKey(pub String); | ||
|
||
/// Public key of the node (gossip network participant) of the form "node:public:<signature scheme>:<hex encoded key material>" | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct NodePublicKey(pub String); | ||
|
||
// Secret key of the node (gossip network participant) of the form "node:secret:<signature scheme>:<hex encoded key material>" | ||
#[derive(PartialEq)] | ||
pub struct NodeSecretKey(pub String); | ||
|
||
impl fmt::Debug for ValidatorSecretKey { | ||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
fmt.write_str("<redacted>") | ||
} | ||
} | ||
|
||
impl fmt::Debug for NodeSecretKey { | ||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
fmt.write_str("<redacted>") | ||
} | ||
} | ||
|
||
/// Network address in the `<domain/ip>:port` format. | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct Host(pub String); | ||
|
||
/// Config (shared between main node and external node). | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct ConsensusConfig { | ||
/// Local socket address to listen for the incoming connections. | ||
pub server_addr: std::net::SocketAddr, | ||
/// Public address of this node (should forward to `server_addr`) | ||
/// that will be advertised to peers, so that they can connect to this | ||
/// node. | ||
pub public_addr: Host, | ||
|
||
/// Validators participating in consensus. | ||
pub validators: BTreeSet<ValidatorPublicKey>, | ||
|
||
/// Maximal allowed size of the payload in bytes. | ||
pub max_payload_size: usize, | ||
|
||
/// Limit on the number of inbound connections outside | ||
/// of the `static_inbound` set. | ||
pub gossip_dynamic_inbound_limit: usize, | ||
/// Inbound gossip connections that should be unconditionally accepted. | ||
pub gossip_static_inbound: BTreeSet<NodePublicKey>, | ||
/// Outbound gossip connections that the node should actively try to | ||
/// establish and maintain. | ||
pub gossip_static_outbound: BTreeMap<NodePublicKey, Host>, | ||
} | ||
|
||
/// Secrets need for consensus. | ||
#[derive(Debug, PartialEq)] | ||
pub struct ConsensusSecrets { | ||
pub validator_key: Option<ValidatorSecretKey>, | ||
pub node_key: Option<NodeSecretKey>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use anyhow::Context as _; | ||
use zksync_config::configs::consensus::{ | ||
ConsensusConfig, ConsensusSecrets, Host, NodePublicKey, NodeSecretKey, ValidatorPublicKey, | ||
ValidatorSecretKey, | ||
}; | ||
use zksync_protobuf::{repr::ProtoRepr, required}; | ||
|
||
use crate::proto::consensus as proto; | ||
|
||
impl ProtoRepr for proto::Config { | ||
type Type = ConsensusConfig; | ||
fn read(&self) -> anyhow::Result<Self::Type> { | ||
let read_addr = |e: &proto::NodeAddr| { | ||
let key = NodePublicKey(required(&e.key).context("key")?.clone()); | ||
let addr = Host(required(&e.addr).context("addr")?.clone()); | ||
anyhow::Ok((key, addr)) | ||
}; | ||
Ok(Self::Type { | ||
server_addr: required(&self.server_addr) | ||
.and_then(|x| Ok(x.parse()?)) | ||
.context("server_addr")?, | ||
public_addr: Host(required(&self.public_addr).context("public_addr")?.clone()), | ||
validators: self | ||
.validators | ||
.iter() | ||
.map(|x| ValidatorPublicKey(x.clone())) | ||
.collect(), | ||
max_payload_size: required(&self.max_payload_size) | ||
.and_then(|x| Ok((*x).try_into()?)) | ||
.context("max_payload_size")?, | ||
gossip_dynamic_inbound_limit: required(&self.gossip_dynamic_inbound_limit) | ||
.and_then(|x| Ok((*x).try_into()?)) | ||
.context("gossip_dynamic_inbound_limit")?, | ||
gossip_static_inbound: self | ||
.gossip_static_inbound | ||
.iter() | ||
.map(|x| NodePublicKey(x.clone())) | ||
.collect(), | ||
gossip_static_outbound: self | ||
.gossip_static_outbound | ||
.iter() | ||
.enumerate() | ||
.map(|(i, e)| read_addr(e).context(i)) | ||
.collect::<Result<_, _>>()?, | ||
}) | ||
} | ||
|
||
fn build(this: &Self::Type) -> Self { | ||
Self { | ||
server_addr: Some(this.server_addr.to_string()), | ||
public_addr: Some(this.public_addr.0.clone()), | ||
validators: this.validators.iter().map(|x| x.0.clone()).collect(), | ||
max_payload_size: Some(this.max_payload_size.try_into().unwrap()), | ||
gossip_dynamic_inbound_limit: Some( | ||
this.gossip_dynamic_inbound_limit.try_into().unwrap(), | ||
), | ||
gossip_static_inbound: this | ||
.gossip_static_inbound | ||
.iter() | ||
.map(|x| x.0.clone()) | ||
.collect(), | ||
gossip_static_outbound: this | ||
.gossip_static_outbound | ||
.iter() | ||
.map(|x| proto::NodeAddr { | ||
key: Some(x.0 .0.clone()), | ||
addr: Some(x.1 .0.clone()), | ||
}) | ||
.collect(), | ||
} | ||
} | ||
} | ||
|
||
impl ProtoRepr for proto::Secrets { | ||
type Type = ConsensusSecrets; | ||
fn read(&self) -> anyhow::Result<Self::Type> { | ||
Ok(Self::Type { | ||
validator_key: self | ||
.validator_key | ||
.as_ref() | ||
.map(|x| ValidatorSecretKey(x.clone())), | ||
node_key: self.node_key.as_ref().map(|x| NodeSecretKey(x.clone())), | ||
}) | ||
} | ||
|
||
fn build(this: &Self::Type) -> Self { | ||
Self { | ||
validator_key: this.validator_key.as_ref().map(|x| x.0.clone()), | ||
node_key: this.node_key.as_ref().map(|x| x.0.clone()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![allow(warnings)] | ||
|
||
pub use self::{config::*, core::*}; | ||
|
||
include!(concat!(env!("OUT_DIR"), "/src/proto/gen.rs")); |
Oops, something went wrong.