Skip to content

Commit

Permalink
Revert "Gas limit beacon proposer preparer (#6080)" (#6094)
Browse files Browse the repository at this point in the history
This reverts commit 89c4d34.
  • Loading branch information
rolfyone authored Aug 18, 2022
1 parent c514633 commit ebfb044
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
import tech.pegasys.teku.validator.client.ProposerConfig.Config;
import tech.pegasys.teku.validator.client.proposerconfig.ProposerConfigProvider;

public class BeaconProposerPreparer
implements ValidatorTimingChannel, ValidatorRegistrationPropertiesProvider {
public class BeaconProposerPreparer implements ValidatorTimingChannel, FeeRecipientProvider {
private static final Logger LOG = LogManager.getLogger();

private final ValidatorApiChannel validatorApiChannel;
private Optional<ValidatorIndexProvider> validatorIndexProvider;
private final ProposerConfigProvider proposerConfigProvider;
private final Optional<Eth1Address> defaultFeeRecipient;
private final UInt64 defaultGasLimit;
private final Spec spec;
private final RuntimeProposerConfig runtimeProposerConfig;

Expand All @@ -53,35 +51,31 @@ public class BeaconProposerPreparer
private final AtomicBoolean sentProposersAtLeastOnce = new AtomicBoolean(false);

BeaconProposerPreparer(
final ValidatorApiChannel validatorApiChannel,
final ValidatorIndexProvider validatorIndexProvider,
final ProposerConfigProvider proposerConfigProvider,
final Optional<Eth1Address> defaultFeeRecipient,
final UInt64 defaultGasLimit,
final Spec spec) {
ValidatorApiChannel validatorApiChannel,
ValidatorIndexProvider validatorIndexProvider,
ProposerConfigProvider proposerConfigProvider,
Optional<Eth1Address> defaultFeeRecipient,
Spec spec) {
this(
validatorApiChannel,
Optional.of(validatorIndexProvider),
proposerConfigProvider,
defaultFeeRecipient,
defaultGasLimit,
spec,
Optional.empty());
}

public BeaconProposerPreparer(
final ValidatorApiChannel validatorApiChannel,
final Optional<ValidatorIndexProvider> validatorIndexProvider,
final ProposerConfigProvider proposerConfigProvider,
final Optional<Eth1Address> defaultFeeRecipient,
final UInt64 defaultGasLimit,
final Spec spec,
final Optional<Path> mutableProposerConfigPath) {
ValidatorApiChannel validatorApiChannel,
Optional<ValidatorIndexProvider> validatorIndexProvider,
ProposerConfigProvider proposerConfigProvider,
Optional<Eth1Address> defaultFeeRecipient,
Spec spec,
Optional<Path> mutableProposerConfigPath) {
this.validatorApiChannel = validatorApiChannel;
this.validatorIndexProvider = validatorIndexProvider;
this.proposerConfigProvider = proposerConfigProvider;
this.defaultFeeRecipient = defaultFeeRecipient;
this.defaultGasLimit = defaultGasLimit;
this.spec = spec;
runtimeProposerConfig = new RuntimeProposerConfig(mutableProposerConfigPath);
}
Expand All @@ -91,7 +85,7 @@ public void initialize(final Optional<ValidatorIndexProvider> provider) {
}

@Override
public void onSlot(final UInt64 slot) {
public void onSlot(UInt64 slot) {
if (validatorIndexProvider.isEmpty()) {
return;
}
Expand All @@ -102,10 +96,10 @@ public void onSlot(final UInt64 slot) {

@Override
public void onHeadUpdate(
final UInt64 slot,
final Bytes32 previousDutyDependentRoot,
final Bytes32 currentDutyDependentRoot,
final Bytes32 headBlockRoot) {}
UInt64 slot,
Bytes32 previousDutyDependentRoot,
Bytes32 currentDutyDependentRoot,
Bytes32 headBlockRoot) {}

@Override
public void onPossibleMissedEvents() {
Expand All @@ -118,13 +112,13 @@ public void onValidatorsAdded() {
}

@Override
public void onBlockProductionDue(final UInt64 slot) {}
public void onBlockProductionDue(UInt64 slot) {}

@Override
public void onAttestationCreationDue(final UInt64 slot) {}
public void onAttestationCreationDue(UInt64 slot) {}

@Override
public void onAttestationAggregationDue(final UInt64 slot) {}
public void onAttestationAggregationDue(UInt64 slot) {}

// 2 configurations, 2 defaults
// Priority order
Expand All @@ -147,22 +141,6 @@ public Optional<Eth1Address> getFeeRecipient(final BLSPublicKey publicKey) {
.or(() -> defaultFeeRecipient);
}

@Override
public Optional<UInt64> getGasLimit(final BLSPublicKey publicKey) {
if (validatorIndexCannotBeResolved(publicKey)) {
return Optional.empty();
}
return maybeProposerConfig
.flatMap(config -> getGasLimitFromProposerConfig(config, publicKey))
.or(() -> runtimeProposerConfig.getGasLimitForPubKey(publicKey))
.or(
() ->
maybeProposerConfig.flatMap(
proposerConfigProvider ->
proposerConfigProvider.getDefaultConfig().getGasLimit()))
.or(() -> Optional.ofNullable(defaultGasLimit));
}

@Override
public boolean isReadyToProvideFeeRecipient() {
return sentProposersAtLeastOnce.get();
Expand All @@ -182,25 +160,12 @@ public void setFeeRecipient(final BLSPublicKey publicKey, final Eth1Address eth1
Optional<Eth1Address> maybeEth1Address =
maybeProposerConfig.flatMap(config -> getFeeRecipientFromProposerConfig(config, publicKey));
if (maybeEth1Address.isPresent()) {
throw new SetFeeRecipientException("Cannot update fee recipient via api.");
throw new SetFeeRecipientException(
"Validator public key has been configured in validators-proposer-config file - cannot update via api.");
}
runtimeProposerConfig.addOrUpdateFeeRecipient(publicKey, eth1Address);
}

public void setGasLimit(final BLSPublicKey publicKey, final UInt64 gasLimit)
throws SetFeeRecipientException {
if (validatorIndexCannotBeResolved(publicKey)) {
throw new SetGasLimitException(
"Validator public key not found when attempting to set gas limit.");
}
Optional<UInt64> maybeGasLimit =
maybeProposerConfig.flatMap(config -> getGasLimitFromProposerConfig(config, publicKey));
if (maybeGasLimit.isPresent()) {
throw new SetGasLimitException("Cannot update gas limit via api.");
}
runtimeProposerConfig.addOrUpdateGasLimit(publicKey, gasLimit);
}

public boolean deleteFeeRecipient(final BLSPublicKey publicKey) {
Optional<Eth1Address> maybeEth1Address =
maybeProposerConfig.flatMap(config -> getFeeRecipientFromProposerConfig(config, publicKey));
Expand All @@ -211,16 +176,6 @@ public boolean deleteFeeRecipient(final BLSPublicKey publicKey) {
return true;
}

public boolean deleteGasLimit(final BLSPublicKey publicKey) {
Optional<UInt64> maybeGasLimit =
maybeProposerConfig.flatMap(config -> getGasLimitFromProposerConfig(config, publicKey));
if (maybeGasLimit.isPresent()) {
return false;
}
runtimeProposerConfig.deleteGasLimit(publicKey);
return true;
}

private boolean isBeginningOfEpoch(final UInt64 slot) {
return slot.mod(spec.getSlotsPerEpoch(slot)).isZero();
}
Expand Down Expand Up @@ -254,8 +209,8 @@ private void sendPreparableProposerList() {
}

private Collection<BeaconPreparableProposer> buildBeaconPreparableProposerList(
final Optional<ProposerConfig> maybeProposerConfig,
final Map<BLSPublicKey, Integer> blsPublicKeyToIndexMap) {
Optional<ProposerConfig> maybeProposerConfig,
Map<BLSPublicKey, Integer> blsPublicKeyToIndexMap) {
this.maybeProposerConfig = maybeProposerConfig;
return blsPublicKeyToIndexMap.entrySet().stream()
.map(
Expand All @@ -274,11 +229,6 @@ private Optional<Eth1Address> getFeeRecipientFromProposerConfig(
return config.getConfigForPubKey(publicKey).flatMap(Config::getFeeRecipient);
}

private Optional<UInt64> getGasLimitFromProposerConfig(
final ProposerConfig config, final BLSPublicKey publicKey) {
return config.getConfigForPubKey(publicKey).flatMap(Config::getGasLimit);
}

private boolean validatorIndexCannotBeResolved(final BLSPublicKey publicKey) {
return validatorIndexProvider.isEmpty()
|| !validatorIndexProvider.get().containsPublicKey(publicKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@

import java.util.Optional;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.eth1.Eth1Address;

public interface ValidatorRegistrationPropertiesProvider {
public interface FeeRecipientProvider {

Optional<Eth1Address> getFeeRecipient(BLSPublicKey publicKey);

Optional<UInt64> getGasLimit(BLSPublicKey publicKey);

boolean isReadyToProvideFeeRecipient();
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ public Optional<Eth1Address> getFeeRecipient() {
return Optional.ofNullable(feeRecipient);
}

public Optional<UInt64> getGasLimit() {
return builder.getGasLimit();
}

public Optional<BuilderConfig> getBuilder() {
return Optional.ofNullable(builder);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ public static ValidatorClientService create(
Optional.empty(),
proposerConfigProvider.get(),
validatorConfig.getProposerDefaultFeeRecipient(),
validatorConfig.getBuilderRegistrationDefaultGasLimit(),
config.getSpec(),
Optional.of(
ValidatorClientService.getKeyManagerPath(services.getDataDirLayout())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class ValidatorRegistrator implements ValidatorTimingChannel {
private final OwnedValidators ownedValidators;
private final ProposerConfigProvider proposerConfigProvider;
private final ValidatorConfig validatorConfig;
private final ValidatorRegistrationPropertiesProvider validatorRegistrationPropertiesProvider;
private final FeeRecipientProvider feeRecipientProvider;
private final ValidatorRegistrationBatchSender validatorRegistrationBatchSender;

public ValidatorRegistrator(
Expand All @@ -69,13 +69,13 @@ public ValidatorRegistrator(
final OwnedValidators ownedValidators,
final ProposerConfigProvider proposerConfigProvider,
final ValidatorConfig validatorConfig,
final ValidatorRegistrationPropertiesProvider validatorRegistrationPropertiesProvider,
final FeeRecipientProvider feeRecipientProvider,
final ValidatorRegistrationBatchSender validatorRegistrationBatchSender) {
this.spec = spec;
this.timeProvider = timeProvider;
this.ownedValidators = ownedValidators;
this.proposerConfigProvider = proposerConfigProvider;
this.validatorRegistrationPropertiesProvider = validatorRegistrationPropertiesProvider;
this.feeRecipientProvider = feeRecipientProvider;
this.validatorRegistrationBatchSender = validatorRegistrationBatchSender;
this.validatorConfig = validatorConfig;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ public int getNumberOfCachedRegistrations() {
}

private boolean isNotReadyToRegister() {
if (!validatorRegistrationPropertiesProvider.isReadyToProvideFeeRecipient()) {
if (!feeRecipientProvider.isReadyToProvideFeeRecipient()) {
LOG.debug("Not ready to register validator(s).");
return true;
}
Expand Down Expand Up @@ -201,8 +201,7 @@ private Optional<SafeFuture<SignedValidatorRegistration>> createSignedValidatorR
return Optional.empty();
}

final Optional<Eth1Address> maybeFeeRecipient =
validatorRegistrationPropertiesProvider.getFeeRecipient(publicKey);
final Optional<Eth1Address> maybeFeeRecipient = feeRecipientProvider.getFeeRecipient(publicKey);

if (maybeFeeRecipient.isEmpty()) {
LOG.debug(
Expand Down
Loading

0 comments on commit ebfb044

Please sign in to comment.