id
stringlengths
7
14
text
stringlengths
1
106k
206414745_1442
public boolean addRemoteTransaction(final Transaction transaction) { final TransactionInfo transactionInfo = new TransactionInfo(transaction, false, clock.instant()); final TransactionAddedStatus transactionAddedStatus = addTransaction(transactionInfo); final boolean added = transactionAddedStatus.equals(ADDED); if (added) { remoteTransactionAddedCounter.inc(); } return added; }
206414745_1443
public OptionalLong getNextNonceForSender(final Address sender) { final TransactionsForSenderInfo transactionsForSenderInfo = transactionsBySender.get(sender); if (transactionsForSenderInfo == null || transactionsForSenderInfo.getTransactionsInfos().isEmpty()) { return OptionalLong.empty(); } else { final OptionalLong maybeNextGap = transactionsForSenderInfo.maybeNextGap(); return maybeNextGap.isEmpty() ? OptionalLong.of(transactionsForSenderInfo.getTransactionsInfos().lastKey() + 1) : maybeNextGap; } }
206414745_1444
@Override public void accept(final Block block) { final long blockNumber = block.getHeader().getNumber(); final String blockHash = block.getHash().toHexString(); final String shortHash = String.format( "%s..%s", blockHash.substring(0, 6), blockHash.substring(blockHash.length() - 4, blockHash.length())); final BlockImporter importer = protocolSchedule.getByBlockNumber(blockNumber).getBlockImporter(); if (!importer.importBlock(protocolContext, block, HeaderValidationMode.SKIP_DETACHED)) { throw new InvalidBlockException("Failed to import block", blockNumber, block.getHash()); } int peerCount = -1; // ethContext is not available in tests if (ethContext != null && ethContext.getEthPeers().peerCount() >= 0) { peerCount = ethContext.getEthPeers().peerCount(); } if (blockNumber % 200 == 0) { LOG.info("Import reached block {} ({}), Peers: {}", blockNumber, shortHash, peerCount); } }
206414745_1445
@Override public void accept(final Block block) { final long blockNumber = block.getHeader().getNumber(); final String blockHash = block.getHash().toHexString(); final String shortHash = String.format( "%s..%s", blockHash.substring(0, 6), blockHash.substring(blockHash.length() - 4, blockHash.length())); final BlockImporter importer = protocolSchedule.getByBlockNumber(blockNumber).getBlockImporter(); if (!importer.importBlock(protocolContext, block, HeaderValidationMode.SKIP_DETACHED)) { throw new InvalidBlockException("Failed to import block", blockNumber, block.getHash()); } int peerCount = -1; // ethContext is not available in tests if (ethContext != null && ethContext.getEthPeers().peerCount() >= 0) { peerCount = ethContext.getEthPeers().peerCount(); } if (blockNumber % 200 == 0) { LOG.info("Import reached block {} ({}), Peers: {}", blockNumber, shortHash, peerCount); } }
206414745_1446
public TrailingPeerRequirements calculateTrailingPeerRequirements() { return syncState.isInSync() ? TrailingPeerRequirements.UNRESTRICTED : new TrailingPeerRequirements( protocolContext.getBlockchain().getChainHeadBlockNumber(), syncConfig.getMaxTrailingPeers()); }
206414745_1447
public TrailingPeerRequirements calculateTrailingPeerRequirements() { return syncState.isInSync() ? TrailingPeerRequirements.UNRESTRICTED : new TrailingPeerRequirements( protocolContext.getBlockchain().getChainHeadBlockNumber(), syncConfig.getMaxTrailingPeers()); }
206414745_1448
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1449
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1450
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1451
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1452
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1453
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1454
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1455
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1456
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1457
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1458
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1459
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1460
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1461
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1462
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1463
public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { final ChainState currentPeerChainState = currentSyncTarget.chainState(); final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer(); return maybeBestPeer .map( bestPeer -> { if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) { // Our current target is better or equal to the best peer return false; } // Require some threshold to be exceeded before switching targets to keep some // stability when multiple peers are in range of each other final ChainState bestPeerChainState = bestPeer.chainState(); final Difficulty tdDifference = bestPeerChainState .getEstimatedTotalDifficulty() .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty()); if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); }
206414745_1464
@Override public void onPeerConnected(final EthPeer peer) { LOG.debug("Requesting chain head info for {}", peer); GetHeadersFromPeerByHashTask.forSingleHash( protocolSchedule, ethContext, Hash.wrap(peer.chainState().getBestBlock().getHash()), 0, metricsSystem) .assignPeer(peer) .run() .whenComplete( (peerResult, error) -> { if (peerResult != null && !peerResult.getResult().isEmpty()) { final BlockHeader chainHeadHeader = peerResult.getResult().get(0); peer.chainState().update(chainHeadHeader); trailingPeerLimiter.enforceTrailingPeerLimit(); } else { LOG.debug( "Failed to retrieve chain head information. Disconnecting " + peer, error); peer.disconnect(DisconnectReason.USELESS_PEER); } }); }
206414745_1465
@Override public void onPeerConnected(final EthPeer peer) { LOG.debug("Requesting chain head info for {}", peer); GetHeadersFromPeerByHashTask.forSingleHash( protocolSchedule, ethContext, Hash.wrap(peer.chainState().getBestBlock().getHash()), 0, metricsSystem) .assignPeer(peer) .run() .whenComplete( (peerResult, error) -> { if (peerResult != null && !peerResult.getResult().isEmpty()) { final BlockHeader chainHeadHeader = peerResult.getResult().get(0); peer.chainState().update(chainHeadHeader); trailingPeerLimiter.enforceTrailingPeerLimit(); } else { LOG.debug( "Failed to retrieve chain head information. Disconnecting " + peer, error); peer.disconnect(DisconnectReason.USELESS_PEER); } }); }
206414745_1466
@Override public void onPeerConnected(final EthPeer peer) { LOG.debug("Requesting chain head info for {}", peer); GetHeadersFromPeerByHashTask.forSingleHash( protocolSchedule, ethContext, Hash.wrap(peer.chainState().getBestBlock().getHash()), 0, metricsSystem) .assignPeer(peer) .run() .whenComplete( (peerResult, error) -> { if (peerResult != null && !peerResult.getResult().isEmpty()) { final BlockHeader chainHeadHeader = peerResult.getResult().get(0); peer.chainState().update(chainHeadHeader); trailingPeerLimiter.enforceTrailingPeerLimit(); } else { LOG.debug( "Failed to retrieve chain head information. Disconnecting " + peer, error); peer.disconnect(DisconnectReason.USELESS_PEER); } }); }
206414745_1467
public void propagate(final Block block, final Difficulty totalDifficulty) { blockPropagatedSubscribers.forEach(listener -> listener.accept(block, totalDifficulty)); final NewBlockMessage newBlockMessage = NewBlockMessage.create(block, totalDifficulty); ethContext .getEthPeers() .streamAvailablePeers() .filter(ethPeer -> !ethPeer.hasSeenBlock(block.getHash())) .forEach( ethPeer -> { ethPeer.registerKnownBlock(block.getHash()); try { ethPeer.send(newBlockMessage); } catch (final PeerConnection.PeerNotConnected e) { LOG.trace("Failed to broadcast new block to peer", e); } }); }
206414745_1468
public void propagate(final Block block, final Difficulty totalDifficulty) { blockPropagatedSubscribers.forEach(listener -> listener.accept(block, totalDifficulty)); final NewBlockMessage newBlockMessage = NewBlockMessage.create(block, totalDifficulty); ethContext .getEthPeers() .streamAvailablePeers() .filter(ethPeer -> !ethPeer.hasSeenBlock(block.getHash())) .forEach( ethPeer -> { ethPeer.registerKnownBlock(block.getHash()); try { ethPeer.send(newBlockMessage); } catch (final PeerConnection.PeerNotConnected e) { LOG.trace("Failed to broadcast new block to peer", e); } }); }
206414745_1469
public boolean registerPendingBlock(final Block pendingBlock) { final Block previousValue = this.pendingBlocks.putIfAbsent(pendingBlock.getHash(), pendingBlock); if (previousValue != null) { return false; } pendingBlocksByParentHash .computeIfAbsent( pendingBlock.getHeader().getParentHash(), h -> { final Set<Hash> set = newSetFromMap(new ConcurrentHashMap<>()); // Go ahead and add our value at construction, so that we don't set an empty set which // could be removed in deregisterPendingBlock set.add(pendingBlock.getHash()); return set; }) .add(pendingBlock.getHash()); return true; }
206414745_1470
public boolean deregisterPendingBlock(final Block block) { final Hash parentHash = block.getHeader().getParentHash(); final Block removed = pendingBlocks.remove(block.getHash()); final Set<Hash> blocksForParent = pendingBlocksByParentHash.get(parentHash); if (blocksForParent != null) { blocksForParent.remove(block.getHash()); pendingBlocksByParentHash.remove(parentHash, Collections.emptySet()); } return removed != null; }
206414745_1471
public boolean isInSync() { return isInSync(Synchronizer.DEFAULT_IN_SYNC_TOLERANCE); }
206414745_1472
public boolean isInSync() { return isInSync(Synchronizer.DEFAULT_IN_SYNC_TOLERANCE); }
206414745_1473
public boolean isInSync() { return isInSync(Synchronizer.DEFAULT_IN_SYNC_TOLERANCE); }
206414745_1474
public void clearSyncTarget() { replaceSyncTarget(Optional.empty()); }
206414745_1475
public boolean isInSync() { return isInSync(Synchronizer.DEFAULT_IN_SYNC_TOLERANCE); }
206414745_1476
public long subscribeInSync(final InSyncListener listener) { return subscribeInSync(listener, Synchronizer.DEFAULT_IN_SYNC_TOLERANCE); }
206414745_1477
public long subscribeInSync(final InSyncListener listener) { return subscribeInSync(listener, Synchronizer.DEFAULT_IN_SYNC_TOLERANCE); }
206414745_1478
public long subscribeInSync(final InSyncListener listener) { return subscribeInSync(listener, Synchronizer.DEFAULT_IN_SYNC_TOLERANCE); }
206414745_1479
public long subscribeInSync(final InSyncListener listener) { return subscribeInSync(listener, Synchronizer.DEFAULT_IN_SYNC_TOLERANCE); }
206414745_1480
public void setSyncTarget(final EthPeer peer, final BlockHeader commonAncestor) { final SyncTarget syncTarget = new SyncTarget(peer, commonAncestor); replaceSyncTarget(Optional.of(syncTarget)); }
206414745_1481
public void markAsCompleteOrFailed( final BlockHeader header, final WorldDownloadState downloadState, final Task<NodeDataRequest> task) { if (task.getData().getData() != null) { enqueueChildren(task, header, downloadState); completedRequestsCounter.inc(); task.markCompleted(); downloadState.checkCompletion(worldStateStorage, header); } else { retriedRequestsCounter.inc(); task.markFailed(); // Marking the task as failed will add it back to the queue so make sure any threads // waiting to read from the queue are notified. downloadState.notifyTaskAvailable(); } }
206414745_1482
public void markAsCompleteOrFailed( final BlockHeader header, final WorldDownloadState downloadState, final Task<NodeDataRequest> task) { if (task.getData().getData() != null) { enqueueChildren(task, header, downloadState); completedRequestsCounter.inc(); task.markCompleted(); downloadState.checkCompletion(worldStateStorage, header); } else { retriedRequestsCounter.inc(); task.markFailed(); // Marking the task as failed will add it back to the queue so make sure any threads // waiting to read from the queue are notified. downloadState.notifyTaskAvailable(); } }
206414745_1483
public CompletableFuture<Void> run(final BlockHeader header) { synchronized (this) { final WorldDownloadState oldDownloadState = this.downloadState.get(); if (oldDownloadState != null && oldDownloadState.isDownloading()) { final CompletableFuture<Void> failed = new CompletableFuture<>(); failed.completeExceptionally( new IllegalStateException( "Cannot run an already running " + this.getClass().getSimpleName())); return failed; } final Hash stateRoot = header.getStateRoot(); if (worldStateStorage.isWorldStateAvailable(stateRoot)) { LOG.info( "World state already available for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); return CompletableFuture.completedFuture(null); } LOG.info( "Begin downloading world state from peers for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); final WorldDownloadState newDownloadState = new WorldDownloadState( taskCollection, maxNodeRequestsWithoutProgress, minMillisBeforeStalling, clock); this.downloadState.set(newDownloadState); if (!newDownloadState.downloadWasResumed()) { // Only queue the root node if we're starting a new download from scratch newDownloadState.enqueueRequest(NodeDataRequest.createAccountDataRequest(stateRoot)); } maybeCompleteTask = Optional.of(new CompleteTaskStep(worldStateStorage, metricsSystem, taskCollection::size)); final WorldStateDownloadProcess downloadProcess = WorldStateDownloadProcess.builder() .hashCountPerRequest(hashCountPerRequest) .maxOutstandingRequests(maxOutstandingRequests) .loadLocalDataStep(new LoadLocalDataStep(worldStateStorage, metricsSystem)) .requestDataStep(new RequestDataStep(ethContext, metricsSystem)) .persistDataStep(new PersistDataStep(worldStateStorage)) .completeTaskStep(maybeCompleteTask.get()) .downloadState(newDownloadState) .pivotBlockHeader(header) .metricsSystem(metricsSystem) .build(); newDownloadState.setWorldStateDownloadProcess(downloadProcess); return newDownloadState.startDownload(downloadProcess, ethContext.getScheduler()); } }
206414745_1484
public CompletableFuture<Void> run(final BlockHeader header) { synchronized (this) { final WorldDownloadState oldDownloadState = this.downloadState.get(); if (oldDownloadState != null && oldDownloadState.isDownloading()) { final CompletableFuture<Void> failed = new CompletableFuture<>(); failed.completeExceptionally( new IllegalStateException( "Cannot run an already running " + this.getClass().getSimpleName())); return failed; } final Hash stateRoot = header.getStateRoot(); if (worldStateStorage.isWorldStateAvailable(stateRoot)) { LOG.info( "World state already available for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); return CompletableFuture.completedFuture(null); } LOG.info( "Begin downloading world state from peers for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); final WorldDownloadState newDownloadState = new WorldDownloadState( taskCollection, maxNodeRequestsWithoutProgress, minMillisBeforeStalling, clock); this.downloadState.set(newDownloadState); if (!newDownloadState.downloadWasResumed()) { // Only queue the root node if we're starting a new download from scratch newDownloadState.enqueueRequest(NodeDataRequest.createAccountDataRequest(stateRoot)); } maybeCompleteTask = Optional.of(new CompleteTaskStep(worldStateStorage, metricsSystem, taskCollection::size)); final WorldStateDownloadProcess downloadProcess = WorldStateDownloadProcess.builder() .hashCountPerRequest(hashCountPerRequest) .maxOutstandingRequests(maxOutstandingRequests) .loadLocalDataStep(new LoadLocalDataStep(worldStateStorage, metricsSystem)) .requestDataStep(new RequestDataStep(ethContext, metricsSystem)) .persistDataStep(new PersistDataStep(worldStateStorage)) .completeTaskStep(maybeCompleteTask.get()) .downloadState(newDownloadState) .pivotBlockHeader(header) .metricsSystem(metricsSystem) .build(); newDownloadState.setWorldStateDownloadProcess(downloadProcess); return newDownloadState.startDownload(downloadProcess, ethContext.getScheduler()); } }
206414745_1485
public CompletableFuture<Void> run(final BlockHeader header) { synchronized (this) { final WorldDownloadState oldDownloadState = this.downloadState.get(); if (oldDownloadState != null && oldDownloadState.isDownloading()) { final CompletableFuture<Void> failed = new CompletableFuture<>(); failed.completeExceptionally( new IllegalStateException( "Cannot run an already running " + this.getClass().getSimpleName())); return failed; } final Hash stateRoot = header.getStateRoot(); if (worldStateStorage.isWorldStateAvailable(stateRoot)) { LOG.info( "World state already available for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); return CompletableFuture.completedFuture(null); } LOG.info( "Begin downloading world state from peers for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); final WorldDownloadState newDownloadState = new WorldDownloadState( taskCollection, maxNodeRequestsWithoutProgress, minMillisBeforeStalling, clock); this.downloadState.set(newDownloadState); if (!newDownloadState.downloadWasResumed()) { // Only queue the root node if we're starting a new download from scratch newDownloadState.enqueueRequest(NodeDataRequest.createAccountDataRequest(stateRoot)); } maybeCompleteTask = Optional.of(new CompleteTaskStep(worldStateStorage, metricsSystem, taskCollection::size)); final WorldStateDownloadProcess downloadProcess = WorldStateDownloadProcess.builder() .hashCountPerRequest(hashCountPerRequest) .maxOutstandingRequests(maxOutstandingRequests) .loadLocalDataStep(new LoadLocalDataStep(worldStateStorage, metricsSystem)) .requestDataStep(new RequestDataStep(ethContext, metricsSystem)) .persistDataStep(new PersistDataStep(worldStateStorage)) .completeTaskStep(maybeCompleteTask.get()) .downloadState(newDownloadState) .pivotBlockHeader(header) .metricsSystem(metricsSystem) .build(); newDownloadState.setWorldStateDownloadProcess(downloadProcess); return newDownloadState.startDownload(downloadProcess, ethContext.getScheduler()); } }
206414745_1486
public CompletableFuture<Void> run(final BlockHeader header) { synchronized (this) { final WorldDownloadState oldDownloadState = this.downloadState.get(); if (oldDownloadState != null && oldDownloadState.isDownloading()) { final CompletableFuture<Void> failed = new CompletableFuture<>(); failed.completeExceptionally( new IllegalStateException( "Cannot run an already running " + this.getClass().getSimpleName())); return failed; } final Hash stateRoot = header.getStateRoot(); if (worldStateStorage.isWorldStateAvailable(stateRoot)) { LOG.info( "World state already available for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); return CompletableFuture.completedFuture(null); } LOG.info( "Begin downloading world state from peers for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); final WorldDownloadState newDownloadState = new WorldDownloadState( taskCollection, maxNodeRequestsWithoutProgress, minMillisBeforeStalling, clock); this.downloadState.set(newDownloadState); if (!newDownloadState.downloadWasResumed()) { // Only queue the root node if we're starting a new download from scratch newDownloadState.enqueueRequest(NodeDataRequest.createAccountDataRequest(stateRoot)); } maybeCompleteTask = Optional.of(new CompleteTaskStep(worldStateStorage, metricsSystem, taskCollection::size)); final WorldStateDownloadProcess downloadProcess = WorldStateDownloadProcess.builder() .hashCountPerRequest(hashCountPerRequest) .maxOutstandingRequests(maxOutstandingRequests) .loadLocalDataStep(new LoadLocalDataStep(worldStateStorage, metricsSystem)) .requestDataStep(new RequestDataStep(ethContext, metricsSystem)) .persistDataStep(new PersistDataStep(worldStateStorage)) .completeTaskStep(maybeCompleteTask.get()) .downloadState(newDownloadState) .pivotBlockHeader(header) .metricsSystem(metricsSystem) .build(); newDownloadState.setWorldStateDownloadProcess(downloadProcess); return newDownloadState.startDownload(downloadProcess, ethContext.getScheduler()); } }
206414745_1487
public CompletableFuture<Void> run(final BlockHeader header) { synchronized (this) { final WorldDownloadState oldDownloadState = this.downloadState.get(); if (oldDownloadState != null && oldDownloadState.isDownloading()) { final CompletableFuture<Void> failed = new CompletableFuture<>(); failed.completeExceptionally( new IllegalStateException( "Cannot run an already running " + this.getClass().getSimpleName())); return failed; } final Hash stateRoot = header.getStateRoot(); if (worldStateStorage.isWorldStateAvailable(stateRoot)) { LOG.info( "World state already available for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); return CompletableFuture.completedFuture(null); } LOG.info( "Begin downloading world state from peers for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); final WorldDownloadState newDownloadState = new WorldDownloadState( taskCollection, maxNodeRequestsWithoutProgress, minMillisBeforeStalling, clock); this.downloadState.set(newDownloadState); if (!newDownloadState.downloadWasResumed()) { // Only queue the root node if we're starting a new download from scratch newDownloadState.enqueueRequest(NodeDataRequest.createAccountDataRequest(stateRoot)); } maybeCompleteTask = Optional.of(new CompleteTaskStep(worldStateStorage, metricsSystem, taskCollection::size)); final WorldStateDownloadProcess downloadProcess = WorldStateDownloadProcess.builder() .hashCountPerRequest(hashCountPerRequest) .maxOutstandingRequests(maxOutstandingRequests) .loadLocalDataStep(new LoadLocalDataStep(worldStateStorage, metricsSystem)) .requestDataStep(new RequestDataStep(ethContext, metricsSystem)) .persistDataStep(new PersistDataStep(worldStateStorage)) .completeTaskStep(maybeCompleteTask.get()) .downloadState(newDownloadState) .pivotBlockHeader(header) .metricsSystem(metricsSystem) .build(); newDownloadState.setWorldStateDownloadProcess(downloadProcess); return newDownloadState.startDownload(downloadProcess, ethContext.getScheduler()); } }
206414745_1488
public CompletableFuture<Void> run(final BlockHeader header) { synchronized (this) { final WorldDownloadState oldDownloadState = this.downloadState.get(); if (oldDownloadState != null && oldDownloadState.isDownloading()) { final CompletableFuture<Void> failed = new CompletableFuture<>(); failed.completeExceptionally( new IllegalStateException( "Cannot run an already running " + this.getClass().getSimpleName())); return failed; } final Hash stateRoot = header.getStateRoot(); if (worldStateStorage.isWorldStateAvailable(stateRoot)) { LOG.info( "World state already available for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); return CompletableFuture.completedFuture(null); } LOG.info( "Begin downloading world state from peers for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); final WorldDownloadState newDownloadState = new WorldDownloadState( taskCollection, maxNodeRequestsWithoutProgress, minMillisBeforeStalling, clock); this.downloadState.set(newDownloadState); if (!newDownloadState.downloadWasResumed()) { // Only queue the root node if we're starting a new download from scratch newDownloadState.enqueueRequest(NodeDataRequest.createAccountDataRequest(stateRoot)); } maybeCompleteTask = Optional.of(new CompleteTaskStep(worldStateStorage, metricsSystem, taskCollection::size)); final WorldStateDownloadProcess downloadProcess = WorldStateDownloadProcess.builder() .hashCountPerRequest(hashCountPerRequest) .maxOutstandingRequests(maxOutstandingRequests) .loadLocalDataStep(new LoadLocalDataStep(worldStateStorage, metricsSystem)) .requestDataStep(new RequestDataStep(ethContext, metricsSystem)) .persistDataStep(new PersistDataStep(worldStateStorage)) .completeTaskStep(maybeCompleteTask.get()) .downloadState(newDownloadState) .pivotBlockHeader(header) .metricsSystem(metricsSystem) .build(); newDownloadState.setWorldStateDownloadProcess(downloadProcess); return newDownloadState.startDownload(downloadProcess, ethContext.getScheduler()); } }
206414745_1489
public CompletableFuture<Void> run(final BlockHeader header) { synchronized (this) { final WorldDownloadState oldDownloadState = this.downloadState.get(); if (oldDownloadState != null && oldDownloadState.isDownloading()) { final CompletableFuture<Void> failed = new CompletableFuture<>(); failed.completeExceptionally( new IllegalStateException( "Cannot run an already running " + this.getClass().getSimpleName())); return failed; } final Hash stateRoot = header.getStateRoot(); if (worldStateStorage.isWorldStateAvailable(stateRoot)) { LOG.info( "World state already available for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); return CompletableFuture.completedFuture(null); } LOG.info( "Begin downloading world state from peers for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); final WorldDownloadState newDownloadState = new WorldDownloadState( taskCollection, maxNodeRequestsWithoutProgress, minMillisBeforeStalling, clock); this.downloadState.set(newDownloadState); if (!newDownloadState.downloadWasResumed()) { // Only queue the root node if we're starting a new download from scratch newDownloadState.enqueueRequest(NodeDataRequest.createAccountDataRequest(stateRoot)); } maybeCompleteTask = Optional.of(new CompleteTaskStep(worldStateStorage, metricsSystem, taskCollection::size)); final WorldStateDownloadProcess downloadProcess = WorldStateDownloadProcess.builder() .hashCountPerRequest(hashCountPerRequest) .maxOutstandingRequests(maxOutstandingRequests) .loadLocalDataStep(new LoadLocalDataStep(worldStateStorage, metricsSystem)) .requestDataStep(new RequestDataStep(ethContext, metricsSystem)) .persistDataStep(new PersistDataStep(worldStateStorage)) .completeTaskStep(maybeCompleteTask.get()) .downloadState(newDownloadState) .pivotBlockHeader(header) .metricsSystem(metricsSystem) .build(); newDownloadState.setWorldStateDownloadProcess(downloadProcess); return newDownloadState.startDownload(downloadProcess, ethContext.getScheduler()); } }
206414745_1490
public CompletableFuture<Void> run(final BlockHeader header) { synchronized (this) { final WorldDownloadState oldDownloadState = this.downloadState.get(); if (oldDownloadState != null && oldDownloadState.isDownloading()) { final CompletableFuture<Void> failed = new CompletableFuture<>(); failed.completeExceptionally( new IllegalStateException( "Cannot run an already running " + this.getClass().getSimpleName())); return failed; } final Hash stateRoot = header.getStateRoot(); if (worldStateStorage.isWorldStateAvailable(stateRoot)) { LOG.info( "World state already available for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); return CompletableFuture.completedFuture(null); } LOG.info( "Begin downloading world state from peers for block {} ({}). State root {}", header.getNumber(), header.getHash(), stateRoot); final WorldDownloadState newDownloadState = new WorldDownloadState( taskCollection, maxNodeRequestsWithoutProgress, minMillisBeforeStalling, clock); this.downloadState.set(newDownloadState); if (!newDownloadState.downloadWasResumed()) { // Only queue the root node if we're starting a new download from scratch newDownloadState.enqueueRequest(NodeDataRequest.createAccountDataRequest(stateRoot)); } maybeCompleteTask = Optional.of(new CompleteTaskStep(worldStateStorage, metricsSystem, taskCollection::size)); final WorldStateDownloadProcess downloadProcess = WorldStateDownloadProcess.builder() .hashCountPerRequest(hashCountPerRequest) .maxOutstandingRequests(maxOutstandingRequests) .loadLocalDataStep(new LoadLocalDataStep(worldStateStorage, metricsSystem)) .requestDataStep(new RequestDataStep(ethContext, metricsSystem)) .persistDataStep(new PersistDataStep(worldStateStorage)) .completeTaskStep(maybeCompleteTask.get()) .downloadState(newDownloadState) .pivotBlockHeader(header) .metricsSystem(metricsSystem) .build(); newDownloadState.setWorldStateDownloadProcess(downloadProcess); return newDownloadState.startDownload(downloadProcess, ethContext.getScheduler()); } }
206414745_1491
public synchronized boolean checkCompletion( final WorldStateStorage worldStateStorage, final BlockHeader header) { if (!internalFuture.isDone() && pendingRequests.allTasksCompleted()) { if (rootNodeData == null) { enqueueRequest(NodeDataRequest.createAccountDataRequest(header.getStateRoot())); return false; } final Updater updater = worldStateStorage.updater(); updater.putAccountStateTrieNode(header.getStateRoot(), rootNodeData); updater.commit(); internalFuture.complete(null); // THere are no more inputs to process so make sure we wake up any threads waiting to dequeue // so they can give up waiting. notifyAll(); LOG.info("Finished downloading world state from peers"); return true; } else { return false; } }
206414745_1492
public static AccountTrieNodeDataRequest createAccountDataRequest(final Hash hash) { return new AccountTrieNodeDataRequest(hash); }
206414745_1493
public static StorageTrieNodeDataRequest createStorageDataRequest(final Hash hash) { return new StorageTrieNodeDataRequest(hash); }
206414745_1494
public static CodeNodeDataRequest createCodeRequest(final Hash hash) { return new CodeNodeDataRequest(hash); }
206414745_1495
public List<Task<NodeDataRequest>> persist( final List<Task<NodeDataRequest>> tasks, final BlockHeader blockHeader, final WorldDownloadState downloadState) { final Updater updater = worldStateStorage.updater(); tasks.stream() .map(Task::getData) .filter(request -> request.getData() != null) .forEach( request -> { if (isRootState(blockHeader, request)) { downloadState.setRootNodeData(request.getData()); } else { request.persist(updater); } }); updater.commit(); return tasks; }
206414745_1496
public List<Task<NodeDataRequest>> persist( final List<Task<NodeDataRequest>> tasks, final BlockHeader blockHeader, final WorldDownloadState downloadState) { final Updater updater = worldStateStorage.updater(); tasks.stream() .map(Task::getData) .filter(request -> request.getData() != null) .forEach( request -> { if (isRootState(blockHeader, request)) { downloadState.setRootNodeData(request.getData()); } else { request.persist(updater); } }); updater.commit(); return tasks; }
206414745_1497
public List<Task<NodeDataRequest>> persist( final List<Task<NodeDataRequest>> tasks, final BlockHeader blockHeader, final WorldDownloadState downloadState) { final Updater updater = worldStateStorage.updater(); tasks.stream() .map(Task::getData) .filter(request -> request.getData() != null) .forEach( request -> { if (isRootState(blockHeader, request)) { downloadState.setRootNodeData(request.getData()); } else { request.persist(updater); } }); updater.commit(); return tasks; }
206414745_1498
public CompletableFuture<List<Task<NodeDataRequest>>> requestData( final List<Task<NodeDataRequest>> requestTasks, final BlockHeader blockHeader, final WorldDownloadState downloadState) { final List<Hash> hashes = requestTasks.stream() .map(Task::getData) .map(NodeDataRequest::getHash) .distinct() .collect(Collectors.toList()); return sendRequest(blockHeader, hashes, downloadState) .thenApply( data -> { for (final Task<NodeDataRequest> task : requestTasks) { final NodeDataRequest request = task.getData(); final Bytes matchingData = data.get(request.getHash()); if (matchingData != null) { request.setData(matchingData); } } return requestTasks; }); }
206414745_1499
public CompletableFuture<List<Task<NodeDataRequest>>> requestData( final List<Task<NodeDataRequest>> requestTasks, final BlockHeader blockHeader, final WorldDownloadState downloadState) { final List<Hash> hashes = requestTasks.stream() .map(Task::getData) .map(NodeDataRequest::getHash) .distinct() .collect(Collectors.toList()); return sendRequest(blockHeader, hashes, downloadState) .thenApply( data -> { for (final Task<NodeDataRequest> task : requestTasks) { final NodeDataRequest request = task.getData(); final Bytes matchingData = data.get(request.getHash()); if (matchingData != null) { request.setData(matchingData); } } return requestTasks; }); }
206414745_1500
public CompletableFuture<List<Task<NodeDataRequest>>> requestData( final List<Task<NodeDataRequest>> requestTasks, final BlockHeader blockHeader, final WorldDownloadState downloadState) { final List<Hash> hashes = requestTasks.stream() .map(Task::getData) .map(NodeDataRequest::getHash) .distinct() .collect(Collectors.toList()); return sendRequest(blockHeader, hashes, downloadState) .thenApply( data -> { for (final Task<NodeDataRequest> task : requestTasks) { final NodeDataRequest request = task.getData(); final Bytes matchingData = data.get(request.getHash()); if (matchingData != null) { request.setData(matchingData); } } return requestTasks; }); }
206414745_1501
public CompletableFuture<List<Task<NodeDataRequest>>> requestData( final List<Task<NodeDataRequest>> requestTasks, final BlockHeader blockHeader, final WorldDownloadState downloadState) { final List<Hash> hashes = requestTasks.stream() .map(Task::getData) .map(NodeDataRequest::getHash) .distinct() .collect(Collectors.toList()); return sendRequest(blockHeader, hashes, downloadState) .thenApply( data -> { for (final Task<NodeDataRequest> task : requestTasks) { final NodeDataRequest request = task.getData(); final Bytes matchingData = data.get(request.getHash()); if (matchingData != null) { request.setData(matchingData); } } return requestTasks; }); }
206414745_1502
public Stream<Task<NodeDataRequest>> loadLocalData( final Task<NodeDataRequest> task, final Pipe<Task<NodeDataRequest>> completedTasks) { final NodeDataRequest request = task.getData(); final Optional<Bytes> existingData = request.getExistingData(worldStateStorage); if (existingData.isPresent()) { existingNodeCounter.inc(); request.setData(existingData.get()); request.setRequiresPersisting(false); completedTasks.put(task); return Stream.empty(); } return Stream.of(task); }
206414745_1503
public Stream<Task<NodeDataRequest>> loadLocalData( final Task<NodeDataRequest> task, final Pipe<Task<NodeDataRequest>> completedTasks) { final NodeDataRequest request = task.getData(); final Optional<Bytes> existingData = request.getExistingData(worldStateStorage); if (existingData.isPresent()) { existingNodeCounter.inc(); request.setData(existingData.get()); request.setRequiresPersisting(false); completedTasks.put(task); return Stream.empty(); } return Stream.of(task); }
206414745_1504
public static DownloadHeaderSequenceTask endingAtHeader( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final BlockHeader referenceHeader, final int segmentLength, final int maxRetries, final ValidationPolicy validationPolicy, final MetricsSystem metricsSystem) { return new DownloadHeaderSequenceTask( protocolSchedule, protocolContext, ethContext, referenceHeader, segmentLength, maxRetries, validationPolicy, metricsSystem); }
206414745_1505
public static DownloadHeaderSequenceTask endingAtHeader( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final BlockHeader referenceHeader, final int segmentLength, final int maxRetries, final ValidationPolicy validationPolicy, final MetricsSystem metricsSystem) { return new DownloadHeaderSequenceTask( protocolSchedule, protocolContext, ethContext, referenceHeader, segmentLength, maxRetries, validationPolicy, metricsSystem); }
206414745_1506
public static PersistBlockTask create( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final Block block, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { return new PersistBlockTask( protocolSchedule, protocolContext, ethContext, block, headerValidationMode, metricsSystem); }
206414745_1507
public static PersistBlockTask create( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final Block block, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { return new PersistBlockTask( protocolSchedule, protocolContext, ethContext, block, headerValidationMode, metricsSystem); }
206414745_1508
public static Supplier<CompletableFuture<List<Block>>> forSequentialBlocks( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final List<Block> blocks, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { checkArgument(!blocks.isEmpty(), "No blocks to import provided"); return () -> { final List<Block> successfulImports = new ArrayList<>(); final Iterator<Block> blockIterator = blocks.iterator(); CompletableFuture<Block> future = importBlockAndAddToList( protocolSchedule, protocolContext, ethContext, blockIterator.next(), successfulImports, headerValidationMode, metricsSystem); while (blockIterator.hasNext()) { final Block block = blockIterator.next(); future = future.thenCompose( b -> importBlockAndAddToList( protocolSchedule, protocolContext, ethContext, block, successfulImports, headerValidationMode, metricsSystem)); } return future.thenApply(r -> successfulImports); }; }
206414745_1509
public static Supplier<CompletableFuture<List<Block>>> forSequentialBlocks( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final List<Block> blocks, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { checkArgument(!blocks.isEmpty(), "No blocks to import provided"); return () -> { final List<Block> successfulImports = new ArrayList<>(); final Iterator<Block> blockIterator = blocks.iterator(); CompletableFuture<Block> future = importBlockAndAddToList( protocolSchedule, protocolContext, ethContext, blockIterator.next(), successfulImports, headerValidationMode, metricsSystem); while (blockIterator.hasNext()) { final Block block = blockIterator.next(); future = future.thenCompose( b -> importBlockAndAddToList( protocolSchedule, protocolContext, ethContext, block, successfulImports, headerValidationMode, metricsSystem)); } return future.thenApply(r -> successfulImports); }; }
206414745_1510
public static Supplier<CompletableFuture<List<Block>>> forSequentialBlocks( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final List<Block> blocks, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { checkArgument(!blocks.isEmpty(), "No blocks to import provided"); return () -> { final List<Block> successfulImports = new ArrayList<>(); final Iterator<Block> blockIterator = blocks.iterator(); CompletableFuture<Block> future = importBlockAndAddToList( protocolSchedule, protocolContext, ethContext, blockIterator.next(), successfulImports, headerValidationMode, metricsSystem); while (blockIterator.hasNext()) { final Block block = blockIterator.next(); future = future.thenCompose( b -> importBlockAndAddToList( protocolSchedule, protocolContext, ethContext, block, successfulImports, headerValidationMode, metricsSystem)); } return future.thenApply(r -> successfulImports); }; }
206414745_1511
public static Supplier<CompletableFuture<List<Block>>> forUnorderedBlocks( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final List<Block> blocks, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { checkArgument(!blocks.isEmpty(), "No blocks to import provided"); return () -> { final CompletableFuture<List<Block>> finalResult = new CompletableFuture<>(); final List<Block> successfulImports = new ArrayList<>(); final Iterator<PersistBlockTask> tasks = blocks.stream() .map( block -> PersistBlockTask.create( protocolSchedule, protocolContext, ethContext, block, headerValidationMode, metricsSystem)) .iterator(); CompletableFuture<Block> future = tasks.next().run(); while (tasks.hasNext()) { final PersistBlockTask task = tasks.next(); future = future .handle((r, t) -> r) .thenCompose( r -> { if (r != null) { successfulImports.add(r); } return task.run(); }); } future.whenComplete( (r, t) -> { if (r != null) { successfulImports.add(r); } if (successfulImports.size() > 0) { finalResult.complete(successfulImports); } else { finalResult.completeExceptionally(t); } }); return finalResult; }; }
206414745_1512
public static Supplier<CompletableFuture<List<Block>>> forUnorderedBlocks( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final List<Block> blocks, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { checkArgument(!blocks.isEmpty(), "No blocks to import provided"); return () -> { final CompletableFuture<List<Block>> finalResult = new CompletableFuture<>(); final List<Block> successfulImports = new ArrayList<>(); final Iterator<PersistBlockTask> tasks = blocks.stream() .map( block -> PersistBlockTask.create( protocolSchedule, protocolContext, ethContext, block, headerValidationMode, metricsSystem)) .iterator(); CompletableFuture<Block> future = tasks.next().run(); while (tasks.hasNext()) { final PersistBlockTask task = tasks.next(); future = future .handle((r, t) -> r) .thenCompose( r -> { if (r != null) { successfulImports.add(r); } return task.run(); }); } future.whenComplete( (r, t) -> { if (r != null) { successfulImports.add(r); } if (successfulImports.size() > 0) { finalResult.complete(successfulImports); } else { finalResult.completeExceptionally(t); } }); return finalResult; }; }
206414745_1513
public static Supplier<CompletableFuture<List<Block>>> forUnorderedBlocks( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final List<Block> blocks, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { checkArgument(!blocks.isEmpty(), "No blocks to import provided"); return () -> { final CompletableFuture<List<Block>> finalResult = new CompletableFuture<>(); final List<Block> successfulImports = new ArrayList<>(); final Iterator<PersistBlockTask> tasks = blocks.stream() .map( block -> PersistBlockTask.create( protocolSchedule, protocolContext, ethContext, block, headerValidationMode, metricsSystem)) .iterator(); CompletableFuture<Block> future = tasks.next().run(); while (tasks.hasNext()) { final PersistBlockTask task = tasks.next(); future = future .handle((r, t) -> r) .thenCompose( r -> { if (r != null) { successfulImports.add(r); } return task.run(); }); } future.whenComplete( (r, t) -> { if (r != null) { successfulImports.add(r); } if (successfulImports.size() > 0) { finalResult.complete(successfulImports); } else { finalResult.completeExceptionally(t); } }); return finalResult; }; }
206414745_1514
public static Supplier<CompletableFuture<List<Block>>> forUnorderedBlocks( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final List<Block> blocks, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { checkArgument(!blocks.isEmpty(), "No blocks to import provided"); return () -> { final CompletableFuture<List<Block>> finalResult = new CompletableFuture<>(); final List<Block> successfulImports = new ArrayList<>(); final Iterator<PersistBlockTask> tasks = blocks.stream() .map( block -> PersistBlockTask.create( protocolSchedule, protocolContext, ethContext, block, headerValidationMode, metricsSystem)) .iterator(); CompletableFuture<Block> future = tasks.next().run(); while (tasks.hasNext()) { final PersistBlockTask task = tasks.next(); future = future .handle((r, t) -> r) .thenCompose( r -> { if (r != null) { successfulImports.add(r); } return task.run(); }); } future.whenComplete( (r, t) -> { if (r != null) { successfulImports.add(r); } if (successfulImports.size() > 0) { finalResult.complete(successfulImports); } else { finalResult.completeExceptionally(t); } }); return finalResult; }; }
206414745_1515
public static PersistBlockTask create( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final Block block, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { return new PersistBlockTask( protocolSchedule, protocolContext, ethContext, block, headerValidationMode, metricsSystem); }
206414745_1516
public static PersistBlockTask create( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final Block block, final HeaderValidationMode headerValidationMode, final MetricsSystem metricsSystem) { return new PersistBlockTask( protocolSchedule, protocolContext, ethContext, block, headerValidationMode, metricsSystem); }
206414745_1517
public static DetermineCommonAncestorTask create( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final EthPeer peer, final int headerRequestSize, final MetricsSystem metricsSystem) { return new DetermineCommonAncestorTask( protocolSchedule, protocolContext, ethContext, peer, headerRequestSize, metricsSystem); }
206414745_1518
public static DetermineCommonAncestorTask create( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final EthPeer peer, final int headerRequestSize, final MetricsSystem metricsSystem) { return new DetermineCommonAncestorTask( protocolSchedule, protocolContext, ethContext, peer, headerRequestSize, metricsSystem); }
206414745_1519
@VisibleForTesting static int calculateSkipInterval(final long range, final int headerRequestSize) { return Math.max(0, Math.toIntExact(range / (headerRequestSize - 1) - 1) - 1); }
206414745_1520
public static DetermineCommonAncestorTask create( final ProtocolSchedule protocolSchedule, final ProtocolContext protocolContext, final EthContext ethContext, final EthPeer peer, final int headerRequestSize, final MetricsSystem metricsSystem) { return new DetermineCommonAncestorTask( protocolSchedule, protocolContext, ethContext, peer, headerRequestSize, metricsSystem); }
206414745_1521
@Override public CompletableFuture<Void> start() { if (!started.compareAndSet(false, true)) { throw new IllegalStateException("Cannot start a chain download twice"); } return performDownload(); }
206414745_1522
@Override public CompletableFuture<Void> start() { if (!started.compareAndSet(false, true)) { throw new IllegalStateException("Cannot start a chain download twice"); } return performDownload(); }
206414745_1523
@Override public CompletableFuture<Void> start() { if (!started.compareAndSet(false, true)) { throw new IllegalStateException("Cannot start a chain download twice"); } return performDownload(); }
206414745_1524
@Override public CompletableFuture<Void> start() { if (!started.compareAndSet(false, true)) { throw new IllegalStateException("Cannot start a chain download twice"); } return performDownload(); }
206414745_1525
@Override public CompletableFuture<Void> start() { if (!started.compareAndSet(false, true)) { throw new IllegalStateException("Cannot start a chain download twice"); } return performDownload(); }
206414745_1526
@Override public CompletableFuture<Void> start() { if (!started.compareAndSet(false, true)) { throw new IllegalStateException("Cannot start a chain download twice"); } return performDownload(); }
206414745_1527
@Override public CompletableFuture<Void> start() { if (!started.compareAndSet(false, true)) { throw new IllegalStateException("Cannot start a chain download twice"); } return performDownload(); }
206414745_1528
@Override public CompletableFuture<Void> start() { if (!started.compareAndSet(false, true)) { throw new IllegalStateException("Cannot start a chain download twice"); } return performDownload(); }
206414745_1529
@Override public HeaderValidationMode getValidationModeForNextBlock() { final HeaderValidationMode mode = Math.random() < targetFullValidationRate ? fullValidationMode : lightValidationMode; fastSyncValidationCounter.labels(mode.name()).inc(); return mode; }
206414745_1530
@Override public HeaderValidationMode getValidationModeForNextBlock() { final HeaderValidationMode mode = Math.random() < targetFullValidationRate ? fullValidationMode : lightValidationMode; fastSyncValidationCounter.labels(mode.name()).inc(); return mode; }
206414745_1531
@Override public HeaderValidationMode getValidationModeForNextBlock() { final HeaderValidationMode mode = Math.random() < targetFullValidationRate ? fullValidationMode : lightValidationMode; fastSyncValidationCounter.labels(mode.name()).inc(); return mode; }
206414745_1532
public CompletableFuture<FastSyncState> waitForSuitablePeers(final FastSyncState fastSyncState) { if (fastSyncState.hasPivotBlockHeader()) { return waitForAnyPeer().thenApply(ignore -> fastSyncState); } LOG.debug("Waiting for at least {} peers.", syncConfig.getFastSyncMinimumPeerCount()); return waitForPeers(syncConfig.getFastSyncMinimumPeerCount()) .thenApply(successfulWaitResult -> fastSyncState); }
206414745_1533
public CompletableFuture<FastSyncState> waitForSuitablePeers(final FastSyncState fastSyncState) { if (fastSyncState.hasPivotBlockHeader()) { return waitForAnyPeer().thenApply(ignore -> fastSyncState); } LOG.debug("Waiting for at least {} peers.", syncConfig.getFastSyncMinimumPeerCount()); return waitForPeers(syncConfig.getFastSyncMinimumPeerCount()) .thenApply(successfulWaitResult -> fastSyncState); }
206414745_1534
public CompletableFuture<FastSyncState> selectPivotBlock(final FastSyncState fastSyncState) { return fastSyncState.hasPivotBlockHeader() ? completedFuture(fastSyncState) : selectPivotBlockFromPeers(); }
206414745_1535
public CompletableFuture<FastSyncState> selectPivotBlock(final FastSyncState fastSyncState) { return fastSyncState.hasPivotBlockHeader() ? completedFuture(fastSyncState) : selectPivotBlockFromPeers(); }
206414745_1536
public CompletableFuture<FastSyncState> selectPivotBlock(final FastSyncState fastSyncState) { return fastSyncState.hasPivotBlockHeader() ? completedFuture(fastSyncState) : selectPivotBlockFromPeers(); }
206414745_1537
public CompletableFuture<FastSyncState> selectPivotBlock(final FastSyncState fastSyncState) { return fastSyncState.hasPivotBlockHeader() ? completedFuture(fastSyncState) : selectPivotBlockFromPeers(); }
206414745_1538
public CompletableFuture<FastSyncState> selectPivotBlock(final FastSyncState fastSyncState) { return fastSyncState.hasPivotBlockHeader() ? completedFuture(fastSyncState) : selectPivotBlockFromPeers(); }
206414745_1539
public CompletableFuture<FastSyncState> selectPivotBlock(final FastSyncState fastSyncState) { return fastSyncState.hasPivotBlockHeader() ? completedFuture(fastSyncState) : selectPivotBlockFromPeers(); }
206414745_1540
public CompletableFuture<FastSyncState> selectPivotBlock(final FastSyncState fastSyncState) { return fastSyncState.hasPivotBlockHeader() ? completedFuture(fastSyncState) : selectPivotBlockFromPeers(); }
206414745_1541
public CompletableFuture<FastSyncState> selectPivotBlock(final FastSyncState fastSyncState) { return fastSyncState.hasPivotBlockHeader() ? completedFuture(fastSyncState) : selectPivotBlockFromPeers(); }