mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Merge branch 'unstable' into merge-unstable-to-deneb-20230808
# Conflicts: # Cargo.lock # beacon_node/beacon_chain/src/lib.rs # beacon_node/execution_layer/src/engine_api.rs # beacon_node/execution_layer/src/engine_api/http.rs # beacon_node/execution_layer/src/test_utils/mod.rs # beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs # beacon_node/lighthouse_network/src/rpc/handler.rs # beacon_node/lighthouse_network/src/rpc/protocol.rs # beacon_node/lighthouse_network/src/service/utils.rs # beacon_node/lighthouse_network/tests/rpc_tests.rs # beacon_node/network/Cargo.toml # beacon_node/network/src/network_beacon_processor/tests.rs # lcli/src/parse_ssz.rs # scripts/cross/Dockerfile # validator_client/src/block_service.rs # validator_client/src/validator_store.rs
This commit is contained in:
@@ -220,9 +220,12 @@ mod tests {
|
||||
let snappy_protocol_id = ProtocolId::new(SupportedProtocol::StatusV1, Encoding::SSZSnappy);
|
||||
|
||||
let fork_context = Arc::new(fork_context(ForkName::Base));
|
||||
|
||||
let chain_spec = Spec::default_spec();
|
||||
|
||||
let mut snappy_outbound_codec = SSZSnappyOutboundCodec::<Spec>::new(
|
||||
snappy_protocol_id,
|
||||
max_rpc_size(&fork_context),
|
||||
max_rpc_size(&fork_context, chain_spec.max_chunk_size as usize),
|
||||
fork_context,
|
||||
);
|
||||
|
||||
@@ -254,9 +257,12 @@ mod tests {
|
||||
let snappy_protocol_id = ProtocolId::new(SupportedProtocol::StatusV1, Encoding::SSZSnappy);
|
||||
|
||||
let fork_context = Arc::new(fork_context(ForkName::Base));
|
||||
|
||||
let chain_spec = Spec::default_spec();
|
||||
|
||||
let mut snappy_outbound_codec = SSZSnappyOutboundCodec::<Spec>::new(
|
||||
snappy_protocol_id,
|
||||
max_rpc_size(&fork_context),
|
||||
max_rpc_size(&fork_context, chain_spec.max_chunk_size as usize),
|
||||
fork_context,
|
||||
);
|
||||
|
||||
@@ -282,7 +288,10 @@ mod tests {
|
||||
|
||||
// Response limits
|
||||
let fork_context = Arc::new(fork_context(ForkName::Base));
|
||||
let max_rpc_size = max_rpc_size(&fork_context);
|
||||
|
||||
let chain_spec = Spec::default_spec();
|
||||
|
||||
let max_rpc_size = max_rpc_size(&fork_context, chain_spec.max_chunk_size as usize);
|
||||
let limit = protocol_id.rpc_response_limits::<Spec>(&fork_context);
|
||||
let mut max = encode_len(limit.max + 1);
|
||||
let mut codec = SSZSnappyOutboundCodec::<Spec>::new(
|
||||
|
||||
@@ -678,8 +678,8 @@ mod tests {
|
||||
use std::sync::Arc;
|
||||
use types::{
|
||||
blob_sidecar::BlobIdentifier, BeaconBlock, BeaconBlockAltair, BeaconBlockBase,
|
||||
BeaconBlockMerge, EmptyBlock, Epoch, ForkContext, FullPayload, Hash256, Signature,
|
||||
SignedBeaconBlock, Slot,
|
||||
BeaconBlockMerge, ChainSpec, EmptyBlock, Epoch, ForkContext, FullPayload, Hash256,
|
||||
Signature, SignedBeaconBlock, Slot,
|
||||
};
|
||||
|
||||
use snap::write::FrameEncoder;
|
||||
@@ -728,7 +728,7 @@ mod tests {
|
||||
}
|
||||
|
||||
/// Merge block with length < max_rpc_size.
|
||||
fn merge_block_small(fork_context: &ForkContext) -> SignedBeaconBlock<Spec> {
|
||||
fn merge_block_small(fork_context: &ForkContext, spec: &ChainSpec) -> SignedBeaconBlock<Spec> {
|
||||
let mut block: BeaconBlockMerge<_, FullPayload<Spec>> =
|
||||
BeaconBlockMerge::empty(&Spec::default_spec());
|
||||
let tx = VariableList::from(vec![0; 1024]);
|
||||
@@ -737,14 +737,14 @@ mod tests {
|
||||
block.body.execution_payload.execution_payload.transactions = txs;
|
||||
|
||||
let block = BeaconBlock::Merge(block);
|
||||
assert!(block.ssz_bytes_len() <= max_rpc_size(fork_context));
|
||||
assert!(block.ssz_bytes_len() <= max_rpc_size(fork_context, spec.max_chunk_size as usize));
|
||||
SignedBeaconBlock::from_block(block, Signature::empty())
|
||||
}
|
||||
|
||||
/// Merge block with length > MAX_RPC_SIZE.
|
||||
/// The max limit for a merge block is in the order of ~16GiB which wouldn't fit in memory.
|
||||
/// Hence, we generate a merge block just greater than `MAX_RPC_SIZE` to test rejection on the rpc layer.
|
||||
fn merge_block_large(fork_context: &ForkContext) -> SignedBeaconBlock<Spec> {
|
||||
fn merge_block_large(fork_context: &ForkContext, spec: &ChainSpec) -> SignedBeaconBlock<Spec> {
|
||||
let mut block: BeaconBlockMerge<_, FullPayload<Spec>> =
|
||||
BeaconBlockMerge::empty(&Spec::default_spec());
|
||||
let tx = VariableList::from(vec![0; 1024]);
|
||||
@@ -753,7 +753,7 @@ mod tests {
|
||||
block.body.execution_payload.execution_payload.transactions = txs;
|
||||
|
||||
let block = BeaconBlock::Merge(block);
|
||||
assert!(block.ssz_bytes_len() > max_rpc_size(fork_context));
|
||||
assert!(block.ssz_bytes_len() > max_rpc_size(fork_context, spec.max_chunk_size as usize));
|
||||
SignedBeaconBlock::from_block(block, Signature::empty())
|
||||
}
|
||||
|
||||
@@ -823,10 +823,11 @@ mod tests {
|
||||
protocol: SupportedProtocol,
|
||||
message: RPCCodedResponse<Spec>,
|
||||
fork_name: ForkName,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<BytesMut, RPCError> {
|
||||
let snappy_protocol_id = ProtocolId::new(protocol, Encoding::SSZSnappy);
|
||||
let fork_context = Arc::new(fork_context(fork_name));
|
||||
let max_packet_size = max_rpc_size(&fork_context);
|
||||
let max_packet_size = max_rpc_size(&fork_context, spec.max_chunk_size as usize);
|
||||
|
||||
let mut buf = BytesMut::new();
|
||||
let mut snappy_inbound_codec =
|
||||
@@ -869,10 +870,11 @@ mod tests {
|
||||
protocol: SupportedProtocol,
|
||||
message: &mut BytesMut,
|
||||
fork_name: ForkName,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Option<RPCResponse<Spec>>, RPCError> {
|
||||
let snappy_protocol_id = ProtocolId::new(protocol, Encoding::SSZSnappy);
|
||||
let fork_context = Arc::new(fork_context(fork_name));
|
||||
let max_packet_size = max_rpc_size(&fork_context);
|
||||
let max_packet_size = max_rpc_size(&fork_context, spec.max_chunk_size as usize);
|
||||
let mut snappy_outbound_codec =
|
||||
SSZSnappyOutboundCodec::<Spec>::new(snappy_protocol_id, max_packet_size, fork_context);
|
||||
// decode message just as snappy message
|
||||
@@ -884,15 +886,20 @@ mod tests {
|
||||
protocol: SupportedProtocol,
|
||||
message: RPCCodedResponse<Spec>,
|
||||
fork_name: ForkName,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Option<RPCResponse<Spec>>, RPCError> {
|
||||
let mut encoded = encode_response(protocol, message, fork_name)?;
|
||||
decode_response(protocol, &mut encoded, fork_name)
|
||||
let mut encoded = encode_response(protocol, message, fork_name, spec)?;
|
||||
decode_response(protocol, &mut encoded, fork_name, spec)
|
||||
}
|
||||
|
||||
/// Verifies that requests we send are encoded in a way that we would correctly decode too.
|
||||
fn encode_then_decode_request(req: OutboundRequest<Spec>, fork_name: ForkName) {
|
||||
fn encode_then_decode_request(
|
||||
req: OutboundRequest<Spec>,
|
||||
fork_name: ForkName,
|
||||
spec: &ChainSpec,
|
||||
) {
|
||||
let fork_context = Arc::new(fork_context(fork_name));
|
||||
let max_packet_size = max_rpc_size(&fork_context);
|
||||
let max_packet_size = max_rpc_size(&fork_context, spec.max_chunk_size as usize);
|
||||
let protocol = ProtocolId::new(req.versioned_protocol(), Encoding::SSZSnappy);
|
||||
// Encode a request we send
|
||||
let mut buf = BytesMut::new();
|
||||
@@ -943,11 +950,14 @@ mod tests {
|
||||
// Test RPCResponse encoding/decoding for V1 messages
|
||||
#[test]
|
||||
fn test_encode_then_decode_v1() {
|
||||
let chain_spec = Spec::default_spec();
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::StatusV1,
|
||||
RPCCodedResponse::Success(RPCResponse::Status(status_message())),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::Status(status_message())))
|
||||
);
|
||||
@@ -957,6 +967,7 @@ mod tests {
|
||||
SupportedProtocol::PingV1,
|
||||
RPCCodedResponse::Success(RPCResponse::Pong(ping_message())),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::Pong(ping_message())))
|
||||
);
|
||||
@@ -966,6 +977,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRangeV1,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRange(Arc::new(empty_base_block()))),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRange(Arc::new(
|
||||
empty_base_block()
|
||||
@@ -978,6 +990,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRangeV1,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRange(Arc::new(altair_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::SSZDecodeError(_)
|
||||
@@ -990,6 +1003,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV1,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRoot(Arc::new(empty_base_block()))),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRoot(
|
||||
Arc::new(empty_base_block())
|
||||
@@ -1002,6 +1016,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV1,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRoot(Arc::new(altair_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::SSZDecodeError(_)
|
||||
@@ -1014,6 +1029,7 @@ mod tests {
|
||||
SupportedProtocol::MetaDataV1,
|
||||
RPCCodedResponse::Success(RPCResponse::MetaData(metadata())),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::MetaData(metadata()))),
|
||||
);
|
||||
@@ -1024,6 +1040,7 @@ mod tests {
|
||||
SupportedProtocol::MetaDataV1,
|
||||
RPCCodedResponse::Success(RPCResponse::MetaData(metadata_v2())),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::MetaData(metadata()))),
|
||||
);
|
||||
@@ -1033,6 +1050,7 @@ mod tests {
|
||||
SupportedProtocol::BlobsByRangeV1,
|
||||
RPCCodedResponse::Success(RPCResponse::BlobsByRange(default_blob_sidecar())),
|
||||
ForkName::Deneb,
|
||||
&chain_spec
|
||||
),
|
||||
Ok(Some(RPCResponse::BlobsByRange(default_blob_sidecar()))),
|
||||
);
|
||||
@@ -1042,6 +1060,7 @@ mod tests {
|
||||
SupportedProtocol::BlobsByRootV1,
|
||||
RPCCodedResponse::Success(RPCResponse::SidecarByRoot(default_blob_sidecar())),
|
||||
ForkName::Deneb,
|
||||
&chain_spec
|
||||
),
|
||||
Ok(Some(RPCResponse::SidecarByRoot(default_blob_sidecar()))),
|
||||
);
|
||||
@@ -1050,11 +1069,14 @@ mod tests {
|
||||
// Test RPCResponse encoding/decoding for V1 messages
|
||||
#[test]
|
||||
fn test_encode_then_decode_v2() {
|
||||
let chain_spec = Spec::default_spec();
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRange(Arc::new(empty_base_block()))),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRange(Arc::new(
|
||||
empty_base_block()
|
||||
@@ -1069,6 +1091,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRange(Arc::new(empty_base_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRange(Arc::new(
|
||||
empty_base_block()
|
||||
@@ -1080,12 +1103,13 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRange(Arc::new(altair_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRange(Arc::new(altair_block()))))
|
||||
);
|
||||
|
||||
let merge_block_small = merge_block_small(&fork_context(ForkName::Merge));
|
||||
let merge_block_large = merge_block_large(&fork_context(ForkName::Merge));
|
||||
let merge_block_small = merge_block_small(&fork_context(ForkName::Merge), &chain_spec);
|
||||
let merge_block_large = merge_block_large(&fork_context(ForkName::Merge), &chain_spec);
|
||||
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
@@ -1094,6 +1118,7 @@ mod tests {
|
||||
merge_block_small.clone()
|
||||
))),
|
||||
ForkName::Merge,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRange(Arc::new(
|
||||
merge_block_small.clone()
|
||||
@@ -1110,6 +1135,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
&mut encoded,
|
||||
ForkName::Merge,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::InvalidData(_)
|
||||
@@ -1122,6 +1148,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRoot(Arc::new(empty_base_block()))),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRoot(
|
||||
Arc::new(empty_base_block())
|
||||
@@ -1136,6 +1163,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRoot(Arc::new(empty_base_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRoot(
|
||||
Arc::new(empty_base_block())
|
||||
@@ -1147,6 +1175,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRoot(Arc::new(altair_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRoot(Arc::new(altair_block()))))
|
||||
);
|
||||
@@ -1158,6 +1187,7 @@ mod tests {
|
||||
merge_block_small.clone()
|
||||
))),
|
||||
ForkName::Merge,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::BlocksByRoot(Arc::new(merge_block_small))))
|
||||
);
|
||||
@@ -1172,6 +1202,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV2,
|
||||
&mut encoded,
|
||||
ForkName::Merge,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::InvalidData(_)
|
||||
@@ -1185,6 +1216,7 @@ mod tests {
|
||||
SupportedProtocol::MetaDataV2,
|
||||
RPCCodedResponse::Success(RPCResponse::MetaData(metadata())),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::MetaData(metadata_v2())))
|
||||
);
|
||||
@@ -1194,6 +1226,7 @@ mod tests {
|
||||
SupportedProtocol::MetaDataV2,
|
||||
RPCCodedResponse::Success(RPCResponse::MetaData(metadata_v2())),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RPCResponse::MetaData(metadata_v2())))
|
||||
);
|
||||
@@ -1204,11 +1237,14 @@ mod tests {
|
||||
fn test_context_bytes_v2() {
|
||||
let fork_context = fork_context(ForkName::Altair);
|
||||
|
||||
let chain_spec = Spec::default_spec();
|
||||
|
||||
// Removing context bytes for v2 messages should error
|
||||
let mut encoded_bytes = encode_response(
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRange(Arc::new(empty_base_block()))),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1218,7 +1254,8 @@ mod tests {
|
||||
decode_response(
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
&mut encoded_bytes,
|
||||
ForkName::Base
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::ErrorResponse(RPCResponseErrorCode::InvalidRequest, _),
|
||||
@@ -1228,6 +1265,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRoot(Arc::new(empty_base_block()))),
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1237,7 +1275,8 @@ mod tests {
|
||||
decode_response(
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
&mut encoded_bytes,
|
||||
ForkName::Base
|
||||
ForkName::Base,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::ErrorResponse(RPCResponseErrorCode::InvalidRequest, _),
|
||||
@@ -1248,6 +1287,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRange(Arc::new(empty_base_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1260,7 +1300,8 @@ mod tests {
|
||||
decode_response(
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
&mut wrong_fork_bytes,
|
||||
ForkName::Altair
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::SSZDecodeError(_),
|
||||
@@ -1271,6 +1312,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRoot(Arc::new(altair_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1282,7 +1324,8 @@ mod tests {
|
||||
decode_response(
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
&mut wrong_fork_bytes,
|
||||
ForkName::Altair
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::SSZDecodeError(_),
|
||||
@@ -1296,6 +1339,7 @@ mod tests {
|
||||
SupportedProtocol::MetaDataV2,
|
||||
RPCCodedResponse::Success(RPCResponse::MetaData(metadata())),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
@@ -1303,7 +1347,8 @@ mod tests {
|
||||
assert!(decode_response(
|
||||
SupportedProtocol::MetaDataV2,
|
||||
&mut encoded_bytes,
|
||||
ForkName::Altair
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.is_err());
|
||||
|
||||
@@ -1312,6 +1357,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRoot(Arc::new(empty_base_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1323,7 +1369,8 @@ mod tests {
|
||||
decode_response(
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
&mut wrong_fork_bytes,
|
||||
ForkName::Altair
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::ErrorResponse(RPCResponseErrorCode::InvalidRequest, _),
|
||||
@@ -1334,6 +1381,7 @@ mod tests {
|
||||
SupportedProtocol::BlocksByRootV2,
|
||||
RPCCodedResponse::Success(RPCResponse::BlocksByRoot(Arc::new(empty_base_block()))),
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1343,7 +1391,8 @@ mod tests {
|
||||
decode_response(
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
&mut part,
|
||||
ForkName::Altair
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(None)
|
||||
)
|
||||
@@ -1364,9 +1413,12 @@ mod tests {
|
||||
OutboundRequest::BlobsByRoot(blbroot_request()),
|
||||
OutboundRequest::MetaData(MetadataRequest::new_v2()),
|
||||
];
|
||||
|
||||
let chain_spec = Spec::default_spec();
|
||||
|
||||
for req in requests.iter() {
|
||||
for fork_name in ForkName::list_all() {
|
||||
encode_then_decode_request(req.clone(), fork_name);
|
||||
encode_then_decode_request(req.clone(), fork_name, &chain_spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1420,9 +1472,16 @@ mod tests {
|
||||
assert_eq!(writer.get_ref().len(), 42);
|
||||
dst.extend_from_slice(writer.get_ref());
|
||||
|
||||
let chain_spec = Spec::default_spec();
|
||||
// 10 (for stream identifier) + 80 + 42 = 132 > `max_compressed_len`. Hence, decoding should fail with `InvalidData`.
|
||||
assert!(matches!(
|
||||
decode_response(SupportedProtocol::StatusV1, &mut dst, ForkName::Base).unwrap_err(),
|
||||
decode_response(
|
||||
SupportedProtocol::StatusV1,
|
||||
&mut dst,
|
||||
ForkName::Base,
|
||||
&chain_spec
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::InvalidData(_)
|
||||
));
|
||||
}
|
||||
@@ -1477,12 +1536,15 @@ mod tests {
|
||||
assert_eq!(writer.get_ref().len(), 8103);
|
||||
dst.extend_from_slice(writer.get_ref());
|
||||
|
||||
let chain_spec = Spec::default_spec();
|
||||
|
||||
// 10 (for stream identifier) + 176156 + 8103 = 184269 > `max_compressed_len`. Hence, decoding should fail with `InvalidData`.
|
||||
assert!(matches!(
|
||||
decode_response(
|
||||
SupportedProtocol::BlocksByRangeV2,
|
||||
&mut dst,
|
||||
ForkName::Altair
|
||||
ForkName::Altair,
|
||||
&chain_spec,
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::InvalidData(_)
|
||||
@@ -1510,8 +1572,12 @@ mod tests {
|
||||
let mut uvi_codec: Uvi<usize> = Uvi::default();
|
||||
let mut dst = BytesMut::with_capacity(1024);
|
||||
|
||||
let chain_spec = Spec::default_spec();
|
||||
|
||||
// Insert length-prefix
|
||||
uvi_codec.encode(MAX_RPC_SIZE + 1, &mut dst).unwrap();
|
||||
uvi_codec
|
||||
.encode(chain_spec.max_chunk_size as usize + 1, &mut dst)
|
||||
.unwrap();
|
||||
|
||||
// Insert snappy stream identifier
|
||||
dst.extend_from_slice(stream_identifier);
|
||||
@@ -1523,7 +1589,13 @@ mod tests {
|
||||
dst.extend_from_slice(writer.get_ref());
|
||||
|
||||
assert!(matches!(
|
||||
decode_response(SupportedProtocol::StatusV1, &mut dst, ForkName::Base).unwrap_err(),
|
||||
decode_response(
|
||||
SupportedProtocol::StatusV1,
|
||||
&mut dst,
|
||||
ForkName::Base,
|
||||
&chain_spec
|
||||
)
|
||||
.unwrap_err(),
|
||||
RPCError::InvalidData(_)
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user