general chaos

This commit is contained in:
realbigsean
2023-03-15 17:48:22 -04:00
parent 3f3358f8af
commit c26ce824a0
10 changed files with 26 additions and 65 deletions

View File

@@ -3,10 +3,12 @@ use serde::{Deserialize, Serialize};
use strum::EnumString; use strum::EnumString;
use superstruct::superstruct; use superstruct::superstruct;
use types::{ use types::{
Blobs, EthSpec, ExecutionBlockHash, ExecutionPayload, ExecutionPayloadCapella, EthSpec, ExecutionBlockHash, ExecutionPayload, ExecutionPayloadCapella,
ExecutionPayloadEip4844, ExecutionPayloadMerge, FixedVector, Transaction, Unsigned, ExecutionPayloadEip4844, ExecutionPayloadMerge, FixedVector, Transaction, Unsigned,
VariableList, Withdrawal, VariableList, Withdrawal,
}; };
use types::beacon_block_body::KzgCommitments;
use types::blob_sidecar::Blobs;
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]

View File

@@ -46,13 +46,15 @@ use types::transaction::{AccessTuple, BlobTransaction, EcdsaSignature, SignedBlo
use types::Withdrawals; use types::Withdrawals;
use types::{AbstractExecPayload, BeaconStateError, ExecPayload, VersionedHash}; use types::{AbstractExecPayload, BeaconStateError, ExecPayload, VersionedHash};
use types::{ use types::{
BlindedPayload, Blobs, BlockType, ChainSpec, Epoch, ExecutionBlockHash, ExecutionPayload, BlindedPayload, BlockType, ChainSpec, Epoch, ExecutionBlockHash, ExecutionPayload,
ExecutionPayloadCapella, ExecutionPayloadEip4844, ExecutionPayloadMerge, ForkName, ExecutionPayloadCapella, ExecutionPayloadEip4844, ExecutionPayloadMerge, ForkName,
}; };
use types::{ use types::{
ProposerPreparationData, PublicKeyBytes, Signature, SignedBeaconBlock, Slot, Transaction, ProposerPreparationData, PublicKeyBytes, Signature, SignedBeaconBlock, Slot, Transaction,
Uint256, Uint256,
}; };
use types::beacon_block_body::KzgCommitments;
use types::blob_sidecar::Blobs;
mod block_hash; mod block_hash;
mod engine_api; mod engine_api;

View File

@@ -20,11 +20,10 @@ use tokio_util::{
codec::Framed, codec::Framed,
compat::{Compat, FuturesAsyncReadCompatExt}, compat::{Compat, FuturesAsyncReadCompatExt},
}; };
use types::BlobsSidecar;
use types::{ use types::{
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockCapella, BeaconBlockMerge, BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockCapella, BeaconBlockMerge,
EmptyBlock, EthSpec, ForkContext, ForkName, Hash256, MainnetEthSpec, Signature, EmptyBlock, EthSpec, ForkContext, ForkName, Hash256, MainnetEthSpec, Signature,
SignedBeaconBlock, SignedBeaconBlock, BlobSidecar
}; };
lazy_static! { lazy_static! {
@@ -115,12 +114,12 @@ lazy_static! {
.as_ssz_bytes() .as_ssz_bytes()
.len(); .len();
pub static ref BLOBS_SIDECAR_MIN: usize = BlobsSidecar::<MainnetEthSpec>::empty().as_ssz_bytes().len(); pub static ref BLOB_SIDECAR_MIN: usize = BlobSidecar::<MainnetEthSpec>::empty().as_ssz_bytes().len();
pub static ref BLOBS_SIDECAR_MAX: usize = BlobsSidecar::<MainnetEthSpec>::max_size(); pub static ref BLOB_SIDECAR_MAX: usize = BlobSidecar::<MainnetEthSpec>::max_size();
//FIXME(sean) these are underestimates //FIXME(sean) these are underestimates
pub static ref SIGNED_BLOCK_AND_BLOBS_MIN: usize = *BLOBS_SIDECAR_MIN + *SIGNED_BEACON_BLOCK_BASE_MIN; pub static ref SIGNED_BLOCK_AND_BLOBS_MIN: usize = *BLOB_SIDECAR_MIN + *SIGNED_BEACON_BLOCK_BASE_MIN;
pub static ref SIGNED_BLOCK_AND_BLOBS_MAX: usize =*BLOBS_SIDECAR_MAX + *SIGNED_BEACON_BLOCK_EIP4844_MAX; pub static ref SIGNED_BLOCK_AND_BLOBS_MAX: usize =*BLOB_SIDECAR_MAX + *SIGNED_BEACON_BLOCK_EIP4844_MAX;
} }
/// The maximum bytes that can be sent across the RPC pre-merge. /// The maximum bytes that can be sent across the RPC pre-merge.
@@ -385,7 +384,7 @@ impl ProtocolId {
Protocol::Goodbye => RpcLimits::new(0, 0), // Goodbye request has no response Protocol::Goodbye => RpcLimits::new(0, 0), // Goodbye request has no response
Protocol::BlocksByRange => rpc_block_limits_by_fork(fork_context.current_fork()), Protocol::BlocksByRange => rpc_block_limits_by_fork(fork_context.current_fork()),
Protocol::BlocksByRoot => rpc_block_limits_by_fork(fork_context.current_fork()), Protocol::BlocksByRoot => rpc_block_limits_by_fork(fork_context.current_fork()),
Protocol::BlobsByRange => RpcLimits::new(*BLOBS_SIDECAR_MIN, *BLOBS_SIDECAR_MAX), Protocol::BlobsByRange => RpcLimits::new(*BLOB_SIDECAR_MIN, *BLOB_SIDECAR_MAX),
Protocol::BlobsByRoot => { Protocol::BlobsByRoot => {
// TODO: wrong too // TODO: wrong too
RpcLimits::new(*SIGNED_BLOCK_AND_BLOBS_MIN, *SIGNED_BLOCK_AND_BLOBS_MAX) RpcLimits::new(*SIGNED_BLOCK_AND_BLOBS_MIN, *SIGNED_BLOCK_AND_BLOBS_MAX)

View File

@@ -66,7 +66,7 @@ pub struct HotColdDB<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
/// The hot database also contains all blocks. /// The hot database also contains all blocks.
pub hot_db: Hot, pub hot_db: Hot,
/// LRU cache of deserialized blobs. Updated whenever a blob is loaded. /// LRU cache of deserialized blobs. Updated whenever a blob is loaded.
blob_cache: Mutex<LruCache<Hash256, BlobsSidecar<E>>>, blob_cache: Mutex<LruCache<Hash256, BlobSidecarList<E>>>,
/// LRU cache of deserialized blocks. Updated whenever a block is loaded. /// LRU cache of deserialized blocks. Updated whenever a block is loaded.
block_cache: Mutex<LruCache<Hash256, SignedBeaconBlock<E>>>, block_cache: Mutex<LruCache<Hash256, SignedBeaconBlock<E>>>,
/// Chain spec. /// Chain spec.
@@ -547,7 +547,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
/// Check if the blobs sidecar for a block exists on disk. /// Check if the blobs sidecar for a block exists on disk.
pub fn blobs_sidecar_exists(&self, block_root: &Hash256) -> Result<bool, Error> { pub fn blobs_sidecar_exists(&self, block_root: &Hash256) -> Result<bool, Error> {
self.get_item::<BlobsSidecar<E>>(block_root) self.get_item::<BlobSidecarList<E>>(block_root)
.map(|blobs| blobs.is_some()) .map(|blobs| blobs.is_some())
} }
@@ -568,7 +568,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
blobs_db.key_delete(DBColumn::BeaconBlob.into(), block_root.as_bytes()) blobs_db.key_delete(DBColumn::BeaconBlob.into(), block_root.as_bytes())
} }
pub fn put_blobs(&self, block_root: &Hash256, blobs: BlobsSidecar<E>) -> Result<(), Error> { pub fn put_blobs(&self, block_root: &Hash256, blobs: BlobSidecarList<E>) -> Result<(), Error> {
let blobs_db = self.blobs_db.as_ref().unwrap_or(&self.cold_db); let blobs_db = self.blobs_db.as_ref().unwrap_or(&self.cold_db);
blobs_db.put_bytes( blobs_db.put_bytes(
DBColumn::BeaconBlob.into(), DBColumn::BeaconBlob.into(),
@@ -582,7 +582,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
pub fn blobs_as_kv_store_ops( pub fn blobs_as_kv_store_ops(
&self, &self,
key: &Hash256, key: &Hash256,
blobs: &BlobsSidecar<E>, blobs: &BlobSidecarList<E>,
ops: &mut Vec<KeyValueStoreOp>, ops: &mut Vec<KeyValueStoreOp>,
) { ) {
let db_key = get_key_for_col(DBColumn::BeaconBlob.into(), key.as_bytes()); let db_key = get_key_for_col(DBColumn::BeaconBlob.into(), key.as_bytes());
@@ -925,8 +925,8 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
for op in blob_cache_ops.iter_mut() { for op in blob_cache_ops.iter_mut() {
let reverse_op = match op { let reverse_op = match op {
StoreOp::PutBlobs(block_root, _) => StoreOp::DeleteBlobs(*block_root), StoreOp::PutBlobs(block_root, _) => StoreOp::DeleteBlobs(*block_root),
StoreOp::DeleteBlobs(_) => match blobs_to_delete.pop() { StoreOp::DeleteBlobs(block_root) => match blobs_to_delete.pop() {
Some(blobs) => StoreOp::PutBlobs(blobs.beacon_block_root, Arc::new(blobs)), Some(blobs) => StoreOp::PutBlobs(*block_root, Arc::new(blobs)),
None => return Err(HotColdDBError::Rollback.into()), None => return Err(HotColdDBError::Rollback.into()),
}, },
_ => return Err(HotColdDBError::Rollback.into()), _ => return Err(HotColdDBError::Rollback.into()),
@@ -1320,12 +1320,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
} }
/// Fetch a blobs sidecar from the store. /// Fetch a blobs sidecar from the store.
pub fn get_blobs(&self, block_root: &Hash256) -> Result<Option<BlobsSidecar<E>>, Error> { pub fn get_blobs(&self, block_root: &Hash256) -> Result<Option<BlobSidecarList<E>>, Error> {
let blobs_db = self.blobs_db.as_ref().unwrap_or(&self.cold_db); let blobs_db = self.blobs_db.as_ref().unwrap_or(&self.cold_db);
match blobs_db.get_bytes(DBColumn::BeaconBlob.into(), block_root.as_bytes())? { match blobs_db.get_bytes(DBColumn::BeaconBlob.into(), block_root.as_bytes())? {
Some(ref blobs_bytes) => { Some(ref blobs_bytes) => {
let blobs = BlobsSidecar::from_ssz_bytes(blobs_bytes)?; let blobs = BlobSidecarList::from_ssz_bytes(blobs_bytes)?;
// FIXME(sean) I was attempting to use a blob cache here but was getting deadlocks, // FIXME(sean) I was attempting to use a blob cache here but was getting deadlocks,
// may want to attempt to use one again // may want to attempt to use one again
self.blob_cache.lock().put(*block_root, blobs.clone()); self.blob_cache.lock().put(*block_root, blobs.clone());

View File

@@ -1,8 +1,8 @@
use crate::{DBColumn, Error, StoreItem}; use crate::{DBColumn, Error, StoreItem};
use ssz::{Decode, Encode}; use ssz::{Decode, Encode};
use types::{ use types::{
BlobsSidecar, EthSpec, ExecutionPayload, ExecutionPayloadCapella, ExecutionPayloadEip4844, EthSpec, ExecutionPayload, ExecutionPayloadCapella, ExecutionPayloadEip4844,
ExecutionPayloadMerge, ExecutionPayloadMerge,BlobSidecarList
}; };
macro_rules! impl_store_item { macro_rules! impl_store_item {
@@ -25,7 +25,7 @@ macro_rules! impl_store_item {
impl_store_item!(ExecutionPayloadMerge); impl_store_item!(ExecutionPayloadMerge);
impl_store_item!(ExecutionPayloadCapella); impl_store_item!(ExecutionPayloadCapella);
impl_store_item!(ExecutionPayloadEip4844); impl_store_item!(ExecutionPayloadEip4844);
impl_store_item!(BlobsSidecar); impl_store_item!(BlobSidecarList);
/// This fork-agnostic implementation should be only used for writing. /// This fork-agnostic implementation should be only used for writing.
/// ///

View File

@@ -159,7 +159,7 @@ pub trait ItemStore<E: EthSpec>: KeyValueStore<E> + Sync + Send + Sized + 'stati
pub enum StoreOp<'a, E: EthSpec> { pub enum StoreOp<'a, E: EthSpec> {
PutBlock(Hash256, Arc<SignedBeaconBlock<E>>), PutBlock(Hash256, Arc<SignedBeaconBlock<E>>),
PutState(Hash256, &'a BeaconState<E>), PutState(Hash256, &'a BeaconState<E>),
PutBlobs(Hash256, Arc<BlobsSidecar<E>>), PutBlobs(Hash256, Arc<BlobSidecarList<E>>),
PutOrphanedBlobsKey(Hash256), PutOrphanedBlobsKey(Hash256),
PutStateSummary(Hash256, HotStateSummary), PutStateSummary(Hash256, HotStateSummary),
PutStateTemporaryFlag(Hash256), PutStateTemporaryFlag(Hash256),

View File

@@ -704,7 +704,7 @@ impl BeaconNodeHttpClient {
pub async fn get_blobs_sidecar<T: EthSpec>( pub async fn get_blobs_sidecar<T: EthSpec>(
&self, &self,
block_id: BlockId, block_id: BlockId,
) -> Result<Option<GenericResponse<BlobsSidecar<T>>>, Error> { ) -> Result<Option<GenericResponse<BlobSidecarList<T>>>, Error> {
let path = self.get_blobs_sidecar_path(block_id)?; let path = self.get_blobs_sidecar_path(block_id)?;
let response = match self.get_response(path, |b| b).await.optional()? { let response = match self.get_response(path, |b| b).await.optional()? {
Some(res) => res, Some(res) => res,

View File

@@ -48,6 +48,7 @@ pub struct BlobSidecar<T: EthSpec> {
} }
pub type BlobSidecarList<T> = VariableList<BlobSidecar<T>, <T as EthSpec>::MaxBlobsPerBlock>; pub type BlobSidecarList<T> = VariableList<BlobSidecar<T>, <T as EthSpec>::MaxBlobsPerBlock>;
pub type Blobs<T> = VariableList<Blob<T>, <T as EthSpec>::MaxExtraDataBytes>;
impl<T: EthSpec> SignedRoot for BlobSidecar<T> {} impl<T: EthSpec> SignedRoot for BlobSidecar<T> {}

View File

@@ -100,7 +100,6 @@ pub mod sqlite;
pub mod beacon_block_and_blob_sidecars; pub mod beacon_block_and_blob_sidecars;
pub mod blob_sidecar; pub mod blob_sidecar;
pub mod signed_blob; pub mod signed_blob;
pub mod signed_block_and_blobs;
pub mod transaction; pub mod transaction;
use ethereum_types::{H160, H256}; use ethereum_types::{H160, H256};
@@ -181,9 +180,6 @@ pub use crate::signed_beacon_block::{
}; };
pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader; pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader;
pub use crate::signed_blob::*; pub use crate::signed_blob::*;
pub use crate::signed_block_and_blobs::{
SignedBeaconBlockAndBlobsSidecar, SignedBeaconBlockAndBlobsSidecarDecode,
};
pub use crate::signed_bls_to_execution_change::SignedBlsToExecutionChange; pub use crate::signed_bls_to_execution_change::SignedBlsToExecutionChange;
pub use crate::signed_contribution_and_proof::SignedContributionAndProof; pub use crate::signed_contribution_and_proof::SignedContributionAndProof;
pub use crate::signed_voluntary_exit::SignedVoluntaryExit; pub use crate::signed_voluntary_exit::SignedVoluntaryExit;

View File

@@ -1,39 +0,0 @@
use crate::{
AbstractExecPayload, EthSpec, SignedBeaconBlock, SignedBeaconBlockEip4844,
SignedBlobSidecar,
};
use crate::{BlobsSidecar, EthSpec, SignedBeaconBlock, SignedBeaconBlockEip4844};
use derivative::Derivative;
use serde_derive::{Deserialize, Serialize};
use ssz::{Decode, DecodeError};
use ssz_derive::{Decode, Encode};
use std::sync::Arc;
use tree_hash_derive::TreeHash;
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, PartialEq)]
#[serde(bound = "T: EthSpec")]
pub struct SignedBeaconBlockAndBlobsSidecarDecode<T: EthSpec> {
pub beacon_block: SignedBeaconBlockEip4844<T>,
pub blobs_sidecar: BlobsSidecar<T>,
}
// TODO: will be removed once we decouple blobs in Gossip
#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash, Derivative)]
#[derivative(PartialEq, Hash(bound = "T: EthSpec"))]
pub struct SignedBeaconBlockAndBlobsSidecar<T: EthSpec> {
pub beacon_block: Arc<SignedBeaconBlock<T>>,
pub blobs_sidecar: Arc<BlobsSidecar<T>>,
}
impl<T: EthSpec> SignedBeaconBlockAndBlobsSidecar<T> {
pub fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
let SignedBeaconBlockAndBlobsSidecarDecode {
beacon_block,
blobs_sidecar,
} = SignedBeaconBlockAndBlobsSidecarDecode::from_ssz_bytes(bytes)?;
Ok(SignedBeaconBlockAndBlobsSidecar {
beacon_block: Arc::new(SignedBeaconBlock::Eip4844(beacon_block)),
blobs_sidecar: Arc::new(blobs_sidecar),
})
}
}