Search in sources :

Example 1 with InvalidRpcMethodVersion

use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion 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"));
}
Also used : RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) InvalidRpcMethodVersion(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion) Spec(tech.pegasys.teku.spec.Spec) BeaconBlocksByRangeRequestMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage) Test(org.junit.jupiter.api.Test)

Example 2 with InvalidRpcMethodVersion

use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion in project teku by ConsenSys.

the class BeaconBlocksByRangeMessageHandler method validateRequest.

@Override
public Optional<RpcException> validateRequest(final String protocolId, final BeaconBlocksByRangeRequestMessage request) {
    final int version = BeaconChainMethodIds.extractBeaconBlocksByRangeVersion(protocolId);
    final SpecMilestone latestMilestoneRequested = spec.getForkSchedule().getSpecMilestoneAtSlot(request.getMaxSlot());
    final boolean isAltairActive = latestMilestoneRequested.isGreaterThanOrEqualTo(SpecMilestone.ALTAIR);
    if (version == 1 && isAltairActive) {
        return Optional.of(new InvalidRpcMethodVersion("Must request altair blocks using v2 protocol"));
    }
    return Optional.empty();
}
Also used : InvalidRpcMethodVersion(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone)

Example 3 with InvalidRpcMethodVersion

use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion in project teku by ConsenSys.

the class BeaconBlocksByRangeMessageHandlerTest method validateRequest_altairSpec_v1RequestForAltairBlock.

@Test
public void validateRequest_altairSpec_v1RequestForAltairBlock() {
    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(32), ONE, ONE));
    assertThat(result).contains(new InvalidRpcMethodVersion("Must request altair blocks using v2 protocol"));
}
Also used : RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) InvalidRpcMethodVersion(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion) Spec(tech.pegasys.teku.spec.Spec) BeaconBlocksByRangeRequestMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage) Test(org.junit.jupiter.api.Test)

Example 4 with InvalidRpcMethodVersion

use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion in project teku by ConsenSys.

the class BeaconBlocksByRootMessageHandlerTest method validateResponse_altairSpec_v1RequestForAltairBlock.

@Test
public void validateResponse_altairSpec_v1RequestForAltairBlock() {
    final Optional<RpcException> result = handler.validateResponse(V1_PROTOCOL_ID, chainUpdater.advanceChain(altairForkSlot).getBlock());
    assertThat(result).contains(new InvalidRpcMethodVersion("Must request altair blocks using v2 protocol"));
}
Also used : RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) InvalidRpcMethodVersion(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with InvalidRpcMethodVersion

use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion in project teku by ConsenSys.

the class BeaconBlocksByRootMessageHandler method validateResponse.

@VisibleForTesting
Optional<RpcException> validateResponse(final String protocolId, final SignedBeaconBlock response) {
    final int version = BeaconChainMethodIds.extractBeaconBlocksByRootVersion(protocolId);
    final SpecMilestone milestoneAtResponse = spec.getForkSchedule().getSpecMilestoneAtSlot(response.getSlot());
    final boolean isAltairActive = milestoneAtResponse.isGreaterThanOrEqualTo(SpecMilestone.ALTAIR);
    if (version == 1 && isAltairActive) {
        return Optional.of(new InvalidRpcMethodVersion("Must request altair blocks using v2 protocol"));
    }
    return Optional.empty();
}
Also used : InvalidRpcMethodVersion(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

InvalidRpcMethodVersion (tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion)5 Test (org.junit.jupiter.api.Test)3 RpcException (tech.pegasys.teku.networking.eth2.rpc.core.RpcException)3 Spec (tech.pegasys.teku.spec.Spec)2 SpecMilestone (tech.pegasys.teku.spec.SpecMilestone)2 BeaconBlocksByRangeRequestMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1