make signed block + sidecar consensus spec

This commit is contained in:
realbigsean 2022-11-10 14:22:30 -05:00
parent cb393f5b7d
commit fe04d945cc
No known key found for this signature in database
GPG Key ID: B372B64D866BF8CC
8 changed files with 37 additions and 19 deletions

View File

@ -3,7 +3,7 @@ use crate::rpc::{
protocol::{Encoding, Protocol, ProtocolId, RPCError, Version, ERROR_TYPE_MAX, ERROR_TYPE_MIN}, protocol::{Encoding, Protocol, ProtocolId, RPCError, Version, ERROR_TYPE_MAX, ERROR_TYPE_MIN},
}; };
use crate::rpc::{InboundRequest, OutboundRequest, RPCCodedResponse, RPCResponse}; use crate::rpc::{InboundRequest, OutboundRequest, RPCCodedResponse, RPCResponse};
use crate::{rpc::methods::*, EnrSyncCommitteeBitfield}; use crate::{rpc::methods::*, EnrSyncCommitteeBitfield, SignedBeaconBlockAndBlobsSidecar};
use libp2p::bytes::BytesMut; use libp2p::bytes::BytesMut;
use snap::read::FrameDecoder; use snap::read::FrameDecoder;
use snap::write::FrameEncoder; use snap::write::FrameEncoder;
@ -642,7 +642,7 @@ fn handle_v2_response<T: EthSpec>(
}, },
Protocol::BlobsByRange => match fork_name { Protocol::BlobsByRange => match fork_name {
ForkName::Eip4844 => Ok(Some(RPCResponse::BlobsByRange(Arc::new( ForkName::Eip4844 => Ok(Some(RPCResponse::BlobsByRange(Arc::new(
BlobsSidecar::from_ssz_bytes(decoded_buffer)?, SignedBeaconBlockAndBlobsSidecar::from_ssz_bytes(decoded_buffer)?,
)))), )))),
_ => Err(RPCError::ErrorResponse( _ => Err(RPCError::ErrorResponse(
RPCResponseErrorCode::InvalidRequest, RPCResponseErrorCode::InvalidRequest,

View File

@ -14,6 +14,7 @@ use strum::IntoStaticStr;
use superstruct::superstruct; use superstruct::superstruct;
use types::blobs_sidecar::BlobsSidecar; use types::blobs_sidecar::BlobsSidecar;
use types::{Epoch, EthSpec, Hash256, SignedBeaconBlock, Slot}; use types::{Epoch, EthSpec, Hash256, SignedBeaconBlock, Slot};
use crate::SignedBeaconBlockAndBlobsSidecar;
/// Maximum number of blocks in a single request. /// Maximum number of blocks in a single request.
pub type MaxRequestBlocks = U1024; pub type MaxRequestBlocks = U1024;
@ -258,7 +259,7 @@ pub enum RPCResponse<T: EthSpec> {
BlocksByRoot(Arc<SignedBeaconBlock<T>>), BlocksByRoot(Arc<SignedBeaconBlock<T>>),
/// A response to a get BLOBS_BY_RANGE request /// A response to a get BLOBS_BY_RANGE request
BlobsByRange(Arc<BlobsSidecar<T>>), BlobsByRange(Arc<SignedBeaconBlockAndBlobsSidecar<T>>),
/// A PONG response to a PING request. /// A PONG response to a PING request.
Pong(Ping), Pong(Ping),

View File

@ -11,6 +11,7 @@ use crate::rpc::{
}, },
OutboundRequest, SubstreamId, OutboundRequest, SubstreamId,
}; };
use crate::SignedBeaconBlockAndBlobsSidecar;
/// Identifier of requests sent by a peer. /// Identifier of requests sent by a peer.
pub type PeerRequestId = (ConnectionId, SubstreamId); pub type PeerRequestId = (ConnectionId, SubstreamId);
@ -69,7 +70,7 @@ pub enum Response<TSpec: EthSpec> {
/// A response to a get BLOCKS_BY_RANGE request. A None response signals the end of the batch. /// A response to a get BLOCKS_BY_RANGE request. A None response signals the end of the batch.
BlocksByRange(Option<Arc<SignedBeaconBlock<TSpec>>>), BlocksByRange(Option<Arc<SignedBeaconBlock<TSpec>>>),
/// A response to a get BLOBS_BY_RANGE request. A None response signals the end of the batch. /// A response to a get BLOBS_BY_RANGE request. A None response signals the end of the batch.
BlobsByRange(Option<Arc<BlobsSidecar<TSpec>>>), BlobsByRange(Option<Arc<SignedBeaconBlockAndBlobsSidecar<TSpec>>>),
/// A response to a get BLOCKS_BY_ROOT request. /// A response to a get BLOCKS_BY_ROOT request.
BlocksByRoot(Option<Arc<SignedBeaconBlock<TSpec>>>), BlocksByRoot(Option<Arc<SignedBeaconBlock<TSpec>>>),
} }

View File

@ -18,16 +18,6 @@ use types::{
SignedContributionAndProof, SignedVoluntaryExit, SubnetId, SyncCommitteeMessage, SyncSubnetId, SignedContributionAndProof, SignedVoluntaryExit, SubnetId, SyncCommitteeMessage, SyncSubnetId,
}; };
/// TODO(pawan): move this to consensus/types? strictly not a consensus type
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, PartialEq)]
#[serde(bound = "T: EthSpec")]
pub struct SignedBeaconBlockAndBlobsSidecar<T: EthSpec> {
// TODO(pawan): switch to a SignedBeaconBlock and use ssz offsets for decoding to make this
// future proof?
pub beacon_block: SignedBeaconBlockEip4844<T>,
pub blobs_sidecar: BlobsSidecar<T>,
}
#[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.

