use of tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema 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.spec.datastructures.blocks.SignedBeaconBlockSchema in project teku by ConsenSys.
the class Eth2OutgoingRequestHandlerTest method setup.
@BeforeEach
@Override
public void setup() {
super.setup();
final SignedBeaconBlockSchema signedBlockSchema = phase0Spec.forMilestone(SpecMilestone.PHASE0).getSchemaDefinitions().getSignedBeaconBlockSchema();
final RpcContextCodec<Bytes, SignedBeaconBlock> contextCodec = RpcContextCodec.noop(signedBlockSchema);
responseEncoder = new RpcResponseEncoder<>(getRpcEncoding(), contextCodec);
chunks = IntStream.range(0, maxChunks).mapToObj(this::chunkBytes).collect(Collectors.toList());
}
use of tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema in project teku by ConsenSys.
the class BeaconChainMethods method createBeaconBlocksByRoot.
private static Eth2RpcMethod<BeaconBlocksByRootRequestMessage, SignedBeaconBlock> createBeaconBlocksByRoot(final Spec spec, final AsyncRunner asyncRunner, final RecentChainData recentChainData, final PeerLookup peerLookup, final RpcEncoding rpcEncoding) {
final BeaconBlocksByRootMessageHandler beaconBlocksByRootHandler = new BeaconBlocksByRootMessageHandler(spec, recentChainData);
final BeaconBlocksByRootRequestMessageSchema requestType = BeaconBlocksByRootRequestMessage.SSZ_SCHEMA;
final boolean expectResponseToRequest = true;
// V1 request only deal with Phase0 blocks
final SignedBeaconBlockSchema phase0BlockSchema = spec.forMilestone(SpecMilestone.PHASE0).getSchemaDefinitions().getSignedBeaconBlockSchema();
final RpcContextCodec<Bytes, SignedBeaconBlock> noContextCodec = RpcContextCodec.noop(phase0BlockSchema);
final SingleProtocolEth2RpcMethod<BeaconBlocksByRootRequestMessage, SignedBeaconBlock> v1Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.BEACON_BLOCKS_BY_ROOT, 1, rpcEncoding, requestType, expectResponseToRequest, noContextCodec, beaconBlocksByRootHandler, peerLookup);
if (spec.isMilestoneSupported(SpecMilestone.ALTAIR)) {
final RpcContextCodec<Bytes4, SignedBeaconBlock> forkDigestContextCodec = RpcContextCodec.forkDigest(spec, recentChainData, ForkDigestPayloadContext.SIGNED_BEACONBLOCK);
final SingleProtocolEth2RpcMethod<BeaconBlocksByRootRequestMessage, SignedBeaconBlock> v2Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.BEACON_BLOCKS_BY_ROOT, 2, rpcEncoding, requestType, expectResponseToRequest, forkDigestContextCodec, beaconBlocksByRootHandler, peerLookup);
return VersionedEth2RpcMethod.create(rpcEncoding, requestType, expectResponseToRequest, List.of(v2Method, v1Method));
} else {
return v1Method;
}
}
Aggregations