use of tech.pegasys.teku.infrastructure.bytes.Bytes4 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.infrastructure.bytes.Bytes4 in project teku by ConsenSys.
the class ActiveEth2P2PNetwork method getEth2Context.
private SafeFuture<Eth2Context> getEth2Context() {
final ChainHead chainHead = recentChainData.getChainHead().orElseThrow();
final Bytes4 forkDigest = recentChainData.getCurrentForkInfo().orElseThrow().getForkDigest(spec);
final UInt64 currentSlot = recentChainData.getCurrentSlot().orElseThrow();
final UInt64 currentEpoch = spec.computeEpochAtSlot(currentSlot);
return chainHead.getState().thenApply(chainHeadState -> {
final UInt64 activeValidatorsEpoch = spec.getMaxLookaheadEpoch(chainHeadState).min(currentEpoch);
final int activeValidators = spec.countActiveValidators(chainHeadState, activeValidatorsEpoch);
return Eth2Context.builder().currentSlot(currentSlot).activeValidatorCount(activeValidators).forkDigest(forkDigest).gossipEncoding(gossipEncoding).build();
});
}
use of tech.pegasys.teku.infrastructure.bytes.Bytes4 in project teku by ConsenSys.
the class Eth2GossipTopicFilter method computeRelevantTopics.
private Set<String> computeRelevantTopics(final RecentChainData recentChainData, final GossipEncoding gossipEncoding) {
final ForkInfo forkInfo = recentChainData.getCurrentForkInfo().orElseThrow();
final Bytes4 forkDigest = forkInfo.getForkDigest(spec);
final Set<String> topics = getAllTopics(gossipEncoding, forkDigest);
spec.getForkSchedule().getForks().stream().filter(fork -> fork.getEpoch().isGreaterThanOrEqualTo(forkInfo.getFork().getEpoch())).map(futureFork -> spec.atEpoch(futureFork.getEpoch()).miscHelpers().computeForkDigest(futureFork.getCurrent_version(), forkInfo.getGenesisValidatorsRoot())).forEach(futureForkDigest -> topics.addAll(getAllTopics(gossipEncoding, futureForkDigest)));
return topics;
}
use of tech.pegasys.teku.infrastructure.bytes.Bytes4 in project teku by ConsenSys.
the class GossipTopicsTest method getTopic.
@Test
public void getTopic() {
final Bytes4 forkDigest = Bytes4.fromHexString("0x01020304");
final String topicName = "test";
final String actual = GossipTopics.getTopic(forkDigest, topicName, gossipEncoding);
assertThat(actual).isEqualTo("/eth2/01020304/test/ssz_snappy");
}
use of tech.pegasys.teku.infrastructure.bytes.Bytes4 in project teku by ConsenSys.
the class PeerStatusFactory method random.
public PeerStatus random() {
final Bytes4 fork = spec.getGenesisSpecConfig().getGenesisForkVersion();
final Bytes32 finalizedRoot = randomBytes32();
final UInt64 finalizedEpoch = randomLong(0, 10);
final Bytes32 headRoot = randomBytes32();
final long minHeadSlot = (finalizedEpoch.longValue() + 2) * spec.getGenesisSpecConfig().getSlotsPerEpoch();
final UInt64 headSlot = randomLong(minHeadSlot, minHeadSlot + 5);
return new PeerStatus(fork, finalizedRoot, finalizedEpoch, headRoot, headSlot);
}
Aggregations