Improve snap logs (#3754)

* snapsync logs

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>

Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/3754/merge
matkt 3 years ago committed by GitHub
parent beb4e3baa3
commit bb7ea08c23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/PersistDataStep.java
  2. 37
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapCounter.java
  3. 108
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadState.java
  4. 18
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldStateDownloader.java
  5. 171
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapsyncMetricsManager.java
  6. 8
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/StackTrie.java
  7. 18
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountRangeDataRequest.java
  8. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/AccountTrieNodeDataRequest.java
  9. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/BytecodeRequest.java
  10. 7
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/SnapDataRequest.java
  11. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageRangeDataRequest.java
  12. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/StorageTrieNodeDataRequest.java
  13. 3
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/TrieNodeDataRequest.java
  14. 6
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/PersistDataStepTest.java
  15. 9
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapWorldDownloadStateTest.java

@ -60,9 +60,9 @@ public class PersistDataStep {
task.getData().persist(worldStateStorage, updater, downloadState, snapSyncState);
if (persistedNodes > 0) {
if (task.getData() instanceof TrieNodeDataRequest) {
downloadState.getHealedNodes().inc(persistedNodes);
downloadState.getMetricsManager().notifyNodesHealed(persistedNodes);
} else {
downloadState.getGeneratedNodes().inc(persistedNodes);
downloadState.getMetricsManager().notifyNodesGenerated(persistedNodes);
}
}
}

@ -1,37 +0,0 @@
/*
* Copyright contributors to Hyperledger Besu
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.eth.sync.snapsync;
import org.hyperledger.besu.metrics.RunnableCounter;
import org.hyperledger.besu.plugin.services.metrics.Counter;
public class SnapCounter extends RunnableCounter {
long oldRunValue = 0;
public SnapCounter(final Counter backedCounter, final Runnable task, final int step) {
super(backedCounter, task, step);
}
@Override
public void inc(final long amount) {
backedCounter.inc(amount);
long value = stepCounter.addAndGet(amount);
if ((value - oldRunValue) >= step) {
oldRunValue = value;
task.run();
}
}
}

@ -24,8 +24,6 @@ import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.StorageRangeDataR
import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldDownloadState;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.metrics.RunnableCounter;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.services.tasks.InMemoryTaskQueue;
import org.hyperledger.besu.services.tasks.InMemoryTasksPriorityQueues;
import org.hyperledger.besu.services.tasks.Task;
@ -46,9 +44,6 @@ public class SnapWorldDownloadState extends WorldDownloadState<SnapDataRequest>
private static final Logger LOG = LoggerFactory.getLogger(SnapWorldDownloadState.class);
private static final int DISPLAY_SNAP_PROGRESS_STEP = 200000;
private static final int DISPLAY_HEAL_PROGRESS_STEP = 10000;
protected final InMemoryTaskQueue<SnapDataRequest> pendingAccountRequests =
new InMemoryTaskQueue<>();
protected final InMemoryTaskQueue<SnapDataRequest> pendingStorageRequests =
@ -65,8 +60,7 @@ public class SnapWorldDownloadState extends WorldDownloadState<SnapDataRequest>
private final SnapSyncState snapSyncState;
// metrics around the snapsync
private final RunnableCounter generatedNodes;
private final RunnableCounter healedNodes;
private final SnapsyncMetricsManager metricsManager;
public SnapWorldDownloadState(
final WorldStateStorage worldStateStorage,
@ -74,7 +68,7 @@ public class SnapWorldDownloadState extends WorldDownloadState<SnapDataRequest>
final InMemoryTasksPriorityQueues<SnapDataRequest> pendingRequests,
final int maxRequestsWithoutProgress,
final long minMillisBeforeStalling,
final MetricsSystem metricsSystem,
final SnapsyncMetricsManager metricsManager,
final Clock clock) {
super(
worldStateStorage,
@ -83,47 +77,42 @@ public class SnapWorldDownloadState extends WorldDownloadState<SnapDataRequest>
minMillisBeforeStalling,
clock);
this.snapSyncState = snapSyncState;
this.generatedNodes =
new SnapCounter(
metricsSystem.createCounter(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_generated_nodes_total",
"Total number of data nodes generated as part of snap sync world state download"),
this::displayWorldStateSyncProgress,
DISPLAY_SNAP_PROGRESS_STEP);
this.healedNodes =
new SnapCounter(
metricsSystem.createCounter(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_healed_nodes_total",
"Total number of data nodes healed as part of snap sync world state heal process"),
this::displayHealProgress,
DISPLAY_HEAL_PROGRESS_STEP);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_account_requests_current",
"Number of account pending requests for snap sync world state download",
pendingAccountRequests::size);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_storage_requests_current",
"Number of storage pending requests for snap sync world state download",
pendingStorageRequests::size);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_big_storage_requests_current",
"Number of storage pending requests for snap sync world state download",
pendingBigStorageRequests::size);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_code_requests_current",
"Number of code pending requests for snap sync world state download",
pendingCodeRequests::size);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_trie_node_requests_current",
"Number of trie node pending requests for snap sync world state download",
pendingTrieNodeRequests::size);
this.metricsManager = metricsManager;
metricsManager
.getMetricsSystem()
.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_account_requests_current",
"Number of account pending requests for snap sync world state download",
pendingAccountRequests::size);
metricsManager
.getMetricsSystem()
.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_storage_requests_current",
"Number of storage pending requests for snap sync world state download",
pendingStorageRequests::size);
metricsManager
.getMetricsSystem()
.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_big_storage_requests_current",
"Number of storage pending requests for snap sync world state download",
pendingBigStorageRequests::size);
metricsManager
.getMetricsSystem()
.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_code_requests_current",
"Number of code pending requests for snap sync world state download",
pendingCodeRequests::size);
metricsManager
.getMetricsSystem()
.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_pending_trie_node_requests_current",
"Number of trie node pending requests for snap sync world state download",
pendingTrieNodeRequests::size);
}
@Override
@ -152,10 +141,7 @@ public class SnapWorldDownloadState extends WorldDownloadState<SnapDataRequest>
final WorldStateStorage.Updater updater = worldStateStorage.updater();
updater.saveWorldState(header.getHash(), header.getStateRoot(), rootNodeData);
updater.commit();
LOG.info(
"Finished downloading world state from peers (generated nodes {} / healed nodes {})",
generatedNodes.get(),
healedNodes.get());
metricsManager.notifySnapSyncCompleted();
internalFuture.complete(null);
return true;
}
@ -279,20 +265,8 @@ public class SnapWorldDownloadState extends WorldDownloadState<SnapDataRequest>
List.of(pendingTrieNodeRequests));
}
public RunnableCounter getGeneratedNodes() {
return generatedNodes;
}
public RunnableCounter getHealedNodes() {
return healedNodes;
}
private void displayWorldStateSyncProgress() {
LOG.info("Retrieved {} world state nodes", generatedNodes.get());
}
private void displayHealProgress() {
LOG.info("Healed {} world sync nodes", healedNodes.get());
public SnapsyncMetricsManager getMetricsManager() {
return metricsManager;
}
public void setDynamicPivotBlockManager(final DynamicPivotBlockManager dynamicPivotBlockManager) {

@ -29,12 +29,14 @@ import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.services.tasks.InMemoryTasksPriorityQueues;
import java.time.Clock;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.IntSupplier;
import org.apache.tuweni.bytes.Bytes32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -120,6 +122,9 @@ public class SnapWorldStateDownloader implements WorldStateDownloader {
header.getHash(),
stateRoot);
final SnapsyncMetricsManager snapsyncMetricsManager =
new SnapsyncMetricsManager(metricsSystem);
final SnapWorldDownloadState newDownloadState =
new SnapWorldDownloadState(
worldStateStorage,
@ -127,14 +132,15 @@ public class SnapWorldStateDownloader implements WorldStateDownloader {
snapTaskCollection,
maxNodeRequestsWithoutProgress,
minMillisBeforeStalling,
metricsSystem,
snapsyncMetricsManager,
clock);
RangeManager.generateAllRanges(16)
.forEach(
(key, value) ->
newDownloadState.enqueueRequest(
createAccountRangeDataRequest(stateRoot, key, value)));
final Map<Bytes32, Bytes32> ranges = RangeManager.generateAllRanges(16);
snapsyncMetricsManager.initRange(ranges);
ranges.forEach(
(key, value) ->
newDownloadState.enqueueRequest(
createAccountRangeDataRequest(stateRoot, key, value)));
maybeCompleteTask = Optional.of(new CompleteTaskStep(snapSyncState, metricsSystem));

@ -0,0 +1,171 @@
/*
* Copyright contributors to Hyperledger Besu
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.eth.sync.snapsync;
import static io.netty.util.internal.ObjectUtil.checkNonEmpty;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.tuweni.bytes.Bytes32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SnapsyncMetricsManager {
private static final Logger LOG = LoggerFactory.getLogger(SnapsyncMetricsManager.class);
private static final long PRINT_DELAY = TimeUnit.MINUTES.toMillis(1);
private final MetricsSystem metricsSystem;
private final AtomicReference<BigDecimal> percentageDownloaded;
private final AtomicLong nbAccounts;
private final AtomicLong nbSlots;
private final AtomicLong nbCodes;
private final AtomicLong nbNodesGenerated;
private final AtomicLong nbNodesHealed;
private long startSyncTime;
private final Map<Bytes32, BigInteger> lastRangeIndex = new HashMap<>();
private long lastNotifyTimestamp;
public SnapsyncMetricsManager(final MetricsSystem metricsSystem) {
this.metricsSystem = metricsSystem;
percentageDownloaded = new AtomicReference<>(new BigDecimal(0));
nbAccounts = new AtomicLong(0);
nbSlots = new AtomicLong(0);
nbCodes = new AtomicLong(0);
nbNodesGenerated = new AtomicLong(0);
nbNodesHealed = new AtomicLong(0);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_generated_nodes_total",
"Total number of data nodes generated as part of snap sync world state download",
nbNodesGenerated::get);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_healed_nodes_total",
"Total number of data nodes healed as part of snap sync world state heal process",
nbNodesHealed::get);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_accounts_total",
"Total number of accounts downloaded as part of snap sync world state",
nbAccounts::get);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_slots_total",
"Total number of slots downloaded as part of snap sync world state",
nbSlots::get);
metricsSystem.createLongGauge(
BesuMetricCategory.SYNCHRONIZER,
"snap_world_state_codes_total",
"Total number of codes downloaded as part of snap sync world state",
nbCodes::get);
}
public void initRange(final Map<Bytes32, Bytes32> ranges) {
for (Map.Entry<Bytes32, Bytes32> entry : ranges.entrySet()) {
lastRangeIndex.put(entry.getValue(), entry.getKey().toUnsignedBigInteger());
}
startSyncTime = System.currentTimeMillis();
lastNotifyTimestamp = startSyncTime;
}
public void notifyStateDownloaded(final Bytes32 startKeyHash, final Bytes32 endKeyHash) {
checkNonEmpty(lastRangeIndex, "snapsync range collection");
if (lastRangeIndex.containsKey(endKeyHash)) {
final BigInteger lastPos = lastRangeIndex.get(endKeyHash);
final BigInteger newPos = startKeyHash.toUnsignedBigInteger();
percentageDownloaded.getAndAccumulate(
BigDecimal.valueOf(100)
.multiply(new BigDecimal(newPos.subtract(lastPos)))
.divide(
new BigDecimal(RangeManager.MAX_RANGE.toUnsignedBigInteger()),
MathContext.DECIMAL32),
BigDecimal::add);
lastRangeIndex.put(endKeyHash, newPos);
print(false);
}
}
public void notifyAccountsDownloaded(final long nbAccounts) {
this.nbAccounts.getAndAdd(nbAccounts);
}
public void notifySlotsDownloaded(final long nbSlots) {
this.nbSlots.getAndAdd(nbSlots);
}
public void notifyCodeDownloaded() {
this.nbCodes.getAndIncrement();
}
public void notifyNodesGenerated(final long nbNodes) {
this.nbNodesGenerated.getAndAdd(nbNodes);
}
public void notifyNodesHealed(final long nbNodes) {
this.nbNodesHealed.getAndAdd(nbNodes);
print(true);
}
private void print(final boolean isHeal) {
final long now = System.currentTimeMillis();
if (now - lastNotifyTimestamp >= PRINT_DELAY) {
lastNotifyTimestamp = now;
if (!isHeal) {
LOG.info(
"Snapsync in progress synced={}%, accounts={}, slots={}, codes={}, nodes={}",
percentageDownloaded.get().setScale(2, RoundingMode.HALF_UP),
nbAccounts,
nbSlots,
nbCodes,
nbNodesGenerated);
} else {
LOG.info("Healed {} world state nodes", nbNodesHealed.get());
}
}
}
public void notifySnapSyncCompleted() {
final Duration duration = Duration.ofMillis(System.currentTimeMillis() - startSyncTime);
LOG.info(
"Finished snapsync with nodes {} (healed={}) duration {}{}:{},{}",
nbNodesGenerated.addAndGet(nbNodesHealed.get()),
nbNodesHealed,
duration.toHoursPart() > 0 ? (duration.toHoursPart() + ":") : "",
duration.toMinutesPart(),
duration.toSecondsPart(),
duration.toMillisPart());
}
public MetricsSystem getMetricsSystem() {
return metricsSystem;
}
}

@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import org.apache.tuweni.bytes.Bytes;
@ -44,6 +45,7 @@ public class StackTrie {
private final int maxSegments;
private final Bytes32 startKeyHash;
private final Map<Bytes32, TaskElement> elements;
private final AtomicLong elementsCount;
public StackTrie(final Hash rootHash, final Bytes32 startKeyHash) {
this(rootHash, 1, 1, startKeyHash);
@ -59,10 +61,12 @@ public class StackTrie {
this.maxSegments = maxSegments;
this.startKeyHash = startKeyHash;
this.elements = new LinkedHashMap<>();
this.elementsCount = new AtomicLong();
}
public void addElement(
final Bytes32 taskIdentifier, final List<Bytes> proofs, final TreeMap<Bytes32, Bytes> keys) {
this.elementsCount.addAndGet(keys.size());
this.elements.put(
taskIdentifier, ImmutableTaskElement.builder().proofs(proofs).keys(keys).build());
}
@ -71,6 +75,10 @@ public class StackTrie {
return this.elements.get(taskIdentifier);
}
public AtomicLong getElementsCount() {
return elementsCount;
}
public void commit(final NodeUpdater nodeUpdater) {
if (nbSegments.decrementAndGet() <= 0 && !elements.isEmpty()) {

@ -23,7 +23,6 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncState;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.StackTrie;
import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldDownloadState;
import org.hyperledger.besu.ethereum.proof.WorldStateProofProvider;
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.trie.NodeUpdater;
@ -101,7 +100,7 @@ public class AccountRangeDataRequest extends SnapDataRequest {
protected int doPersist(
final WorldStateStorage worldStateStorage,
final Updater updater,
final WorldDownloadState<SnapDataRequest> downloadState,
final SnapWorldDownloadState downloadState,
final SnapSyncState snapSyncState) {
if (startStorageRange.isPresent() && endStorageRange.isPresent()) {
@ -120,6 +119,8 @@ public class AccountRangeDataRequest extends SnapDataRequest {
stackTrie.commit(nodeUpdater);
downloadState.getMetricsManager().notifyAccountsDownloaded(stackTrie.getElementsCount().get());
return nbNodesSaved.get();
}
@ -153,10 +154,15 @@ public class AccountRangeDataRequest extends SnapDataRequest {
final StackTrie.TaskElement taskElement = stackTrie.getElement(startKeyHash);
// new request is added if the response does not match all the requested range
findNewBeginElementInRange(getRootHash(), taskElement.proofs(), taskElement.keys(), endKeyHash)
.ifPresent(
missingRightElement ->
childRequests.add(
createAccountRangeDataRequest(getRootHash(), missingRightElement, endKeyHash)));
.ifPresentOrElse(
missingRightElement -> {
downloadState
.getMetricsManager()
.notifyStateDownloaded(missingRightElement, endKeyHash);
childRequests.add(
createAccountRangeDataRequest(getRootHash(), missingRightElement, endKeyHash));
},
() -> downloadState.getMetricsManager().notifyStateDownloaded(endKeyHash, endKeyHash));
// find missing storages and code
for (Map.Entry<Bytes32, Bytes> account : taskElement.keys().entrySet()) {

@ -17,7 +17,7 @@ package org.hyperledger.besu.ethereum.eth.sync.snapsync.request;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncState;
import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldDownloadState;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState;
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.trie.CompactEncoding;
import org.hyperledger.besu.ethereum.trie.MerklePatriciaTrie;
@ -52,7 +52,7 @@ public class AccountTrieNodeDataRequest extends TrieNodeDataRequest {
protected int doPersist(
final WorldStateStorage worldStateStorage,
final WorldStateStorage.Updater updater,
final WorldDownloadState<SnapDataRequest> downloadState,
final SnapWorldDownloadState downloadState,
final SnapSyncState snapSyncState) {
if (isRoot()) {
downloadState.setRootNodeData(data);

@ -20,7 +20,6 @@ import static org.slf4j.LoggerFactory.getLogger;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncState;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState;
import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldDownloadState;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater;
@ -53,9 +52,10 @@ public class BytecodeRequest extends SnapDataRequest {
protected int doPersist(
final WorldStateStorage worldStateStorage,
final Updater updater,
final WorldDownloadState<SnapDataRequest> downloadState,
final SnapWorldDownloadState downloadState,
final SnapSyncState snapSyncState) {
updater.putCode(Hash.wrap(accountHash), code);
downloadState.getMetricsManager().notifyCodeDownloaded();
return possibleParent
.map(
trieNodeDataRequest ->

@ -20,7 +20,6 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.RequestType;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncState;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState;
import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldDownloadState;
import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloaderException;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.services.tasks.TasksPriorityProvider;
@ -99,7 +98,7 @@ public abstract class SnapDataRequest implements TasksPriorityProvider {
public int persist(
final WorldStateStorage worldStateStorage,
final WorldStateStorage.Updater updater,
final WorldDownloadState<SnapDataRequest> downloadState,
final SnapWorldDownloadState downloadState,
final SnapSyncState snapSyncState) {
return doPersist(worldStateStorage, updater, downloadState, snapSyncState);
}
@ -107,7 +106,7 @@ public abstract class SnapDataRequest implements TasksPriorityProvider {
protected abstract int doPersist(
final WorldStateStorage worldStateStorage,
final WorldStateStorage.Updater updater,
final WorldDownloadState<SnapDataRequest> downloadState,
final SnapWorldDownloadState downloadState,
final SnapSyncState snapSyncState);
public abstract boolean isResponseReceived();
@ -137,7 +136,7 @@ public abstract class SnapDataRequest implements TasksPriorityProvider {
protected int saveParent(
final WorldStateStorage worldStateStorage,
final WorldStateStorage.Updater updater,
final WorldDownloadState<SnapDataRequest> downloadState,
final SnapWorldDownloadState downloadState,
final SnapSyncState snapSyncState) {
if (pendingChildren.decrementAndGet() == 0) {
return persist(worldStateStorage, updater, downloadState, snapSyncState);

@ -84,7 +84,7 @@ public class StorageRangeDataRequest extends SnapDataRequest {
protected int doPersist(
final WorldStateStorage worldStateStorage,
final Updater updater,
final WorldDownloadState<SnapDataRequest> downloadState,
final SnapWorldDownloadState downloadState,
final SnapSyncState snapSyncState) {
// search incomplete nodes in the range
@ -103,6 +103,8 @@ public class StorageRangeDataRequest extends SnapDataRequest {
updaterTmp.get().commit();
downloadState.getMetricsManager().notifySlotsDownloaded(stackTrie.getElementsCount().get());
return nbNodesSaved.get();
}

@ -17,7 +17,7 @@ package org.hyperledger.besu.ethereum.eth.sync.snapsync.request;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncState;
import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldDownloadState;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState;
import org.hyperledger.besu.ethereum.trie.CompactEncoding;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage.Updater;
@ -44,7 +44,7 @@ public class StorageTrieNodeDataRequest extends TrieNodeDataRequest {
protected int doPersist(
final WorldStateStorage worldStateStorage,
final Updater updater,
final WorldDownloadState<SnapDataRequest> downloadState,
final SnapWorldDownloadState downloadState,
final SnapSyncState snapSyncState) {
updater.putAccountStorageTrieNode(getAccountHash(), getLocation(), getNodeHash(), data);
return 1;

@ -20,7 +20,6 @@ import static org.hyperledger.besu.ethereum.eth.sync.snapsync.RequestType.TRIE_N
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncState;
import org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldDownloadState;
import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldDownloadState;
import org.hyperledger.besu.ethereum.trie.Node;
import org.hyperledger.besu.ethereum.trie.TrieNodeDecoder;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
@ -55,7 +54,7 @@ public abstract class TrieNodeDataRequest extends SnapDataRequest implements Tas
public int persist(
final WorldStateStorage worldStateStorage,
final WorldStateStorage.Updater updater,
final WorldDownloadState<SnapDataRequest> downloadState,
final SnapWorldDownloadState downloadState,
final SnapSyncState snapSyncState) {
if (isExpired(snapSyncState) || pendingChildren.get() > 0) {
// we do nothing. Our last child will eventually persist us.

@ -28,8 +28,6 @@ import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.StorageRangeDataR
import org.hyperledger.besu.ethereum.trie.StoredMerklePatriciaTrie;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.metrics.RunnableCounter;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.services.tasks.Task;
import java.util.List;
@ -50,9 +48,7 @@ public class PersistDataStepTest {
@Before
public void setUp() {
final RunnableCounter runnableCounter =
new RunnableCounter(NoOpMetricsSystem.NO_OP_COUNTER, () -> {}, 100);
when(downloadState.getGeneratedNodes()).thenReturn(runnableCounter);
when(downloadState.getMetricsManager()).thenReturn(mock(SnapsyncMetricsManager.class));
}
@Test

@ -33,7 +33,7 @@ import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloadProce
import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
import org.hyperledger.besu.services.tasks.InMemoryTasksPriorityQueues;
import org.hyperledger.besu.testutil.TestClock;
@ -69,7 +69,7 @@ public class SnapWorldDownloadStateTest {
private final WorldStateDownloadProcess worldStateDownloadProcess =
mock(WorldStateDownloadProcess.class);
private final SnapSyncState snapSyncState = mock(SnapSyncState.class);
private final MetricsSystem metricsSystem = mock(MetricsSystem.class);
private final SnapsyncMetricsManager metricsManager = mock(SnapsyncMetricsManager.class);
private final TestClock clock = new TestClock();
private SnapWorldDownloadState downloadState;
@ -89,6 +89,9 @@ public class SnapWorldDownloadStateTest {
@Before
public void setUp() {
when(metricsManager.getMetricsSystem()).thenReturn(new NoOpMetricsSystem());
if (storageFormat == DataStorageFormat.BONSAI) {
worldStateStorage =
new BonsaiWorldStateKeyValueStorage(new InMemoryKeyValueStorageProvider());
@ -102,7 +105,7 @@ public class SnapWorldDownloadStateTest {
pendingRequests,
MAX_REQUESTS_WITHOUT_PROGRESS,
MIN_MILLIS_BEFORE_STALLING,
metricsSystem,
metricsManager,
clock);
final DynamicPivotBlockManager dynamicPivotBlockManager = mock(DynamicPivotBlockManager.class);
doAnswer(

Loading…
Cancel
Save