Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove --validator-ids option from watermark-repair subcommand #909

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 23.9.1

### Breaking Changes
- Remove --validator-ids option from watermark-repair subcommand [#909](https://github.com/Consensys/web3signer/pull/909)

---
## 23.9.0

### Features Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ private CommandArgs createSubCommandArgs() {
YAML_NUMERIC_FMT,
"eth2.watermark-repair.epoch",
watermarkRepairParameters.getEpoch()));
yamlConfig.append(
formatStringList(
"eth2.watermark-repair.validator-ids", watermarkRepairParameters.getValidators()));
}

return new CommandArgs(params, yamlConfig.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,6 @@ private List<String> createSubCommandArgs() {
params.add(Long.toString(watermarkRepairParameters.getEpoch()));
params.add("--slot");
params.add(Long.toString(watermarkRepairParameters.getSlot()));
if (!watermarkRepairParameters.getValidators().isEmpty()) {
params.add(
"--validator-ids" + "=" + String.join(",", watermarkRepairParameters.getValidators()));
}
}

return params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,54 +106,6 @@ void allLowWatermarksAreUpdated(@TempDir final Path testDirectory) throws URISyn
assertThat(validator2.get("target_epoch")).isEqualTo(epoch);
}

@Test
void onlySpecifiedWatermarksAreUpdated(@TempDir final Path testDirectory)
throws URISyntaxException {
setupSigner(testDirectory);

importSlashingProtectionData(testDirectory);

final SignerConfigurationBuilder repairBuilder = new SignerConfigurationBuilder();
repairBuilder.withMode("eth2");
repairBuilder.withSlashingEnabled(true);
repairBuilder.withSlashingProtectionDbUrl(signer.getSlashingDbUrl());
repairBuilder.withSlashingProtectionDbUsername("postgres");
repairBuilder.withSlashingProtectionDbPassword("postgres");
repairBuilder.withWatermarkRepairParameters(
new WatermarkRepairParameters(
20000,
30000,
List.of(
"0x98d083489b3b06b8740da2dfec5cc3c01b2086363fe023a9d7dc1f907633b1ff11f7b99b19e0533e969862270061d884")));
repairBuilder.withHttpPort(12345); // prevent wait for Ports file in AT

final Signer watermarkRepairSigner = new Signer(repairBuilder.build(), null);
watermarkRepairSigner.start();
waitFor(() -> assertThat(watermarkRepairSigner.isRunning()).isFalse());

final Map<Object, List<Map<String, Object>>> watermarks = getWatermarks();

assertThat(watermarks).hasSize(2);

final Map<String, Object> validator1 =
watermarks
.get(
"0x8f3f44b74d316c3293cced0c48c72e021ef8d145d136f2908931090e7181c3b777498128a348d07b0b9cd3921b5ca537")
.get(0);
assertThat(validator1.get("slot")).isEqualTo(BigDecimal.valueOf(12345));
assertThat(validator1.get("source_epoch")).isEqualTo(BigDecimal.valueOf(5));
assertThat(validator1.get("target_epoch")).isEqualTo(BigDecimal.valueOf(6));

final Map<String, Object> validator2 =
watermarks
.get(
"0x98d083489b3b06b8740da2dfec5cc3c01b2086363fe023a9d7dc1f907633b1ff11f7b99b19e0533e969862270061d884")
.get(0);
assertThat(validator2.get("slot")).isEqualTo(BigDecimal.valueOf(20000));
assertThat(validator2.get("source_epoch")).isEqualTo(BigDecimal.valueOf(30000));
assertThat(validator2.get("target_epoch")).isEqualTo(BigDecimal.valueOf(30000));
}

private Map<Object, List<Map<String, Object>>> getWatermarks() {
final Jdbi jdbi = Jdbi.create(signer.getSlashingDbUrl(), DB_USERNAME, DB_PASSWORD);
return jdbi.withHandle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,17 @@
import tech.pegasys.web3signer.slashingprotection.dao.Validator;
import tech.pegasys.web3signer.slashingprotection.dao.ValidatorsDao;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt64;
import org.jdbi.v3.core.Jdbi;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.HelpCommand;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.ParameterException;
import picocli.CommandLine.Spec;

@Command(
name = "watermark-repair",
Expand All @@ -46,8 +40,6 @@
public class Eth2WatermarkRepairSubCommand implements Runnable {
private static final Logger LOG = LogManager.getLogger();

@Spec private CommandSpec commandSpec;

@CommandLine.ParentCommand private Eth2SubCommand eth2Config;

@Option(
Expand All @@ -64,25 +56,10 @@ public class Eth2WatermarkRepairSubCommand implements Runnable {
arity = "1")
Long slot;

@Option(
names = "--validator-ids",
paramLabel = "<publicKey>",
description =
"List of validator public keys as hexadecimal to apply low watermark update to. If none are specified"
+ " then all validators low watermarks will be updated (default: ${DEFAULT-VALUE}).",
split = ",",
arity = "0..*")
List<String> validatorIds = new ArrayList<>();

@Override
public void run() {
final LowWatermarkDao lowWatermarkDao = new LowWatermarkDao();
final ValidatorsDao validatorsDao = new ValidatorsDao();
final List<Bytes> validatorIdPublicKeys =
validatorIds.stream()
.filter(StringUtils::isNotEmpty)
.map(this::convertToBytes)
.collect(Collectors.toList());

final SlashingProtectionContext slashingProtectionContext =
SlashingProtectionContextFactory.create(eth2Config.getSlashingProtectionParameters());
Expand All @@ -91,14 +68,7 @@ public void run() {
final List<Validator> allValidators =
jdbi.inTransaction(h -> validatorsDao.findAllValidators(h).collect(Collectors.toList()));

final List<Validator> validators =
validatorIdPublicKeys.isEmpty()
? allValidators
: allValidators.stream()
.filter(v -> validatorIdPublicKeys.contains(v.getPublicKey()))
.collect(Collectors.toList());

validators.stream()
allValidators.stream()
.parallel()
.forEach(
validator ->
Expand All @@ -109,16 +79,6 @@ public void run() {
lowWatermarkDao.updateEpochWatermarksFor(
h, validator.getId(), UInt64.valueOf(epoch), UInt64.valueOf(epoch));
}));
LOG.info("Updated low watermark for {} validators", validators.size());
}

private Bytes convertToBytes(final String value) {
try {
return Bytes.fromHexString(value);
} catch (final IllegalArgumentException e) {
throw new ParameterException(
commandSpec.commandLine(),
"Invalid value for validator public key " + value + ". Value must be in hexadecimal.");
}
LOG.info("Updated low watermark for {} validators", allValidators.size());
}
}