Search in sources :

Example 1 with PeerLookup

use of tech.pegasys.teku.networking.eth2.peers.PeerLookup in project teku by ConsenSys.

the class BeaconChainMethods method createMetadata.

private static Eth2RpcMethod<EmptyMessage, MetadataMessage> createMetadata(final Spec spec, final AsyncRunner asyncRunner, final MetadataMessagesFactory metadataMessagesFactory, final PeerLookup peerLookup, final RpcEncoding rpcEncoding) {
    final MetadataMessageHandler messageHandler = new MetadataMessageHandler(spec, metadataMessagesFactory);
    final EmptyMessageSchema requestType = EmptyMessage.SSZ_SCHEMA;
    final boolean expectResponse = true;
    final SszSchema<MetadataMessage> phase0MetadataSchema = SszSchema.as(MetadataMessage.class, spec.forMilestone(SpecMilestone.PHASE0).getSchemaDefinitions().getMetadataMessageSchema());
    final RpcContextCodec<?, MetadataMessage> phase0ContextCodec = RpcContextCodec.noop(phase0MetadataSchema);
    final SingleProtocolEth2RpcMethod<EmptyMessage, MetadataMessage> v1Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.GET_METADATA, 1, rpcEncoding, requestType, expectResponse, phase0ContextCodec, messageHandler, peerLookup);
    if (spec.isMilestoneSupported(SpecMilestone.ALTAIR)) {
        final SszSchema<MetadataMessage> altairMetadataSchema = SszSchema.as(MetadataMessage.class, spec.forMilestone(SpecMilestone.ALTAIR).getSchemaDefinitions().getMetadataMessageSchema());
        final RpcContextCodec<?, MetadataMessage> altairContextCodec = RpcContextCodec.noop(altairMetadataSchema);
        final SingleProtocolEth2RpcMethod<EmptyMessage, MetadataMessage> v2Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.GET_METADATA, 2, rpcEncoding, requestType, expectResponse, altairContextCodec, messageHandler, peerLookup);
        return VersionedEth2RpcMethod.create(rpcEncoding, requestType, expectResponse, List.of(v2Method, v1Method));
    } else {
        return v1Method;
    }
}
Also used : MetadataMessageHandler(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessageHandler) SingleProtocolEth2RpcMethod(tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod) MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) EmptyMessageSchema(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage.EmptyMessageSchema) EmptyMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage)

Example 2 with PeerLookup

use of tech.pegasys.teku.networking.eth2.peers.PeerLookup 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 3 with PeerLookup

use of tech.pegasys.teku.networking.eth2.peers.PeerLookup in project teku by ConsenSys.

the class BeaconChainMethods method createStatus.

private static Eth2RpcMethod<StatusMessage, StatusMessage> createStatus(final AsyncRunner asyncRunner, final StatusMessageFactory statusMessageFactory, final PeerLookup peerLookup, final RpcEncoding rpcEncoding) {
    final StatusMessageHandler statusHandler = new StatusMessageHandler(statusMessageFactory);
    final RpcContextCodec<?, StatusMessage> contextCodec = RpcContextCodec.noop(StatusMessage.SSZ_SCHEMA);
    return new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.STATUS, 1, rpcEncoding, StatusMessage.SSZ_SCHEMA, true, contextCodec, statusHandler, peerLookup);
}
Also used : SingleProtocolEth2RpcMethod(tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod) StatusMessageHandler(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.StatusMessageHandler) StatusMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.StatusMessage)

Example 4 with PeerLookup

use of tech.pegasys.teku.networking.eth2.peers.PeerLookup in project teku by ConsenSys.

the class BeaconChainMethods method createGoodBye.

private static Eth2RpcMethod<GoodbyeMessage, GoodbyeMessage> createGoodBye(final AsyncRunner asyncRunner, final MetricsSystem metricsSystem, final PeerLookup peerLookup, final RpcEncoding rpcEncoding) {
    final GoodbyeMessageHandler goodbyeHandler = new GoodbyeMessageHandler(metricsSystem);
    final RpcContextCodec<?, GoodbyeMessage> contextCodec = RpcContextCodec.noop(GoodbyeMessage.SSZ_SCHEMA);
    return new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.GOODBYE, 1, rpcEncoding, GoodbyeMessage.SSZ_SCHEMA, false, contextCodec, goodbyeHandler, peerLookup);
}
Also used : SingleProtocolEth2RpcMethod(tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod) GoodbyeMessageHandler(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.GoodbyeMessageHandler) GoodbyeMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.GoodbyeMessage)

Example 5 with PeerLookup

use of tech.pegasys.teku.networking.eth2.peers.PeerLookup in project teku by ConsenSys.

the class BeaconChainMethods method createPing.

private static Eth2RpcMethod<PingMessage, PingMessage> createPing(final AsyncRunner asyncRunner, final MetadataMessagesFactory metadataMessagesFactory, final PeerLookup peerLookup, final RpcEncoding rpcEncoding) {
    final PingMessageHandler statusHandler = new PingMessageHandler(metadataMessagesFactory);
    final RpcContextCodec<?, PingMessage> contextCodec = RpcContextCodec.noop(PingMessage.SSZ_SCHEMA);
    return new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.PING, 1, rpcEncoding, PingMessage.SSZ_SCHEMA, true, contextCodec, statusHandler, peerLookup);
}
Also used : SingleProtocolEth2RpcMethod(tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod) PingMessageHandler(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.PingMessageHandler) PingMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.PingMessage)

Aggregations

SingleProtocolEth2RpcMethod (tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod)6 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)2 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)2 SignedBeaconBlockSchema (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema)2 Bytes (org.apache.tuweni.bytes.Bytes)1 BeaconBlocksByRangeMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRangeMessageHandler)1 BeaconBlocksByRootMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRootMessageHandler)1 GoodbyeMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.GoodbyeMessageHandler)1 MetadataMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessageHandler)1 PingMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.PingMessageHandler)1 StatusMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.StatusMessageHandler)1 BeaconBlocksByRangeRequestMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage)1 BeaconBlocksByRangeRequestMessageSchema (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage.BeaconBlocksByRangeRequestMessageSchema)1 BeaconBlocksByRootRequestMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage)1 BeaconBlocksByRootRequestMessageSchema (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema)1 EmptyMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage)1 EmptyMessageSchema (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage.EmptyMessageSchema)1 GoodbyeMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.GoodbyeMessage)1 PingMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.PingMessage)1 StatusMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.StatusMessage)1