Skip to content

Commit

Permalink
throw when fee recipient is not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Oct 17, 2023
1 parent 085ea2d commit c22b71f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public SafeFuture<SignedValidatorRegistration> createSignedValidatorRegistration

final BLSPublicKey publicKey = validator.getPublicKey();

final Eth1Address feeRecipient =
proposerConfigPropertiesProvider
.getFeeRecipient(publicKey)
.orElseGet(
() -> {
LOG.warn(
"Fee recipient not configured for {}. Will use a burn address for the validator registration.",
validator.getPublicKey());
return Eth1Address.ZERO;
});
final Optional<Eth1Address> feeRecipient =
proposerConfigPropertiesProvider.getFeeRecipient(publicKey);

if (feeRecipient.isEmpty()) {
return SafeFuture.failedFuture(
new IllegalStateException(
String.format(
"Fee recipient not configured for %s. Will skip registering it.", publicKey)));
}

final UInt64 gasLimit = proposerConfigPropertiesProvider.getGasLimit(publicKey);

final Optional<UInt64> maybeTimestampOverride =
Expand All @@ -67,7 +67,7 @@ public SafeFuture<SignedValidatorRegistration> createSignedValidatorRegistration
final ValidatorRegistration validatorRegistration =
createValidatorRegistration(
VALIDATOR_BUILDER_PUBLIC_KEY.apply(validator, proposerConfigPropertiesProvider),
feeRecipient,
feeRecipient.get(),
gasLimit,
maybeTimestampOverride.orElse(timeProvider.getTimeInSeconds()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,34 @@ public void onAttestationAggregationDue(final UInt64 slot) {}
public void onUpdatedValidatorStatuses(
final Map<BLSPublicKey, ValidatorStatus> newValidatorStatuses,
final boolean possibleMissingEvents) {
if (!isReadyToRegister()) {
return;
}
final List<Validator> validators = getValidatorsRequiringRegistration(newValidatorStatuses);
if (validators.isEmpty()) {
LOG.debug("No validator registrations are required to be sent");
return;
}
if (registrationNeedsToBeRun(possibleMissingEvents)) {
registerValidators(validators, true);
} else {
final List<Validator> newValidators =
validators.stream()
.filter(
validator -> !cachedValidatorRegistrations.containsKey(validator.getPublicKey()))
.toList();
if (newValidators.isEmpty()) {
return;
}
registerValidators(newValidators, false);
}
proposerConfigPropertiesProvider
.refresh()
.thenRun(
() -> {
if (!isReadyToRegister()) {
return;
}
final List<Validator> validators =
getValidatorsRequiringRegistration(newValidatorStatuses);
if (validators.isEmpty()) {
LOG.debug("No validator registrations are required to be sent");
return;
}
if (registrationNeedsToBeRun(possibleMissingEvents)) {
registerValidators(validators, true);
} else {
final List<Validator> newValidators =
validators.stream()
.filter(
validator ->
!cachedValidatorRegistrations.containsKey(validator.getPublicKey()))
.toList();
if (newValidators.isEmpty()) {
return;
}
registerValidators(newValidators, false);
}
});
}

public int getNumberOfCachedRegistrations() {
Expand Down Expand Up @@ -207,9 +214,7 @@ private void registerValidators(
lastRunEpoch.set(currentEpoch.get());
}

proposerConfigPropertiesProvider
.refresh()
.thenCompose(__ -> processInBatches(validators))
processInBatches(validators)
.handleException(VALIDATOR_LOGGER::registeringValidatorsFailed)
.always(
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.ethereum.execution.types.Eth1Address;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.async.SafeFutureAssert;
import tech.pegasys.teku.infrastructure.time.StubTimeProvider;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
Expand Down Expand Up @@ -273,20 +274,20 @@ void setsCorrectFeeRecipientForValidators() {
}

@TestTemplate
void usesBurnAddressWhenFeeRecipientNotSpecified() {
void throwsWhenFeeRecipientIsNotConfigured() {
// no fee recipient provided
when(proposerConfigPropertiesProvider.getFeeRecipient(validator.getPublicKey()))
.thenReturn(Optional.empty());

final SafeFuture<SignedValidatorRegistration> signedValidatorRegistration =
signedValidatorRegistrationFactory.createSignedValidatorRegistration(
validator, Optional.empty(), throwable -> {});
verify(signer).signValidatorRegistration(any());
assertThat(signedValidatorRegistration)
.isCompletedWithValueMatching(
result ->
result.getMessage().getPublicKey().equals(validator.getPublicKey())
&& result.getMessage().getFeeRecipient().equals(Eth1Address.ZERO));
verify(signer, never()).signValidatorRegistration(any());
SafeFutureAssert.assertThatSafeFuture(signedValidatorRegistration)
.isCompletedExceptionallyWithMessage(
String.format(
"Fee recipient not configured for %s. Will skip registering it.",
validator.getPublicKey()));
}

private SignedValidatorRegistration createSignedValidatorRegistration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void registersNewlyAddedValidators() {
}

@TestTemplate
void registerValidatorsEvenIfOneRegistrationSigningFails() {
void registerValidatorsEvenIfOneRegistrationCreationFails() {
setOwnedValidators(validator1, validator2, validator3);

reset(signedValidatorRegistrationFactory);
Expand Down

0 comments on commit c22b71f

Please sign in to comment.