progress on gossip stuff
This commit is contained in:
parent
8473f08d10
commit
bcc738cb9d
@ -20,6 +20,8 @@ pub struct GossipCache {
|
|||||||
topic_msgs: HashMap<GossipTopic, HashMap<Vec<u8>, Key>>,
|
topic_msgs: HashMap<GossipTopic, HashMap<Vec<u8>, Key>>,
|
||||||
/// Timeout for blocks.
|
/// Timeout for blocks.
|
||||||
beacon_block: Option<Duration>,
|
beacon_block: Option<Duration>,
|
||||||
|
/// Timeout for blobs.
|
||||||
|
blobs_sidecar: Option<Duration>,
|
||||||
/// Timeout for aggregate attestations.
|
/// Timeout for aggregate attestations.
|
||||||
aggregates: Option<Duration>,
|
aggregates: Option<Duration>,
|
||||||
/// Timeout for attestations.
|
/// Timeout for attestations.
|
||||||
@ -41,6 +43,8 @@ pub struct GossipCacheBuilder {
|
|||||||
default_timeout: Option<Duration>,
|
default_timeout: Option<Duration>,
|
||||||
/// Timeout for blocks.
|
/// Timeout for blocks.
|
||||||
beacon_block: Option<Duration>,
|
beacon_block: Option<Duration>,
|
||||||
|
/// Timeout for blob sidecars.
|
||||||
|
blobs_sidecar: Option<Duration>,
|
||||||
/// Timeout for aggregate attestations.
|
/// Timeout for aggregate attestations.
|
||||||
aggregates: Option<Duration>,
|
aggregates: Option<Duration>,
|
||||||
/// Timeout for attestations.
|
/// Timeout for attestations.
|
||||||
@ -117,6 +121,7 @@ impl GossipCacheBuilder {
|
|||||||
let GossipCacheBuilder {
|
let GossipCacheBuilder {
|
||||||
default_timeout,
|
default_timeout,
|
||||||
beacon_block,
|
beacon_block,
|
||||||
|
blobs_sidecar,
|
||||||
aggregates,
|
aggregates,
|
||||||
attestation,
|
attestation,
|
||||||
voluntary_exit,
|
voluntary_exit,
|
||||||
@ -129,6 +134,7 @@ impl GossipCacheBuilder {
|
|||||||
expirations: DelayQueue::default(),
|
expirations: DelayQueue::default(),
|
||||||
topic_msgs: HashMap::default(),
|
topic_msgs: HashMap::default(),
|
||||||
beacon_block: beacon_block.or(default_timeout),
|
beacon_block: beacon_block.or(default_timeout),
|
||||||
|
blobs_sidecar: blobs_sidecar.or(default_timeout),
|
||||||
aggregates: aggregates.or(default_timeout),
|
aggregates: aggregates.or(default_timeout),
|
||||||
attestation: attestation.or(default_timeout),
|
attestation: attestation.or(default_timeout),
|
||||||
voluntary_exit: voluntary_exit.or(default_timeout),
|
voluntary_exit: voluntary_exit.or(default_timeout),
|
||||||
@ -151,6 +157,7 @@ impl GossipCache {
|
|||||||
pub fn insert(&mut self, topic: GossipTopic, data: Vec<u8>) {
|
pub fn insert(&mut self, topic: GossipTopic, data: Vec<u8>) {
|
||||||
let expire_timeout = match topic.kind() {
|
let expire_timeout = match topic.kind() {
|
||||||
GossipKind::BeaconBlock => self.beacon_block,
|
GossipKind::BeaconBlock => self.beacon_block,
|
||||||
|
GossipKind::BlobsSidecar => self.blobs_sidecar,
|
||||||
GossipKind::BeaconAggregateAndProof => self.aggregates,
|
GossipKind::BeaconAggregateAndProof => self.aggregates,
|
||||||
GossipKind::Attestation(_) => self.attestation,
|
GossipKind::Attestation(_) => self.attestation,
|
||||||
GossipKind::VoluntaryExit => self.voluntary_exit,
|
GossipKind::VoluntaryExit => self.voluntary_exit,
|
||||||
|
@ -14,11 +14,14 @@ use types::{
|
|||||||
SignedBeaconBlockMerge, SignedBeaconBlockEip4844, SignedContributionAndProof, SignedVoluntaryExit, SubnetId,
|
SignedBeaconBlockMerge, SignedBeaconBlockEip4844, SignedContributionAndProof, SignedVoluntaryExit, SubnetId,
|
||||||
SyncCommitteeMessage, SyncSubnetId,
|
SyncCommitteeMessage, SyncSubnetId,
|
||||||
};
|
};
|
||||||
|
use types::signed_blobs_sidecar::SignedBlobsSidecar;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum PubsubMessage<T: EthSpec> {
|
pub enum PubsubMessage<T: EthSpec> {
|
||||||
/// Gossipsub message providing notification of a new block.
|
/// Gossipsub message providing notification of a new block.
|
||||||
BeaconBlock(Arc<SignedBeaconBlock<T>>),
|
BeaconBlock(Arc<SignedBeaconBlock<T>>),
|
||||||
|
/// Gossipsub message providing notification of a new blobs sidecar.
|
||||||
|
BlobsSidecars(Arc<SignedBlobsSidecar<T>>),
|
||||||
/// Gossipsub message providing notification of a Aggregate attestation and associated proof.
|
/// Gossipsub message providing notification of a Aggregate attestation and associated proof.
|
||||||
AggregateAndProofAttestation(Box<SignedAggregateAndProof<T>>),
|
AggregateAndProofAttestation(Box<SignedAggregateAndProof<T>>),
|
||||||
/// Gossipsub message providing notification of a raw un-aggregated attestation with its shard id.
|
/// Gossipsub message providing notification of a raw un-aggregated attestation with its shard id.
|
||||||
@ -106,6 +109,7 @@ impl<T: EthSpec> PubsubMessage<T> {
|
|||||||
pub fn kind(&self) -> GossipKind {
|
pub fn kind(&self) -> GossipKind {
|
||||||
match self {
|
match self {
|
||||||
PubsubMessage::BeaconBlock(_) => GossipKind::BeaconBlock,
|
PubsubMessage::BeaconBlock(_) => GossipKind::BeaconBlock,
|
||||||
|
PubsubMessage::BlobsSidecars(_) => GossipKind::BlobsSidecar,
|
||||||
PubsubMessage::AggregateAndProofAttestation(_) => GossipKind::BeaconAggregateAndProof,
|
PubsubMessage::AggregateAndProofAttestation(_) => GossipKind::BeaconAggregateAndProof,
|
||||||
PubsubMessage::Attestation(attestation_data) => {
|
PubsubMessage::Attestation(attestation_data) => {
|
||||||
GossipKind::Attestation(attestation_data.0)
|
GossipKind::Attestation(attestation_data.0)
|
||||||
|
@ -11,6 +11,7 @@ use crate::Subnet;
|
|||||||
pub const TOPIC_PREFIX: &str = "eth2";
|
pub const TOPIC_PREFIX: &str = "eth2";
|
||||||
pub const SSZ_SNAPPY_ENCODING_POSTFIX: &str = "ssz_snappy";
|
pub const SSZ_SNAPPY_ENCODING_POSTFIX: &str = "ssz_snappy";
|
||||||
pub const BEACON_BLOCK_TOPIC: &str = "beacon_block";
|
pub const BEACON_BLOCK_TOPIC: &str = "beacon_block";
|
||||||
|
pub const BLOBS_SIDECAR_TOPIC: &str = "blobs_sidecar";
|
||||||
pub const BEACON_AGGREGATE_AND_PROOF_TOPIC: &str = "beacon_aggregate_and_proof";
|
pub const BEACON_AGGREGATE_AND_PROOF_TOPIC: &str = "beacon_aggregate_and_proof";
|
||||||
pub const BEACON_ATTESTATION_PREFIX: &str = "beacon_attestation_";
|
pub const BEACON_ATTESTATION_PREFIX: &str = "beacon_attestation_";
|
||||||
pub const VOLUNTARY_EXIT_TOPIC: &str = "voluntary_exit";
|
pub const VOLUNTARY_EXIT_TOPIC: &str = "voluntary_exit";
|
||||||
@ -19,8 +20,9 @@ pub const ATTESTER_SLASHING_TOPIC: &str = "attester_slashing";
|
|||||||
pub const SIGNED_CONTRIBUTION_AND_PROOF_TOPIC: &str = "sync_committee_contribution_and_proof";
|
pub const SIGNED_CONTRIBUTION_AND_PROOF_TOPIC: &str = "sync_committee_contribution_and_proof";
|
||||||
pub const SYNC_COMMITTEE_PREFIX_TOPIC: &str = "sync_committee_";
|
pub const SYNC_COMMITTEE_PREFIX_TOPIC: &str = "sync_committee_";
|
||||||
|
|
||||||
pub const CORE_TOPICS: [GossipKind; 6] = [
|
pub const CORE_TOPICS: [GossipKind; 7] = [
|
||||||
GossipKind::BeaconBlock,
|
GossipKind::BeaconBlock,
|
||||||
|
GossipKind::BlobsSidecar,
|
||||||
GossipKind::BeaconAggregateAndProof,
|
GossipKind::BeaconAggregateAndProof,
|
||||||
GossipKind::VoluntaryExit,
|
GossipKind::VoluntaryExit,
|
||||||
GossipKind::ProposerSlashing,
|
GossipKind::ProposerSlashing,
|
||||||
@ -47,6 +49,8 @@ pub struct GossipTopic {
|
|||||||
pub enum GossipKind {
|
pub enum GossipKind {
|
||||||
/// Topic for publishing beacon blocks.
|
/// Topic for publishing beacon blocks.
|
||||||
BeaconBlock,
|
BeaconBlock,
|
||||||
|
/// Topic for publishing blob sidecars.
|
||||||
|
BlobsSidecar,
|
||||||
/// Topic for publishing aggregate attestations and proofs.
|
/// Topic for publishing aggregate attestations and proofs.
|
||||||
BeaconAggregateAndProof,
|
BeaconAggregateAndProof,
|
||||||
/// Topic for publishing raw attestations on a particular subnet.
|
/// Topic for publishing raw attestations on a particular subnet.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use ssz_types::VariableList;
|
use ssz_types::VariableList;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use ssz::{Decode, DecodeError, Encode};
|
use ssz::{Decode, DecodeError, Encode};
|
||||||
|
use tree_hash::TreeHash;
|
||||||
use crate::test_utils::RngCore;
|
use crate::test_utils::RngCore;
|
||||||
use crate::bls_field_element::BlsFieldElement;
|
use crate::bls_field_element::BlsFieldElement;
|
||||||
use crate::{EthSpec, Uint256};
|
use crate::{EthSpec, Uint256};
|
||||||
@ -20,4 +21,54 @@ impl <T: EthSpec> TestRandom for Blob<T> {
|
|||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: EthSpec> Encode for Blob<T> {
|
||||||
|
fn is_ssz_fixed_len() -> bool {
|
||||||
|
<VariableList<BlsFieldElement, T::FieldElementsPerBlob> as Encode>::is_ssz_fixed_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssz_fixed_len() -> usize {
|
||||||
|
<VariableList<BlsFieldElement, T::FieldElementsPerBlob> as Encode>::ssz_fixed_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssz_bytes_len(&self) -> usize {
|
||||||
|
self.0.ssz_bytes_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssz_append(&self, buf: &mut Vec<u8>) {
|
||||||
|
self.0.ssz_append(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: EthSpec> Decode for Blob<T> {
|
||||||
|
fn is_ssz_fixed_len() -> bool {
|
||||||
|
<VariableList<BlsFieldElement, T::FieldElementsPerBlob> as Decode>::is_ssz_fixed_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssz_fixed_len() -> usize {
|
||||||
|
<VariableList<BlsFieldElement, T::FieldElementsPerBlob> as Decode>::ssz_fixed_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
|
||||||
|
<VariableList<BlsFieldElement, T::FieldElementsPerBlob>>::from_ssz_bytes(bytes).map(Self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: EthSpec> TreeHash for Blob<T> {
|
||||||
|
fn tree_hash_type() -> tree_hash::TreeHashType {
|
||||||
|
<VariableList<BlsFieldElement, T::FieldElementsPerBlob>>::tree_hash_type()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
|
||||||
|
self.0.tree_hash_packed_encoding()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tree_hash_packing_factor() -> usize {
|
||||||
|
<VariableList<BlsFieldElement, T::FieldElementsPerBlob>>::tree_hash_packing_factor()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tree_hash_root(&self) -> tree_hash::Hash256 {
|
||||||
|
self.0.tree_hash_root()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
16
consensus/types/src/blobs_sidecar.rs
Normal file
16
consensus/types/src/blobs_sidecar.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
use ssz_types::VariableList;
|
||||||
|
use crate::{EthSpec, Hash256, Slot};
|
||||||
|
use crate::blob::Blob;
|
||||||
|
use crate::kzg_proof::KzgProof;
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use ssz_derive::{Encode, Decode};
|
||||||
|
use tree_hash_derive::TreeHash;
|
||||||
|
use derivative::Derivative;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TreeHash, Derivative)]
|
||||||
|
pub struct BlobsSidecar<T: EthSpec> {
|
||||||
|
beacon_block_root: Hash256,
|
||||||
|
beacon_block_slot: Slot,
|
||||||
|
blobs: VariableList<Blob<T>, T::MaxBlobsPerBlock>,
|
||||||
|
kzg_aggregate_proof: KzgProof,
|
||||||
|
}
|
@ -1,7 +1,59 @@
|
|||||||
use crate::Uint256;
|
use crate::{EthSpec, Uint256};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ssz::{Decode, DecodeError, Encode};
|
use ssz::{Decode, DecodeError, Encode};
|
||||||
|
use tree_hash::TreeHash;
|
||||||
|
|
||||||
#[derive(Default, Debug, PartialEq, Hash, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Default, Debug, PartialEq, Hash, Clone, Copy, Serialize, Deserialize)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct BlsFieldElement(pub Uint256);
|
pub struct BlsFieldElement(pub Uint256);
|
||||||
|
|
||||||
|
|
||||||
|
impl Encode for BlsFieldElement {
|
||||||
|
fn is_ssz_fixed_len() -> bool {
|
||||||
|
<Uint256 as Encode>::is_ssz_fixed_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssz_fixed_len() -> usize {
|
||||||
|
<Uint256 as Encode>::ssz_fixed_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssz_bytes_len(&self) -> usize {
|
||||||
|
self.0.ssz_bytes_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssz_append(&self, buf: &mut Vec<u8>) {
|
||||||
|
self.0.ssz_append(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decode for BlsFieldElement {
|
||||||
|
fn is_ssz_fixed_len() -> bool {
|
||||||
|
<Uint256 as Decode>::is_ssz_fixed_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssz_fixed_len() -> usize {
|
||||||
|
<Uint256 as Decode>::ssz_fixed_len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
|
||||||
|
<Uint256 as Decode>::from_ssz_bytes(bytes).map(Self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TreeHash for BlsFieldElement {
|
||||||
|
fn tree_hash_type() -> tree_hash::TreeHashType {
|
||||||
|
<Uint256>::tree_hash_type()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
|
||||||
|
self.0.tree_hash_packed_encoding()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tree_hash_packing_factor() -> usize {
|
||||||
|
<Uint256>::tree_hash_packing_factor()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tree_hash_root(&self) -> tree_hash::Hash256 {
|
||||||
|
self.0.tree_hash_root()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -96,6 +96,8 @@ pub mod kzg_commitment;
|
|||||||
pub mod kzg_proof;
|
pub mod kzg_proof;
|
||||||
pub mod bls_field_element;
|
pub mod bls_field_element;
|
||||||
pub mod blob;
|
pub mod blob;
|
||||||
|
pub mod signed_blobs_sidecar;
|
||||||
|
pub mod blobs_sidecar;
|
||||||
|
|
||||||
use ethereum_types::{H160, H256};
|
use ethereum_types::{H160, H256};
|
||||||
|
|
||||||
|
13
consensus/types/src/signed_blobs_sidecar.rs
Normal file
13
consensus/types/src/signed_blobs_sidecar.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use bls::Signature;
|
||||||
|
use crate::blobs_sidecar::BlobsSidecar;
|
||||||
|
use crate::EthSpec;
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
use ssz_derive::{Encode, Decode};
|
||||||
|
use tree_hash_derive::TreeHash;
|
||||||
|
use derivative::Derivative;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TreeHash, Derivative)]
|
||||||
|
pub struct SignedBlobsSidecar<T: EthSpec> {
|
||||||
|
pub message: BlobsSidecar<T>,
|
||||||
|
pub signature: Signature,
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user