Search in sources :

Example 1 with FastSyncStateStorage

use of org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncStateStorage in project besu by hyperledger.

the class CheckpointDownloaderFactory method createCheckpointDownloader.

public static Optional<FastSyncDownloader<?>> createCheckpointDownloader(final PivotBlockSelector pivotBlockSelector, final SynchronizerConfiguration syncConfig, final Path dataDirectory, final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, final WorldStateStorage worldStateStorage, final SyncState syncState, final Clock clock) {
    final Path fastSyncDataDirectory = dataDirectory.resolve(FAST_SYNC_FOLDER);
    final FastSyncStateStorage fastSyncStateStorage = new FastSyncStateStorage(fastSyncDataDirectory);
    if (SyncMode.isFullSync(syncConfig.getSyncMode())) {
        if (fastSyncStateStorage.isFastSyncInProgress()) {
            throw new IllegalStateException("Unable to change the sync mode when snap sync is incomplete, please restart with checkpoint sync mode");
        } else {
            return Optional.empty();
        }
    }
    ensureDirectoryExists(fastSyncDataDirectory.toFile());
    final FastSyncState fastSyncState = fastSyncStateStorage.loadState(ScheduleBasedBlockHeaderFunctions.create(protocolSchedule));
    if (fastSyncState.getPivotBlockHeader().isEmpty() && protocolContext.getBlockchain().getChainHeadBlockNumber() != BlockHeader.GENESIS_BLOCK_NUMBER) {
        LOG.info("Checkpoint sync was requested, but cannot be enabled because the local blockchain is not empty.");
        return Optional.empty();
    }
    final FastSyncActions fastSyncActions;
    if (syncState.getCheckpoint().isEmpty()) {
        LOG.warn("Unable to find a valid checkpoint configuration. The genesis will be used");
        fastSyncActions = new FastSyncActions(syncConfig, worldStateStorage, protocolSchedule, protocolContext, ethContext, syncState, pivotBlockSelector, metricsSystem);
    } else {
        LOG.info("Checkpoint sync start with block {} and hash {}", syncState.getCheckpoint().get().blockNumber(), syncState.getCheckpoint().get().blockHash());
        fastSyncActions = new CheckpointSyncActions(syncConfig, worldStateStorage, protocolSchedule, protocolContext, ethContext, syncState, pivotBlockSelector, metricsSystem);
    }
    final SnapSyncState snapSyncState = new SnapSyncState(fastSyncStateStorage.loadState(ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)));
    worldStateStorage.clear();
    final InMemoryTasksPriorityQueues<SnapDataRequest> snapTaskCollection = createSnapWorldStateDownloaderTaskCollection();
    final WorldStateDownloader snapWorldStateDownloader = new SnapWorldStateDownloader(ethContext, worldStateStorage, snapTaskCollection, syncConfig.getSnapSyncConfiguration(), syncConfig.getWorldStateRequestParallelism(), syncConfig.getWorldStateMaxRequestsWithoutProgress(), syncConfig.getWorldStateMinMillisBeforeStalling(), clock, metricsSystem);
    final FastSyncDownloader<SnapDataRequest> fastSyncDownloader = new SnapSyncDownloader(fastSyncActions, worldStateStorage, snapWorldStateDownloader, fastSyncStateStorage, snapTaskCollection, fastSyncDataDirectory, snapSyncState);
    syncState.setWorldStateDownloadStatus(snapWorldStateDownloader);
    return Optional.of(fastSyncDownloader);
}
Also used : Path(java.nio.file.Path) SnapDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest) SnapWorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldStateDownloader) WorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader) FastSyncState(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState) SnapSyncState(org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncState) FastSyncActions(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncActions) FastSyncStateStorage(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncStateStorage) SnapSyncDownloader(org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncDownloader) SnapWorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldStateDownloader)

Example 2 with FastSyncStateStorage

use of org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncStateStorage in project besu by hyperledger.

the class SnapDownloaderFactory method createSnapDownloader.

public static Optional<FastSyncDownloader<?>> createSnapDownloader(final PivotBlockSelector pivotBlockSelector, final SynchronizerConfiguration syncConfig, final Path dataDirectory, final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, final WorldStateStorage worldStateStorage, final SyncState syncState, final Clock clock) {
    final Path fastSyncDataDirectory = dataDirectory.resolve(FAST_SYNC_FOLDER);
    final FastSyncStateStorage fastSyncStateStorage = new FastSyncStateStorage(fastSyncDataDirectory);
    if (SyncMode.isFullSync(syncConfig.getSyncMode())) {
        if (fastSyncStateStorage.isFastSyncInProgress()) {
            throw new IllegalStateException("Unable to change the sync mode when snap sync is incomplete, please restart with snap sync mode");
        } else {
            return Optional.empty();
        }
    }
    ensureDirectoryExists(fastSyncDataDirectory.toFile());
    final FastSyncState fastSyncState = fastSyncStateStorage.loadState(ScheduleBasedBlockHeaderFunctions.create(protocolSchedule));
    if (fastSyncState.getPivotBlockHeader().isEmpty() && protocolContext.getBlockchain().getChainHeadBlockNumber() != BlockHeader.GENESIS_BLOCK_NUMBER) {
        LOG.info("Snap sync was requested, but cannot be enabled because the local blockchain is not empty.");
        return Optional.empty();
    }
    final SnapSyncState snapSyncState = new SnapSyncState(fastSyncStateStorage.loadState(ScheduleBasedBlockHeaderFunctions.create(protocolSchedule)));
    worldStateStorage.clear();
    final InMemoryTasksPriorityQueues<SnapDataRequest> snapTaskCollection = createSnapWorldStateDownloaderTaskCollection();
    final WorldStateDownloader snapWorldStateDownloader = new SnapWorldStateDownloader(ethContext, worldStateStorage, snapTaskCollection, syncConfig.getSnapSyncConfiguration(), syncConfig.getWorldStateRequestParallelism(), syncConfig.getWorldStateMaxRequestsWithoutProgress(), syncConfig.getWorldStateMinMillisBeforeStalling(), clock, metricsSystem);
    final FastSyncDownloader<SnapDataRequest> fastSyncDownloader = new SnapSyncDownloader(new FastSyncActions(syncConfig, worldStateStorage, protocolSchedule, protocolContext, ethContext, syncState, pivotBlockSelector, metricsSystem), worldStateStorage, snapWorldStateDownloader, fastSyncStateStorage, snapTaskCollection, fastSyncDataDirectory, snapSyncState);
    syncState.setWorldStateDownloadStatus(snapWorldStateDownloader);
    return Optional.of(fastSyncDownloader);
}
Also used : Path(java.nio.file.Path) FastSyncState(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState) FastSyncActions(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncActions) SnapDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest) FastSyncStateStorage(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncStateStorage) WorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader)

