diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorage.java index ddb25b7780..40088373ad 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateKeyValueStorage.java @@ -140,6 +140,15 @@ public class BonsaiWorldStateKeyValueStorage implements WorldStateStorage { || trieLogStorage.containsKey(blockHash.toArrayUnsafe()); } + @Override + public void clear() { + accountStorage.clear(); + codeStorage.clear(); + storageStorage.clear(); + trieBranchStorage.clear(); + trieLogStorage.clear(); + } + @Override public Updater updater() { return new Updater( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStateKeyValueStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStateKeyValueStorage.java index e59baa7efe..e424376ce8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStateKeyValueStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStateKeyValueStorage.java @@ -92,6 +92,11 @@ public class WorldStateKeyValueStorage implements WorldStateStorage { return getAccountStateTrieNode(Bytes.EMPTY, rootHash).isPresent(); } + @Override + public void clear() { + keyValueStorage.clear(); + } + @Override public Updater updater() { return new Updater(lock, keyValueStorage.startTransaction(), nodeAddedListeners); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateStorage.java index eb5ceaf9a5..a5594b4b92 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/WorldStateStorage.java @@ -42,6 +42,8 @@ public interface WorldStateStorage { return getNodeData(null, hash).isPresent(); } + void clear(); + Updater updater(); long prune(Predicate inUseCheck); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactory.java index 7a81f2fac1..4f22064c2c 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactory.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.eth.sync.fastsync; 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.eth.manager.EthContext; 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."); return Optional.empty(); } - + if (worldStateStorage instanceof BonsaiPersistedWorldState) { + worldStateStorage.clear(); + } final CachingTaskCollection taskCollection = createWorldStateDownloaderTaskCollection( getStateQueueDirectory(dataDirectory),