use of tech.pegasys.teku.networking.eth2.rpc.core.methods.Eth2RpcMethod 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.Eth2RpcMethod 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.Eth2RpcMethod 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.Eth2RpcMethod in project teku by ConsenSys.
the class ErrorConditionsIntegrationTest method shouldRejectInvalidRequests.
@Test
public void shouldRejectInvalidRequests() throws Exception {
final Eth2P2PNetwork network1 = networkFactory.builder().rpcEncoding(rpcEncoding).startNetwork();
final Eth2P2PNetwork network2 = networkFactory.builder().rpcEncoding(rpcEncoding).peer(network1).startNetwork();
final Eth2Peer peer = network1.getPeer(network2.getNodeId()).orElseThrow();
final Eth2RpcMethod<StatusMessage, StatusMessage> status = ((ActiveEth2P2PNetwork) network1).getBeaconChainMethods().status();
final SafeFuture<StatusMessage> response = peer.requestSingleItem(status, new InvalidStatusMessage(spec.getGenesisSpecConfig().getGenesisForkVersion()));
final RpcException expected = new LengthOutOfBoundsException();
Assertions.assertThatThrownBy(() -> Waiter.waitFor(response)).isInstanceOf(ExecutionException.class).extracting(Throwable::getCause).isInstanceOf(RpcException.class).is(new Condition<>(error -> {
final RpcException rpcException = (RpcException) error;
return rpcException.getErrorMessageString().equals(expected.getErrorMessageString()) && rpcException.getResponseCode() == expected.getResponseCode();
}, "Exception did not match expected exception %s", expected));
}
use of tech.pegasys.teku.networking.eth2.rpc.core.methods.Eth2RpcMethod 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);
}
Aggregations