Search in sources :

Example 1 with BeaconBlocksByRangeMessageHandler

use of tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRangeMessageHandler 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;
    }
}
Also used : SingleProtocolEth2RpcMethod(tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod) BeaconBlocksByRangeRequestMessageSchema(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage.BeaconBlocksByRangeRequestMessageSchema) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) BeaconBlocksByRangeMessageHandler(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRangeMessageHandler) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBeaconBlockSchema(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema) BeaconBlocksByRangeRequestMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage)

Example 2 with BeaconBlocksByRangeMessageHandler

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

Example 3 with BeaconBlocksByRangeMessageHandler

use of tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRangeMessageHandler 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();
}
Also used : RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) 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 BeaconBlocksByRangeMessageHandler

use of tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRangeMessageHandler 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 5 with BeaconBlocksByRangeMessageHandler

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

Aggregations

BeaconBlocksByRangeRequestMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage)7 Test (org.junit.jupiter.api.Test)6 RpcException (tech.pegasys.teku.networking.eth2.rpc.core.RpcException)6 Spec (tech.pegasys.teku.spec.Spec)6 InvalidRpcMethodVersion (tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion)2 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)1 BeaconBlocksByRangeMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRangeMessageHandler)1 SingleProtocolEth2RpcMethod (tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod)1 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)1 SignedBeaconBlockSchema (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema)1 BeaconBlocksByRangeRequestMessageSchema (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage.BeaconBlocksByRangeRequestMessageSchema)1