Skip to content

Commit 51807fb

Browse files
Use slot-based SchemaDefinitions when creating/singing block for Deneb (#8047)
1 parent 6e65915 commit 51807fb

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,20 @@
2121
import tech.pegasys.teku.infrastructure.async.SafeFuture;
2222
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
2323
import tech.pegasys.teku.spec.Spec;
24-
import tech.pegasys.teku.spec.SpecMilestone;
2524
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar;
2625
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
2726
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
2827
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContents;
28+
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContentsSchema;
2929
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle;
3030
import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData;
3131
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
3232
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
3333

3434
public class BlockFactoryDeneb extends BlockFactoryPhase0 {
3535

36-
private final SchemaDefinitionsDeneb schemaDefinitionsDeneb;
37-
3836
public BlockFactoryDeneb(final Spec spec, final BlockOperationSelectorFactory operationSelector) {
3937
super(spec, operationSelector);
40-
this.schemaDefinitionsDeneb =
41-
SchemaDefinitionsDeneb.required(
42-
spec.forMilestone(SpecMilestone.DENEB).getSchemaDefinitions());
4338
}
4439

4540
@Override
@@ -81,8 +76,12 @@ public List<BlobSidecar> createBlobSidecars(final SignedBlockContainer blockCont
8176

8277
private BlockContents createBlockContents(
8378
final BeaconBlock block, final BlobsBundle blobsBundle) {
84-
return schemaDefinitionsDeneb
85-
.getBlockContentsSchema()
79+
return getBlockContentsSchema(block.getSlot())
8680
.create(block, blobsBundle.getProofs(), blobsBundle.getBlobs());
8781
}
82+
83+
private BlockContentsSchema getBlockContentsSchema(final UInt64 slot) {
84+
return SchemaDefinitionsDeneb.required(spec.atSlot(slot).getSchemaDefinitions())
85+
.getBlockContentsSchema();
86+
}
8887
}

validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/BlockContainerSignerDeneb.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515

1616
import tech.pegasys.teku.infrastructure.async.SafeFuture;
1717
import tech.pegasys.teku.infrastructure.ssz.SszList;
18+
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
1819
import tech.pegasys.teku.spec.Spec;
1920
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
2021
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
2122
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer;
2223
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
2324
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
25+
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.SignedBlockContentsSchema;
2426
import tech.pegasys.teku.spec.datastructures.state.ForkInfo;
2527
import tech.pegasys.teku.spec.datastructures.type.SszKZGProof;
2628
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
@@ -29,12 +31,9 @@
2931
public class BlockContainerSignerDeneb implements BlockContainerSigner {
3032

3133
private final Spec spec;
32-
private final SchemaDefinitionsDeneb schemaDefinitions;
3334

34-
public BlockContainerSignerDeneb(
35-
final Spec spec, final SchemaDefinitionsDeneb schemaDefinitions) {
35+
public BlockContainerSignerDeneb(final Spec spec) {
3636
this.spec = spec;
37-
this.schemaDefinitions = schemaDefinitions;
3837
}
3938

4039
@Override
@@ -67,8 +66,7 @@ public SafeFuture<SignedBlockContainer> sign(
6766
String.format(
6867
"Unable to get blobs when signing Deneb block at slot %d",
6968
unsignedBlockContainer.getSlot().longValue())));
70-
return schemaDefinitions
71-
.getSignedBlockContentsSchema()
69+
return getSignedBlockContentsSchema(signedBlock.getSlot())
7270
.create(signedBlock, kzgProofs, blobs);
7371
}
7472
});
@@ -81,4 +79,9 @@ private SafeFuture<SignedBeaconBlock> signBlock(
8179
.signBlock(unsignedBlock, forkInfo)
8280
.thenApply(signature -> SignedBeaconBlock.create(spec, unsignedBlock, signature));
8381
}
82+
83+
private SignedBlockContentsSchema getSignedBlockContentsSchema(final UInt64 slot) {
84+
return SchemaDefinitionsDeneb.required(spec.atSlot(slot).getSchemaDefinitions())
85+
.getSignedBlockContentsSchema();
86+
}
8487
}

validator/client/src/main/java/tech/pegasys/teku/validator/client/signer/MilestoneBasedBlockContainerSigner.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer;
2424
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
2525
import tech.pegasys.teku.spec.datastructures.state.ForkInfo;
26-
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
2726
import tech.pegasys.teku.validator.client.Validator;
2827

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

4039
// Not needed for all milestones
4140
final Supplier<BlockContainerSignerDeneb> blockContainerSignerDeneb =
42-
Suppliers.memoize(
43-
() -> {
44-
final SchemaDefinitionsDeneb schemaDefinitions =
45-
SchemaDefinitionsDeneb.required(
46-
spec.forMilestone(SpecMilestone.DENEB).getSchemaDefinitions());
47-
return new BlockContainerSignerDeneb(spec, schemaDefinitions);
48-
});
41+
Suppliers.memoize(() -> new BlockContainerSignerDeneb(spec));
4942

5043
// Populate forks signers
5144
spec.getEnabledMilestones()

0 commit comments

Comments
 (0)