Search in sources :

Example 1 with BeaconBlocksByRangeRequestMessage

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;
    }
}
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 BeaconBlocksByRangeRequestMessage

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();
}
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 BeaconBlocksByRangeRequestMessage

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();
}
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 BeaconBlocksByRangeRequestMessage

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"));
}
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 BeaconBlocksByRangeRequestMessage

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();
}
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)15 Test (org.junit.jupiter.api.Test)11 RpcException (tech.pegasys.teku.networking.eth2.rpc.core.RpcException)10 Spec (tech.pegasys.teku.spec.Spec)7 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)4 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)4 InvalidRpcMethodVersion (tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion)3 Throwables (com.google.common.base.Throwables)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 NavigableMap (java.util.NavigableMap)1 Optional (java.util.Optional)1 TreeMap (java.util.TreeMap)1 LogManager (org.apache.logging.log4j.LogManager)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 SafeFuture.completedFuture (tech.pegasys.teku.infrastructure.async.SafeFuture.completedFuture)1 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)1 ONE (tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE)1 ZERO (tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO)1