Search in sources :

Example 1 with SpecMilestone

use of tech.pegasys.teku.spec.SpecMilestone in project teku by ConsenSys.

the class BeaconBlocksByRangeMessageHandler method validateRequest.

@Override
public Optional<RpcException> validateRequest(final String protocolId, final BeaconBlocksByRangeRequestMessage request) {
    final int version = BeaconChainMethodIds.extractBeaconBlocksByRangeVersion(protocolId);
    final SpecMilestone latestMilestoneRequested = spec.getForkSchedule().getSpecMilestoneAtSlot(request.getMaxSlot());
    final boolean isAltairActive = latestMilestoneRequested.isGreaterThanOrEqualTo(SpecMilestone.ALTAIR);
    if (version == 1 && isAltairActive) {
        return Optional.of(new InvalidRpcMethodVersion("Must request altair blocks using v2 protocol"));
    }
    return Optional.empty();
}
Also used : InvalidRpcMethodVersion(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone)

Example 2 with SpecMilestone

use of tech.pegasys.teku.spec.SpecMilestone in project teku by ConsenSys.

the class ForkDigestRpcContextCodec method encodeContext.

@Override
public Bytes encodeContext(TPayload responsePayload) {
    final UInt64 slot = payloadContext.getSlotFromPayload(responsePayload);
    final SpecMilestone specMilestone = spec.getForkSchedule().getSpecMilestoneAtSlot(slot);
    return recentChainData.getForkDigestByMilestone(specMilestone).map(Bytes4::getWrappedBytes).orElseThrow();
}
Also used : UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone)

Example 3 with SpecMilestone

use of tech.pegasys.teku.spec.SpecMilestone in project web3signer by ConsenSys.

the class BlockRequestDeserializer method deserialize.

@Override
public BlockRequest deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
    final ObjectCodec codec = p.getCodec();
    final JsonNode node = codec.readTree(p);
    final SpecMilestone specMilestone = SpecMilestone.valueOf(node.findValue("version").asText());
    final BeaconBlock beaconBlock;
    final BeaconBlockHeader beaconBlockHeader;
    final BlockRequest blockRequest;
    switch(specMilestone) {
        case PHASE0:
            beaconBlock = codec.treeToValue(node.findValue("block"), BeaconBlock.class);
            blockRequest = new BlockRequest(specMilestone, beaconBlock);
            break;
        case ALTAIR:
            beaconBlock = codec.treeToValue(node.findValue("block"), BeaconBlockAltair.class);
            blockRequest = new BlockRequest(specMilestone, beaconBlock);
            break;
        case BELLATRIX:
            // for BELLATRIX we only need block_header instead of complete block
            beaconBlockHeader = codec.treeToValue(node.findValue("block_header"), BeaconBlockHeader.class);
            blockRequest = new BlockRequest(specMilestone, beaconBlockHeader);
            break;
        default:
            throw new IllegalStateException("Fork version not yet supported: " + specMilestone);
    }
    return blockRequest;
}
Also used : BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) BeaconBlockHeader(tech.pegasys.teku.api.schema.BeaconBlockHeader) BlockRequest(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) BeaconBlockAltair(tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)

Example 4 with SpecMilestone

use of tech.pegasys.teku.spec.SpecMilestone in project teku by ConsenSys.

the class SnappyPreparedGossipMessage method createMessageIdCalculator.

private MessageIdCalculator createMessageIdCalculator(final String topic, final Bytes compressedData, final ForkDigestToMilestone forkDigestToMilestone) {
    final Bytes4 forkDigest = GossipTopics.extractForkDigest(topic);
    final SpecMilestone milestone = forkDigestToMilestone.getMilestone(forkDigest).orElseThrow(() -> new IllegalStateException("Failed to associate a milestone with the forkDigest in topic: " + topic));
    switch(milestone) {
        case PHASE0:
            return new MesssageIdCalculatorPhase0(compressedData);
        case ALTAIR:
        default:
            return new MesssageIdCalculatorAltair(compressedData, topic);
    }
}
Also used : Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone)

Example 5 with SpecMilestone

use of tech.pegasys.teku.spec.SpecMilestone in project teku by ConsenSys.

the class BeaconBlocksByRootMessageHandler method validateResponse.

@VisibleForTesting
Optional<RpcException> validateResponse(final String protocolId, final SignedBeaconBlock response) {
    final int version = BeaconChainMethodIds.extractBeaconBlocksByRootVersion(protocolId);
    final SpecMilestone milestoneAtResponse = spec.getForkSchedule().getSpecMilestoneAtSlot(response.getSlot());
    final boolean isAltairActive = milestoneAtResponse.isGreaterThanOrEqualTo(SpecMilestone.ALTAIR);
    if (version == 1 && isAltairActive) {
        return Optional.of(new InvalidRpcMethodVersion("Must request altair blocks using v2 protocol"));
    }
    return Optional.empty();
}
Also used : InvalidRpcMethodVersion(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

SpecMilestone (tech.pegasys.teku.spec.SpecMilestone)6 InvalidRpcMethodVersion (tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion)2 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)1 BeaconBlockHeader (tech.pegasys.teku.api.schema.BeaconBlockHeader)1 BeaconBlockAltair (tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)1 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 BlockRequest (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest)1