Skip to content

Commit

Permalink
merge branch master
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Jul 24, 2023
2 parents 995c7a8 + 793182b commit 29150ad
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 29 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ target/
tmp/
build/
out/
ganache-cli/
pow/src/main/resources/keys.json
!validator_test_data.json
/interopDepositsAndKeys.json
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ For information on changes in released versions of Teku, see the [releases page]

### Additions and Improvements

Introduce `--exchange-capabilities-monitoring-enabled` parameter. If enabled, EL will be queried periodically for the Engine API methods it supports. If incompatibility is detected, there will be a warning raised in the logs. The default is `true`.
- Introduce `--exchange-capabilities-monitoring-enabled` parameter. If enabled, EL will be queried periodically for the Engine API methods it supports. If incompatibility is detected, a warning is raised in the logs. The default is `true`.

### Bug Fixes
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,13 @@ private boolean isHexString(final String identifier) {
}

private T createSelectorForKeywordOrSlot(final String identifier) {
switch (identifier) {
case HEAD:
return headSelector();
case GENESIS:
return genesisSelector();
case FINALIZED:
return finalizedSelector();
case JUSTIFIED:
return justifiedSelector();
}
return slotSelector(UInt64.valueOf(identifier));
return switch (identifier) {
case HEAD -> headSelector();
case GENESIS -> genesisSelector();
case FINALIZED -> finalizedSelector();
case JUSTIFIED -> justifiedSelector();
default -> slotSelector(UInt64.valueOf(identifier));
};
}

