Skip to content

Commit

Permalink
Use slot-based SchemaDefinitions when creating/singing block for Deneb (
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Mar 6, 2024
1 parent 6e65915 commit 51807fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,20 @@
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContents;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContentsSchema;
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle;
import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;

public class BlockFactoryDeneb extends BlockFactoryPhase0 {

private final SchemaDefinitionsDeneb schemaDefinitionsDeneb;

public BlockFactoryDeneb(final Spec spec, final BlockOperationSelectorFactory operationSelector) {
super(spec, operationSelector);
this.schemaDefinitionsDeneb =
SchemaDefinitionsDeneb.required(
spec.forMilestone(SpecMilestone.DENEB).getSchemaDefinitions());
}

@Override
Expand Down Expand Up @@ -81,8 +76,12 @@ public List<BlobSidecar> createBlobSidecars(final SignedBlockContainer blockCont

private BlockContents createBlockContents(
final BeaconBlock block, final BlobsBundle blobsBundle) {
return schemaDefinitionsDeneb
.getBlockContentsSchema()
return getBlockContentsSchema(block.getSlot())
.create(block, blobsBundle.getProofs(), blobsBundle.getBlobs());
}

private BlockContentsSchema getBlockContentsSchema(final UInt64 slot) {
return SchemaDefinitionsDeneb.required(spec.atSlot(slot).getSchemaDefinitions())
.getBlockContentsSchema();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@

import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContentsSchema;
import tech.pegasys.teku.spec.datastructures.state.ForkInfo;
import tech.pegasys.teku.spec.datastructures.type.SszKZGProof;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
Expand All @@ -29,12 +31,9 @@
public class BlockContainerSignerDeneb implements BlockContainerSigner {

private final Spec spec;
private final SchemaDefinitionsDeneb schemaDefinitions;

public BlockContainerSignerDeneb(
final Spec spec, final SchemaDefinitionsDeneb schemaDefinitions) {
public BlockContainerSignerDeneb(final Spec spec) {
this.spec = spec;
this.schemaDefinitions = schemaDefinitions;
}

@Override
Expand Down Expand Up @@ -67,8 +66,7 @@ public SafeFuture<SignedBlockContainer> sign(
String.format(
"Unable to get blobs when signing Deneb block at slot %d",
unsignedBlockContainer.getSlot().longValue())));
return schemaDefinitions
.getSignedBlockContentsSchema()
return getSignedBlockContentsSchema(signedBlock.getSlot())
.create(signedBlock, kzgProofs, blobs);
}
});
Expand All @@ -81,4 +79,9 @@ private SafeFuture<SignedBeaconBlock> signBlock(
.signBlock(unsignedBlock, forkInfo)
.thenApply(signature -> SignedBeaconBlock.create(spec, unsignedBlock, signature));
}

private SignedBlockContentsSchema getSignedBlockContentsSchema(final UInt64 slot) {
return SchemaDefinitionsDeneb.required(spec.atSlot(slot).getSchemaDefinitions())
.getSignedBlockContentsSchema();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.state.ForkInfo;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
import tech.pegasys.teku.validator.client.Validator;

public class MilestoneBasedBlockContainerSigner implements BlockContainerSigner {
Expand All @@ -39,13 +38,7 @@ public MilestoneBasedBlockContainerSigner(final Spec spec) {

// Not needed for all milestones
final Supplier<BlockContainerSignerDeneb> blockContainerSignerDeneb =
Suppliers.memoize(
() -> {
final SchemaDefinitionsDeneb schemaDefinitions =
SchemaDefinitionsDeneb.required(
spec.forMilestone(SpecMilestone.DENEB).getSchemaDefinitions());
return new BlockContainerSignerDeneb(spec, schemaDefinitions);
});
Suppliers.memoize(() -> new BlockContainerSignerDeneb(spec));

// Populate forks signers
spec.getEnabledMilestones()
Expand Down

0 comments on commit 51807fb

Please sign in to comment.