Search in sources :

Example 1 with FastWorldStateDownloader

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

the class FastDownloaderFactory method create.

public static Optional<FastSyncDownloader> create(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 (syncConfig.getSyncMode() != SyncMode.FAST) {
        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.clear();
    } 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 fastSyncDownloader = new FastSyncDownloader(new FastSyncActions(syncConfig, protocolSchedule, protocolContext, ethContext, syncState, metricsSystem), worldStateStorage, worldStateDownloader, fastSyncStateStorage, taskCollection, fastSyncDataDirectory, fastSyncState);
    syncState.setWorldStateDownloadStatus(worldStateDownloader);
    return Optional.of(fastSyncDownloader);
}
Also used : Path(java.nio.file.Path) FastWorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate.FastWorldStateDownloader) BonsaiWorldStateKeyValueStorage(org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage) NodeDataRequest(org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate.NodeDataRequest) FastWorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate.FastWorldStateDownloader) WorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader)

Example 2 with FastWorldStateDownloader

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

the class WorldStateDownloaderBenchmark method setUpUnchangedState.

@Setup(Level.Invocation)
public void setUpUnchangedState() {
    final SynchronizerConfiguration syncConfig = new SynchronizerConfiguration.Builder().worldStateHashCountPerRequest(200).build();
    final Hash stateRoot = createExistingWorldState();
    blockHeader = new BlockHeaderTestFixture().stateRoot(stateRoot).buildHeader();
    tempDir = Files.createTempDir().toPath();
    ethProtocolManager = EthProtocolManagerTestUtil.create(new EthScheduler(syncConfig.getDownloaderParallelism(), syncConfig.getTransactionsParallelism(), syncConfig.getComputationParallelism(), metricsSystem));
    peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockHeader.getNumber());
    final EthContext ethContext = ethProtocolManager.ethContext();
    final StorageProvider storageProvider = createKeyValueStorageProvider(tempDir, tempDir.resolve("database"));
    worldStateStorage = storageProvider.createWorldStateStorage(DataStorageFormat.FOREST);
    pendingRequests = new InMemoryTasksPriorityQueues<>();
    worldStateDownloader = new FastWorldStateDownloader(ethContext, worldStateStorage, pendingRequests, syncConfig.getWorldStateHashCountPerRequest(), syncConfig.getWorldStateRequestParallelism(), syncConfig.getWorldStateMaxRequestsWithoutProgress(), syncConfig.getWorldStateMinMillisBeforeStalling(), Clock.fixed(Instant.ofEpochSecond(1000), ZoneOffset.UTC), metricsSystem);
}
Also used : EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) FastWorldStateDownloader(org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate.FastWorldStateDownloader) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) KeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder) SynchronizerConfiguration(org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration) Hash(org.hyperledger.besu.datatypes.Hash) StorageProvider(org.hyperledger.besu.ethereum.storage.StorageProvider) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

FastWorldStateDownloader (org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate.FastWorldStateDownloader)2 Path (java.nio.file.Path)1 Hash (org.hyperledger.besu.datatypes.Hash)1 BonsaiWorldStateKeyValueStorage (org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage)1 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)1 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)1 EthScheduler (org.hyperledger.besu.ethereum.eth.manager.EthScheduler)1 SynchronizerConfiguration (org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration)1 NodeDataRequest (org.hyperledger.besu.ethereum.eth.sync.fastsync.worldstate.NodeDataRequest)1 WorldStateDownloader (org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader)1 StorageProvider (org.hyperledger.besu.ethereum.storage.StorageProvider)1 KeyValueStorageProviderBuilder (org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder)1 Setup (org.openjdk.jmh.annotations.Setup)1