use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage in project teku by ConsenSys.
the class BeaconChainMethods method createBeaconBlocksByRange.
private static Eth2RpcMethod<BeaconBlocksByRangeRequestMessage, SignedBeaconBlock> createBeaconBlocksByRange(final Spec spec, final AsyncRunner asyncRunner, final RecentChainData recentChainData, final CombinedChainDataClient combinedChainDataClient, final PeerLookup peerLookup, final RpcEncoding rpcEncoding) {
final BeaconBlocksByRangeMessageHandler beaconBlocksByRangeHandler = new BeaconBlocksByRangeMessageHandler(spec, combinedChainDataClient, MAX_BLOCK_BY_RANGE_REQUEST_SIZE);
// V1 request only deal with Phase0 blocks
final SignedBeaconBlockSchema phase0BlockSchema = spec.forMilestone(SpecMilestone.PHASE0).getSchemaDefinitions().getSignedBeaconBlockSchema();
final RpcContextCodec<?, SignedBeaconBlock> noContextCodec = RpcContextCodec.noop(phase0BlockSchema);
final BeaconBlocksByRangeRequestMessageSchema requestType = BeaconBlocksByRangeRequestMessage.SSZ_SCHEMA;
final boolean expectResponseToRequest = true;
final SingleProtocolEth2RpcMethod<BeaconBlocksByRangeRequestMessage, SignedBeaconBlock> v1Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.BEACON_BLOCKS_BY_RANGE, 1, rpcEncoding, requestType, expectResponseToRequest, noContextCodec, beaconBlocksByRangeHandler, peerLookup);
if (spec.isMilestoneSupported(SpecMilestone.ALTAIR)) {
final RpcContextCodec<Bytes4, SignedBeaconBlock> forkDigestContextCodec = RpcContextCodec.forkDigest(spec, recentChainData, ForkDigestPayloadContext.SIGNED_BEACONBLOCK);
final SingleProtocolEth2RpcMethod<BeaconBlocksByRangeRequestMessage, SignedBeaconBlock> v2Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.BEACON_BLOCKS_BY_RANGE, 2, rpcEncoding, requestType, expectResponseToRequest, forkDigestContextCodec, beaconBlocksByRangeHandler, peerLookup);
return VersionedEth2RpcMethod.create(rpcEncoding, requestType, expectResponseToRequest, List.of(v2Method, v1Method));
} else {
return v1Method;
}
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage in project teku by ConsenSys.
the class BeaconBlocksByRangeMessageHandlerTest method validateRequest_altairSpec_v2RequestForPhase0Block.
@Test
public void validateRequest_altairSpec_v2RequestForPhase0Block() {
final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(UInt64.valueOf(4));
final BeaconBlocksByRangeMessageHandler handler = new BeaconBlocksByRangeMessageHandler(spec, combinedChainDataClient, maxRequestSize);
final Optional<RpcException> result = handler.validateRequest(V2_PROTOCOL_ID, new BeaconBlocksByRangeRequestMessage(ZERO, ONE, ONE));
assertThat(result).isEmpty();
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage in project teku by ConsenSys.
the class BeaconBlocksByRangeMessageHandlerTest method validateRequest_altairSpec_v2RequestForRangeOfBlocksAcrossForkBoundary.
@Test
public void validateRequest_altairSpec_v2RequestForRangeOfBlocksAcrossForkBoundary() {
final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(UInt64.valueOf(4));
final BeaconBlocksByRangeMessageHandler handler = new BeaconBlocksByRangeMessageHandler(spec, combinedChainDataClient, maxRequestSize);
final Optional<RpcException> result = handler.validateRequest(V2_PROTOCOL_ID, new BeaconBlocksByRangeRequestMessage(UInt64.valueOf(30), UInt64.valueOf(10), ONE));
assertThat(result).isEmpty();
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage in project teku by ConsenSys.
the class BeaconBlocksByRangeMessageHandlerTest method validateRequest_altairSpec_v1RequestForRangeOfBlocksAcrossForkBoundary.
@Test
public void validateRequest_altairSpec_v1RequestForRangeOfBlocksAcrossForkBoundary() {
final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(UInt64.valueOf(4));
final BeaconBlocksByRangeMessageHandler handler = new BeaconBlocksByRangeMessageHandler(spec, combinedChainDataClient, maxRequestSize);
final Optional<RpcException> result = handler.validateRequest(V1_PROTOCOL_ID, new BeaconBlocksByRangeRequestMessage(UInt64.valueOf(30), UInt64.valueOf(10), ONE));
assertThat(result).contains(new InvalidRpcMethodVersion("Must request altair blocks using v2 protocol"));
}
use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage in project teku by ConsenSys.
the class BeaconBlocksByRangeMessageHandlerTest method validateRequest_altairSpec_v2RequestForAltairBlock.
@Test
public void validateRequest_altairSpec_v2RequestForAltairBlock() {
final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(UInt64.valueOf(4));
final BeaconBlocksByRangeMessageHandler handler = new BeaconBlocksByRangeMessageHandler(spec, combinedChainDataClient, maxRequestSize);
final Optional<RpcException> result = handler.validateRequest(V2_PROTOCOL_ID, new BeaconBlocksByRangeRequestMessage(UInt64.valueOf(32), ONE, ONE));
assertThat(result).isEmpty();
}
Aggregations