Skip to content

Commit

Permalink
Revert deletion of the lowest announced block detection (#3178)
Browse files Browse the repository at this point in the history
Signed-off-by: Karim TAAM <[email protected]>
  • Loading branch information
matkt authored Dec 16, 2021
1 parent 424ad3c commit ff55ccb
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthMessage;
import org.hyperledger.besu.ethereum.eth.manager.EthPeer;
import org.hyperledger.besu.ethereum.eth.manager.task.GetBlockFromPeersTask;
import org.hyperledger.besu.ethereum.eth.manager.task.RetryingGetBlockFromPeersTask;
import org.hyperledger.besu.ethereum.eth.messages.EthPV62;
import org.hyperledger.besu.ethereum.eth.messages.NewBlockHashesMessage;
Expand Down Expand Up @@ -149,6 +151,27 @@ private void onBlockAdded(final BlockAddedEvent blockAddedEvent) {
LOG.info("Imported {} pending blocks", r.size());
}
});
} else {

LOG.trace("Not ready for import blocks found for {}", newBlock.getHeader().getNumber());

pendingBlocksManager
.lowestAnnouncedBlock()
.map(ProcessableBlockHeader::getNumber)
.ifPresent(
minAnnouncedBlockNumber -> {
long distance =
minAnnouncedBlockNumber
- protocolContext.getBlockchain().getChainHeadBlockNumber();
LOG.trace(
"Found lowest announced block {} with distance {}",
minAnnouncedBlockNumber,
distance);
if (distance < config.getBlockPropagationRange().upperEndpoint()
&& minAnnouncedBlockNumber > newBlock.getHeader().getNumber()) {
retrieveMissingAnnouncedBlock(newBlock.getHeader().getNumber() + 1);
}
});
}

if (blockAddedEvent.getEventType().equals(EventType.HEAD_ADVANCED)) {
Expand Down Expand Up @@ -251,6 +274,18 @@ private void handleNewBlockHashesFromNetwork(final EthMessage message) {
}
}

private CompletableFuture<Block> retrieveMissingAnnouncedBlock(final long blockNumber) {
LOG.trace("Retrieve missing announced block {} from peer", blockNumber);
final List<EthPeer> peers =
ethContext.getEthPeers().streamBestPeers().collect(Collectors.toList());
final GetBlockFromPeersTask getBlockTask =
GetBlockFromPeersTask.create(
peers, protocolSchedule, ethContext, Optional.empty(), blockNumber, metricsSystem);
return getBlockTask
.run()
.thenCompose((r) -> importOrSavePendingBlock(r.getResult(), r.getPeer().nodeId()));
}

private CompletableFuture<Block> processAnnouncedBlock(final NewBlockHash newBlock) {
final RetryingGetBlockFromPeersTask getBlockTask =
RetryingGetBlockFromPeersTask.create(
Expand Down

0 comments on commit ff55ccb

Please sign in to comment.