Skip to content

Commit

Permalink
remove unsused types
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed May 16, 2023
1 parent 79351b0 commit 57ef3d0
Show file tree
Hide file tree
Showing 38 changed files with 113 additions and 2,051 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,70 @@
package tech.pegasys.teku.beaconrestapi.handlers.v1.beacon;

import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.teku.api.schema.deneb.SignedBeaconBlockDeneb.SIGNED_BEACON_BLOCK_DENEB_TYPE;
import static tech.pegasys.teku.api.schema.deneb.SignedBlockContents.SIGNED_BLOCK_CONTENTS_TYPE;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.io.Resources;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.api.schema.SignedBeaconBlock;
import tech.pegasys.teku.api.schema.deneb.BlockContainer;
import tech.pegasys.teku.api.schema.deneb.SignedBeaconBlockDeneb;
import tech.pegasys.teku.api.schema.deneb.SignedBlockContents;
import tech.pegasys.teku.infrastructure.json.JsonUtil;
import tech.pegasys.teku.infrastructure.json.types.DeserializableOneOfTypeDefinition;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchema;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.SignedBlobSidecarSchema;
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContents;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContentsSchema;

public class DeserializeBlocksTest {

static Spec spec = TestSpecFactory.createMinimalDeneb();
public static final DeserializableOneOfTypeDefinition<BlockContainer, BlockContainerBuilder>
public static final DeserializableOneOfTypeDefinition<
tech.pegasys.teku.spec.datastructures.blocks.BlockContainer, BlockContainerBuilder>
DESERIALIZABLE_ONE_OF_SIGNED_BEACON_BLOCK_OR_SIGNED_BLOCK_CONTENTS =
DeserializableOneOfTypeDefinition.object(
BlockContainer.class, BlockContainerBuilder.class)
tech.pegasys.teku.spec.datastructures.blocks.BlockContainer.class,
BlockContainerBuilder.class)
.description(
"Submit a signed beacon block to the beacon node to be imported."
+ " The beacon node performs the required validation.")
.withType(
SignedBeaconBlock.isInstance,
tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock.isInstance,
s -> !s.contains("blob_sidecars"),
SIGNED_BEACON_BLOCK_DENEB_TYPE)
spec.getGenesisSchemaDefinitions()
.getSignedBeaconBlockSchema()
.getJsonTypeDefinition())
.withType(
SignedBlockContents.isInstance,
tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContents
.isInstance,
s -> s.contains("blob_sidecars"),
SIGNED_BLOCK_CONTENTS_TYPE)
SignedBlockContentsSchema.create(
spec.getGenesisSpecConfig().toVersionDeneb().orElseThrow(),
SignedBlobSidecarSchema.create(
BlobSidecarSchema.create(
new BlobSchema(
spec.getGenesisSpecConfig().toVersionDeneb().orElseThrow()))),
spec.getGenesisSchemaDefinitions().getSignedBeaconBlockSchema())
.getJsonTypeDefinition())
.build();

@Test
void shouldDeserializeSignedBlockContents() throws JsonProcessingException {
final BlockContainer result =
final tech.pegasys.teku.spec.datastructures.blocks.BlockContainer result =
JsonUtil.parse(
readResource("json/signed_block_contents.json"),
DESERIALIZABLE_ONE_OF_SIGNED_BEACON_BLOCK_OR_SIGNED_BLOCK_CONTENTS);
assertThat(result).isInstanceOf(SignedBlockContents.class);

SignedBlockContents signedBlockContents = (SignedBlockContents) result;

tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContents
internalSignedBlockContents =
signedBlockContents.asInternalSignedBlockContents(
spec.getGenesisSchemaDefinitions()
.toVersionDeneb()
.orElseThrow()
.getSignedBlockContentsSchema(),
spec.getGenesisSchemaDefinitions()
.toVersionDeneb()
.orElseThrow()
.getSignedBlobSidecarSchema(),
spec);
assertThat(internalSignedBlockContents.getSignedBeaconBlock()).isPresent();
assertThat(internalSignedBlockContents.getSignedBlobSidecars()).isPresent();
assertThat(internalSignedBlockContents.getSignedBlobSidecars().get())
assertThat(signedBlockContents.getSignedBeaconBlock()).isPresent();
assertThat(signedBlockContents.getSignedBlobSidecars()).isPresent();
assertThat(signedBlockContents.getSignedBlobSidecars().get())
.hasSize(spec.getMaxBlobsPerBlock().orElseThrow());
}

