use of tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod 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;
}
}
use of tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod 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.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod 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);
}
use of tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod 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);
}
use of tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod 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);
}
Aggregations