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();
}
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();
}
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;
}
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);
}
}
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();
}
Aggregations