From 4c20f7871d1c3e050d6bc221ea47571192cc64e5 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Wed, 22 Nov 2023 14:08:27 +0000 Subject: [PATCH] Avoid unnecessary ssz conversions when signing block for Deneb (#7747) --- .../blocks/versions/deneb/SignedBlockContents.java | 10 +++++++++- .../versions/deneb/SignedBlockContentsSchema.java | 7 +++++++ .../client/signer/BlockContainerSignerDeneb.java | 14 +++----------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContents.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContents.java index 8fe5acceef8..a8ebb3317e2 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContents.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContents.java @@ -37,7 +37,7 @@ public SignedBlockContents( final SignedBeaconBlock signedBeaconBlock, final List kzgProofs, final List blobs) { - super( + this( schema, signedBeaconBlock, schema @@ -46,6 +46,14 @@ public SignedBlockContents( schema.getBlobsSchema().createFromElements(blobs)); } + public SignedBlockContents( + final SignedBlockContentsSchema schema, + final SignedBeaconBlock signedBeaconBlock, + final SszList kzgProofs, + final SszList blobs) { + super(schema, signedBeaconBlock, kzgProofs, blobs); + } + @Override public SignedBeaconBlock getSignedBlock() { return getField0(); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContentsSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContentsSchema.java index 90899c0bc06..34f68ca6540 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContentsSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/versions/deneb/SignedBlockContentsSchema.java @@ -68,6 +68,13 @@ public SignedBlockContents create( return new SignedBlockContents(this, signedBeaconBlock, kzgProofs, blobs); } + public SignedBlockContents create( + final SignedBeaconBlock signedBeaconBlock, + final SszList kzgProofs, + final SszList blobs) { + return new SignedBlockContents(this, signedBeaconBlock, kzgProofs, blobs); + } + @Override public SignedBlockContents createFromBackingNode(final TreeNode node) { return new SignedBlockContents(this, node); 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 97fd2d69c9f..aa0648f3f1b 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 @@ -13,10 +13,8 @@ package tech.pegasys.teku.validator.client.signer; -import java.util.List; import tech.pegasys.teku.infrastructure.async.SafeFuture; -import tech.pegasys.teku.infrastructure.ssz.SszCollection; -import tech.pegasys.teku.kzg.KZGProof; +import tech.pegasys.teku.infrastructure.ssz.SszList; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; @@ -51,24 +49,18 @@ public SafeFuture sign( if (signedBlock.isBlinded()) { return signedBlock; } else { - final List kzgProofs = + final SszList kzgProofs = unsignedBlockContainer .getKzgProofs() - .map( - sszKzgProofs -> - sszKzgProofs.asList().stream() - .map(SszKZGProof::getKZGProof) - .toList()) .orElseThrow( () -> new RuntimeException( String.format( "Unable to get KZG Proofs when signing Deneb block at slot %d", unsignedBlockContainer.getSlot().longValue()))); - final List blobs = + final SszList blobs = unsignedBlockContainer .getBlobs() - .map(SszCollection::asList) .orElseThrow( () -> new RuntimeException(