Example 3 with FastSyncStateStorage

use of org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncStateStorage in project besu by hyperledger.

the class FastDownloaderFactory method create.

public static Optional<FastSyncDownloader<?>> create(final PivotBlockSelector pivotBlockSelector, final SynchronizerConfiguration syncConfig, final Path dataDirectory, final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, final WorldStateStorage worldStateStorage, final SyncState syncState, final Clock clock) {
    final Path fastSyncDataDirectory = dataDirectory.resolve(FAST_SYNC_FOLDER);
    final FastSyncStateStorage fastSyncStateStorage = new FastSyncStateStorage(fastSyncDataDirectory);
    if (SyncMode.isFullSync(syncConfig.getSyncMode())) {
        if (fastSyncStateStorage.isFastSyncInProgress()) {
            throw new IllegalStateException("Unable to change the sync mode when fast sync is incomplete, please restart with fast sync mode");
        } else {
            return Optional.empty();
        }
    }
    ensureDirectoryExists(fastSyncDataDirectory.toFile());
    final FastSyncState fastSyncState = fastSyncStateStorage.loadState(ScheduleBasedBlockHeaderFunctions.create(protocolSchedule));
    if (fastSyncState.getPivotBlockHeader().isEmpty() && protocolContext.getBlockchain().getChainHeadBlockNumber() != BlockHeader.GENESIS_BLOCK_NUMBER) {
        LOG.info("Fast sync was requested, but cannot be enabled because the local blockchain is not empty.");
        return Optional.empty();
    }
    if (worldStateStorage instanceof BonsaiWorldStateKeyValueStorage) {
        worldStateStorage.clearFlatDatabase();
    } else {
        final Path queueDataDir = fastSyncDataDirectory.resolve("statequeue");
        if (queueDataDir.toFile().exists()) {
            LOG.warn("Fast sync is picking up after old fast sync version. Pruning the world state and starting from scratch.");
            clearOldFastSyncWorldStateData(worldStateStorage, queueDataDir);
        }
    }
    final InMemoryTasksPriorityQueues<NodeDataRequest> taskCollection = createWorldStateDownloaderTaskCollection(metricsSystem, syncConfig.getWorldStateTaskCacheSize());
    final WorldStateDownloader worldStateDownloader = new FastWorldStateDownloader(ethContext, worldStateStorage, taskCollection, syncConfig.getWorldStateHashCountPerRequest(), syncConfig.getWorldStateRequestParallelism(), syncConfig.getWorldStateMaxRequestsWithoutProgress(), syncConfig.getWorldStateMinMillisBeforeStalling(), clock, metricsSystem);
    final FastSyncDownloader<NodeDataRequest> fastSyncDownloader = new FastSyncDownloader<>(new FastSyncActions(syncConfig, worldStateStorage, protocolSchedule, protocolContext, ethContext, syncState, pivotBlockSelector, metricsSystem), worldStateStorage, worldStateDownloader, fastSyncStateStorage, taskCollection, fastSyncDataDirectory, fastSyncState);
    syncState.setWorldStateDownloadStatus(worldStateDownloader);
    return Optional.of(fastSyncDownloader);
}
Also used : Path(java.nio.file.Path) FastSyncState(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState) FastSyncDownloader(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncDownloader) FastSyncActions(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncActions) BonsaiWorldStateKeyValueStorage(org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage) FastSyncStateStorage(org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncStateStorage) WorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader)

Aggregations

Path (java.nio.file.Path)3 FastSyncActions (org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncActions)3 FastSyncState (org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState)3 FastSyncStateStorage (org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncStateStorage)3 WorldStateDownloader (org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader)3 SnapDataRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest)2 BonsaiWorldStateKeyValueStorage (org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage)1 FastSyncDownloader (org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncDownloader)1 SnapSyncDownloader (org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncDownloader)1 SnapSyncState (org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapSyncState)1 SnapWorldStateDownloader (org.hyperledger.besu.ethereum.eth.sync.snapsync.SnapWorldStateDownloader)1