Skip to content

Commit

Permalink
Move blobs availability check to on_execution_payload (Consensys#8691)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Oct 10, 2024
1 parent 00fbe20 commit a26a49b
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.deneb.BeaconBlockBodyDeneb;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadEnvelope;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.logic.versions.deneb.blobs.BlobSidecarsAndValidationResult;
import tech.pegasys.teku.spec.logic.versions.deneb.blobs.BlobSidecarsAvailabilityChecker;
Expand Down Expand Up @@ -125,6 +126,12 @@ private BlobSidecarsAndValidationResult validateImmediately(
};
}

@Override
public BlobSidecarsAvailabilityChecker createAvailabilityChecker(
final SignedBeaconBlock block, final ExecutionPayloadEnvelope executionPayloadEnvelope) {
throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public BlobSidecarsAndValidationResult createAvailabilityCheckerAndValidateImmediately(
final SignedBeaconBlock block, final List<BlobSidecar> blobSidecars) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ public static SpecLogicEip7732 create(

// State upgrade
final Eip7732StateUpgrade stateUpgrade =
new Eip7732StateUpgrade(
config, schemaDefinitions, beaconStateAccessors, beaconStateMutators);
new Eip7732StateUpgrade(config, schemaDefinitions, beaconStateAccessors);

// Execution payload processing
// EIP7732 TODO: dirty way to leverage Electra operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.electra.BeaconStateElectra;
import tech.pegasys.teku.spec.logic.common.forktransition.StateUpgrade;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.BeaconStateAccessorsElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.BeaconStateMutatorsElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.MiscHelpersElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.PredicatesElectra;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip7732;
Expand All @@ -38,17 +37,14 @@ public class Eip7732StateUpgrade implements StateUpgrade<BeaconStateElectra> {
private final SpecConfigEip7732 specConfig;
private final SchemaDefinitionsEip7732 schemaDefinitions;
private final BeaconStateAccessorsElectra beaconStateAccessors;
private final BeaconStateMutatorsElectra beaconStateMutators;

public Eip7732StateUpgrade(
final SpecConfigEip7732 specConfig,
final SchemaDefinitionsEip7732 schemaDefinitions,
final BeaconStateAccessorsElectra beaconStateAccessors,
final BeaconStateMutatorsElectra beaconStateMutators) {
final BeaconStateAccessorsElectra beaconStateAccessors) {
this.specConfig = specConfig;
this.schemaDefinitions = schemaDefinitions;
this.beaconStateAccessors = beaconStateAccessors;
this.beaconStateMutators = beaconStateMutators;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MAX_EFFECTIVE_BALANCE_ELECTRA: 2048000000000
# State list lengths
# ---------------------------------------------------------------
# `uint64(2**27)` (= 134,217,728)
PENDING_BALANCE_DEPOSITS_LIMIT: 134217728
PENDING_DEPOSITS_LIMIT: 134217728
# `uint64(2**27)` (= 134,217,728)
PENDING_PARTIAL_WITHDRAWALS_LIMIT: 134217728
# `uint64(2**18)` (= 262,144)
Expand Down Expand Up @@ -42,4 +42,9 @@ MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD: 16
# Withdrawals processing
# ---------------------------------------------------------------
# 2**3 ( = 8) pending withdrawals
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: 8
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP: 8

# Pending deposits processing
# ---------------------------------------------------------------
# 2**4 ( = 4) pending deposits
MAX_PENDING_DEPOSITS_PER_EPOCH: 16
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
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.logic.versions.deneb.blobs.BlobSidecarsAndValidationResult;
import tech.pegasys.teku.spec.logic.versions.deneb.blobs.BlobSidecarsAvailabilityChecker;
import tech.pegasys.teku.statetransition.validation.InternalValidationResult;
Expand Down Expand Up @@ -52,6 +53,13 @@ public BlobSidecarsAvailabilityChecker createAvailabilityChecker(
return BlobSidecarsAvailabilityChecker.NOOP;
}

@Override
public BlobSidecarsAvailabilityChecker createAvailabilityChecker(
final SignedBeaconBlock block,
final ExecutionPayloadEnvelope executionPayloadEnvelope) {
return BlobSidecarsAvailabilityChecker.NOOP;
}

@Override
public BlobSidecarsAndValidationResult createAvailabilityCheckerAndValidateImmediately(
final SignedBeaconBlock block, final List<BlobSidecar> blobSidecars) {
Expand All @@ -70,6 +78,10 @@ SafeFuture<InternalValidationResult> validateAndPrepareForBlockImport(

BlobSidecarsAvailabilityChecker createAvailabilityChecker(SignedBeaconBlock block);

// ePBS
BlobSidecarsAvailabilityChecker createAvailabilityChecker(
SignedBeaconBlock block, ExecutionPayloadEnvelope executionPayloadEnvelope);

BlobSidecarsAndValidationResult createAvailabilityCheckerAndValidateImmediately(
SignedBeaconBlock block, List<BlobSidecar> blobSidecars);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import tech.pegasys.teku.spec.Spec;
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.logic.versions.deneb.blobs.BlobSidecarsAndValidationResult;
import tech.pegasys.teku.spec.logic.versions.deneb.blobs.BlobSidecarsAvailabilityChecker;
import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceBlobSidecarsAvailabilityChecker;
Expand Down Expand Up @@ -132,6 +133,17 @@ public BlobSidecarsAvailabilityChecker createAvailabilityChecker(final SignedBea
spec, asyncRunner, recentChainData, blockBlobSidecarsTracker, kzg);
}

@Override
public BlobSidecarsAvailabilityChecker createAvailabilityChecker(
final SignedBeaconBlock block, final ExecutionPayloadEnvelope executionPayloadEnvelope) {
final BlockBlobSidecarsTracker blockBlobSidecarsTracker =
blockBlobSidecarsTrackersPool.getOrCreateBlockBlobSidecarsTracker(
block, executionPayloadEnvelope);

return new ForkChoiceBlobSidecarsAvailabilityChecker(
spec, asyncRunner, recentChainData, blockBlobSidecarsTracker, kzg);
}

@Override
public BlobSidecarsAndValidationResult createAvailabilityCheckerAndValidateImmediately(
final SignedBeaconBlock block, final List<BlobSidecar> blobSidecars) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.deneb.BeaconBlockBodyDeneb;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadEnvelope;
import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BlobIdentifier;
import tech.pegasys.teku.statetransition.block.BlockImportChannel;

Expand All @@ -52,6 +53,9 @@ public class BlockBlobSidecarsTracker {
private final AtomicReference<Optional<SignedBeaconBlock>> block =
new AtomicReference<>(Optional.empty());

private final AtomicReference<Optional<ExecutionPayloadEnvelope>> executionPayloadEnvelope =
new AtomicReference<>(Optional.empty());

private final AtomicBoolean blockImportOnCompletionEnabled = new AtomicBoolean(false);

private final NavigableMap<UInt64, BlobSidecar> blobSidecars = new ConcurrentSkipListMap<>();
Expand Down Expand Up @@ -101,6 +105,10 @@ public Optional<SignedBeaconBlock> getBlock() {
return block.get();
}

public Optional<ExecutionPayloadEnvelope> getExecutionPayloadEnvelope() {
return executionPayloadEnvelope.get();
}

public boolean containsBlobSidecar(final BlobIdentifier blobIdentifier) {
return Optional.ofNullable(blobSidecars.get(blobIdentifier.getIndex()))
.map(blobSidecar -> blobSidecar.getBlockRoot().equals(blobIdentifier.getBlockRoot()))
Expand Down Expand Up @@ -193,6 +201,29 @@ public boolean setBlock(final SignedBeaconBlock block) {
return true;
}

public boolean setBlockAndExecutionPayloadEnvelope(
final SignedBeaconBlock block, final ExecutionPayloadEnvelope executionPayloadEnvelope) {
checkArgument(block.getSlotAndBlockRoot().equals(slotAndBlockRoot), "Wrong block");
final Optional<SignedBeaconBlock> oldBlock = this.block.getAndSet(Optional.of(block));
final Optional<ExecutionPayloadEnvelope> oldExecutionPayloadEnvelope =
this.executionPayloadEnvelope.getAndSet(Optional.of(executionPayloadEnvelope));
if (oldBlock.isPresent() || oldExecutionPayloadEnvelope.isPresent()) {
return false;
}

LOG.debug(
"Block and execution payload envelope received for {}", slotAndBlockRoot::toLogString);
maybeDebugTimings.ifPresent(
debugTimings -> {
debugTimings.put(BLOCK_ARRIVAL_TIMING_IDX, System.currentTimeMillis());
});

pruneExcessiveBlobSidecars();
checkCompletion();

return true;
}

public void enableBlockImportOnCompletion(final BlockImportChannel blockImportChannel) {
final boolean alreadyEnabled = blockImportOnCompletionEnabled.getAndSet(true);
if (alreadyEnabled) {
Expand Down Expand Up @@ -279,7 +310,13 @@ private Optional<Integer> getBlobKzgCommitmentsCount() {
b ->
BeaconBlockBodyDeneb.required(b.getMessage().getBody())
.getOptionalBlobKzgCommitments()
.map(SszList::size));
.map(SszList::size))
// ePBS
.or(
() ->
executionPayloadEnvelope
.get()
.map(envelope -> envelope.getBlobKzgCommitments().size()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
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.networking.libp2p.rpc.BlobIdentifier;
import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager.RemoteOrigin;

Expand Down Expand Up @@ -73,6 +74,13 @@ public BlockBlobSidecarsTracker getOrCreateBlockBlobSidecarsTracker(
throw new UnsupportedOperationException();
}

@Override
public BlockBlobSidecarsTracker getOrCreateBlockBlobSidecarsTracker(
final SignedBeaconBlock block,
final ExecutionPayloadEnvelope executionPayloadEnvelope) {
throw new UnsupportedOperationException();
}

@Override
public Optional<BlockBlobSidecarsTracker> getBlockBlobSidecarsTracker(
final SignedBeaconBlock block) {
Expand Down Expand Up @@ -127,6 +135,10 @@ public void subscribeNewBlobSidecar(NewBlobSidecarSubscriber newBlobSidecarSubsc

BlockBlobSidecarsTracker getOrCreateBlockBlobSidecarsTracker(SignedBeaconBlock block);

// ePBS
BlockBlobSidecarsTracker getOrCreateBlockBlobSidecarsTracker(
SignedBeaconBlock block, ExecutionPayloadEnvelope executionPayloadEnvelope);

Optional<BlockBlobSidecarsTracker> getBlockBlobSidecarsTracker(SignedBeaconBlock block);

void enableBlockImportOnCompletion(SignedBeaconBlock block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ private SafeFuture<Void> onExecutionPayload(
final ForkChoicePayloadExecutorEip7732 payloadExecutor =
ForkChoicePayloadExecutorEip7732.create(executionLayer, block.getSlot());
final BlobSidecarsAvailabilityChecker blobSidecarsAvailabilityChecker =
blobSidecarManager.createAvailabilityChecker(block);
blobSidecarManager.createAvailabilityChecker(block, signedEnvelope.getMessage());

blobSidecarsAvailabilityChecker.initiateDataAvailabilityCheck();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,15 @@ static Supplier<List<KZGCommitment>> createLazyKzgCommitmentsSupplier(
.flatMap(SignedBeaconBlock::getBeaconBlock)
.map(BeaconBlock::getBody)
.orElseThrow())
.getBlobKzgCommitments()
.getOptionalBlobKzgCommitments()
// ePBS
.orElseGet(
() ->
availabilityChecker
.blockBlobSidecarsTracker
.getExecutionPayloadEnvelope()
.orElseThrow()
.getBlobKzgCommitments())
.stream()
.map(SszKZGCommitment::getKZGCommitment)
.toList());
Expand Down
Loading

0 comments on commit a26a49b

Please sign in to comment.