Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Sep 10, 2024
1 parent 5f4bd6c commit bf60b7e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadResult;
import tech.pegasys.teku.spec.datastructures.execution.SignedExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
Expand All @@ -63,10 +64,11 @@
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip7732;
import tech.pegasys.teku.statetransition.OperationPool;
import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool;
import tech.pegasys.teku.statetransition.attestation.AttestationForkChecker;
import tech.pegasys.teku.statetransition.attestation.PayloadAttestationPool;
import tech.pegasys.teku.statetransition.execution.ExecutionPayloadHeaderPool;
import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier;
import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool;

Expand All @@ -78,6 +80,8 @@ public class BlockOperationSelectorFactory {
private final OperationPool<SignedVoluntaryExit> voluntaryExitPool;
private final OperationPool<SignedBlsToExecutionChange> blsToExecutionChangePool;
private final SyncCommitteeContributionPool contributionPool;
private final ExecutionPayloadHeaderPool executionPayloadHeaderPool;
private final PayloadAttestationPool payloadAttestationPool;
private final DepositProvider depositProvider;
private final Eth1DataCache eth1DataCache;
private final GraffitiBuilder graffitiBuilder;
Expand All @@ -92,6 +96,8 @@ public BlockOperationSelectorFactory(
final OperationPool<SignedVoluntaryExit> voluntaryExitPool,
final OperationPool<SignedBlsToExecutionChange> blsToExecutionChangePool,
final SyncCommitteeContributionPool contributionPool,
final ExecutionPayloadHeaderPool executionPayloadHeaderPool,
final PayloadAttestationPool payloadAttestationPool,
final DepositProvider depositProvider,
final Eth1DataCache eth1DataCache,
final GraffitiBuilder graffitiBuilder,
Expand All @@ -104,6 +110,8 @@ public BlockOperationSelectorFactory(
this.voluntaryExitPool = voluntaryExitPool;
this.blsToExecutionChangePool = blsToExecutionChangePool;
this.contributionPool = contributionPool;
this.executionPayloadHeaderPool = executionPayloadHeaderPool;
this.payloadAttestationPool = payloadAttestationPool;
this.depositProvider = depositProvider;
this.eth1DataCache = eth1DataCache;
this.graffitiBuilder = graffitiBuilder;
Expand Down Expand Up @@ -173,6 +181,12 @@ public Function<BeaconBlockBodyBuilder, SafeFuture<Void>> createSelector(
blsToExecutionChangePool.getItemsForBlock(blockSlotState));
}

// Post-ePBS: Payload attestations
if (bodyBuilder.supportsPayloadAttestations()) {
bodyBuilder.payloadAttestations(
payloadAttestationPool.getPayloadAttestationsForBlock(blockSlotState));
}

final SchemaDefinitions schemaDefinitions =
spec.atSlot(blockSlotState.getSlot()).getSchemaDefinitions();

Expand Down Expand Up @@ -226,32 +240,17 @@ private SafeFuture<Void> setExecutionData(
return SafeFuture.COMPLETE;
}

// ePBS (TODO: placeholder) also the whole flow requires refactor
// ePBS (EIP7732 TODO: placeholder) need to think about the 3 flows (local, builder, p2p pool)
if (bodyBuilder.supportsSignedExecutionPayloadHeader()) {
final SchemaDefinitionsEip7732 schemaDefinitionsEip7732 =
SchemaDefinitionsEip7732.required(schemaDefinitions);
final ExecutionPayloadHeader emptyHeader =
schemaDefinitions
.getExecutionPayloadHeaderSchema()
.createExecutionPayloadHeader(
builder ->
builder
.parentBlockHash(() -> Bytes32.ZERO)
.parentBlockRoot(() -> Bytes32.ZERO)
.blockHash(Bytes32.ZERO)
.gasLimit(UInt64.ZERO)
.builderIndex(() -> UInt64.ZERO)
.slot(() -> UInt64.ZERO)
.value(() -> UInt64.ZERO)
.blobKzgCommitmentsRoot(() -> Bytes32.ZERO));
// empty signed header
bodyBuilder.signedExecutionPayloadHeader(
schemaDefinitionsEip7732
.getSignedExecutionPayloadHeaderSchema()
.create(emptyHeader, BLSSignature.empty()));
// empty list
bodyBuilder.payloadAttestations(
schemaDefinitionsEip7732.getPayloadAttestationsSchema().createFromElements(List.of()));
final SignedExecutionPayloadHeader bid =
executionPayloadHeaderPool
.selectBidForBlock(blockSlotState)
.orElseThrow(
() ->
new IllegalStateException(
"No bid available during block production for slot "
+ blockSlotState.getSlot()));
bodyBuilder.signedExecutionPayloadHeader(bid);
return SafeFuture.COMPLETE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
import tech.pegasys.teku.spec.util.DataStructureUtil;
import tech.pegasys.teku.statetransition.OperationPool;
import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool;
import tech.pegasys.teku.statetransition.attestation.PayloadAttestationPool;
import tech.pegasys.teku.statetransition.execution.ExecutionPayloadHeaderPool;
import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier;
import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool;
import tech.pegasys.teku.storage.client.RecentChainData;
Expand All @@ -109,6 +111,10 @@ public abstract class AbstractBlockFactoryTest {
mock(ExecutionLayerBlockProductionManager.class);
protected final SyncCommitteeContributionPool syncCommitteeContributionPool =
mock(SyncCommitteeContributionPool.class);
protected final ExecutionPayloadHeaderPool executionPayloadHeaderPool =
mock(ExecutionPayloadHeaderPool.class);
protected final PayloadAttestationPool payloadAttestationPool =
mock(PayloadAttestationPool.class);
protected final DepositProvider depositProvider = mock(DepositProvider.class);
protected final Eth1DataCache eth1DataCache = mock(Eth1DataCache.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ public BlockFactory createBlockFactory(final Spec spec) {
voluntaryExitPool,
blsToExecutionChangePool,
syncCommitteeContributionPool,
executionPayloadHeaderPool,
payloadAttestationPool,
depositProvider,
eth1DataCache,
graffitiBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ public BlockFactory createBlockFactory(final Spec spec) {
voluntaryExitPool,
blsToExecutionChangePool,
syncCommitteeContributionPool,
executionPayloadHeaderPool,
payloadAttestationPool,
depositProvider,
eth1DataCache,
graffitiBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
import tech.pegasys.teku.statetransition.OperationPool;
import tech.pegasys.teku.statetransition.SimpleOperationPool;
import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool;
import tech.pegasys.teku.statetransition.attestation.PayloadAttestationPool;
import tech.pegasys.teku.statetransition.execution.ExecutionPayloadHeaderPool;
import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier;
import tech.pegasys.teku.statetransition.synccommittee.SignedContributionAndProofValidator;
import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool;
Expand Down Expand Up @@ -128,6 +130,9 @@ class BlockOperationSelectorFactoryTest {
private final SignedContributionAndProofValidator contributionValidator =
mock(SignedContributionAndProofValidator.class);

private final OperationValidator<SignedExecutionPayloadHeader> executionPayloadHeaderValidator =
mock(OperationValidator.class);

private final AggregatingAttestationPool attestationPool = mock(AggregatingAttestationPool.class);
private final OperationPool<AttesterSlashing> attesterSlashingPool =
new SimpleOperationPool<>(
Expand Down Expand Up @@ -162,6 +167,12 @@ class BlockOperationSelectorFactoryTest {
private final SyncCommitteeContributionPool contributionPool =
new SyncCommitteeContributionPool(spec, contributionValidator);

private final ExecutionPayloadHeaderPool executionPayloadHeaderPool =
new ExecutionPayloadHeaderPool(executionPayloadHeaderValidator);

private final PayloadAttestationPool payloadAttestationPool =
new PayloadAttestationPool(spec, metricsSystem);

private final DepositProvider depositProvider = mock(DepositProvider.class);
private final Eth1DataCache eth1DataCache = mock(Eth1DataCache.class);
private final Bytes32 defaultGraffiti = dataStructureUtil.randomBytes32();
Expand Down Expand Up @@ -192,6 +203,8 @@ class BlockOperationSelectorFactoryTest {
voluntaryExitPool,
blsToExecutionChangePool,
contributionPool,
executionPayloadHeaderPool,
payloadAttestationPool,
depositProvider,
eth1DataCache,
graffitiBuilder,
Expand All @@ -206,6 +219,8 @@ class BlockOperationSelectorFactoryTest {
voluntaryExitPool,
blsToExecutionChangePool,
contributionPool,
executionPayloadHeaderPool,
payloadAttestationPool,
depositProvider,
eth1DataCache,
graffitiBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tech.pegasys.teku.api.schema.bellatrix.BeaconStateBellatrix;
import tech.pegasys.teku.api.schema.capella.BeaconStateCapella;
import tech.pegasys.teku.api.schema.deneb.BeaconStateDeneb;
import tech.pegasys.teku.api.schema.eip7732.BeaconStateEip7732;
import tech.pegasys.teku.api.schema.electra.BeaconStateElectra;
import tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0;
import tech.pegasys.teku.spec.Spec;
Expand All @@ -42,7 +43,7 @@ public void shouldConvertToInternalObject(final SpecContext ctx) {
case CAPELLA -> new BeaconStateCapella(beaconStateInternal);
case DENEB -> new BeaconStateDeneb(beaconStateInternal);
case ELECTRA -> new BeaconStateElectra(beaconStateInternal);
case EIP7732 -> throw new UnsupportedOperationException("EIP7732 TODO");
case EIP7732 -> new BeaconStateEip7732(beaconStateInternal);
};

assertThat(beaconState.asInternalBeaconState(spec)).isEqualTo(beaconStateInternal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.infrastructure.ssz.schema.SszPrimitiveSchemas;
import tech.pegasys.teku.infrastructure.ssz.tree.GIndexUtil;
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode;
import tech.pegasys.teku.spec.config.SpecConfigEip7732;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
Expand Down Expand Up @@ -226,12 +225,9 @@ public long getBlobKzgCommitmentsGeneralizedIndex() {
throw new UnsupportedOperationException("BlobKzgCommitments removed in Eip7732");
}

// TODO: not sure what to do here
@Override
public LongList getBlindedNodeGeneralizedIndices() {
return GIndexUtil.gIdxComposeAll(
getChildGeneralizedIndex(getFieldIndex(BlockBodyFields.EXECUTION_PAYLOAD)),
getExecutionPayloadSchema().getBlindedNodeGeneralizedIndices());
return LongList.of();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.TestSpecContext;
import tech.pegasys.teku.spec.TestSpecInvocationContextProvider.SpecContext;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.util.DataStructureUtil;

@TestSpecContext(allMilestones = true)
class SignedBeaconBlockTest {

private Spec spec;
private SpecMilestone milestone;
private DataStructureUtil dataStructureUtil;

@BeforeEach
void setUp(final SpecContext specContext) {
spec = specContext.getSpec();
milestone = specContext.getSpecMilestone();
dataStructureUtil = specContext.getDataStructureUtil();
}

Expand All @@ -56,11 +59,10 @@ void shouldBlindAndUnblind() {
final SignedBeaconBlock blinded = original.blind(spec.getGenesisSchemaDefinitions());
assertThat(blinded.hashTreeRoot()).isEqualTo(original.hashTreeRoot());

if (!blinded.getMessage().getBody().isBlinded()) {
if (!blinded.getMessage().getBody().isBlinded()
&& !milestone.isGreaterThanOrEqualTo(SpecMilestone.EIP7732)) {
// Didn't blind the block so we must have a spec prior to bellatrix that doesn't have payloads
assertThat(
spec.getGenesisSpec().getMilestone().isGreaterThanOrEqualTo(SpecMilestone.BELLATRIX))
.isFalse();
assertThat(milestone.isGreaterThanOrEqualTo(SpecMilestone.BELLATRIX)).isFalse();
} else {
// Check the blinded block actually matches the schema by serializing it
assertThatNoException().isThrownBy(blinded::sszSerialize);
Expand All @@ -74,10 +76,12 @@ void shouldBlindAndUnblind() {
.getJsonTypeDefinition()));

// Otherwise, we should be able to unblind it again
final ExecutionPayload executionPayload =
milestone.isGreaterThanOrEqualTo(SpecMilestone.EIP7732)
? null
: original.getMessage().getBody().getOptionalExecutionPayload().orElseThrow();
final SignedBeaconBlock unblinded =
blinded.unblind(
spec.getGenesisSchemaDefinitions(),
original.getMessage().getBody().getOptionalExecutionPayload().orElseThrow());
blinded.unblind(spec.getGenesisSchemaDefinitions(), executionPayload);
assertThat(unblinded.hashTreeRoot()).isEqualTo(original.hashTreeRoot());
assertThat(unblinded.sszSerialize()).isEqualTo(original.sszSerialize());
assertThatNoException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,8 @@ public void initValidatorApiHandler() {
voluntaryExitPool,
blsToExecutionChangePool,
syncCommitteeContributionPool,
executionPayloadHeaderPool,
payloadAttestationPool,
depositProvider,
eth1DataCache,
graffitiBuilder,
Expand Down

0 comments on commit bf60b7e

Please sign in to comment.