Skip to content

Commit

Permalink
Rename AbstractSidecar to Sidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed Jul 4, 2023
1 parent c03802c commit b0d8d90
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
16 changes: 8 additions & 8 deletions beacon_node/beacon_chain/src/blob_cache.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
use lru::LruCache;
use parking_lot::Mutex;
use types::{AbstractSidecar, EthSpec, Hash256, SidecarList};
use types::{EthSpec, Hash256, Sidecar, SidecarList};

pub const DEFAULT_BLOB_CACHE_SIZE: usize = 10;

/// A cache blobs by beacon block root.
pub struct BlobCache<T: EthSpec, Sidecar: AbstractSidecar<T>> {
blobs: Mutex<LruCache<BlobCacheId, SidecarList<T, Sidecar>>>,
pub struct BlobCache<T: EthSpec, S: Sidecar<T>> {
blobs: Mutex<LruCache<BlobCacheId, SidecarList<T, S>>>,
}

#[derive(Hash, PartialEq, Eq)]
struct BlobCacheId(Hash256);

impl<T: EthSpec, Sidecar: AbstractSidecar<T>> Default for BlobCache<T, Sidecar> {
impl<T: EthSpec, S: Sidecar<T>> Default for BlobCache<T, S> {
fn default() -> Self {
BlobCache {
blobs: Mutex::new(LruCache::new(DEFAULT_BLOB_CACHE_SIZE)),
}
}
}

impl<T: EthSpec, Sidecar: AbstractSidecar<T>> BlobCache<T, Sidecar> {
impl<T: EthSpec, S: Sidecar<T>> BlobCache<T, S> {
pub fn put(
&self,
beacon_block: Hash256,
blobs: SidecarList<T, Sidecar>,
) -> Option<SidecarList<T, Sidecar>> {
blobs: SidecarList<T, S>,
) -> Option<SidecarList<T, S>> {
self.blobs.lock().put(BlobCacheId(beacon_block), blobs)
}

pub fn pop(&self, root: &Hash256) -> Option<SidecarList<T, Sidecar>> {
pub fn pop(&self, root: &Hash256) -> Option<SidecarList<T, S>> {
self.blobs.lock().pop(&BlobCacheId(*root))
}
}
14 changes: 7 additions & 7 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ mod tests {

pub trait BlockProposal<T: EthSpec> {
type Payload: AbstractExecPayload<T>;
type Sidecar: AbstractSidecar<T>;
type Sidecar: Sidecar<T>;
}

pub struct FullBlockProposal {}
Expand Down Expand Up @@ -1491,10 +1491,10 @@ impl<T: EthSpec, B: BlockProposal<T>> ForkVersionDeserialize for BeaconBlockAndB
fork_name: ForkName,
) -> Result<Self, D::Error> {
#[derive(Deserialize)]
#[serde(bound = "T: EthSpec, Sidecar: AbstractSidecar<T>")]
struct Helper<T: EthSpec, Sidecar: AbstractSidecar<T>> {
#[serde(bound = "T: EthSpec, S: Sidecar<T>")]
struct Helper<T: EthSpec, S: Sidecar<T>> {
block: serde_json::Value,
blob_sidecars: SidecarList<T, Sidecar>,
blob_sidecars: SidecarList<T, S>,
}
let helper: Helper<T, B::Sidecar> =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Expand Down Expand Up @@ -1532,10 +1532,10 @@ impl<T: EthSpec, B: BlockProposal<T>> ForkVersionDeserialize
fork_name: ForkName,
) -> Result<Self, D::Error> {
#[derive(Deserialize)]
#[serde(bound = "T: EthSpec, Sidecar: AbstractSidecar<T>,")]
struct Helper<T: EthSpec, Sidecar: AbstractSidecar<T>> {
#[serde(bound = "T: EthSpec, S: Sidecar<T>")]
struct Helper<T: EthSpec, S: Sidecar<T>> {
blinded_block: serde_json::Value,
blinded_blob_sidecars: SidecarList<T, Sidecar>,
blinded_blob_sidecars: SidecarList<T, S>,
}
let helper: Helper<T, B::Sidecar> =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Expand Down
6 changes: 3 additions & 3 deletions consensus/types/src/blob_sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use test_random_derive::TestRandom;
use crate::test_utils::TestRandom;
use crate::{Blob, ChainSpec, Domain, EthSpec, Fork, Hash256, SignedBlobSidecar, SignedRoot, Slot};

pub trait AbstractSidecar<E: EthSpec>:
pub trait Sidecar<E: EthSpec>:
serde::Serialize
+ DeserializeOwned
+ Encode
Expand Down Expand Up @@ -86,7 +86,7 @@ pub struct BlobSidecar<T: EthSpec> {
pub kzg_proof: KzgProof,
}

impl<E: EthSpec> AbstractSidecar<E> for BlobSidecar<E> {
impl<E: EthSpec> Sidecar<E> for BlobSidecar<E> {
fn slot(&self) -> Slot {
self.slot
}
Expand Down Expand Up @@ -211,7 +211,7 @@ pub struct BlindedBlobSidecar {

impl SignedRoot for BlindedBlobSidecar {}

impl<E: EthSpec> AbstractSidecar<E> for BlindedBlobSidecar {
impl<E: EthSpec> Sidecar<E> for BlindedBlobSidecar {
fn slot(&self) -> Slot {
self.slot
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ pub use crate::beacon_block_header::BeaconBlockHeader;
pub use crate::beacon_committee::{BeaconCommittee, OwnedBeaconCommittee};
pub use crate::beacon_state::{BeaconTreeHashCache, Error as BeaconStateError, *};
pub use crate::blob_sidecar::{
AbstractSidecar, BlindedBlobSidecar, BlindedBlobSidecarList, BlobRoots, BlobSidecar,
BlobSidecarList, Blobs, SidecarList,
BlindedBlobSidecar, BlindedBlobSidecarList, BlobRoots, BlobSidecar, BlobSidecarList, Blobs,
Sidecar, SidecarList,
};
pub use crate::bls_to_execution_change::BlsToExecutionChange;
pub use crate::chain_spec::{ChainSpec, Config, Domain};
Expand Down
20 changes: 10 additions & 10 deletions consensus/types/src/signed_blob.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
test_utils::TestRandom, AbstractSidecar, BlobSidecar, ChainSpec, Domain, EthSpec, Fork,
Hash256, Signature, SignedRoot, SigningData,
test_utils::TestRandom, BlobSidecar, ChainSpec, Domain, EthSpec, Fork, Hash256, Sidecar,
Signature, SignedRoot, SigningData,
};
use bls::PublicKey;
use derivative::Derivative;
Expand All @@ -26,11 +26,11 @@ use tree_hash_derive::TreeHash;
Derivative,
arbitrary::Arbitrary,
)]
#[serde(bound = "T: EthSpec, Sidecar: AbstractSidecar<T>")]
#[arbitrary(bound = "T: EthSpec, Sidecar: AbstractSidecar<T>")]
#[derivative(Hash(bound = "T: EthSpec, Sidecar: AbstractSidecar<T>"))]
pub struct SignedSidecar<T: EthSpec, Sidecar: AbstractSidecar<T>> {
pub message: Arc<Sidecar>,
#[serde(bound = "T: EthSpec, S: Sidecar<T>")]
#[arbitrary(bound = "T: EthSpec, S: Sidecar<T>")]
#[derivative(Hash(bound = "T: EthSpec, S: Sidecar<T>"))]
pub struct SignedSidecar<T: EthSpec, S: Sidecar<T>> {
pub message: Arc<S>,
pub signature: Signature,
#[ssz(skip_serializing, skip_deserializing)]
#[tree_hash(skip_hashing)]
Expand All @@ -39,8 +39,8 @@ pub struct SignedSidecar<T: EthSpec, Sidecar: AbstractSidecar<T>> {
pub _phantom: PhantomData<T>,
}

impl<T: EthSpec, Sidecar: AbstractSidecar<T>> SignedSidecar<T, Sidecar> {
pub fn new(message: Arc<Sidecar>, signature: Signature) -> SignedSidecar<T, Sidecar> {
impl<T: EthSpec, S: Sidecar<T>> SignedSidecar<T, S> {
pub fn new(message: Arc<S>, signature: Signature) -> SignedSidecar<T, S> {
Self {
message,
signature,
Expand All @@ -49,7 +49,7 @@ impl<T: EthSpec, Sidecar: AbstractSidecar<T>> SignedSidecar<T, Sidecar> {
}
}

/// List of Signed Sidecars that implements `AbstractSidecar`.
/// List of Signed Sidecars that implements `Sidecar`.
pub type SignedSidecarList<T, Sidecar> =
VariableList<SignedSidecar<T, Sidecar>, <T as EthSpec>::MaxBlobsPerBlock>;

Expand Down
8 changes: 4 additions & 4 deletions validator_client/src/validator_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use std::path::Path;
use std::sync::Arc;
use task_executor::TaskExecutor;
use types::{
attestation::Error as AttestationError, graffiti::GraffitiString, AbstractSidecar, Address,
AggregateAndProof, Attestation, BeaconBlock, ChainSpec, ContributionAndProof, Domain, Epoch,
EthSpec, Fork, Graffiti, Hash256, Keypair, PublicKeyBytes, SelectionProof, SidecarList,
Signature, SignedAggregateAndProof, SignedBeaconBlock, SignedContributionAndProof, SignedRoot,
attestation::Error as AttestationError, graffiti::GraffitiString, Address, AggregateAndProof,
Attestation, BeaconBlock, ChainSpec, ContributionAndProof, Domain, Epoch, EthSpec, Fork,
Graffiti, Hash256, Keypair, PublicKeyBytes, SelectionProof, Sidecar, SidecarList, Signature,
SignedAggregateAndProof, SignedBeaconBlock, SignedContributionAndProof, SignedRoot,
SignedSidecar, SignedSidecarList, SignedValidatorRegistrationData, SignedVoluntaryExit, Slot,
SyncAggregatorSelectionData, SyncCommitteeContribution, SyncCommitteeMessage,
SyncSelectionProof, SyncSubnetId, ValidatorRegistrationData, VoluntaryExit,
Expand Down

0 comments on commit b0d8d90

Please sign in to comment.