Skip to content

Commit

Permalink
Merge branch 'master' into rename_deposit_receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassaldanha authored Jun 24, 2024
2 parents ec5bde4 + 644d69e commit 5303645
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ public class GraffitiBuilder implements ExecutionClientVersionChannel {

private final ClientGraffitiAppendFormat clientGraffitiAppendFormat;
private final ClientVersion consensusClientVersion;
private final Optional<Bytes32> defaultUserGraffiti;

public GraffitiBuilder(
final ClientGraffitiAppendFormat clientGraffitiAppendFormat,
final Optional<Bytes32> defaultUserGraffiti) {
public GraffitiBuilder(final ClientGraffitiAppendFormat clientGraffitiAppendFormat) {
this.clientGraffitiAppendFormat = clientGraffitiAppendFormat;
this.consensusClientVersion = createTekuClientVersion();
this.defaultUserGraffiti = defaultUserGraffiti;
}

private ClientVersion createTekuClientVersion() {
Expand All @@ -73,18 +69,18 @@ public ClientVersion getConsensusClientVersion() {
@Override
public void onExecutionClientVersion(final ClientVersion executionClientVersion) {
this.executionClientVersion = Optional.of(executionClientVersion);
logDefaultGraffiti();
logGraffitiWatermark();
}

@Override
public void onExecutionClientVersionNotAvailable() {
logDefaultGraffiti();
logGraffitiWatermark();
}

private void logDefaultGraffiti() {
final Optional<Bytes32> defaultGraffiti = Optional.of(buildGraffiti(defaultUserGraffiti));
EVENT_LOG.logDefaultGraffiti(
extractGraffiti(defaultGraffiti, calculateGraffitiLength(defaultGraffiti)));
private void logGraffitiWatermark() {
final Optional<Bytes32> graffitiWatermark = Optional.of(buildGraffiti(Optional.empty()));
EVENT_LOG.logGraffitiWatermark(
extractGraffiti(graffitiWatermark, calculateGraffitiLength(graffitiWatermark)));
}

public Bytes32 buildGraffiti(final Optional<Bytes32> userGraffiti) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public abstract class AbstractBlockFactoryTest {
protected ExecutionPayloadResult cachedExecutionPayloadResult = null;

protected GraffitiBuilder graffitiBuilder =
new GraffitiBuilder(ClientGraffitiAppendFormat.DISABLED, Optional.empty());
new GraffitiBuilder(ClientGraffitiAppendFormat.DISABLED);

@BeforeAll
public static void initSession() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class BlockOperationSelectorFactoryTest {
new CapturingBeaconBlockBodyBuilder(false, false);

private final GraffitiBuilder graffitiBuilder =
new GraffitiBuilder(ClientGraffitiAppendFormat.DISABLED, Optional.empty());
new GraffitiBuilder(ClientGraffitiAppendFormat.DISABLED);

private final BlockOperationSelectorFactory factoryElectra =
new BlockOperationSelectorFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@

public class GraffitiBuilderTest {
private ClientGraffitiAppendFormat clientGraffitiAppendFormat = AUTO;
private Optional<Bytes32> userGraffiti = Optional.empty();
private GraffitiBuilder graffitiBuilder =
new GraffitiBuilder(clientGraffitiAppendFormat, userGraffiti);
private GraffitiBuilder graffitiBuilder = new GraffitiBuilder(clientGraffitiAppendFormat);

private static final ClientVersion TEKU_CLIENT_VERSION =
new GraffitiBuilder(DISABLED, Optional.empty()).getConsensusClientVersion();
new GraffitiBuilder(DISABLED).getConsensusClientVersion();
private static final ClientVersion BESU_CLIENT_VERSION =
new ClientVersion("BU", "Besu", "23.4.1", Bytes4.fromHexString("abcdef12"));

Expand All @@ -58,41 +56,37 @@ public class GraffitiBuilderTest {
@BeforeEach
public void setup() {
this.clientGraffitiAppendFormat = AUTO;
this.userGraffiti = Optional.empty();
this.graffitiBuilder = new GraffitiBuilder(clientGraffitiAppendFormat, userGraffiti);
this.graffitiBuilder = new GraffitiBuilder(clientGraffitiAppendFormat);
}

@Test
public void onExecutionClientVersion_shouldLogDefaultGraffiti() {
public void onExecutionClientVersion_shouldLogGraffitiWatermark() {
this.graffitiBuilder = new GraffitiBuilder(clientGraffitiAppendFormat);
try (final LogCaptor logCaptor = LogCaptor.forClass(EventLogger.class)) {
graffitiBuilder.onExecutionClientVersion(BESU_CLIENT_VERSION);
logCaptor.assertInfoLog(
"Default graffiti to use when building block without external VC: \"TK"
"Using graffiti watermark: \"TK"
+ TEKU_CLIENT_VERSION.commit().toUnprefixedHexString()
+ "BUabcdef12\". "
+ "To change check validator graffiti options.");
+ "This will be appended to any user-defined graffiti or used if none is defined. Refer to validator graffiti options to customize.");
}
}

@Test
public void onExecutionClientVersion_shouldLogDefaultMergedGraffiti() {
this.graffitiBuilder =
new GraffitiBuilder(
clientGraffitiAppendFormat, Optional.of(Bytes32Parser.toBytes32(ASCII_GRAFFITI_20)));
public void onExecutionClientVersionNotAvailable_shouldLogGraffitiWatermark() {
try (final LogCaptor logCaptor = LogCaptor.forClass(EventLogger.class)) {
graffitiBuilder.onExecutionClientVersion(BESU_CLIENT_VERSION);
graffitiBuilder.onExecutionClientVersionNotAvailable();
logCaptor.assertInfoLog(
"Default graffiti to use when building block without external VC: \"I've proposed ablock TK"
+ TEKU_CLIENT_VERSION.commit().toUnprefixedHexString().substring(0, 2)
+ "BUab\". "
+ "To change check validator graffiti options.");
"Using graffiti watermark: \"TK"
+ TEKU_CLIENT_VERSION.commit().toUnprefixedHexString()
+ "\". This will be appended to any user-defined graffiti or used if none is defined. Refer to validator graffiti options to customize.");
}
}

@Test
public void buildGraffiti_shouldNotFail() {
this.graffitiBuilder =
new GraffitiBuilder(clientGraffitiAppendFormat, userGraffiti) {
new GraffitiBuilder(clientGraffitiAppendFormat) {
@Override
protected int calculateGraffitiLength(final Optional<Bytes32> graffiti) {
throw new RuntimeException("");
Expand All @@ -105,10 +99,9 @@ protected int calculateGraffitiLength(final Optional<Bytes32> graffiti) {

@Test
public void buildGraffiti_shouldPreferCallInput() {
final Bytes32 defaultGraffiti = Bytes32Parser.toBytes32(asciiGraffiti32);
final Bytes32 userGraffiti = Bytes32Parser.toBytes32(ASCII_GRAFFITI_20);
final Bytes32 expectedGraffiti = Bytes32Parser.toBytes32(ASCII_GRAFFITI_20 + " TK");
this.graffitiBuilder = new GraffitiBuilder(CLIENT_CODES, Optional.of(defaultGraffiti));
this.graffitiBuilder = new GraffitiBuilder(CLIENT_CODES);
assertThat(graffitiBuilder.buildGraffiti(Optional.of(userGraffiti)))
.isEqualTo(expectedGraffiti);
}
Expand All @@ -119,7 +112,7 @@ public void buildGraffiti_shouldProvideCorrectOutput(
final ClientGraffitiAppendFormat clientGraffitiAppendFormat,
final Optional<String> maybeUserGraffiti,
final String expectedGraffiti) {
this.graffitiBuilder = new GraffitiBuilder(clientGraffitiAppendFormat, userGraffiti);
this.graffitiBuilder = new GraffitiBuilder(clientGraffitiAppendFormat);
graffitiBuilder.onExecutionClientVersion(BESU_CLIENT_VERSION);
final Bytes32 expectedGraffitiBytes = Bytes32Parser.toBytes32(expectedGraffiti);
assertThat(
Expand All @@ -140,7 +133,7 @@ public void buildGraffiti_shouldProvideCorrectOutput_whenElInfoNa(
final ClientGraffitiAppendFormat clientGraffitiAppendFormat,
final Optional<String> maybeUserGraffiti,
final String expectedGraffiti) {
this.graffitiBuilder = new GraffitiBuilder(clientGraffitiAppendFormat, userGraffiti);
this.graffitiBuilder = new GraffitiBuilder(clientGraffitiAppendFormat);
final Bytes32 expectedGraffitiBytes = Bytes32Parser.toBytes32(expectedGraffiti);
assertThat(
new String(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ public void logExecutionClientVersion(final String name, final String version) {
log.info("Execution Client version: {} {}", name, version);
}

public void logDefaultGraffiti(final String graffiti) {
public void logGraffitiWatermark(final String graffitiWatermark) {
log.info(
"Default graffiti to use when building block without external VC: \"{}\". "
+ "To change check validator graffiti options.",
graffiti);
"Using graffiti watermark: \"{}\". This will be appended to any user-defined graffiti or used if none is defined. "
+ "Refer to validator graffiti options to customize.",
graffitiWatermark);
}

public void builderIsNotAvailable(final String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,7 @@ public void initRewardCalculator() {
public void initValidatorApiHandler() {
LOG.debug("BeaconChainController.initValidatorApiHandler()");
final GraffitiBuilder graffitiBuilder =
new GraffitiBuilder(
beaconConfig.validatorConfig().getClientGraffitiAppendFormat(),
beaconConfig.validatorConfig().getGraffitiProvider().get());
new GraffitiBuilder(beaconConfig.validatorConfig().getClientGraffitiAppendFormat());
eventChannels.subscribe(ExecutionClientVersionChannel.class, graffitiBuilder);
final ExecutionClientVersionProvider executionClientVersionProvider =
new ExecutionClientVersionProvider(
Expand Down

0 comments on commit 5303645

Please sign in to comment.