Search in sources :

Example 1 with SignedBeaconBlockSchema

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;
    }
}
Also used : SingleProtocolEth2RpcMethod(tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod) BeaconBlocksByRangeRequestMessageSchema(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage.BeaconBlocksByRangeRequestMessageSchema) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) BeaconBlocksByRangeMessageHandler(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRangeMessageHandler) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBeaconBlockSchema(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema) BeaconBlocksByRangeRequestMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage)

Example 2 with SignedBeaconBlockSchema

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());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBeaconBlockSchema(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with SignedBeaconBlockSchema

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;
    }
}
Also used : BeaconBlocksByRootMessageHandler(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRootMessageHandler) Bytes(org.apache.tuweni.bytes.Bytes) SingleProtocolEth2RpcMethod(tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod) BeaconBlocksByRootRequestMessageSchema(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema) BeaconBlocksByRootRequestMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBeaconBlockSchema(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema)

Aggregations

SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)3 SignedBeaconBlockSchema (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema)3 Bytes (org.apache.tuweni.bytes.Bytes)2 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)2 SingleProtocolEth2RpcMethod (tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 BeaconBlocksByRangeMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRangeMessageHandler)1 BeaconBlocksByRootMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BeaconBlocksByRootMessageHandler)1 BeaconBlocksByRangeRequestMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage)1 BeaconBlocksByRangeRequestMessageSchema (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage.BeaconBlocksByRangeRequestMessageSchema)1 BeaconBlocksByRootRequestMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage)1 BeaconBlocksByRootRequestMessageSchema (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema)1