Search in sources :

Example 1 with SszBytes32

use of tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32 in project teku by ConsenSys.

the class BeaconBlocksByRootMessageHandler method onIncomingMessage.

@Override
public void onIncomingMessage(final String protocolId, final Eth2Peer peer, final BeaconBlocksByRootRequestMessage message, final ResponseCallback<SignedBeaconBlock> callback) {
    LOG.trace("Peer {} requested BeaconBlocks with roots: {}", peer.getId(), message);
    if (storageClient.getStore() != null) {
        SafeFuture<Void> future = SafeFuture.COMPLETE;
        if (!peer.wantToMakeRequest() || !peer.wantToReceiveObjects(callback, message.size())) {
            peer.disconnectCleanly(DisconnectReason.RATE_LIMITING).reportExceptions();
            return;
        }
        for (SszBytes32 blockRoot : message) {
            future = future.thenCompose(__ -> storageClient.getStore().retrieveSignedBlock(blockRoot.get()).thenCompose(block -> {
                final Optional<RpcException> validationResult = block.flatMap(b -> validateResponse(protocolId, b));
                if (validationResult.isPresent()) {
                    return SafeFuture.failedFuture(validationResult.get());
                }
                return block.map(callback::respond).orElse(SafeFuture.COMPLETE);
            }));
        }
        future.finish(callback::completeSuccessfully, err -> handleError(callback, err));
    } else {
        callback.completeSuccessfully();
    }
}
Also used : PeerRequiredLocalMessageHandler(tech.pegasys.teku.networking.eth2.rpc.core.PeerRequiredLocalMessageHandler) BeaconBlocksByRootRequestMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage) RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) ClosedChannelException(java.nio.channels.ClosedChannelException) Throwables(com.google.common.base.Throwables) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SszBytes32(tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32) ResponseCallback(tech.pegasys.teku.networking.eth2.rpc.core.ResponseCallback) DisconnectReason(tech.pegasys.teku.networking.p2p.peer.DisconnectReason) StreamClosedException(tech.pegasys.teku.networking.p2p.rpc.StreamClosedException) BeaconChainMethodIds(tech.pegasys.teku.networking.eth2.rpc.beaconchain.BeaconChainMethodIds) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) LogManager(org.apache.logging.log4j.LogManager) InvalidRpcMethodVersion(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) SszBytes32(tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32) RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Throwables (com.google.common.base.Throwables)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 Optional (java.util.Optional)1 LogManager (org.apache.logging.log4j.LogManager)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 SszBytes32 (tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32)1 Eth2Peer (tech.pegasys.teku.networking.eth2.peers.Eth2Peer)1 BeaconChainMethodIds (tech.pegasys.teku.networking.eth2.rpc.beaconchain.BeaconChainMethodIds)1 PeerRequiredLocalMessageHandler (tech.pegasys.teku.networking.eth2.rpc.core.PeerRequiredLocalMessageHandler)1 ResponseCallback (tech.pegasys.teku.networking.eth2.rpc.core.ResponseCallback)1 RpcException (tech.pegasys.teku.networking.eth2.rpc.core.RpcException)1 InvalidRpcMethodVersion (tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion)1 DisconnectReason (tech.pegasys.teku.networking.p2p.peer.DisconnectReason)1 StreamClosedException (tech.pegasys.teku.networking.p2p.rpc.StreamClosedException)1 Spec (tech.pegasys.teku.spec.Spec)1 SpecMilestone (tech.pegasys.teku.spec.SpecMilestone)1 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)1 BeaconBlocksByRootRequestMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage)1 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)1