mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +00:00
Add Fulu boilerplate (#6695)
* Add Fulu boilerplate * Add more boilerplate * Change fulu_time to osaka_time * Merge branch 'unstable' into fulu-boilerplate * Fix tests * Merge branch 'unstable' into fulu-boilerplate * More test fixes * Apply suggestions * Remove `get_payload` boilerplate * Add lightclient fulu types and fix beacon-chain-tests * Disable Fulu in ef-tests * Reduce boilerplate for future forks * Small fixes * One more fix * Apply suggestions * Merge branch 'unstable' into fulu-boilerplate * Fix lints
This commit is contained in:
@@ -20,7 +20,7 @@ use types::{
|
||||
LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate,
|
||||
LightClientUpdate, RuntimeVariableList, SignedBeaconBlock, SignedBeaconBlockAltair,
|
||||
SignedBeaconBlockBase, SignedBeaconBlockBellatrix, SignedBeaconBlockCapella,
|
||||
SignedBeaconBlockDeneb, SignedBeaconBlockElectra,
|
||||
SignedBeaconBlockDeneb, SignedBeaconBlockElectra, SignedBeaconBlockFulu,
|
||||
};
|
||||
use unsigned_varint::codec::Uvi;
|
||||
|
||||
@@ -458,6 +458,9 @@ fn context_bytes<E: EthSpec>(
|
||||
return match **ref_box_block {
|
||||
// NOTE: If you are adding another fork type here, be sure to modify the
|
||||
// `fork_context.to_context_bytes()` function to support it as well!
|
||||
SignedBeaconBlock::Fulu { .. } => {
|
||||
fork_context.to_context_bytes(ForkName::Fulu)
|
||||
}
|
||||
SignedBeaconBlock::Electra { .. } => {
|
||||
fork_context.to_context_bytes(ForkName::Electra)
|
||||
}
|
||||
@@ -682,18 +685,18 @@ fn handle_rpc_response<E: EthSpec>(
|
||||
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(decoded_buffer)?),
|
||||
)))),
|
||||
SupportedProtocol::BlobsByRangeV1 => match fork_name {
|
||||
Some(ForkName::Deneb) | Some(ForkName::Electra) => {
|
||||
Ok(Some(RpcSuccessResponse::BlobsByRange(Arc::new(
|
||||
BlobSidecar::from_ssz_bytes(decoded_buffer)?,
|
||||
))))
|
||||
Some(fork_name) => {
|
||||
if fork_name.deneb_enabled() {
|
||||
Ok(Some(RpcSuccessResponse::BlobsByRange(Arc::new(
|
||||
BlobSidecar::from_ssz_bytes(decoded_buffer)?,
|
||||
))))
|
||||
} else {
|
||||
Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
"Invalid fork name for blobs by range".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
Some(ForkName::Base)
|
||||
| Some(ForkName::Altair)
|
||||
| Some(ForkName::Bellatrix)
|
||||
| Some(ForkName::Capella) => Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
"Invalid fork name for blobs by range".to_string(),
|
||||
)),
|
||||
None => Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
format!(
|
||||
@@ -703,18 +706,18 @@ fn handle_rpc_response<E: EthSpec>(
|
||||
)),
|
||||
},
|
||||
SupportedProtocol::BlobsByRootV1 => match fork_name {
|
||||
Some(ForkName::Deneb) | Some(ForkName::Electra) => {
|
||||
Ok(Some(RpcSuccessResponse::BlobsByRoot(Arc::new(
|
||||
BlobSidecar::from_ssz_bytes(decoded_buffer)?,
|
||||
))))
|
||||
Some(fork_name) => {
|
||||
if fork_name.deneb_enabled() {
|
||||
Ok(Some(RpcSuccessResponse::BlobsByRoot(Arc::new(
|
||||
BlobSidecar::from_ssz_bytes(decoded_buffer)?,
|
||||
))))
|
||||
} else {
|
||||
Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
"Invalid fork name for blobs by root".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
Some(ForkName::Base)
|
||||
| Some(ForkName::Altair)
|
||||
| Some(ForkName::Bellatrix)
|
||||
| Some(ForkName::Capella) => Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
"Invalid fork name for blobs by root".to_string(),
|
||||
)),
|
||||
None => Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
format!(
|
||||
@@ -864,6 +867,9 @@ fn handle_rpc_response<E: EthSpec>(
|
||||
decoded_buffer,
|
||||
)?),
|
||||
)))),
|
||||
Some(ForkName::Fulu) => Ok(Some(RpcSuccessResponse::BlocksByRange(Arc::new(
|
||||
SignedBeaconBlock::Fulu(SignedBeaconBlockFulu::from_ssz_bytes(decoded_buffer)?),
|
||||
)))),
|
||||
None => Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
format!(
|
||||
@@ -897,6 +903,9 @@ fn handle_rpc_response<E: EthSpec>(
|
||||
decoded_buffer,
|
||||
)?),
|
||||
)))),
|
||||
Some(ForkName::Fulu) => Ok(Some(RpcSuccessResponse::BlocksByRoot(Arc::new(
|
||||
SignedBeaconBlock::Fulu(SignedBeaconBlockFulu::from_ssz_bytes(decoded_buffer)?),
|
||||
)))),
|
||||
None => Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
format!(
|
||||
@@ -948,12 +957,14 @@ mod tests {
|
||||
let capella_fork_epoch = Epoch::new(3);
|
||||
let deneb_fork_epoch = Epoch::new(4);
|
||||
let electra_fork_epoch = Epoch::new(5);
|
||||
let fulu_fork_epoch = Epoch::new(6);
|
||||
|
||||
chain_spec.altair_fork_epoch = Some(altair_fork_epoch);
|
||||
chain_spec.bellatrix_fork_epoch = Some(bellatrix_fork_epoch);
|
||||
chain_spec.capella_fork_epoch = Some(capella_fork_epoch);
|
||||
chain_spec.deneb_fork_epoch = Some(deneb_fork_epoch);
|
||||
chain_spec.electra_fork_epoch = Some(electra_fork_epoch);
|
||||
chain_spec.fulu_fork_epoch = Some(fulu_fork_epoch);
|
||||
|
||||
let current_slot = match fork_name {
|
||||
ForkName::Base => Slot::new(0),
|
||||
@@ -962,6 +973,7 @@ mod tests {
|
||||
ForkName::Capella => capella_fork_epoch.start_slot(Spec::slots_per_epoch()),
|
||||
ForkName::Deneb => deneb_fork_epoch.start_slot(Spec::slots_per_epoch()),
|
||||
ForkName::Electra => electra_fork_epoch.start_slot(Spec::slots_per_epoch()),
|
||||
ForkName::Fulu => fulu_fork_epoch.start_slot(Spec::slots_per_epoch()),
|
||||
};
|
||||
ForkContext::new::<Spec>(current_slot, Hash256::zero(), &chain_spec)
|
||||
}
|
||||
@@ -1396,6 +1408,16 @@ mod tests {
|
||||
Ok(Some(RpcSuccessResponse::BlobsByRange(empty_blob_sidecar()))),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::BlobsByRangeV1,
|
||||
RpcResponse::Success(RpcSuccessResponse::BlobsByRange(empty_blob_sidecar())),
|
||||
ForkName::Fulu,
|
||||
&chain_spec
|
||||
),
|
||||
Ok(Some(RpcSuccessResponse::BlobsByRange(empty_blob_sidecar()))),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::BlobsByRootV1,
|
||||
@@ -1416,6 +1438,16 @@ mod tests {
|
||||
Ok(Some(RpcSuccessResponse::BlobsByRoot(empty_blob_sidecar()))),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::BlobsByRootV1,
|
||||
RpcResponse::Success(RpcSuccessResponse::BlobsByRoot(empty_blob_sidecar())),
|
||||
ForkName::Fulu,
|
||||
&chain_spec
|
||||
),
|
||||
Ok(Some(RpcSuccessResponse::BlobsByRoot(empty_blob_sidecar()))),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::DataColumnsByRangeV1,
|
||||
@@ -1444,6 +1476,20 @@ mod tests {
|
||||
))),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::DataColumnsByRangeV1,
|
||||
RpcResponse::Success(RpcSuccessResponse::DataColumnsByRange(
|
||||
empty_data_column_sidecar()
|
||||
)),
|
||||
ForkName::Fulu,
|
||||
&chain_spec
|
||||
),
|
||||
Ok(Some(RpcSuccessResponse::DataColumnsByRange(
|
||||
empty_data_column_sidecar()
|
||||
))),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::DataColumnsByRootV1,
|
||||
@@ -1471,6 +1517,20 @@ mod tests {
|
||||
empty_data_column_sidecar()
|
||||
))),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::DataColumnsByRootV1,
|
||||
RpcResponse::Success(RpcSuccessResponse::DataColumnsByRoot(
|
||||
empty_data_column_sidecar()
|
||||
)),
|
||||
ForkName::Fulu,
|
||||
&chain_spec
|
||||
),
|
||||
Ok(Some(RpcSuccessResponse::DataColumnsByRoot(
|
||||
empty_data_column_sidecar()
|
||||
))),
|
||||
);
|
||||
}
|
||||
|
||||
// Test RPCResponse encoding/decoding for V1 messages
|
||||
|
||||
Reference in New Issue
Block a user