Skip to content

Commit

Permalink
Merge branch 'master' into enable-publish-blob-afte-block-by-default
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr authored Dec 2, 2024
2 parents df6e68f + 6f78534 commit 9e47dff
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.spec.datastructures.operations;

import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
Expand All @@ -34,9 +35,13 @@ public interface Attestation extends SszContainer {
@Override
AttestationSchema<? extends Attestation> getSchema();

UInt64 getEarliestSlotForForkChoiceProcessing(final Spec spec);
default UInt64 getEarliestSlotForForkChoiceProcessing(final Spec spec) {
return getData().getEarliestSlotForForkChoice(spec);
}

Collection<Bytes32> getDependentBlockRoots();
default Collection<Bytes32> getDependentBlockRoots() {
return Sets.newHashSet(getData().getTarget().getRoot(), getData().getBeaconBlockRoot());
}

AttestationData getData();

Expand Down Expand Up @@ -65,4 +70,16 @@ default List<UInt64> getCommitteeIndicesRequired() {
}

boolean requiresCommitteeBits();

default boolean isSingleAttestation() {
return false;
}

default SingleAttestation toSingleAttestationRequired() {
throw new UnsupportedOperationException("Not a SingleAttestation");
}

default UInt64 getValidatorIndexRequired() {
throw new UnsupportedOperationException("Not a SingleAttestation");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ default SszBitlist createEmptyAggregationBits() {
return bitsSchema.ofBits(Math.toIntExact(bitsSchema.getMaxLength()));
}

default SszBitlist createAggregationBitsOf(final int size, final int... indices) {
final SszBitlistSchema<?> bitsSchema = getAggregationBitsSchema();
return bitsSchema.ofBits(size, indices);
}

default Optional<SszBitvector> createEmptyCommitteeBits() {
return getCommitteeBitsSchema().map(SszBitvectorSchema::ofBits);
}
Expand All @@ -54,6 +59,10 @@ default Optional<AttestationElectraSchema> toVersionElectra() {
return Optional.empty();
}

default SingleAttestationSchema toSingleAttestationSchemaRequired() {
throw new UnsupportedOperationException("Not a SingleAttestationSchema");
}

SszBitlistSchema<?> getAggregationBitsSchema();

Optional<SszBitvectorSchema<?>> getCommitteeBitsSchema();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright Consensys Software Inc., 2024
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.spec.datastructures.operations;

import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.ssz.containers.Container4;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;

public class SingleAttestation
extends Container4<SingleAttestation, SszUInt64, SszUInt64, AttestationData, SszSignature>
implements Attestation {
public SingleAttestation(final SingleAttestationSchema type, final TreeNode backingNode) {
super(type, backingNode);
}

public SingleAttestation(
final SingleAttestationSchema schema,
final UInt64 committeeIndex,
final UInt64 validatorIndex,
final AttestationData data,
final BLSSignature signature) {
super(
schema,
SszUInt64.of(committeeIndex),
SszUInt64.of(validatorIndex),
data,
new SszSignature(signature));
}

@Override
public SingleAttestationSchema getSchema() {
return (SingleAttestationSchema) super.getSchema();
}

@Override
public AttestationData getData() {
return getField2();
}

@Override
public SszBitlist getAggregationBits() {
throw new UnsupportedOperationException("Not supported in SingleAttestation");
}

@Override
public UInt64 getFirstCommitteeIndex() {
return getField0().get();
}

@Override
public BLSSignature getAggregateSignature() {
return getField3().getSignature();
}

public BLSSignature getSignature() {
return getField3().getSignature();
}

@Override
public boolean requiresCommitteeBits() {
return false;
}

@Override
public boolean isSingleAttestation() {
return true;
}

@Override
public SingleAttestation toSingleAttestationRequired() {
return this;
}

@Override
public UInt64 getValidatorIndexRequired() {
return getField1().get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright Consensys Software Inc., 2024
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.spec.datastructures.operations;

import java.util.Optional;
import java.util.function.Supplier;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema4;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitlistSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;

public class SingleAttestationSchema
extends ContainerSchema4<SingleAttestation, SszUInt64, SszUInt64, AttestationData, SszSignature>
implements AttestationSchema<SingleAttestation> {
public SingleAttestationSchema() {
super(
"SingleAttestation",
namedSchema("committee_index", SszPrimitiveSchemas.UINT64_SCHEMA),
namedSchema("attester_index", SszPrimitiveSchemas.UINT64_SCHEMA),
namedSchema("data", AttestationData.SSZ_SCHEMA),
namedSchema("signature", SszSignatureSchema.INSTANCE));
}

@Override
public SingleAttestation createFromBackingNode(final TreeNode node) {
return new SingleAttestation(this, node);
}

public SingleAttestation create(
final UInt64 committeeIndex,
final UInt64 attesterIndex,
final AttestationData data,
final BLSSignature signature) {
return new SingleAttestation(this, committeeIndex, attesterIndex, data, signature);
}

@Override
public Attestation create(
final SszBitlist aggregationBits,
final AttestationData data,
final BLSSignature signature,
final Supplier<SszBitvector> committeeBits) {
throw new UnsupportedOperationException("Not supported in SingleAttestation");
}

@Override
public SszBitlistSchema<?> getAggregationBitsSchema() {
throw new UnsupportedOperationException("Not supported in SingleAttestation");
}

@Override
public Optional<SszBitvectorSchema<?>> getCommitteeBitsSchema() {
return Optional.empty();
}

@Override
public SingleAttestationSchema toSingleAttestationSchemaRequired() {
return this;
}

@Override
public boolean requiresCommitteeBits() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@

package tech.pegasys.teku.spec.datastructures.operations.versions.electra;

import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector;
import tech.pegasys.teku.infrastructure.ssz.containers.Container4;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
Expand All @@ -51,16 +47,6 @@ public AttestationElectraSchema getSchema() {
return (AttestationElectraSchema) super.getSchema();
}

@Override
public UInt64 getEarliestSlotForForkChoiceProcessing(final Spec spec) {
return getData().getEarliestSlotForForkChoice(spec);
}

@Override
public Collection<Bytes32> getDependentBlockRoots() {
return Sets.newHashSet(getData().getTarget().getRoot(), getData().getBeaconBlockRoot());
}

@Override
public SszBitlist getAggregationBits() {
return getField0();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@

package tech.pegasys.teku.spec.datastructures.operations.versions.phase0;

import com.google.common.collect.Sets;
import java.util.Collection;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist;
import tech.pegasys.teku.infrastructure.ssz.containers.Container3;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
Expand All @@ -47,16 +43,6 @@ public AttestationPhase0Schema getSchema() {
return (AttestationPhase0Schema) super.getSchema();
}

@Override
public UInt64 getEarliestSlotForForkChoiceProcessing(final Spec spec) {
return getData().getEarliestSlotForForkChoice(spec);
}

@Override
public Collection<Bytes32> getDependentBlockRoots() {
return Sets.newHashSet(getData().getTarget().getRoot(), getData().getBeaconBlockRoot());
}

@Override
public SszBitlist getAggregationBits() {
return getField0();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.PENDING_CONSOLIDATIONS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.PENDING_DEPOSITS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.PENDING_PARTIAL_WITHDRAWALS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SINGLE_ATTESTATION_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_REQUEST_SCHEMA;

import java.util.Optional;
Expand All @@ -31,6 +32,7 @@
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.DepositRequestSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.WithdrawalRequestSchema;
import tech.pegasys.teku.spec.datastructures.operations.SingleAttestationSchema;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingConsolidation;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingConsolidation.PendingConsolidationSchema;
import tech.pegasys.teku.spec.datastructures.state.versions.electra.PendingDeposit;
Expand All @@ -53,13 +55,17 @@ public class SchemaDefinitionsElectra extends SchemaDefinitionsDeneb {
private final PendingPartialWithdrawalSchema pendingPartialWithdrawalSchema;
private final PendingConsolidationSchema pendingConsolidationSchema;

private final SingleAttestationSchema singleAttestationSchema;

public SchemaDefinitionsElectra(final SchemaRegistry schemaRegistry) {
super(schemaRegistry);
this.executionRequestsSchema = schemaRegistry.get(EXECUTION_REQUESTS_SCHEMA);
this.pendingDepositsSchema = schemaRegistry.get(PENDING_DEPOSITS_SCHEMA);
this.pendingPartialWithdrawalsSchema = schemaRegistry.get(PENDING_PARTIAL_WITHDRAWALS_SCHEMA);
this.pendingConsolidationsSchema = schemaRegistry.get(PENDING_CONSOLIDATIONS_SCHEMA);

this.singleAttestationSchema = schemaRegistry.get(SINGLE_ATTESTATION_SCHEMA);

this.depositRequestSchema = schemaRegistry.get(DEPOSIT_REQUEST_SCHEMA);
this.withdrawalRequestSchema = schemaRegistry.get(WITHDRAWAL_REQUEST_SCHEMA);
this.consolidationRequestSchema = schemaRegistry.get(CONSOLIDATION_REQUEST_SCHEMA);
Expand Down Expand Up @@ -126,6 +132,10 @@ public PendingConsolidation.PendingConsolidationSchema getPendingConsolidationSc
return pendingPartialWithdrawalsSchema;
}

public SingleAttestationSchema getSingleAttestationSchema() {
return singleAttestationSchema;
}

public SszListSchema<PendingConsolidation, ?> getPendingConsolidationsSchema() {
return pendingConsolidationsSchema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BLOCK_CONTENTS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BLS_TO_EXECUTION_CHANGE_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SIGNED_BUILDER_BID_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SINGLE_ATTESTATION_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SYNCNETS_ENR_FIELD_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_REQUEST_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.WITHDRAWAL_SCHEMA;
Expand Down Expand Up @@ -117,6 +118,7 @@
import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema;
import tech.pegasys.teku.spec.datastructures.operations.SingleAttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttestationElectraSchema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema;
Expand Down Expand Up @@ -188,7 +190,14 @@ public static SchemaRegistryBuilder create() {
.addProvider(createDepositRequestSchemaProvider())
.addProvider(createWithdrawalRequestSchemaProvider())
.addProvider(createConsolidationRequestSchemaProvider())
.addProvider(createExecutionRequestsSchemaProvider());
.addProvider(createExecutionRequestsSchemaProvider())
.addProvider(createSingleAttestationSchemaProvider());
}

private static SchemaProvider<?> createSingleAttestationSchemaProvider() {
return providerBuilder(SINGLE_ATTESTATION_SCHEMA)
.withCreator(ELECTRA, (registry, specConfig, schemaName) -> new SingleAttestationSchema())
.build();
}

private static SchemaProvider<?> createDepositRequestSchemaProvider() {
Expand Down
Loading

0 comments on commit 9e47dff

Please sign in to comment.