Fix fastsync with bonsai (#2372)

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
pull/2463/head
matkt 3 years ago committed by GitHub
parent 23f50e81ef
commit 012eff06c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorage.java
  2. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStateKeyValueStorage.java
  3. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateStorage.java
  4. 5
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactory.java

@ -140,6 +140,15 @@ public class BonsaiWorldStateKeyValueStorage implements WorldStateStorage {
|| trieLogStorage.containsKey(blockHash.toArrayUnsafe()); || trieLogStorage.containsKey(blockHash.toArrayUnsafe());
} }
@Override
public void clear() {
accountStorage.clear();
codeStorage.clear();
storageStorage.clear();
trieBranchStorage.clear();
trieLogStorage.clear();
}
@Override @Override
public Updater updater() { public Updater updater() {
return new Updater( return new Updater(

@ -92,6 +92,11 @@ public class WorldStateKeyValueStorage implements WorldStateStorage {
return getAccountStateTrieNode(Bytes.EMPTY, rootHash).isPresent(); return getAccountStateTrieNode(Bytes.EMPTY, rootHash).isPresent();
} }
@Override
public void clear() {
keyValueStorage.clear();
}
@Override @Override
public Updater updater() { public Updater updater() {
return new Updater(lock, keyValueStorage.startTransaction(), nodeAddedListeners); return new Updater(lock, keyValueStorage.startTransaction(), nodeAddedListeners);

@ -42,6 +42,8 @@ public interface WorldStateStorage {
return getNodeData(null, hash).isPresent(); return getNodeData(null, hash).isPresent();
} }
void clear();
Updater updater(); Updater updater();
long prune(Predicate<byte[]> inUseCheck); long prune(Predicate<byte[]> inUseCheck);

@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.eth.sync.fastsync; package org.hyperledger.besu.ethereum.eth.sync.fastsync;
import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.bonsai.BonsaiPersistedWorldState;
import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
@ -79,7 +80,9 @@ public class FastDownloaderFactory {
"Fast sync was requested, but cannot be enabled because the local blockchain is not empty."); "Fast sync was requested, but cannot be enabled because the local blockchain is not empty.");
return Optional.empty(); return Optional.empty();
} }
if (worldStateStorage instanceof BonsaiPersistedWorldState) {
worldStateStorage.clear();
}
final CachingTaskCollection<NodeDataRequest> taskCollection = final CachingTaskCollection<NodeDataRequest> taskCollection =
createWorldStateDownloaderTaskCollection( createWorldStateDownloaderTaskCollection(
getStateQueueDirectory(dataDirectory), getStateQueueDirectory(dataDirectory),

Loading…
Cancel
Save