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

Tide up state pruner validation #8459

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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.exceptions.InvalidConfigurationException;
import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.service.serviceutils.Service;
Expand All @@ -36,6 +37,7 @@
import tech.pegasys.teku.storage.server.ChainStorage;
import tech.pegasys.teku.storage.server.CombinedStorageChannelSplitter;
import tech.pegasys.teku.storage.server.Database;
import tech.pegasys.teku.storage.server.DatabaseVersion;
import tech.pegasys.teku.storage.server.DepositStorage;
import tech.pegasys.teku.storage.server.RetryingStorageUpdateChannel;
import tech.pegasys.teku.storage.server.StorageConfiguration;
Expand Down Expand Up @@ -117,24 +119,29 @@ protected SafeFuture<?> doStart() {
pruningActiveLabelledGauge));
}
if (config.getDataStorageMode().storesFinalizedStates()
&& config.getRetainedSlots() > -1) {
LOG.info(
"State pruner will run every: {} minute(s), retaining states for the last {} finalized slots. Limited to {} state prune per execution. ",
config.getStatePruningInterval().toMinutes(),
config.getRetainedSlots(),
config.getStatePruningLimit());
statePruner =
Optional.of(
new StatePruner(
config.getSpec(),
database,
storagePrunerAsyncRunner,
config.getStatePruningInterval(),
config.getRetainedSlots(),
config.getStatePruningLimit(),
"state",
pruningTimingsLabelledGauge,
pruningActiveLabelledGauge));
&& config.getRetainedSlots() > 0) {
if (config.getDataStorageCreateDbVersion() == DatabaseVersion.LEVELDB_TREE) {
throw new InvalidConfigurationException(
"State pruning is not supported with leveldb_tree database.");
} else {
LOG.info(
"State pruner will run every: {} minute(s), retaining states for the last {} finalized slots. Limited to {} state prune per execution. ",
config.getStatePruningInterval().toMinutes(),
config.getRetainedSlots(),
config.getStatePruningLimit());
statePruner =
Optional.of(
new StatePruner(
config.getSpec(),
database,
storagePrunerAsyncRunner,
config.getStatePruningInterval(),
config.getRetainedSlots(),
config.getStatePruningLimit(),
"state",
pruningTimingsLabelledGauge,
pruningActiveLabelledGauge));
}
}
if (config.getSpec().isMilestoneSupported(SpecMilestone.DENEB)) {
blobsPruner =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class StorageConfiguration {
public static final int DEFAULT_BLOCK_PRUNING_LIMIT = 5000;
public static final Duration DEFAULT_BLOBS_PRUNING_INTERVAL = Duration.ofMinutes(1);
public static final Duration DEFAULT_STATE_PRUNING_INTERVAL = Duration.ofMinutes(5);
public static final long DEFAULT_STORAGE_RETAINED_SLOTS = -1;
public static final long DEFAULT_STORAGE_RETAINED_SLOTS = 0;
public static final int DEFAULT_STATE_PRUNING_LIMIT = 1;

// 60/12 = 5 blocks per minute * 6 max blobs per block = 30 blobs per minute at maximum, 15 as
Expand Down Expand Up @@ -275,7 +275,7 @@ public Builder blobsPruningLimit(final int blobsPruningLimit) {
}

public Builder retainedSlots(final long retainedSlots) {
if (retainedSlots < -1) {
gfukushima marked this conversation as resolved.
Show resolved Hide resolved
if (retainedSlots < 0) {
throw new InvalidConfigurationException(
"Invalid number of slots to retain finalized states for");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ public void shouldSucceedIfDatabaseStorageModeFileIsInvalidAndExplicitOptionIsSe
}

@Test
public void shouldFailIfUserConfiguresStatePrunerIntervalTooLow() {
public void shouldFailIfUserConfiguresStatePruneSlotsRetainedLowerThanAllowed() {

assertThatThrownBy(
() -> StorageConfiguration.builder().dataStorageMode(ARCHIVE).retainedSlots(-1))
.isInstanceOf(InvalidConfigurationException.class)
.hasMessageContaining("Invalid number of slots to retain finalized states for");
}

@Test
public void shouldFailIfUserConfiguresStatePrunerLowerThanAllowed() {

assertThatThrownBy(
() ->
Expand All @@ -122,7 +131,7 @@ public void shouldFailIfUserConfiguresStatePrunerIntervalTooLow() {
}

@Test
public void shouldFailIfUserConfiguresStatePrunerIntervalTooHigh() {
public void shouldFailIfUserConfiguresStatePrunerIntervalGreaterThanAllowed() {

assertThatThrownBy(
() ->
Expand All @@ -135,7 +144,7 @@ public void shouldFailIfUserConfiguresStatePrunerIntervalTooHigh() {
}

@Test
public void shouldFailIfUserConfiguresStatePrunerLimitTooHigh() {
public void shouldFailIfUserConfiguresStatePrunerLimitGreaterThanAllowed() {

assertThatThrownBy(
() -> StorageConfiguration.builder().dataStorageMode(ARCHIVE).statePruningLimit(101))
Expand Down