Skip to content

Commit

Permalink
Add a cli option + not run validation only when it's gossip
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jun 4, 2024
1 parent b496e05 commit 78bc07d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ the [releases page](https://github.com/Consensys/teku/releases).
### Breaking Changes

### Additions and Improvements

- Added metadata fields to `/eth/v1/beacon/blob_sidecars/{block_id}` Beacon API response as per https://github.com/ethereum/beacon-APIs/pull/441
- Added rest api endpoint `/teku/v1/beacon/state/finalized/slot/before/{slot}` to return most recent stored state at or before a specified slot.
- The validator client will start using the `v2` variant of the beacon node block publishing endpoints which perform an additional gossip validation unless the block has been produced in the same beacon node.
- The validator client will start using the `v2` variant of the beacon node block publishing
endpoints. The beacon node would perform an additional gossip validation unless the block has been
produced in the same node. This behaviour can be changed by a new hidden CLI option: `--Xvalidate-locally-created-blocks`

### Bug Fixes
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public class ValidatorApiHandlerIntegrationTest {
syncCommitteeContributionPool,
syncCommitteeSubscriptionManager,
new BlockProductionAndPublishingPerformanceFactory(
new SystemTimeProvider(), __ -> UInt64.ZERO, true, 0, 0, 0, 0));
new SystemTimeProvider(), __ -> UInt64.ZERO, true, 0, 0, 0, 0),
false);

@BeforeEach
public void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static tech.pegasys.teku.infrastructure.metrics.Validator.ValidatorDutyMetricUtils.startTimer;
import static tech.pegasys.teku.infrastructure.metrics.Validator.ValidatorDutyMetricsSteps.CREATE;
import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT;
import static tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel.GOSSIP;
import static tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel.NOT_REQUIRED;

