From 51807fbf17f15f343a0d84aa9fadaf6dc64c30e5 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Wed, 6 Mar 2024 15:58:40 +0000 Subject: [PATCH] Use slot-based SchemaDefinitions when creating/singing block for Deneb (#8047) --- .../validator/coordinator/BlockFactoryDeneb.java | 15 +++++++-------- .../client/signer/BlockContainerSignerDeneb.java | 15 +++++++++------ .../MilestoneBasedBlockContainerSigner.java | 9 +-------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java index ef0aeb8ec5d..c2fef608644 100644 --- a/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java +++ b/beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java @@ -21,11 +21,11 @@ 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; @@ -33,13 +33,8 @@ 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 @@ -81,8 +76,12 @@ public List 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(); + } } diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/BlockContainerSignerDeneb.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/BlockContainerSignerDeneb.java index aa0648f3f1b..d7aaaf16c9d 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/BlockContainerSignerDeneb.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/BlockContainerSignerDeneb.java @@ -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; @@ -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 @@ -67,8 +66,7 @@ public SafeFuture 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); } }); @@ -81,4 +79,9 @@ private SafeFuture 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(); + } } diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/MilestoneBasedBlockContainerSigner.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/MilestoneBasedBlockContainerSigner.java index 8856a254b55..46b7528d514 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/MilestoneBasedBlockContainerSigner.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/MilestoneBasedBlockContainerSigner.java @@ -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 { @@ -39,13 +38,7 @@ public MilestoneBasedBlockContainerSigner(final Spec spec) { // Not needed for all milestones final Supplier 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()