private BadRequestException badRequestException(final String type, final String identifier) {
Expand Down
1 change: 0 additions & 1 deletion gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ dependencyManagement {
dependency 'org.apache.commons:commons-text:1.10.0'
dependency 'org.apache.commons:commons-lang3:3.12.0'
dependency 'commons-io:commons-io:2.13.0'
dependency 'org.apache.commons:commons-compress:1.21'
dependency 'org.commonjava.mimeparse:mimeparse:0.1.3.3'

dependencySet(group: 'org.apache.logging.log4j', version: '2.20.0') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@

public class SszUInt64 extends AbstractSszPrimitive<UInt64, SszUInt64> {

public static final SszUInt64 ZERO = SszUInt64.of(UInt64.ZERO);
public static final SszUInt64 ZERO = new SszUInt64(UInt64.ZERO);
public static final SszUInt64 THIRTY_TWO_ETH = new SszUInt64(UInt64.THIRTY_TWO_ETH);
public static final SszUInt64 MAX_VALUE = new SszUInt64(UInt64.MAX_VALUE);

public static SszUInt64 of(UInt64 val) {
public static SszUInt64 of(final UInt64 val) {
if (val.isZero()) {
return ZERO;
}
if (val.isThirtyTwoEth()) {
return THIRTY_TWO_ETH;
}
if (val.isMaxValue()) {
return MAX_VALUE;
}
return new SszUInt64(val);
}

private SszUInt64(UInt64 val) {
private SszUInt64(final UInt64 val) {
super(val, SszPrimitiveSchemas.UINT64_SCHEMA);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class UInt64 implements Comparable<UInt64> {

public static final UInt64 ZERO = new UInt64(0);
public static final UInt64 ONE = new UInt64(1);
public static final UInt64 THIRTY_TWO_ETH = new UInt64(32_000_000_000L);
public static final UInt64 MAX_VALUE = new UInt64(-1L);

private final long value;
Expand Down Expand Up @@ -82,7 +83,16 @@ public static UInt64 valueOf(final BigInteger value) {
* @return the created UInt64.
*/
public static UInt64 fromLongBits(final long value) {
return value == 0 ? ZERO : new UInt64(value);
if (value == 0L) {
return ZERO;
}
if (value == 32_000_000_000L) {
return THIRTY_TWO_ETH;
}
if (value == -1L) {
return MAX_VALUE;
}
return new UInt64(value);
}

/**
Expand Down Expand Up @@ -365,6 +375,19 @@ public boolean isZero() {
return value == 0;
}

/**
* Returns true if the value is 32_000_000_000L
*
* @return true if the value is 32_000_000_000L
*/
public boolean isThirtyTwoEth() {
return value == 32_000_000_000L;
}

public boolean isMaxValue() {
return value == -1L;
}

/**
* Returns true if this value is strictly greater than the specified value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ void lessThanOrEqualTo_shouldReturnTrueWhenNumberIsLessThanOrEqual(
@Test
void constants_shouldHaveExpectedValues() {
assertThat(UInt64.ZERO).isEqualTo(UInt64.valueOf(0));
assertThat(UInt64.THIRTY_TWO_ETH).isEqualTo(UInt64.valueOf(32_000_000_000L));
assertThat(UInt64.ONE).isEqualTo(UInt64.valueOf(1));
assertThat(UInt64.MAX_VALUE).isEqualTo(UInt64.fromLongBits(-1));
}
Expand Down
1 change: 1 addition & 0 deletions services/chainstorage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies {
implementation project(':infrastructure:async')
implementation project(':infrastructure:exceptions')
implementation project(':infrastructure:logging')
implementation project(':infrastructure:metrics')
implementation project(':infrastructure:serviceutils')
implementation project(':storage')
implementation project(':storage:api')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread;
import tech.pegasys.teku.infrastructure.events.EventChannels;
import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.service.serviceutils.Service;
import tech.pegasys.teku.service.serviceutils.ServiceConfig;
import tech.pegasys.teku.spec.SpecMilestone;
Expand Down Expand Up @@ -80,14 +82,33 @@ protected SafeFuture<?> doStart() {

database.migrate();

final SettableLabelledGauge pruningTimingsLabelledGauge =
SettableLabelledGauge.create(
serviceConfig.getMetricsSystem(),
TekuMetricCategory.STORAGE,
"pruning_time",
"Tracks last pruning duration in milliseconds",
"type");

final SettableLabelledGauge pruningActiveLabelledGauge =
SettableLabelledGauge.create(
serviceConfig.getMetricsSystem(),
TekuMetricCategory.STORAGE,
"pruning_active",
"Tracks when pruner is active",
"type");

if (!config.getDataStorageMode().storesAllBlocks()) {
blockPruner =
Optional.of(
new BlockPruner(
config.getSpec(),
database,
storagePrunerAsyncRunner,
config.getBlockPruningInterval()));
config.getBlockPruningInterval(),
"block",
pruningTimingsLabelledGauge,
pruningActiveLabelledGauge));
}
if (config.getSpec().isMilestoneSupported(SpecMilestone.DENEB)) {
blobsPruner =
Expand All @@ -101,6 +122,9 @@ protected SafeFuture<?> doStart() {
config.getBlobsPruningInterval(),
config.getBlobsPruningLimit(),
blobSidecarsStorageCountersEnabled,
"blob_sidecar",
pruningTimingsLabelledGauge,
pruningActiveLabelledGauge,
config.isStoreNonCanonicalBlocksEnabled()));
}
final EventChannels eventChannels = serviceConfig.getEventChannels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tech.pegasys.teku.infrastructure.async.AsyncRunner;
import tech.pegasys.teku.infrastructure.async.Cancellable;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
Expand All @@ -44,6 +45,9 @@ public class BlobSidecarPruner extends Service {
private final int pruneLimit;
private final TimeProvider timeProvider;
private final boolean blobSidecarsStorageCountersEnabled;
private final String pruningMetricsType;
private final SettableLabelledGauge pruningTimingsLabelledGauge;
private final SettableLabelledGauge pruningActiveLabelledGauge;

private Optional<Cancellable> scheduledPruner = Optional.empty();
private Optional<UInt64> genesisTime = Optional.empty();
Expand All @@ -61,6 +65,9 @@ public BlobSidecarPruner(
final Duration pruneInterval,
final int pruneLimit,
final boolean blobSidecarsStorageCountersEnabled,
final String pruningMetricsType,
final SettableLabelledGauge pruningTimingsLabelledGauge,
final SettableLabelledGauge pruningActiveLabelledGauge,
final boolean storeNonCanonicalBlobSidecars) {
this.spec = spec;
this.database = database;
Expand All @@ -69,6 +76,9 @@ public BlobSidecarPruner(
this.pruneLimit = pruneLimit;
this.timeProvider = timeProvider;
this.blobSidecarsStorageCountersEnabled = blobSidecarsStorageCountersEnabled;
this.pruningMetricsType = pruningMetricsType;
this.pruningTimingsLabelledGauge = pruningTimingsLabelledGauge;
this.pruningActiveLabelledGauge = pruningActiveLabelledGauge;
this.storeNonCanonicalBlobSidecars = storeNonCanonicalBlobSidecars;

if (blobSidecarsStorageCountersEnabled) {
Expand Down Expand Up @@ -103,8 +113,14 @@ protected synchronized SafeFuture<?> doStop() {
}

private void pruneBlobs() {
pruningActiveLabelledGauge.set(1, pruningMetricsType);
final long start = System.currentTimeMillis();

pruneBlobsPriorToAvailabilityWindow();

pruningTimingsLabelledGauge.set(System.currentTimeMillis() - start, pruningMetricsType);
pruningActiveLabelledGauge.set(0, pruningMetricsType);

if (blobSidecarsStorageCountersEnabled) {
blobColumnSize.set(database.getBlobSidecarColumnCount());
earliestBlobSidecarSlot.set(
Expand Down Expand Up @@ -147,6 +163,8 @@ private void pruneBlobsPriorToAvailabilityWindow() {
nonCanonicalBlobsPruningStart,
nonCanonicalBlobsLimitReached);
}
final boolean limitReached = database.pruneOldestBlobSidecars(latestPrunableSlot, pruneLimit);
LOG.debug("Blobs pruning finished. Limit reached: {}", () -> limitReached);
} catch (ShuttingDownException | RejectedExecutionException ex) {
LOG.debug("Shutting down", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tech.pegasys.teku.infrastructure.async.AsyncRunner;
import tech.pegasys.teku.infrastructure.async.Cancellable;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.service.serviceutils.Service;
import tech.pegasys.teku.spec.Spec;
Expand All @@ -35,26 +36,42 @@ public class BlockPruner extends Service {
private final Database database;
private final AsyncRunner asyncRunner;
private final Duration pruneInterval;
private final SettableLabelledGauge pruningTimingsLabelledGauge;
private final SettableLabelledGauge pruningActiveLabelledGauge;
private final String pruningMetricsType;

private Optional<Cancellable> scheduledPruner = Optional.empty();

public BlockPruner(
final Spec spec,
final Database database,
final AsyncRunner asyncRunner,
final Duration pruneInterval) {
final Duration pruneInterval,
final String pruningMetricsType,
final SettableLabelledGauge pruningTimingsLabelledGauge,
final SettableLabelledGauge pruningActiveLabelledGauge) {
this.spec = spec;
this.database = database;
this.asyncRunner = asyncRunner;
this.pruneInterval = pruneInterval;
this.pruningMetricsType = pruningMetricsType;
this.pruningTimingsLabelledGauge = pruningTimingsLabelledGauge;
this.pruningActiveLabelledGauge = pruningActiveLabelledGauge;
}

@Override
protected synchronized SafeFuture<?> doStart() {
scheduledPruner =
Optional.of(
asyncRunner.runWithFixedDelay(
this::pruneBlocks,
() -> {
pruningActiveLabelledGauge.set(1, pruningMetricsType);
final long start = System.currentTimeMillis();
pruneBlocks();
pruningTimingsLabelledGauge.set(
System.currentTimeMillis() - start, pruningMetricsType);
pruningActiveLabelledGauge.set(0, pruningMetricsType);
},
Duration.ZERO,
pruneInterval,
error -> LOG.error("Failed to prune old blocks", error)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.infrastructure.async.StubAsyncRunner;
import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge;
import tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem;
import tech.pegasys.teku.infrastructure.time.StubTimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
Expand Down Expand Up @@ -64,6 +65,9 @@ public class BlobSidecarPrunerTest {
PRUNE_INTERVAL,
PRUNE_LIMIT,
false,
"test",
mock(SettableLabelledGauge.class),
mock(SettableLabelledGauge.class),
false);

@BeforeEach
Expand Down Expand Up @@ -149,6 +153,9 @@ void shouldUseEpochsStoreBlobs() {
PRUNE_INTERVAL,
PRUNE_LIMIT,
false,
"test",
mock(SettableLabelledGauge.class),
mock(SettableLabelledGauge.class),
false);
when(databaseOverride.getGenesisTime()).thenReturn(Optional.of(genesisTime));
assertThat(blobsPrunerOverride.start()).isCompleted();
Expand Down Expand Up @@ -201,6 +208,9 @@ void shouldNotPruneWhenEpochsStoreBlobsIsMax() {
PRUNE_INTERVAL,
PRUNE_LIMIT,
false,
"test",
mock(SettableLabelledGauge.class),
mock(SettableLabelledGauge.class),
false);
when(databaseOverride.getGenesisTime()).thenReturn(Optional.of(genesisTime));
assertThat(blobsPrunerOverride.start()).isCompleted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.infrastructure.async.StubAsyncRunner;
import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge;
import tech.pegasys.teku.infrastructure.time.StubTimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
Expand All @@ -51,7 +52,15 @@ class BlockPrunerTest {
private final StubAsyncRunner asyncRunner = new StubAsyncRunner(timeProvider);
private final Database database = mock(Database.class);

private final BlockPruner pruner = new BlockPruner(spec, database, asyncRunner, PRUNE_INTERVAL);
private final BlockPruner pruner =
new BlockPruner(
spec,
database,
asyncRunner,
PRUNE_INTERVAL,
"test",
mock(SettableLabelledGauge.class),
mock(SettableLabelledGauge.class));

@BeforeEach
void setUp() {
Expand Down
Loading

0 comments on commit 29150ad

Please sign in to comment.