import com.google.common.annotations.VisibleForTesting;
import it.unimi.dsi.fastutil.ints.IntCollection;
Expand Down Expand Up @@ -141,6 +143,7 @@ public class ValidatorApiHandler implements ValidatorApiChannel {
private final SyncCommitteeContributionPool syncCommitteeContributionPool;
private final ProposersDataManager proposersDataManager;
private final BlockPublisher blockPublisher;
private final boolean validateLocallyCreatedBlocks;

private final AttesterDutiesGenerator attesterDutiesGenerator;

Expand All @@ -167,7 +170,8 @@ public ValidatorApiHandler(
final SyncCommitteeContributionPool syncCommitteeContributionPool,
final SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager,
final BlockProductionAndPublishingPerformanceFactory
blockProductionAndPublishingPerformanceFactory) {
blockProductionAndPublishingPerformanceFactory,
final boolean validateLocallyCreatedBlocks) {
this.blockProductionAndPublishingPerformanceFactory =
blockProductionAndPublishingPerformanceFactory;
this.chainDataProvider = chainDataProvider;
Expand All @@ -187,6 +191,7 @@ public ValidatorApiHandler(
this.syncCommitteeContributionPool = syncCommitteeContributionPool;
this.syncCommitteeSubscriptionManager = syncCommitteeSubscriptionManager;
this.proposersDataManager = proposersDataManager;
this.validateLocallyCreatedBlocks = validateLocallyCreatedBlocks;
this.blockPublisher =
new MilestoneBasedBlockPublisher(
spec,
Expand Down Expand Up @@ -647,9 +652,10 @@ public SafeFuture<SendSignedBlockResult> sendSignedBlock(
return blockPublisher
.sendSignedBlock(
maybeBlindedBlockContainer,
// no validation required for locally created blocks
isLocallyCreatedBlock(maybeBlindedBlockContainer)
? BroadcastValidationLevel.NOT_REQUIRED
!validateLocallyCreatedBlocks
&& broadcastValidationLevel == GOSSIP
&& isLocallyCreatedBlock(maybeBlindedBlockContainer)
? NOT_REQUIRED
: broadcastValidationLevel,
blockPublishingPerformance)
.exceptionally(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public void setUp() {
syncCommitteeMessagePool,
syncCommitteeContributionPool,
syncCommitteeSubscriptionManager,
blockProductionPerformanceFactory);
blockProductionPerformanceFactory,
false);

when(syncStateProvider.getCurrentSyncState()).thenReturn(SyncState.IN_SYNC);
when(forkChoiceTrigger.prepareForBlockProduction(any(), any())).thenReturn(SafeFuture.COMPLETE);
Expand Down Expand Up @@ -470,7 +471,8 @@ void getSyncCommitteeDuties_shouldNotUseEpochPriorToFork() {
syncCommitteeMessagePool,
syncCommitteeContributionPool,
syncCommitteeSubscriptionManager,
blockProductionPerformanceFactory);
blockProductionPerformanceFactory,
false);
// Best state is still in Phase0
final BeaconState state =
dataStructureUtil.stateBuilderPhase0().slot(previousEpochStartSlot.minus(1)).build();
Expand Down Expand Up @@ -1379,7 +1381,8 @@ private void setupDeneb() {
syncCommitteeMessagePool,
syncCommitteeContributionPool,
syncCommitteeSubscriptionManager,
blockProductionPerformanceFactory);
blockProductionPerformanceFactory,
false);

// BlobSidecar builder
doAnswer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,8 @@ public void initValidatorApiHandler() {
syncCommitteeMessagePool,
syncCommitteeContributionPool,
syncCommitteeSubscriptionManager,
blockProductionPerformanceFactory);
blockProductionPerformanceFactory,
beaconConfig.validatorConfig().isValidateLocallyCreatedBlocksEnabled());
eventChannels
.subscribe(SlotEventsChannel.class, activeValidatorTracker)
.subscribe(ExecutionClientEventsChannel.class, executionClientVersionProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ public class ValidatorOptions {
fallbackValue = "true")
private boolean blockV3Enabled = ValidatorConfig.DEFAULT_BLOCK_V3_ENABLED;

@Option(
names = {"--Xvalidate-locally-created-blocks"},
paramLabel = "<BOOLEAN>",
description =
"""
Enable gossip validation when publishing a block which has been created locally.
This is only applicable when "gossip" broadcast validation level has been requested,""",
hidden = true,
showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
arity = "0..1",
fallbackValue = "true")
private boolean validateLocallyCreatedBlocks =
ValidatorConfig.DEFAULT_VALIDATE_LOCALLY_CREATED_BLOCKS;

@Option(
names = {"--exit-when-no-validator-keys-enabled"},
paramLabel = "<BOOLEAN>",
Expand Down Expand Up @@ -194,6 +208,7 @@ public void configure(final TekuConfiguration.Builder builder) {
.doppelgangerDetectionEnabled(doppelgangerDetectionEnabled)
.executorThreads(executorThreads)
.blockV3enabled(blockV3Enabled)
.validateLocallyCreatedBlocks(validateLocallyCreatedBlocks)
.exitWhenNoValidatorKeysEnabled(exitWhenNoValidatorKeysEnabled)
.shutdownWhenValidatorSlashedEnabled(shutdownWhenValidatorSlashed));
validatorProposerOptions.configure(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ValidatorConfig {
public static final boolean DEFAULT_FAILOVERS_SEND_SUBNET_SUBSCRIPTIONS_ENABLED = true;
public static final boolean DEFAULT_FAILOVERS_PUBLISH_SIGNED_DUTIES_ENABLED = true;
public static final boolean DEFAULT_BLOCK_V3_ENABLED = false;
public static final boolean DEFAULT_VALIDATE_LOCALLY_CREATED_BLOCKS = false;
public static final boolean DEFAULT_EXIT_WHEN_NO_VALIDATOR_KEYS_ENABLED = false;
public static final boolean DEFAULT_VALIDATOR_CLIENT_SSZ_BLOCKS_ENABLED = true;
public static final boolean DEFAULT_VALIDATOR_CLIENT_USE_POST_VALIDATORS_ENDPOINT_ENABLED = true;
Expand Down Expand Up @@ -97,6 +98,7 @@ public class ValidatorConfig {
private final boolean failoversSendSubnetSubscriptionsEnabled;
private final boolean failoversPublishSignedDutiesEnabled;
private final boolean blockV3Enabled;
private final boolean validateLocallyCreatedBlocks;
private final boolean exitWhenNoValidatorKeysEnabled;
private final boolean shutdownWhenValidatorSlashedEnabled;
private final UInt64 builderRegistrationDefaultGasLimit;
Expand Down Expand Up @@ -140,6 +142,7 @@ private ValidatorConfig(
final boolean failoversSendSubnetSubscriptionsEnabled,
final boolean failoversPublishSignedDutiesEnabled,
final boolean blockV3Enabled,
final boolean validateLocallyCreatedBlocks,
final boolean exitWhenNoValidatorKeysEnabled,
final boolean shutdownWhenValidatorSlashedEnabled,
final UInt64 builderRegistrationDefaultGasLimit,
Expand Down Expand Up @@ -183,6 +186,7 @@ private ValidatorConfig(
this.failoversSendSubnetSubscriptionsEnabled = failoversSendSubnetSubscriptionsEnabled;
this.failoversPublishSignedDutiesEnabled = failoversPublishSignedDutiesEnabled;
this.blockV3Enabled = blockV3Enabled;
this.validateLocallyCreatedBlocks = validateLocallyCreatedBlocks;
this.exitWhenNoValidatorKeysEnabled = exitWhenNoValidatorKeysEnabled;
this.shutdownWhenValidatorSlashedEnabled = shutdownWhenValidatorSlashedEnabled;
this.builderRegistrationDefaultGasLimit = builderRegistrationDefaultGasLimit;
Expand Down Expand Up @@ -324,6 +328,10 @@ public boolean isBlockV3Enabled() {
return blockV3Enabled;
}

public boolean isValidateLocallyCreatedBlocksEnabled() {
return validateLocallyCreatedBlocks;
}

public boolean isExitWhenNoValidatorKeysEnabled() {
return exitWhenNoValidatorKeysEnabled;
}
Expand Down Expand Up @@ -404,6 +412,7 @@ public static final class Builder {
private boolean failoversPublishSignedDutiesEnabled =
DEFAULT_FAILOVERS_PUBLISH_SIGNED_DUTIES_ENABLED;
private boolean blockV3Enabled = DEFAULT_BLOCK_V3_ENABLED;
private boolean validateLocallyCreatedBlocks = DEFAULT_VALIDATE_LOCALLY_CREATED_BLOCKS;
private boolean exitWhenNoValidatorKeysEnabled = DEFAULT_EXIT_WHEN_NO_VALIDATOR_KEYS_ENABLED;
private boolean shutdownWhenValidatorSlashedEnabled =
DEFAULT_SHUTDOWN_WHEN_VALIDATOR_SLASHED_ENABLED;
Expand Down Expand Up @@ -609,6 +618,11 @@ public Builder blockV3enabled(final boolean useBlockV3) {
return this;
}

public Builder validateLocallyCreatedBlocks(final boolean validateLocallyCreatedBlocks) {
this.validateLocallyCreatedBlocks = validateLocallyCreatedBlocks;
return this;
}

public Builder exitWhenNoValidatorKeysEnabled(final boolean exitWhenNoValidatorKeysEnabled) {
this.exitWhenNoValidatorKeysEnabled = exitWhenNoValidatorKeysEnabled;
return this;
Expand Down Expand Up @@ -704,6 +718,7 @@ public ValidatorConfig build() {
failoversSendSubnetSubscriptionsEnabled,
failoversPublishSignedDutiesEnabled,
blockV3Enabled,
validateLocallyCreatedBlocks,
exitWhenNoValidatorKeysEnabled,
shutdownWhenValidatorSlashedEnabled,
builderRegistrationDefaultGasLimit,
Expand Down

0 comments on commit 78bc07d

Please sign in to comment.