Skip to content

Commit

Permalink
clean PR
Browse files Browse the repository at this point in the history
Signed-off-by: Karim Taam <[email protected]>
  • Loading branch information
matkt committed Oct 17, 2024
1 parent b40d4c4 commit 82f562e
Show file tree
Hide file tree
Showing 38 changed files with 871 additions and 1,101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.DEFAULT_DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE;
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.DEFAULT_RECEIPT_COMPACTION_ENABLED;
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.MINIMUM_DIFFBASED_TRIE_LOG_RETENTION_LIMIT;
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.Unstable.DEFAULT_DIFFBASED_CODE_USING_CODE_HASH_ENABLED;
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.Unstable.DEFAULT_BONSAI_FULL_FLAT_DB_ENABLED;
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.Unstable.DEFAULT_DIFFBASED_CODE_USING_CODE_HASH_ENABLED;
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.Unstable.DEFAULT_VERKLE_STEM_FLAT_DB_ENABLED;

import org.hyperledger.besu.cli.options.CLIOptions;
Expand Down Expand Up @@ -75,7 +75,7 @@ public class DataStorageOptions implements CLIOptions<DataStorageConfiguration>
@SuppressWarnings("ExperimentalCliOptionMustBeCorrectlyDisplayed")
@CommandLine.Option(
names = {
DIFFBASED_LIMIT_TRIE_LOGS_ENABLED,
DIFFBASED_LIMIT_TRIE_LOGS_ENABLED,
"--Xbonsai-limit-trie-logs-enabled", // deprecated
"--Xbonsai-trie-log-pruning-enabled" // deprecated
},
Expand All @@ -87,12 +87,13 @@ public class DataStorageOptions implements CLIOptions<DataStorageConfiguration>
@SuppressWarnings("ExperimentalCliOptionMustBeCorrectlyDisplayed")
@CommandLine.Option(
names = {
DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE,
DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE,
"--Xbonsai-trie-logs-pruning-window-size" // deprecated
},
description =
"The max number of blocks to load and prune trie logs for at startup. (default: ${DEFAULT-VALUE})")
private Integer diffBasedTrieLogPruningWindowSize = DEFAULT_DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE;
private Integer diffBasedTrieLogPruningWindowSize =
DEFAULT_DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE;

@Option(
names = "--receipt-compaction-enabled",
Expand Down Expand Up @@ -138,12 +139,12 @@ public static class Unstable {
private Boolean isParallelTxProcessingEnabled = false;

@CommandLine.Option(
hidden = true,
names = {
"--Xverkle-stem-flat-db-enabled",
},
arity = "1",
description = "Enables stem flat database strategy for verkle. (default: ${DEFAULT-VALUE})")
hidden = true,
names = {
"--Xverkle-stem-flat-db-enabled",
},
arity = "1",
description = "Enables stem flat database strategy for verkle. (default: ${DEFAULT-VALUE})")
private Boolean verkleStemFlatDbEnabled = DEFAULT_VERKLE_STEM_FLAT_DB_ENABLED;

/** Default Constructor. */
Expand All @@ -165,21 +166,22 @@ public static DataStorageOptions create() {
* @param commandLine the full commandLine to check all the options specified by the user
*/
public void validate(final CommandLine commandLine) {
if (DataStorageFormat.BONSAI == dataStorageFormat || DataStorageFormat.VERKLE == dataStorageFormat) {
if (DataStorageFormat.BONSAI == dataStorageFormat
|| DataStorageFormat.VERKLE == dataStorageFormat) {
if (diffBasedLimitTrieLogsEnabled) {
if (diffBasedMaxLayersToLoad < MINIMUM_DIFFBASED_TRIE_LOG_RETENTION_LIMIT) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
DIFFBASED_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD + " minimum value is %d",
MINIMUM_DIFFBASED_TRIE_LOG_RETENTION_LIMIT));
MINIMUM_DIFFBASED_TRIE_LOG_RETENTION_LIMIT));
}
if (diffBasedTrieLogPruningWindowSize <= 0) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE + "=%d must be greater than 0",
diffBasedTrieLogPruningWindowSize));
diffBasedTrieLogPruningWindowSize));
}
if (diffBasedTrieLogPruningWindowSize <= diffBasedMaxLayersToLoad) {
throw new CommandLine.ParameterException(
Expand All @@ -189,8 +191,8 @@ public void validate(final CommandLine commandLine) {
+ "=%d must be greater than "
+ DIFFBASED_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD
+ "=%d",
diffBasedTrieLogPruningWindowSize,
diffBasedMaxLayersToLoad));
diffBasedTrieLogPruningWindowSize,
diffBasedMaxLayersToLoad));
}
}
} else {
Expand All @@ -213,7 +215,8 @@ public static DataStorageOptions fromConfig(final DataStorageConfiguration domai
dataStorageOptions.dataStorageFormat = domainObject.getDataStorageFormat();
dataStorageOptions.diffBasedMaxLayersToLoad = domainObject.getDiffbasedMaxLayersToLoad();
dataStorageOptions.receiptCompactionEnabled = domainObject.getReceiptCompactionEnabled();
dataStorageOptions.diffBasedLimitTrieLogsEnabled = domainObject.getDiffbasedLimitTrieLogsEnabled();
dataStorageOptions.diffBasedLimitTrieLogsEnabled =
domainObject.getDiffbasedLimitTrieLogsEnabled();
dataStorageOptions.diffBasedTrieLogPruningWindowSize =
domainObject.getDiffbasedTrieLogPruningWindowSize();
dataStorageOptions.unstableOptions.bonsaiFullFlatDbEnabled =
Expand All @@ -223,7 +226,7 @@ public static DataStorageOptions fromConfig(final DataStorageConfiguration domai
dataStorageOptions.unstableOptions.isParallelTxProcessingEnabled =
domainObject.getUnstable().isParallelTxProcessingEnabled();
dataStorageOptions.unstableOptions.verkleStemFlatDbEnabled =
domainObject.getUnstable().getVerkleStemFlatDbEnabled();
domainObject.getUnstable().getVerkleStemFlatDbEnabled();

return dataStorageOptions;
}
Expand All @@ -239,9 +242,10 @@ public DataStorageConfiguration toDomainObject() {
.unstable(
ImmutableDataStorageConfiguration.Unstable.builder()
.bonsaiFullFlatDbEnabled(unstableOptions.bonsaiFullFlatDbEnabled)
.diffbasedCodeStoredByCodeHashEnabled(unstableOptions.bonsaiCodeUsingCodeHashEnabled)
.diffbasedCodeStoredByCodeHashEnabled(
unstableOptions.bonsaiCodeUsingCodeHashEnabled)
.isParallelTxProcessingEnabled(unstableOptions.isParallelTxProcessingEnabled)
.verkleStemFlatDbEnabled(unstableOptions.verkleStemFlatDbEnabled)
.verkleStemFlatDbEnabled(unstableOptions.verkleStemFlatDbEnabled)
.build())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ boolean prune(
String.format(
"Remaining trie logs (%d) did not match %s (%d). Trie logs backup files (in %s) have not been deleted, it is safe to rerun the subcommand.",
countAfterPrune,
DIFFBASED_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD,
DIFFBASED_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD,
layersToRetain,
batchFileNameBase));
}
Expand Down Expand Up @@ -303,7 +303,8 @@ void validatePruneConfiguration(final DataStorageConfiguration config) {
checkArgument(
config.getDiffbasedTrieLogPruningWindowSize() > 0,
String.format(
DataStorageOptions.DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE + "=%d must be greater than 0",
DataStorageOptions.DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE
+ "=%d must be greater than 0",
config.getDiffbasedTrieLogPruningWindowSize()));
checkArgument(
config.getDiffbasedTrieLogPruningWindowSize() > config.getDiffbasedMaxLayersToLoad(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ private static BesuController createBesuController() {
.besuCommand
.setupControllerBuilder()
.dataStorageConfiguration(
ImmutableDataStorageConfiguration.copyOf(config).withDiffbasedLimitTrieLogsEnabled(false))
ImmutableDataStorageConfiguration.copyOf(config)
.withDiffbasedLimitTrieLogsEnabled(false))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class DataStorageOptionsTest
public void bonsaiTrieLogPruningLimitOption() {
internalTestSuccess(
dataStorageConfiguration ->
assertThat(dataStorageConfiguration.getDiffbasedTrieLogPruningWindowSize()).isEqualTo(600),
assertThat(dataStorageConfiguration.getDiffbasedTrieLogPruningWindowSize())
.isEqualTo(600),
"--bonsai-limit-trie-logs-enabled",
"--bonsai-trie-logs-pruning-window-size",
"600");
Expand All @@ -41,7 +42,8 @@ public void bonsaiTrieLogPruningLimitOption() {
public void bonsaiTrieLogPruningLimitLegacyOption() {
internalTestSuccess(
dataStorageConfiguration ->
assertThat(dataStorageConfiguration.getDiffbasedTrieLogPruningWindowSize()).isEqualTo(600),
assertThat(dataStorageConfiguration.getDiffbasedTrieLogPruningWindowSize())
.isEqualTo(600),
"--Xbonsai-limit-trie-logs-enabled",
"--Xbonsai-trie-logs-pruning-window-size",
"600");
Expand All @@ -51,7 +53,8 @@ public void bonsaiTrieLogPruningLimitLegacyOption() {
public void bonsaiTrieLogsEnabled_explicitlySetToFalse() {
internalTestSuccess(
dataStorageConfiguration ->
assertThat(dataStorageConfiguration.getDiffbasedLimitTrieLogsEnabled()).isEqualTo(false),
assertThat(dataStorageConfiguration.getDiffbasedLimitTrieLogsEnabled())
.isEqualTo(false),
"--bonsai-limit-trie-logs-enabled=false");
}

Expand Down Expand Up @@ -109,7 +112,9 @@ public void bonsaiCodeUsingCodeHashEnabledCanBeEnabled() {
internalTestSuccess(
dataStorageConfiguration ->
assertThat(
dataStorageConfiguration.getUnstable().getDiffbasedCodeStoredByCodeHashEnabled())
dataStorageConfiguration
.getUnstable()
.getDiffbasedCodeStoredByCodeHashEnabled())
.isEqualTo(true),
"--Xbonsai-code-using-code-hash-enabled",
"true");
Expand All @@ -120,7 +125,9 @@ public void bonsaiCodeUsingCodeHashEnabledCanBeDisabled() {
internalTestSuccess(
dataStorageConfiguration ->
assertThat(
dataStorageConfiguration.getUnstable().getDiffbasedCodeStoredByCodeHashEnabled())
dataStorageConfiguration
.getUnstable()
.getDiffbasedCodeStoredByCodeHashEnabled())
.isEqualTo(false),
"--Xbonsai-code-using-code-hash-enabled",
"false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ public void mismatchInPrunedTrieLogCountShouldNotDeleteFiles(final @TempDir Path

final BonsaiWorldStateKeyValueStorage inMemoryWorldStateSpy = spy(inMemoryWorldState);
// force a different value the second time the trie log count is called
when(inMemoryWorldStateSpy.streamTrieLogKeys(3L + DEFAULT_DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE))
when(inMemoryWorldStateSpy.streamTrieLogKeys(
3L + DEFAULT_DIFFBASED_TRIE_LOG_PRUNING_WINDOW_SIZE))
.thenCallRealMethod()
.thenReturn(Stream.empty());
assertThatThrownBy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,19 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
final ValidationResult<RpcErrorType> parameterValidationResult =
validateParameters(blockParam, maybeVersionedHashParam, maybeParentBeaconBlockRootParam);
if (!parameterValidationResult.isValid()) {
System.out.println("invalid15");
return new JsonRpcErrorResponse(reqId, parameterValidationResult);
}

final ValidationResult<RpcErrorType> forkValidationResult =
validateForkSupported(blockParam.getTimestamp());
if (!forkValidationResult.isValid()) {
System.out.println("invalid14");
return new JsonRpcErrorResponse(reqId, forkValidationResult);
}

final Optional<List<VersionedHash>> maybeVersionedHashes;
try {
maybeVersionedHashes = extractVersionedHashes(maybeVersionedHashParam);
} catch (RuntimeException ex) {
System.out.println("issie " + ex.getMessage());
return respondWithInvalid(
reqId,
blockParam,
Expand Down Expand Up @@ -231,7 +228,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
if (!getExecutionWitnessValidator(
protocolSchedule.get(), blockParam.getTimestamp(), blockParam.getBlockNumber())
.validateExecutionWitness(maybeExecutionWitness)) {
System.out.println("invalid10");
return new JsonRpcErrorResponse(
reqId, new JsonRpcError(RpcErrorType.INVALID_PARAMS, "Invalid executionWitness"));
}
Expand Down Expand Up @@ -266,7 +262,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
.log();
}));
} catch (final RLPException | IllegalArgumentException e) {
System.out.println("issie " + e.getMessage());
return respondWithInvalid(
reqId,
blockParam,
Expand All @@ -276,7 +271,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
}

if (blockParam.getExtraData() == null) {
System.out.println("invalid9");
return respondWithInvalid(
reqId,
blockParam,
Expand Down Expand Up @@ -321,7 +315,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
"Computed block hash %s does not match block hash parameter %s",
newBlockHeader.getBlockHash(), blockParam.getBlockHash());
LOG.debug(errorMessage);
System.out.println("invalid8");
return respondWithInvalid(reqId, blockParam, null, getInvalidBlockHashStatus(), errorMessage);
}

Expand All @@ -336,7 +329,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
maybeVersionedHashes,
protocolSchedule.get().getByBlockHeader(newBlockHeader));
if (!blobValidationResult.isValid()) {
System.out.println("invalid7");
return respondWithInvalid(
reqId,
blockParam,
Expand All @@ -348,11 +340,9 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
// do we already have this payload
if (protocolContext.getBlockchain().getBlockByHash(newBlockHeader.getBlockHash()).isPresent()) {
LOG.debug("block already present");
System.out.println("invalid6");
return respondWith(reqId, blockParam, blockParam.getBlockHash(), VALID);
}
if (mergeCoordinator.isBadBlock(blockParam.getBlockHash())) {
System.out.println("invalid5");
return respondWithInvalid(
reqId,
blockParam,
Expand All @@ -366,7 +356,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
if (maybeParentHeader.isPresent()
&& (Long.compareUnsigned(maybeParentHeader.get().getTimestamp(), blockParam.getTimestamp())
>= 0)) {
System.out.println("invalid4");
return respondWithInvalid(
reqId,
blockParam,
Expand All @@ -381,7 +370,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
new BlockBody(transactions, Collections.emptyList(), maybeWithdrawals, maybeRequests));

if (maybeParentHeader.isEmpty()) {
System.out.println("invalid3");
LOG.atInfo()
.setMessage("Parent of block {} is not present, append it to backward sync")
.addArgument(block::toLogString)
Expand All @@ -393,7 +381,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
final var latestValidAncestor = mergeCoordinator.getLatestValidAncestor(newBlockHeader);

if (latestValidAncestor.isEmpty()) {
System.out.println("invalid 2c ");
return respondWith(reqId, blockParam, null, ACCEPTED);
}

Expand All @@ -416,7 +403,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
return respondWith(reqId, blockParam, newBlockHeader.getHash(), VALID);
} else {
if (executionResult.causedBy().isPresent()) {
System.out.println("invalid 1");
Throwable causedBy = executionResult.causedBy().get();
if (causedBy instanceof StorageException || causedBy instanceof MerkleTrieException) {
RpcErrorType error = RpcErrorType.INTERNAL_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public WorldStateKeyValueStorage createWorldStateStorage(
if (dataStorageConfiguration.getDataStorageFormat().equals(DataStorageFormat.BONSAI)) {
return new BonsaiWorldStateKeyValueStorage(this, metricsSystem, dataStorageConfiguration);
} else if (dataStorageConfiguration.getDataStorageFormat().equals(DataStorageFormat.VERKLE)) {
return new VerkleWorldStateKeyValueStorage(this, new StemPreloader(),dataStorageConfiguration, metricsSystem);
return new VerkleWorldStateKeyValueStorage(
this, new StemPreloader(), dataStorageConfiguration, metricsSystem);
} else {
return new ForestWorldStateKeyValueStorage(
getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.WORLD_STATE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ private static MutableWorldState createGenesisBonsaiWorldState() {
new DiffBasedWorldStateConfig());
}

private static MutableWorldState createGenesisVerkleWorldState(final DataStorageConfiguration dataStorageConfiguration) {
private static MutableWorldState createGenesisVerkleWorldState(
final DataStorageConfiguration dataStorageConfiguration) {
final VerkleWorldStateKeyValueStorage verkleWorldStateKeyValueStorage =
new VerkleWorldStateKeyValueStorage(
new KeyValueStorageProvider(
segmentIdentifiers -> new SegmentedInMemoryKeyValueStorage(),
new InMemoryKeyValueStorage(),
new NoOpMetricsSystem()),
new StemPreloader(),
dataStorageConfiguration,
dataStorageConfiguration,
new NoOpMetricsSystem());
return new VerkleWorldState(
verkleWorldStateKeyValueStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.flat.BonsaiFlatDbStrategy;
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.storage.flat.BonsaiFlatDbStrategyProvider;
import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.DiffBasedWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.trie.diffbased.common.storage.flat.FlatDbStrategyProvider;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
import org.hyperledger.besu.ethereum.worldstate.FlatDbMode;
import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue;
Expand All @@ -43,10 +42,8 @@
import java.util.List;
import java.util.NavigableMap;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.function.Supplier;

import kotlin.Pair;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;

Expand Down
Loading

0 comments on commit 82f562e

Please sign in to comment.