Skip to content

Commit

Permalink
tiny refactors for late block reorg (#7939)
Browse files Browse the repository at this point in the history
adjunct to #6595

Signed-off-by: Paul Harris <[email protected]>
  • Loading branch information
rolfyone authored Feb 1, 2024
1 parent ecefc10 commit b61574c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ private SafeFuture<Optional<BlockContainer>> createBlock(
return SafeFuture.completedFuture(Optional.empty());
}
final BeaconState blockSlotState = maybeBlockSlotState.get();
final Bytes32 parentRoot = spec.getBlockRootAtSlot(blockSlotState, slot.minus(1));
final Bytes32 parentRoot = spec.getBlockRootAtSlot(blockSlotState, slot.decrement());
LOG.debug("parent block {}:({})", parentRoot, slot);
if (combinedChainDataClient.isOptimisticBlock(parentRoot)) {
LOG.warn(
"Unable to produce block at slot {} because parent has optimistically validated payload",
Expand Down
6 changes: 3 additions & 3 deletions ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -696,16 +696,16 @@ public BeaconState processSlots(BeaconState preState, UInt64 slot)

// Block Proposal
public SafeFuture<BeaconBlockAndState> createNewUnsignedBlock(
final UInt64 newSlot,
final UInt64 proposalSlot,
final int proposerIndex,
final BeaconState blockSlotState,
final Bytes32 parentBlockSigningRoot,
final Function<BeaconBlockBodyBuilder, SafeFuture<Void>> bodyBuilder,
final BlockProductionPerformance blockProductionPerformance) {
return atSlot(newSlot)
return atSlot(proposalSlot)
.getBlockProposalUtil()
.createNewUnsignedBlock(
newSlot,
proposalSlot,
proposerIndex,
blockSlotState,
parentBlockSigningRoot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ public BlockProposalUtil(
}

public SafeFuture<BeaconBlockAndState> createNewUnsignedBlock(
final UInt64 newSlot,
final UInt64 proposalSlot,
final int proposerIndex,
final BeaconState blockSlotState,
final Bytes32 parentBlockSigningRoot,
final Function<BeaconBlockBodyBuilder, SafeFuture<Void>> bodyBuilder,
final BlockProductionPerformance blockProductionPerformance) {
checkArgument(
blockSlotState.getSlot().equals(newSlot),
blockSlotState.getSlot().equals(proposalSlot),
"Block slot state from incorrect slot. Expected %s but got %s",
newSlot,
proposalSlot,
blockSlotState.getSlot());

// Create block body
Expand All @@ -72,7 +72,7 @@ public SafeFuture<BeaconBlockAndState> createNewUnsignedBlock(
? schemaDefinitions.getBlindedBeaconBlockSchema()
: schemaDefinitions.getBeaconBlockSchema();
return beaconBlockSchema.create(
newSlot,
proposalSlot,
UInt64.valueOf(proposerIndex),
parentBlockSigningRoot,
tmpStateRoot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
import tech.pegasys.teku.storage.client.EarliestAvailableBlockSlot;
import tech.pegasys.teku.storage.client.RecentChainData;
import tech.pegasys.teku.storage.client.StorageBackedRecentChainData;
import tech.pegasys.teku.storage.client.ValidatorIsConnectedProvider;
import tech.pegasys.teku.storage.store.FileKeyValueStore;
import tech.pegasys.teku.storage.store.KeyValueStore;
import tech.pegasys.teku.storage.store.StoreConfig;
Expand Down Expand Up @@ -397,6 +398,9 @@ protected SafeFuture<?> initialize() {
storageQueryChannel = combinedStorageChannel;
storageUpdateChannel = combinedStorageChannel;
final VoteUpdateChannel voteUpdateChannel = eventChannels.getPublisher(VoteUpdateChannel.class);

final ValidatorIsConnectedProvider validatorIsConnectedProvider =
new ValidatorIsConnectedProviderImpl(() -> forkChoiceNotifier);
// Init other services
return initWeakSubjectivity(storageQueryChannel, storageUpdateChannel)
.thenCompose(
Expand All @@ -414,7 +418,7 @@ protected SafeFuture<?> initialize() {
voteUpdateChannel,
eventChannels.getPublisher(FinalizedCheckpointChannel.class, beaconAsyncRunner),
coalescingChainHeadChannel,
new ValidatorIsConnectedProviderImpl(forkChoiceNotifier),
validatorIsConnectedProvider,
spec))
.thenCompose(
client -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@

package tech.pegasys.teku.services.beaconchain;

import java.util.function.Supplier;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier;
import tech.pegasys.teku.storage.client.ValidatorIsConnectedProvider;

public class ValidatorIsConnectedProviderImpl implements ValidatorIsConnectedProvider {
private final ForkChoiceNotifier forkChoiceNotifier;
private final Supplier<ForkChoiceNotifier> forkChoiceNotifier;

public ValidatorIsConnectedProviderImpl(ForkChoiceNotifier forkChoiceNotifier) {
public ValidatorIsConnectedProviderImpl(Supplier<ForkChoiceNotifier> forkChoiceNotifier) {
this.forkChoiceNotifier = forkChoiceNotifier;
}

@Override
public boolean isValidatorConnected(int validatorId, UInt64 slot) {
return forkChoiceNotifier.validatorIsConnected(UInt64.valueOf(validatorId), slot);
return forkChoiceNotifier.get().validatorIsConnected(UInt64.valueOf(validatorId), slot);
}
}

0 comments on commit b61574c

Please sign in to comment.