@Override
  protected int doPersist(
      final WorldStateStorageCoordinator worldStateStorageCoordinator,
      final WorldStateKeyValueStorage.Updater updater,
      final SnapWorldDownloadState downloadState,
      final SnapSyncProcessState snapSyncState,
      final SnapSyncConfiguration syncConfig) {

    if (!isProofValid) { // if proof is not valid we need to fix the flat database

      final BonsaiWorldStateKeyValueStorage.Updater bonsaiUpdater =
          (BonsaiWorldStateKeyValueStorage.Updater) updater;

      final MerkleTrie<Bytes, Bytes> accountTrie =
          new StoredMerklePatriciaTrie<>(
              worldStateStorageCoordinator::getAccountStateTrieNode,
              getRootHash(),
              Function.identity(),
              Function.identity());

      // retrieve the data from the trie in order to know what to fix in the flat database
      final RangeStorageEntriesCollector collector =
          RangeStorageEntriesCollector.createCollector(
              startKeyHash,
              existingAccounts.isEmpty() ? endKeyHash : existingAccounts.lastKey(),
              existingAccounts.isEmpty()
                  ? syncConfig.getLocalFlatAccountCountToHealPerRequest()
                  : Integer.MAX_VALUE,
              Integer.MAX_VALUE);

      // put all flat accounts in the list, and gradually keep only those that are not in the trie
      // to remove and heal them.
      flatDbAccounts = new TreeMap<>(existingAccounts);

      final TrieIterator<Bytes> visitor = RangeStorageEntriesCollector.createVisitor(collector);
      existingAccounts =
          (TreeMap<Bytes32, Bytes>)
              accountTrie.entriesFrom(
                  root ->
                      RangeStorageEntriesCollector.collectEntries(
                          collector, visitor, root, startKeyHash));

      // Process each existing account
      existingAccounts.forEach(
          (key, value) -> {
            // Remove the key from the flat db list and get its associated value
            Bytes flatDbEntry = flatDbAccounts.remove(key);
            // If the key was in flat db and its associated value is different from the
            // current value
            if (!value.equals(flatDbEntry)) {
              Hash accountHash = Hash.wrap(key);
              // Add the account to the list of accounts to be repaired
              downloadState.addAccountToHealingList(CompactEncoding.bytesToPath(accountHash));
              // Update the account info state
              bonsaiUpdater.putAccountInfoState(accountHash, value);
            }
          });

      // For each remaining account in flat db list, remove the account info state and add it to
      // the list of accounts to be repaired
      flatDbAccounts
          .keySet()
          .forEach(
              key -> {
                Hash accountHash = Hash.wrap(key);
                downloadState.addAccountToHealingList(CompactEncoding.bytesToPath(accountHash));
                bonsaiUpdater.removeAccountInfoState(accountHash);
              });
    }
    return existingAccounts.size() + flatDbAccounts.size();
  }
The AccountFlatDatabaseHealingRangeRequest class represents a request to heal a range of account
in the flat databases. It encapsulates the necessary information to identify the range and
initiate the healing process.
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/request/heal/AccountFlatDatabaseHealingRangeRequest.java