-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare types for network queueing system (#151)
- Loading branch information
Showing
13 changed files
with
195 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::OperatorId; | ||
use alloy::primitives::keccak256; | ||
use derive_more::{Deref, From}; | ||
|
||
const COMMITTEE_ID_LEN: usize = 32; | ||
|
||
/// Unique identifier for a committee | ||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash, From, Deref)] | ||
pub struct CommitteeId(pub [u8; COMMITTEE_ID_LEN]); | ||
|
||
impl From<Vec<OperatorId>> for CommitteeId { | ||
fn from(mut operator_ids: Vec<OperatorId>) -> Self { | ||
// Sort the operator IDs | ||
operator_ids.sort(); | ||
let mut data: Vec<u8> = Vec::with_capacity(operator_ids.len() * 4); | ||
|
||
// Add the operator IDs as 32 byte values | ||
for id in operator_ids { | ||
data.extend_from_slice(&id.to_le_bytes()); | ||
} | ||
|
||
// Hash it all | ||
keccak256(data).0.into() | ||
} | ||
} | ||
|
||
impl TryFrom<&[u8]> for CommitteeId { | ||
type Error = (); | ||
|
||
fn try_from(value: &[u8]) -> Result<Self, ()> { | ||
value.try_into().map(CommitteeId).map_err(|_| ()) | ||
} | ||
} |
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,12 +1,15 @@ | ||
pub use cluster::{Cluster, ClusterId, ClusterMember, ValidatorIndex, ValidatorMetadata}; | ||
pub use committee::CommitteeId; | ||
pub use operator::{Operator, OperatorId}; | ||
pub use share::Share; | ||
mod cluster; | ||
mod committee; | ||
pub mod consensus; | ||
pub mod domain_type; | ||
pub mod message; | ||
pub mod msgid; | ||
mod operator; | ||
pub mod partial_sig; | ||
mod share; | ||
mod sql_conversions; | ||
mod util; |
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,93 @@ | ||
use crate::{OperatorId, ValidatorIndex}; | ||
use ssz::{Decode, DecodeError, Encode}; | ||
use ssz_derive::{Decode, Encode}; | ||
use types::{Hash256, Signature, Slot}; | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub enum PartialSignatureKind { | ||
// PostConsensusPartialSig is a partial signature over a decided duty (attestation data, block, etc) | ||
PostConsensus = 0, | ||
// RandaoPartialSig is a partial signature over randao reveal | ||
RandaoPartialSig = 1, | ||
// SelectionProofPartialSig is a partial signature for aggregator selection proof | ||
SelectionProofPartialSig = 2, | ||
// ContributionProofs is the partial selection proofs for sync committee contributions (it's an array of sigs) | ||
ContributionProofs = 3, | ||
// ValidatorRegistrationPartialSig is a partial signature over a ValidatorRegistration object | ||
ValidatorRegistration = 4, | ||
// VoluntaryExitPartialSig is a partial signature over a VoluntaryExit object | ||
VoluntaryExit = 5, | ||
} | ||
|
||
impl TryFrom<u64> for PartialSignatureKind { | ||
type Error = (); | ||
|
||
fn try_from(value: u64) -> Result<Self, Self::Error> { | ||
match value { | ||
0 => Ok(PartialSignatureKind::PostConsensus), | ||
1 => Ok(PartialSignatureKind::RandaoPartialSig), | ||
2 => Ok(PartialSignatureKind::SelectionProofPartialSig), | ||
3 => Ok(PartialSignatureKind::ContributionProofs), | ||
4 => Ok(PartialSignatureKind::ValidatorRegistration), | ||
5 => Ok(PartialSignatureKind::VoluntaryExit), | ||
_ => Err(()), | ||
} | ||
} | ||
} | ||
|
||
const U64_SIZE: usize = 8; // u64 is 8 bytes | ||
|
||
impl Encode for PartialSignatureKind { | ||
fn is_ssz_fixed_len() -> bool { | ||
true | ||
} | ||
|
||
fn ssz_append(&self, buf: &mut Vec<u8>) { | ||
buf.extend_from_slice(&(*self as u64).to_le_bytes()); | ||
} | ||
|
||
fn ssz_fixed_len() -> usize { | ||
U64_SIZE | ||
} | ||
|
||
fn ssz_bytes_len(&self) -> usize { | ||
U64_SIZE | ||
} | ||
} | ||
|
||
impl Decode for PartialSignatureKind { | ||
fn is_ssz_fixed_len() -> bool { | ||
true | ||
} | ||
|
||
fn ssz_fixed_len() -> usize { | ||
U64_SIZE | ||
} | ||
|
||
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { | ||
if bytes.len() != U64_SIZE { | ||
return Err(DecodeError::InvalidByteLength { | ||
len: bytes.len(), | ||
expected: U64_SIZE, | ||
}); | ||
} | ||
let value = u64::from_le_bytes(bytes.try_into().unwrap()); | ||
value.try_into().map_err(|_| DecodeError::NoMatchingVariant) | ||
} | ||
} | ||
|
||
// A partial signature specific message | ||
#[derive(Clone, Debug, Encode, Decode)] | ||
pub struct PartialSignatureMessages { | ||
pub kind: PartialSignatureKind, | ||
pub slot: Slot, | ||
pub messages: Vec<PartialSignatureMessage>, | ||
} | ||
|
||
#[derive(Clone, Debug, Encode, Decode)] | ||
pub struct PartialSignatureMessage { | ||
pub partial_signature: Signature, | ||
pub signing_root: Hash256, | ||
pub signer: OperatorId, | ||
pub validator_index: ValidatorIndex, | ||
} |
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
Oops, something went wrong.