Expand All @@ -89,13 +90,10 @@ void shouldDeserializeSignedBeaconBlock() throws JsonProcessingException {

assertThat(result).isInstanceOf(SignedBeaconBlock.class);

SignedBeaconBlockDeneb signedBeaconBlockDeneb = (SignedBeaconBlockDeneb) result;

tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock internalSignedBeaconBlock =
signedBeaconBlockDeneb.asInternalSignedBeaconBlock(spec);
SignedBeaconBlock signedBeaconBlock = (SignedBeaconBlock) result;

assertThat(internalSignedBeaconBlock.getSignedBeaconBlock()).isPresent();
assertThat(internalSignedBeaconBlock.getSignedBlobSidecars()).isEmpty();
assertThat(signedBeaconBlock.getSignedBeaconBlock()).isPresent();
assertThat(signedBeaconBlock.getSignedBlobSidecars()).isEmpty();
}

protected String readResource(final String resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

package tech.pegasys.teku.api.schema;

import static tech.pegasys.teku.api.schema.AttestationData.ATTESTATION_DATA_TYPE;
import static tech.pegasys.teku.api.schema.BLSSignature.BLS_SIGNATURE_TYPE;
import static tech.pegasys.teku.api.schema.SchemaConstants.DESCRIPTION_BYTES96;
import static tech.pegasys.teku.api.schema.SchemaConstants.DESCRIPTION_BYTES_SSZ;

Expand All @@ -23,36 +21,19 @@
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Objects;
import org.apache.tuweni.bytes.Bytes;
import tech.pegasys.teku.infrastructure.json.types.CoreTypes;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema;

@SuppressWarnings("JavaCase")
public class Attestation {
@Schema(type = "string", format = "byte", description = DESCRIPTION_BYTES_SSZ)
public Bytes aggregation_bits;
public final Bytes aggregation_bits;

public AttestationData data;
public final AttestationData data;

@Schema(type = "string", format = "byte", description = DESCRIPTION_BYTES96)
public BLSSignature signature;

public static final DeserializableTypeDefinition<Attestation> ATTESTATION_TYPE =
DeserializableTypeDefinition.object(Attestation.class)
.initializer(Attestation::new)
.withField(
"aggregation_bits",
CoreTypes.BYTES_TYPE,
Attestation::getAggregationBits,
Attestation::setAggregationBits)
.withField("data", ATTESTATION_DATA_TYPE, Attestation::getData, Attestation::setData)
.withField(
"signature", BLS_SIGNATURE_TYPE, Attestation::getSignature, Attestation::setSignature)
.build();

public Attestation() {}
public final BLSSignature signature;

public Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation attestation) {
this.aggregation_bits = attestation.getAggregationBits().sszSerialize();
Expand All @@ -70,30 +51,6 @@ public Attestation(
this.signature = signature;
}

public Bytes getAggregationBits() {
return aggregation_bits;
}

public void setAggregationBits(Bytes aggregation_bits) {
this.aggregation_bits = aggregation_bits;
}

public AttestationData getData() {
return data;
}

public void setData(AttestationData data) {
this.data = data;
}

public BLSSignature getSignature() {
return signature;
}

public void setSignature(BLSSignature signature) {
this.signature = signature;
}

public tech.pegasys.teku.spec.datastructures.operations.Attestation asInternalAttestation(
final Spec spec) {
return asInternalAttestation(spec.atSlot(data.slot));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,28 @@

package tech.pegasys.teku.api.schema;

import static tech.pegasys.teku.api.schema.Checkpoint.CHECKPOINT_TYPE;
import static tech.pegasys.teku.api.schema.SchemaConstants.DESCRIPTION_BYTES32;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Objects;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.infrastructure.json.types.CoreTypes;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

@SuppressWarnings("JavaCase")
public class AttestationData {
@Schema(type = "string", format = "uint64")
public UInt64 slot;
public final UInt64 slot;

@Schema(type = "string", format = "uint64")
public UInt64 index;
public final UInt64 index;

@Schema(type = "string", format = "byte", description = DESCRIPTION_BYTES32)
public Bytes32 beacon_block_root;
public final Bytes32 beacon_block_root;

public Checkpoint source;
public Checkpoint target;

public static final DeserializableTypeDefinition<AttestationData> ATTESTATION_DATA_TYPE =
DeserializableTypeDefinition.object(AttestationData.class)
.initializer(AttestationData::new)
.withField(
"slot", CoreTypes.UINT64_TYPE, AttestationData::getSlot, AttestationData::setSlot)
.withField(
"index", CoreTypes.UINT64_TYPE, AttestationData::getIndex, AttestationData::setIndex)
.withField(
"beacon_block_root",
CoreTypes.BYTES32_TYPE,
AttestationData::getBeaconBlockRoot,
AttestationData::setBeaconBlockRoot)
.withField(
"source", CHECKPOINT_TYPE, AttestationData::getSource, AttestationData::setSource)
.withField(
"target", CHECKPOINT_TYPE, AttestationData::getTarget, AttestationData::setTarget)
.build();

public AttestationData() {}
public final Checkpoint source;
public final Checkpoint target;

@JsonCreator
public AttestationData(
Expand All @@ -81,46 +58,6 @@ public AttestationData(tech.pegasys.teku.spec.datastructures.operations.Attestat
this.target = new Checkpoint(data.getTarget());
}

public UInt64 getSlot() {
return slot;
}

public void setSlot(UInt64 slot) {
this.slot = slot;
}

public UInt64 getIndex() {
return index;
}

public void setIndex(UInt64 index) {
this.index = index;
}

public Bytes32 getBeaconBlockRoot() {
return beacon_block_root;
}

public void setBeaconBlockRoot(Bytes32 beacon_block_root) {
this.beacon_block_root = beacon_block_root;
}

public Checkpoint getSource() {
return source;
}

public void setSource(Checkpoint source) {
this.source = source;
}

public Checkpoint getTarget() {
return target;
}

public void setTarget(Checkpoint target) {
this.target = target;
}

public tech.pegasys.teku.spec.datastructures.operations.AttestationData
asInternalAttestationData() {
tech.pegasys.teku.spec.datastructures.state.Checkpoint src = source.asInternalCheckpoint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,17 @@

package tech.pegasys.teku.api.schema;

import static tech.pegasys.teku.api.schema.IndexedAttestation.INDEXED_ATTESTATION_TYPE;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing.AttesterSlashingSchema;

@SuppressWarnings("JavaCase")
public class AttesterSlashing {
public IndexedAttestation attestation_1;
public IndexedAttestation attestation_2;

public static final DeserializableTypeDefinition<AttesterSlashing> ATTESTER_SLASHING_TYPE =
DeserializableTypeDefinition.object(AttesterSlashing.class)
.initializer(AttesterSlashing::new)
.withField(
"attestation_1",
INDEXED_ATTESTATION_TYPE,
AttesterSlashing::getAttestation1,
AttesterSlashing::setAttestation1)
.withField(
"attestation_2",
INDEXED_ATTESTATION_TYPE,
AttesterSlashing::getAttestation2,
AttesterSlashing::setAttestation2)
.build();

public AttesterSlashing() {}
public final IndexedAttestation attestation_1;
public final IndexedAttestation attestation_2;

public AttesterSlashing(
tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing attesterSlashing) {
Expand All @@ -64,22 +44,6 @@ public AttesterSlashing(
return asInternalAttesterSlashing(spec.atSlot(attestation_1.data.slot));
}

public IndexedAttestation getAttestation1() {
return attestation_1;
}

public void setAttestation1(IndexedAttestation attestation_1) {
this.attestation_1 = attestation_1;
}

public IndexedAttestation getAttestation2() {
return attestation_2;
}

public void setAttestation2(IndexedAttestation attestation_2) {
this.attestation_2 = attestation_2;
}

public tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing
asInternalAttesterSlashing(final SpecVersion spec) {
final AttesterSlashingSchema attesterSlashingSchema =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes48;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.json.types.StringValueTypeDefinition;

@SuppressWarnings("JavaCase")
public class BLSPubKey {
Expand All @@ -29,13 +27,6 @@ public class BLSPubKey {

private final Bytes bytes;

public static final StringValueTypeDefinition<BLSPubKey> BLS_PUB_KEY_TYPE =
DeserializableTypeDefinition.string(BLSPubKey.class)
.formatter(BLSPubKey::toString)
.parser(BLSPubKey::fromHexString)
.format("byte")
.build();

public BLSPubKey(Bytes bytes) {
checkArgument(
bytes.size() == SIZE,
Expand Down
Loading

0 comments on commit 57ef3d0

Please sign in to comment.