Skip to content

Commit

Permalink
8933 containers (#8986)
Browse files Browse the repository at this point in the history
* add inclusion list containers
  • Loading branch information
mehdi-aouadi authored Jan 13, 2025
1 parent 9f1c122 commit a3cd37b
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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.List;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.containers.Container4;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
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.execution.Transaction;

public class InclusionList
extends Container4<InclusionList, SszUInt64, SszUInt64, SszBytes32, SszList<Transaction>> {
protected InclusionList(
final InclusionListSchema schema,
final SszUInt64 slot,
final SszUInt64 validatorIndex,
final SszBytes32 inclusionListCommitteeRoot,
final SszList<Transaction> transactions) {
super(schema, slot, validatorIndex, inclusionListCommitteeRoot, transactions);
}

InclusionList(final InclusionListSchema type, final TreeNode backingNode) {
super(type, backingNode);
}

public UInt64 getSlot() {
return getField0().get();
}

public UInt64 getValidatorIndex() {
return getField1().get();
}

public Bytes32 getInclusionListCommitteeRoot() {
return getField2().get();
}

public List<Transaction> getTransactions() {
return getField3().asList();
}

@Override
public InclusionListSchema getSchema() {
return (InclusionListSchema) super.getSchema();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema4;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.config.SpecConfigEip7805;
import tech.pegasys.teku.spec.datastructures.execution.Transaction;
import tech.pegasys.teku.spec.datastructures.execution.TransactionSchema;

public class InclusionListSchema
extends ContainerSchema4<
InclusionList, SszUInt64, SszUInt64, SszBytes32, SszList<Transaction>> {

public InclusionListSchema(final SpecConfigEip7805 specConfigEip7805) {
super(
"InclusionList",
namedSchema("slot", SszPrimitiveSchemas.UINT64_SCHEMA),
namedSchema("validator_index", SszPrimitiveSchemas.UINT64_SCHEMA),
namedSchema("inclusion_list_committee_root", SszPrimitiveSchemas.BYTES32_SCHEMA),
namedSchema(
"transactions",
SszListSchema.create(
new TransactionSchema(specConfigEip7805),
specConfigEip7805.getMaxTransactionsPerInclusionList())));
}

@Override
public InclusionList createFromBackingNode(final TreeNode node) {
return new InclusionList(this, node);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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.containers.Container2;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;

public class SignedInclusionList
extends Container2<SignedInclusionList, InclusionList, SszSignature> {

public SignedInclusionList(final SignedInclusionListSchema type, final TreeNode backingNode) {
super(type, backingNode);
}

public SignedInclusionList(
final SignedInclusionListSchema schema,
final InclusionList message,
final BLSSignature signature) {
super(schema, message, new SszSignature(signature));
}

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

public InclusionList getMessage() {
return getField0();
}

public BLSSignature getSignature() {
return getField1().getSignature();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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 static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.INCLUSION_LIST_SCHEMA;

import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class SignedInclusionListSchema
extends ContainerSchema2<SignedInclusionList, InclusionList, SszSignature> {

public SignedInclusionListSchema(
final String containerName, final SchemaRegistry schemaRegistry) {
super(
containerName,
namedSchema("message", schemaRegistry.get(INCLUSION_LIST_SCHEMA)),
namedSchema("signature", SszSignatureSchema.INSTANCE));
}

public InclusionListSchema getInclusionListSchema() {
return (InclusionListSchema) getFieldSchema0();
}

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

public SignedInclusionList create(final InclusionList message, final BLSSignature signature) {
return new SignedInclusionList(this, message, signature);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
import static com.google.common.base.Preconditions.checkArgument;

import java.util.Optional;
import tech.pegasys.teku.spec.datastructures.operations.InclusionListSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedInclusionListSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;
import tech.pegasys.teku.spec.schemas.registry.SchemaTypes;

public class SchemaDefinitionsEip7805 extends SchemaDefinitionsElectra {

private final InclusionListSchema inclusionListSchema;
private final SignedInclusionListSchema signedInclusionListSchema;

public SchemaDefinitionsEip7805(final SchemaRegistry schemaRegistry) {
super(schemaRegistry);
this.inclusionListSchema = schemaRegistry.get(SchemaTypes.INCLUSION_LIST_SCHEMA);
this.signedInclusionListSchema = schemaRegistry.get(SchemaTypes.SIGNED_INCLUSION_LIST_SCHEMA);
}

public static SchemaDefinitionsEip7805 required(final SchemaDefinitions schemaDefinitions) {
Expand All @@ -33,6 +41,14 @@ public static SchemaDefinitionsEip7805 required(final SchemaDefinitions schemaDe
return (SchemaDefinitionsEip7805) schemaDefinitions;
}

public InclusionListSchema getInclusionListSchema() {
return inclusionListSchema;
}

public SignedInclusionListSchema getSignedInclusionListSchema() {
return signedInclusionListSchema;
}

@Override
public Optional<SchemaDefinitionsEip7805> toVersionEip7805() {
return Optional.of(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static tech.pegasys.teku.spec.SpecMilestone.BELLATRIX;
import static tech.pegasys.teku.spec.SpecMilestone.CAPELLA;
import static tech.pegasys.teku.spec.SpecMilestone.DENEB;
import static tech.pegasys.teku.spec.SpecMilestone.EIP7805;
import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA;
import static tech.pegasys.teku.spec.SpecMilestone.PHASE0;
import static tech.pegasys.teku.spec.schemas.registry.BaseSchemaProvider.providerBuilder;
Expand Down Expand Up @@ -48,6 +49,7 @@
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.EXECUTION_REQUESTS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_BATCH_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_SUMMARIES_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.INCLUSION_LIST_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.INDEXED_ATTESTATION_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.PENDING_CONSOLIDATIONS_SCHEMA;
import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.PENDING_DEPOSITS_SCHEMA;
Expand All @@ -58,6 +60,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.SIGNED_INCLUSION_LIST_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;
Expand All @@ -73,6 +76,7 @@
import tech.pegasys.teku.spec.config.SpecConfigBellatrix;
import tech.pegasys.teku.spec.config.SpecConfigCapella;
import tech.pegasys.teku.spec.config.SpecConfigDeneb;
import tech.pegasys.teku.spec.config.SpecConfigEip7805;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.constants.NetworkConstants;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobKzgCommitmentsSchema;
Expand Down Expand Up @@ -115,9 +119,11 @@
import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema;
import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChangeSchema;
import tech.pegasys.teku.spec.datastructures.operations.InclusionListSchema;
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.SignedInclusionListSchema;
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;
Expand Down Expand Up @@ -191,7 +197,11 @@ public static SchemaRegistryBuilder create() {
.addProvider(createWithdrawalRequestSchemaProvider())
.addProvider(createConsolidationRequestSchemaProvider())
.addProvider(createExecutionRequestsSchemaProvider())
.addProvider(createSingleAttestationSchemaProvider());
.addProvider(createSingleAttestationSchemaProvider())

// EIP7805
.addProvider(createInclusionListSchemaProvider())
.addProvider(createSignedInclusionListSchemaProvider());
}

private static SchemaProvider<?> createSingleAttestationSchemaProvider() {
Expand Down Expand Up @@ -664,6 +674,24 @@ private static SchemaProvider<?> createSignedAggregateAndProofSchemaProvider() {
.build();
}

private static SchemaProvider<?> createInclusionListSchemaProvider() {
return providerBuilder(INCLUSION_LIST_SCHEMA)
.withCreator(
EIP7805,
(registry, specConfig, schemaName) ->
new InclusionListSchema(SpecConfigEip7805.required(specConfig)))
.build();
}

private static SchemaProvider<?> createSignedInclusionListSchemaProvider() {
return providerBuilder(SIGNED_INCLUSION_LIST_SCHEMA)
.withCreator(
EIP7805,
(registry, specConfig, schemaName) ->
new SignedInclusionListSchema(schemaName, registry))
.build();
}

private static long getMaxValidatorsPerAttestationPhase0(final SpecConfig specConfig) {
return specConfig.getMaxValidatorsPerCommittee();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema;
import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChangeSchema;
import tech.pegasys.teku.spec.datastructures.operations.InclusionListSchema;
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.SignedInclusionListSchema;
import tech.pegasys.teku.spec.datastructures.operations.SingleAttestationSchema;
import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
Expand Down Expand Up @@ -173,6 +175,12 @@ public class SchemaTypes {
public static final SchemaId<SingleAttestationSchema> SINGLE_ATTESTATION_SCHEMA =
create("SINGLE_ATTESTATION_SCHEMA");

// EIP7805
public static final SchemaId<InclusionListSchema> INCLUSION_LIST_SCHEMA =
create("INCLUSION_LIST_SCHEMA");
public static final SchemaId<SignedInclusionListSchema> SIGNED_INCLUSION_LIST_SCHEMA =
create("SIGNED_INCLUSION_LIST_SCHEMA");

private SchemaTypes() {
// Prevent instantiation
}
Expand Down

0 comments on commit a3cd37b

Please sign in to comment.