-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into k8s_deploy_script
- Loading branch information
Showing
5 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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,12 +1,10 @@ | ||
CODEOWNERS @brunoffranca | ||
|
||
/node/actors/consensus/ @brunoffranca @moshababo | ||
/node/actors/executor/ @brunoffranca @pompon0 @slowli | ||
/node/actors/network/ @pompon0 | ||
/node/actors/sync_blocks/ @slowli | ||
|
||
/node/libs/concurrency/ @pompon0 | ||
/node/libs/crypto/ @brunoffranca | ||
/node/libs/protobuf/ @pompon0 | ||
/node/libs/protobuf_build/ @pompon0 | ||
/node/libs/storage/ @slowli | ||
/node/libs/protobuf_build/ @pompon0 |
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,33 @@ | ||
//! Trait for defining proto conversion for external types. | ||
|
||
use crate::build::prost_reflect::ReflectMessage; | ||
use anyhow::Context as _; | ||
|
||
/// Trait reverse to `zksync_protobuf::ProtoFmt` for cases where | ||
/// you would like to specify a custom proto encoding for an externally defined type. | ||
pub trait ProtoRepr: ReflectMessage + Default { | ||
/// The externally defined type associated with the proto Self. | ||
type Type; | ||
/// Converts proto Self to `Type`. | ||
fn read(&self) -> anyhow::Result<Self::Type>; | ||
/// Converts `Type` to proto Self. | ||
fn build(this: &Self::Type) -> Self; | ||
} | ||
|
||
/// Parses a required proto field. | ||
pub fn read_required_repr<P: ProtoRepr>(field: &Option<P>) -> anyhow::Result<P::Type> { | ||
field.as_ref().context("missing field")?.read() | ||
} | ||
|
||
/// Encodes a proto message. | ||
/// Currently it outputs a canonical encoding, but `decode` accepts | ||
/// non-canonical encoding as well. | ||
pub fn encode<P: ProtoRepr>(msg: &P::Type) -> Vec<u8> { | ||
let msg = P::build(msg); | ||
super::canonical_raw(&msg.encode_to_vec(), &msg.descriptor()).unwrap() | ||
} | ||
|
||
/// Decodes a proto message. | ||
pub fn decode<P: ProtoRepr>(bytes: &[u8]) -> anyhow::Result<P::Type> { | ||
P::read(&P::decode(bytes)?) | ||
} |
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,27 @@ | ||
//! Util types for generating random values in tests. | ||
|
||
use rand::Rng; | ||
|
||
/// Generator of random values. | ||
pub struct GenValue<'a, R: Rng> { | ||
/// Underlying RNG. | ||
pub rng: &'a mut R, | ||
/// Generate values with only required fields. | ||
pub required_only: bool, | ||
/// Generate decimal fractions for f64 | ||
/// to avoid rounding errors of decimal encodings. | ||
pub decimal_fractions: bool, | ||
} | ||
|
||
impl<'a, R: Rng> GenValue<'a, R> { | ||
/// Generates a random value of type `C`. | ||
pub fn gen<C: RandomValue>(&mut self) -> C { | ||
C::sample(self) | ||
} | ||
} | ||
|
||
/// Types that can be used to generate a random instance. | ||
pub trait RandomValue { | ||
/// Generates a random value. | ||
fn sample(g: &mut GenValue<impl Rng>) -> Self; | ||
} |
3 changes: 3 additions & 0 deletions
3
node/libs/protobuf/src/testonly.rs → node/libs/protobuf/src/testonly/mod.rs
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