forked from Consensys/teku
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ePBS] Block production (part 2) (Consensys#8598)
- Loading branch information
1 parent
8d95fed
commit 878969a
Showing
12 changed files
with
328 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...ch/pegasys/teku/validator/coordinator/CachingExecutionPayloadAndBlobSidecarsRevealer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* 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.validator.coordinator; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.IntStream; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.infrastructure.ssz.SszList; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.kzg.KZGProof; | ||
import tech.pegasys.teku.spec.Spec; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; | ||
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; | ||
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip7732.BeaconBlockBodyEip7732; | ||
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle; | ||
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadEnvelope; | ||
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; | ||
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse; | ||
import tech.pegasys.teku.spec.datastructures.execution.versions.eip7732.ExecutionPayloadHeaderEip7732; | ||
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; | ||
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; | ||
import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; | ||
import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb; | ||
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip7732; | ||
|
||
public class CachingExecutionPayloadAndBlobSidecarsRevealer | ||
implements ExecutionPayloadAndBlobSidecarsRevealer { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
// EIP7732 TODO: should probably use more optimized data structure | ||
private final Map<Bytes32, GetPayloadResponse> committedPayloads = new ConcurrentHashMap<>(); | ||
|
||
private final Spec spec; | ||
|
||
public CachingExecutionPayloadAndBlobSidecarsRevealer(final Spec spec) { | ||
this.spec = spec; | ||
} | ||
|
||
@Override | ||
public void commit( | ||
final ExecutionPayloadHeader header, final GetPayloadResponse getPayloadResponse) { | ||
committedPayloads.put(header.hashTreeRoot(), getPayloadResponse); | ||
} | ||
|
||
@Override | ||
public Optional<ExecutionPayloadEnvelope> revealExecutionPayload( | ||
final SignedBeaconBlock block, final BeaconState state) { | ||
final ExecutionPayloadHeaderEip7732 committedHeader = | ||
ExecutionPayloadHeaderEip7732.required( | ||
BeaconBlockBodyEip7732.required(block.getMessage().getBody()) | ||
.getSignedExecutionPayloadHeader() | ||
.getMessage()); | ||
final GetPayloadResponse getPayloadResponse = | ||
committedPayloads.get(committedHeader.hashTreeRoot()); | ||
if (getPayloadResponse == null) { | ||
logMissingPayload(block); | ||
return Optional.empty(); | ||
} | ||
final SchemaDefinitionsEip7732 schemaDefinitions = | ||
SchemaDefinitionsEip7732.required(spec.atSlot(block.getSlot()).getSchemaDefinitions()); | ||
final SszList<SszKZGCommitment> blobKzgCommitments = | ||
schemaDefinitions | ||
.getBlobKzgCommitmentsSchema() | ||
.createFromBlobsBundle(getPayloadResponse.getBlobsBundle().orElseThrow()); | ||
final ExecutionPayloadEnvelope executionPayload = | ||
schemaDefinitions | ||
.getExecutionPayloadEnvelopeSchema() | ||
.create( | ||
getPayloadResponse.getExecutionPayload(), | ||
committedHeader.getBuilderIndex(), | ||
block.getRoot(), | ||
blobKzgCommitments, | ||
false, | ||
state.hashTreeRoot()); | ||
return Optional.of(executionPayload); | ||
} | ||
|
||
@Override | ||
public List<BlobSidecar> revealBlobSidecars(final SignedBeaconBlock block) { | ||
final Bytes32 committedHeaderRoot = | ||
BeaconBlockBodyEip7732.required(block.getMessage().getBody()) | ||
.getSignedExecutionPayloadHeader() | ||
.getMessage() | ||
.hashTreeRoot(); | ||
// clean up the cached payload since it would be no longer used | ||
final GetPayloadResponse getPayloadResponse = committedPayloads.remove(committedHeaderRoot); | ||
if (getPayloadResponse == null) { | ||
logMissingPayload(block); | ||
return List.of(); | ||
} | ||
final MiscHelpersDeneb miscHelpersDeneb = | ||
MiscHelpersDeneb.required(spec.atSlot(block.getSlot()).miscHelpers()); | ||
|
||
final BlobsBundle blobsBundle = getPayloadResponse.getBlobsBundle().orElseThrow(); | ||
|
||
final List<Blob> blobs = blobsBundle.getBlobs(); | ||
final List<KZGProof> proofs = blobsBundle.getProofs(); | ||
|
||
// EIP7732 TODO: need to modify the constructBlobSidecar method in ePBS | ||
return IntStream.range(0, blobsBundle.getNumberOfBlobs()) | ||
.mapToObj( | ||
index -> | ||
miscHelpersDeneb.constructBlobSidecar( | ||
block, | ||
UInt64.valueOf(index), | ||
blobs.get(index), | ||
new SszKZGProof(proofs.get(index)))) | ||
.toList(); | ||
} | ||
|
||
private void logMissingPayload(final SignedBeaconBlock block) { | ||
LOG.error( | ||
"There is no committed payload for block with slot {} and root {}", | ||
block.getSlot(), | ||
block.getRoot()); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...java/tech/pegasys/teku/validator/coordinator/ExecutionPayloadAndBlobSidecarsRevealer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* 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.validator.coordinator; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; | ||
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; | ||
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadEnvelope; | ||
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; | ||
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse; | ||
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; | ||
|
||
public interface ExecutionPayloadAndBlobSidecarsRevealer { | ||
|
||
/** 1. builder commits to a header */ | ||
void commit(ExecutionPayloadHeader header, GetPayloadResponse getPayloadResponse); | ||
|
||
/** 2. builder reveals the payload */ | ||
Optional<ExecutionPayloadEnvelope> revealExecutionPayload( | ||
SignedBeaconBlock block, BeaconState state); | ||
|
||
/** 3. builder reveals the blob sidecars */ | ||
List<BlobSidecar> revealBlobSidecars(SignedBeaconBlock block); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.