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.
Support Deneb fork choice reference tests
- Loading branch information
1 parent
78a929f
commit 27ad1ac
Showing
9 changed files
with
288 additions
and
88 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
139 changes: 139 additions & 0 deletions
139
...erenceTest/java/tech/pegasys/teku/reference/phase0/forkchoice/StubBlobSidecarManager.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,139 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2023 | ||
* | ||
* 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.reference.phase0.forkchoice; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.infrastructure.async.SafeFuture; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.kzg.KZGCommitment; | ||
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.blobs.versions.deneb.SignedBlobSidecar; | ||
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; | ||
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.deneb.BeaconBlockBodyDeneb; | ||
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; | ||
import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers; | ||
import tech.pegasys.teku.spec.logic.versions.deneb.blobs.BlobSidecarsAndValidationResult; | ||
import tech.pegasys.teku.spec.logic.versions.deneb.blobs.BlobSidecarsAvailabilityChecker; | ||
import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; | ||
import tech.pegasys.teku.statetransition.blobs.BlobSidecarManagerImpl; | ||
import tech.pegasys.teku.statetransition.validation.InternalValidationResult; | ||
|
||
/** Simplified version of {@link BlobSidecarManagerImpl} which is used in reference tests */ | ||
class StubBlobSidecarManager implements BlobSidecarManager { | ||
|
||
private final Map<Bytes32, BlobsAndProofs> blobsAndProofsByBlockRoot = new HashMap<>(); | ||
|
||
private final Spec spec; | ||
|
||
StubBlobSidecarManager(final Spec spec) { | ||
this.spec = spec; | ||
} | ||
|
||
/** Manually provide blobs and proofs for a block * */ | ||
public void prepareBlobsAndProofsForBlock( | ||
final SignedBeaconBlock block, final List<Blob> blobs, final List<KZGProof> proofs) { | ||
blobsAndProofsByBlockRoot.put(block.getRoot(), new BlobsAndProofs(blobs, proofs)); | ||
} | ||
|
||
@Override | ||
public SafeFuture<InternalValidationResult> validateAndPrepareForBlockImport( | ||
final SignedBlobSidecar signedBlobSidecar) { | ||
return SafeFuture.failedFuture( | ||
new UnsupportedOperationException("Not available in fork_choice reference tests")); | ||
} | ||
|
||
@Override | ||
public void prepareForBlockImport(final BlobSidecar blobSidecar) { | ||
// NOOP | ||
} | ||
|
||
@Override | ||
public void subscribeToReceivedBlobSidecar( | ||
final ReceivedBlobSidecarListener receivedBlobSidecarListener) { | ||
// NOOP | ||
} | ||
|
||
@Override | ||
public boolean isAvailabilityRequiredAtSlot(final UInt64 slot) { | ||
// NOOP | ||
return false; | ||
} | ||
|
||
/** | ||
* Creates an implementation of {@link BlobSidecarsAvailabilityChecker} which uses the simplified | ||
* {@link MiscHelpers#isDataAvailable(List, List, List)} method with the already provided blobs | ||
* and proofs by the reference test | ||
*/ | ||
@Override | ||
public BlobSidecarsAvailabilityChecker createAvailabilityChecker(final SignedBeaconBlock block) { | ||
return new BlobSidecarsAvailabilityChecker() { | ||
@Override | ||
public boolean initiateDataAvailabilityCheck() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public SafeFuture<BlobSidecarsAndValidationResult> getAvailabilityCheckResult() { | ||
final BlobsAndProofs blobsAndProofs = blobsAndProofsByBlockRoot.get(block.getRoot()); | ||
if (blobsAndProofs == null) { | ||
return SafeFuture.completedFuture(BlobSidecarsAndValidationResult.NOT_REQUIRED); | ||
} | ||
return SafeFuture.completedFuture(validateBatch(block, blobsAndProofs)); | ||
} | ||
|
||
@Override | ||
public BlobSidecarsAndValidationResult validateImmediately( | ||
final List<BlobSidecar> blobSidecars) { | ||
throw new UnsupportedOperationException("Not available in fork_choice reference tests"); | ||
} | ||
|
||
public BlobSidecarsAndValidationResult validateBatch( | ||
final SignedBeaconBlock block, final BlobsAndProofs blobsAndProofs) { | ||
final List<KZGCommitment> kzgCommitments = | ||
BeaconBlockBodyDeneb.required(block.getMessage().getBody()) | ||
.getBlobKzgCommitments() | ||
.stream() | ||
.map(SszKZGCommitment::getKZGCommitment) | ||
.toList(); | ||
final List<Bytes> blobs = blobsAndProofs.blobs.stream().map(Blob::getBytes).toList(); | ||
try { | ||
if (!spec.atSlot(block.getSlot()) | ||
.miscHelpers() | ||
.isDataAvailable(blobs, kzgCommitments, blobsAndProofs.proofs)) { | ||
return BlobSidecarsAndValidationResult.invalidResult(Collections.emptyList()); | ||
} | ||
} catch (final Exception ex) { | ||
return BlobSidecarsAndValidationResult.invalidResult(Collections.emptyList(), ex); | ||
} | ||
return BlobSidecarsAndValidationResult.validResult(Collections.emptyList()); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public BlobSidecarsAndValidationResult createAvailabilityCheckerAndValidateImmediately( | ||
final SignedBeaconBlock block, final List<BlobSidecar> blobSidecars) { | ||
throw new UnsupportedOperationException("Not available in fork_choice reference tests"); | ||
} | ||
|
||
private record BlobsAndProofs(List<Blob> blobs, List<KZGProof> proofs) {} | ||
} |
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.