Skip to content

Commit

Permalink
Create NOOP graffiti manager
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 21, 2024
1 parent 40a1beb commit 3ae1f5e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import tech.pegasys.teku.spec.SpecFactory;
import tech.pegasys.teku.spec.datastructures.state.CommitteeAssignment;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.validator.api.GraffitiManager;
import tech.pegasys.teku.validator.api.ValidatorApiChannel;
import tech.pegasys.teku.validator.api.noop.NoOpGraffitiManager;
import tech.pegasys.teku.validator.beaconnode.GenesisDataProvider;
import tech.pegasys.teku.validator.client.KeyManager;
import tech.pegasys.teku.validator.client.NoOpKeyManager;
Expand Down Expand Up @@ -167,7 +167,7 @@ public int generateSwaggerDocs(
new SystemTimeProvider(),
Optional.empty(),
new DoppelgangerDetectionAlert(),
new GraffitiManager(dataDirLayout));
new NoOpGraffitiManager());

if (api.getRestApiDocs().isPresent()) {
final String docs = api.getRestApiDocs().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@
import tech.pegasys.teku.service.serviceutils.layout.DataDirLayout;

public class GraffitiManager {
private static final Logger LOG = LogManager.getLogger();
static final String GRAFFITI_DIR = "graffiti";

private static final Logger LOG = LogManager.getLogger();
private final Path graffitiPath;

public GraffitiManager(final DataDirLayout dataDirLayout) {
this.graffitiPath = createManagementDirectory(dataDirLayout);
this(dataDirLayout.getValidatorDataDirectory().resolve(GRAFFITI_DIR));
}

private Path createManagementDirectory(final DataDirLayout dataDirLayout) {
final Path graffitiDirectory = dataDirLayout.getValidatorDataDirectory().resolve(GRAFFITI_DIR);
if (!graffitiDirectory.toFile().exists() && !graffitiDirectory.toFile().mkdirs()) {
throw new IllegalStateException(
"Unable to create " + GRAFFITI_DIR + " directory for graffiti management.");
public GraffitiManager(final Path graffitiPath) {
this.graffitiPath = graffitiPath;
if (!graffitiPath.toFile().exists() && !graffitiPath.toFile().mkdirs()) {
throw new IllegalStateException("Unable to create directory for graffiti management.");
}
return graffitiDirectory;
}

public Optional<String> setGraffiti(final BLSPublicKey publicKey, final String graffiti) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Consensys Software Inc., 2024
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.validator.api.noop;

import java.nio.file.Path;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.validator.api.GraffitiManager;

public class NoOpGraffitiManager extends GraffitiManager {
public NoOpGraffitiManager() {
super(Path.of("."));
}

@Override
public Optional<String> setGraffiti(final BLSPublicKey publicKey, final String graffiti) {
return Optional.empty();
}

@Override
public Optional<String> deleteGraffiti(final BLSPublicKey publicKey) {
return Optional.empty();
}

@Override
public Optional<Bytes32> getGraffiti(final BLSPublicKey publicKey) {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void shouldThrowExceptionWhenUnableToCreateManagementDirectory(@TempDir final Pa

assertThatThrownBy(() -> new GraffitiManager(dataDirLayout))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Unable to create graffiti directory for graffiti management.");
.hasMessage("Unable to create directory for graffiti management.");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import tech.pegasys.teku.service.serviceutils.layout.DataDirLayout;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecFactory;
import tech.pegasys.teku.validator.api.GraffitiManager;
import tech.pegasys.teku.validator.api.ValidatorApiChannel;
import tech.pegasys.teku.validator.api.noop.NoOpGraffitiManager;
import tech.pegasys.teku.validator.beaconnode.GenesisDataProvider;
import tech.pegasys.teku.validator.client.OwnedKeyManager;
import tech.pegasys.teku.validator.client.ProposerConfigManager;
Expand Down Expand Up @@ -71,7 +71,7 @@ void setup() throws IOException {
new SystemTimeProvider(),
Optional.empty(),
doppelgangerDetectionAction,
new GraffitiManager(dataDirLayout));
new NoOpGraffitiManager());
final Optional<String> maybeJson = restApi.getRestApiDocs();
assertThat(maybeJson).isPresent();
jsonNode = util.parseSwagger(maybeJson.orElseThrow());
Expand Down

0 comments on commit 3ae1f5e

Please sign in to comment.