View File

@ -220,7 +220,7 @@ impl<T: BeaconChainTypes> Processor<T> {
&mut self, &mut self,
peer_id: PeerId, peer_id: PeerId,
request_id: RequestId, request_id: RequestId,
blob_wrapper: Option<Arc<BlobsSidecar<T::EthSpec>>>, blob_wrapper: Option<Arc<SignedBeaconBlockAndBlobsSidecar<T::EthSpec>>>,
) { ) {
trace!( trace!(
self.log, self.log,

View File

@ -45,7 +45,7 @@ use beacon_chain::{BeaconChain, BeaconChainTypes, BlockError, EngineState};
use futures::StreamExt; use futures::StreamExt;
use lighthouse_network::rpc::methods::MAX_REQUEST_BLOCKS; use lighthouse_network::rpc::methods::MAX_REQUEST_BLOCKS;
use lighthouse_network::types::{NetworkGlobals, SyncState}; use lighthouse_network::types::{NetworkGlobals, SyncState};
use lighthouse_network::SyncInfo; use lighthouse_network::{SignedBeaconBlockAndBlobsSidecar, SyncInfo};
use lighthouse_network::{PeerAction, PeerId}; use lighthouse_network::{PeerAction, PeerId};
use slog::{crit, debug, error, info, trace, Logger}; use slog::{crit, debug, error, info, trace, Logger};
use std::boxed::Box; use std::boxed::Box;
@ -97,7 +97,7 @@ pub enum SyncMessage<T: EthSpec> {
RpcBlob { RpcBlob {
peer_id: PeerId, peer_id: PeerId,
request_id: RequestId, request_id: RequestId,
blob_sidecar: Option<Arc<BlobsSidecar<T>>>, blob_sidecar: Option<Arc<SignedBeaconBlockAndBlobsSidecar<T>>>,
seen_timestamp: Duration, seen_timestamp: Duration,
}, },
@ -592,8 +592,14 @@ impl<T: BeaconChainTypes> SyncManager<T> {
.block_lookups .block_lookups
.parent_chain_processed(chain_hash, result, &mut self.network), .parent_chain_processed(chain_hash, result, &mut self.network),
}, },
//FIXME(sean) SyncMessage::RpcBlob {
SyncMessage::RpcBlob { .. } => todo!(), peer_id,
request_id,
blob_sidecar,
seen_timestamp,
} => {
self.rpc_block_received(request_id, peer_id, beacon_block, seen_timestamp);
},
} }
} }

View File

@ -97,6 +97,7 @@ pub mod sqlite;
pub mod blobs_sidecar; pub mod blobs_sidecar;
pub mod kzg_commitment; pub mod kzg_commitment;
pub mod kzg_proof; pub mod kzg_proof;
pub mod signed_block_and_blobs;
use ethereum_types::{H160, H256}; use ethereum_types::{H160, H256};
@ -149,6 +150,7 @@ pub use crate::historical_batch::HistoricalBatch;
pub use crate::indexed_attestation::IndexedAttestation; pub use crate::indexed_attestation::IndexedAttestation;
pub use crate::kzg_commitment::KzgCommitment; pub use crate::kzg_commitment::KzgCommitment;
pub use crate::kzg_proof::KzgProof; pub use crate::kzg_proof::KzgProof;
pub use crate::signed_block_and_blobs::SignedBeaconBlockAndBlobsSidecar;
pub use crate::participation_flags::ParticipationFlags; pub use crate::participation_flags::ParticipationFlags;
pub use crate::participation_list::ParticipationList; pub use crate::participation_list::ParticipationList;
pub use crate::payload::{ pub use crate::payload::{

View File

@ -0,0 +1,18 @@
use serde_derive::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use tree_hash_derive::TreeHash;
use crate::{BlobsSidecar, EthSpec, SignedBeaconBlock};
#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash, PartialEq)]
#[serde(bound = "T: EthSpec")]
pub struct SignedBeaconBlockAndBlobsSidecar<T: EthSpec> {
pub beacon_block: SignedBeaconBlock<T>,
pub blobs_sidecar: BlobsSidecar<T>,
}
impl<T: EthSpec> SignedBeaconBlockAndBlobsSidecar<T> {
/// SSZ decode with fork variant determined by slot.
pub fn from_ssz_bytes(bytes: &[u8], spec: &ChainSpec) -> Result<Self, ssz::DecodeError> {
SignedBeaconBlock::from_ssz_bytes(bytes, spec)
}
}