add context bytes to blob messages, fix rpc limits, sync past finalized checkpoint during finalized sync so we can advance our own finalization, fix stream termination bug in blobs by range

This commit is contained in:
realbigsean
2022-12-21 13:56:52 -05:00
parent a67fa516c7
commit ff772311fa
6 changed files with 74 additions and 59 deletions

View File

@@ -439,6 +439,9 @@ fn context_bytes<T: EthSpec>(
SignedBeaconBlock::Base { .. } => Some(fork_context.genesis_context_bytes()),
};
}
if let RPCResponse::BlobsByRange(_) | RPCResponse::BlobsByRoot(_) = rpc_variant {
return fork_context.to_context_bytes(ForkName::Eip4844);
}
}
}
None
@@ -570,42 +573,38 @@ fn handle_v1_response<T: EthSpec>(
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(decoded_buffer)?),
)))),
Protocol::BlobsByRange => {
Ok(Some(RPCResponse::BlobsByRange(Arc::new(
BlobsSidecar::from_ssz_bytes(decoded_buffer)?,
))))
//FIXME(sean) do we need context bytes?
// let fork_name = fork_name.take().ok_or_else(|| {
// RPCError::ErrorResponse(
// RPCResponseErrorCode::InvalidRequest,
// format!("No context bytes provided for {} response", protocol),
// )
// })?;
// match fork_name {
// ForkName::Eip4844 => ,
// _ => Err(RPCError::ErrorResponse(
// RPCResponseErrorCode::InvalidRequest,
// "Invalid forkname for blobsbyrange".to_string(),
// )),
// }
let fork_name = fork_name.take().ok_or_else(|| {
RPCError::ErrorResponse(
RPCResponseErrorCode::InvalidRequest,
format!("No context bytes provided for {} response", protocol),
)
})?;
match fork_name {
ForkName::Eip4844 => Ok(Some(RPCResponse::BlobsByRange(Arc::new(
BlobsSidecar::from_ssz_bytes(decoded_buffer)?,
)))),
_ => Err(RPCError::ErrorResponse(
RPCResponseErrorCode::InvalidRequest,
"Invalid forkname for blobsbyrange".to_string(),
)),
}
}
Protocol::BlobsByRoot => {
Ok(Some(RPCResponse::BlobsByRoot(Arc::new(
SignedBeaconBlockAndBlobsSidecar::from_ssz_bytes(decoded_buffer)?,
))))
//FIXME(sean) do we need context bytes?
// let fork_name = fork_name.take().ok_or_else(|| {
// RPCError::ErrorResponse(
// RPCResponseErrorCode::InvalidRequest,
// format!("No context bytes provided for {} response", protocol),
// )
// })?;
// match fork_name {
// ForkName::Eip4844 =>
// _ => Err(RPCError::ErrorResponse(
// RPCResponseErrorCode::InvalidRequest,
// "Invalid forkname for blobsbyroot".to_string(),
// )),
// }
let fork_name = fork_name.take().ok_or_else(|| {
RPCError::ErrorResponse(
RPCResponseErrorCode::InvalidRequest,
format!("No context bytes provided for {} response", protocol),
)
})?;
match fork_name {
ForkName::Eip4844 => Ok(Some(RPCResponse::BlobsByRoot(Arc::new(
SignedBeaconBlockAndBlobsSidecar::from_ssz_bytes(decoded_buffer)?,
)))),
_ => Err(RPCError::ErrorResponse(
RPCResponseErrorCode::InvalidRequest,
"Invalid forkname for blobsbyroot".to_string(),
)),
}
}
Protocol::Ping => Ok(Some(RPCResponse::Pong(Ping {
data: u64::from_ssz_bytes(decoded_buffer)?,

View File

@@ -23,7 +23,7 @@ use tokio_util::{
use types::BlobsSidecar;
use types::{
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockMerge, Blob, EmptyBlock, EthSpec,
ForkContext, ForkName, Hash256, MainnetEthSpec, Signature, SignedBeaconBlock
ForkContext, ForkName, Hash256, MainnetEthSpec, Signature, SignedBeaconBlock,
};
lazy_static! {
@@ -364,16 +364,10 @@ impl ProtocolId {
Protocol::Goodbye => RpcLimits::new(0, 0), // Goodbye request has no response
Protocol::BlocksByRange => 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::BlobsByRoot => RpcLimits::new(
*SIGNED_BLOCK_AND_BLOBS_MIN,
*SIGNED_BLOCK_AND_BLOBS_MAX,
),
Protocol::BlobsByRange => RpcLimits::new(*BLOBS_SIDECAR_MIN, *BLOBS_SIDECAR_MAX),
Protocol::BlobsByRoot => {
RpcLimits::new(*SIGNED_BLOCK_AND_BLOBS_MIN, *SIGNED_BLOCK_AND_BLOBS_MAX)
}
Protocol::Ping => RpcLimits::new(
<Ping as Encode>::ssz_fixed_len(),
<Ping as Encode>::ssz_fixed_len(),
@@ -392,13 +386,16 @@ impl ProtocolId {
/// Returns `true` if the given `ProtocolId` should expect `context_bytes` in the
/// beginning of the stream, else returns `false`.
pub fn has_context_bytes(&self) -> bool {
if self.version == Version::V2 {
match self.message_name {
match self.version {
Version::V2 => match self.message_name {
Protocol::BlocksByRange | Protocol::BlocksByRoot => return true,
_ => return false,
}
},
Version::V1 => match self.message_name {
Protocol::BlobsByRange | Protocol::BlobsByRoot => return true,
_ => return false,
},
}
false
}
}